From 242a1a18cbd9904b6b571559c75f73414e7029f9 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Fri, 27 Jan 2023 13:25:39 +0100 Subject: [PATCH] gps: add support to the data model Signed-off-by: John Crispin --- renderer/templates/services/gps.uc | 11 ++++++++ schema/service.gps.yml | 18 ++++++++++++ schema/service.yml | 2 ++ schemareader.uc | 45 ++++++++++++++++++++++++++++++ ucentral.schema.json | 21 ++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 renderer/templates/services/gps.uc create mode 100644 schema/service.gps.yml diff --git a/renderer/templates/services/gps.uc b/renderer/templates/services/gps.uc new file mode 100644 index 0000000..6b18d00 --- /dev/null +++ b/renderer/templates/services/gps.uc @@ -0,0 +1,11 @@ +{%- + let enable = length(gps); + services.set_enabled("umdns", enable); + if (!enable) + return; +%} + +# Configure GPS +set gps.@gps[-1].disabled=0 +set gps.@gps[-1].adjust_time={{ b(gps.adjust_time) }} +set gps.@gps[-1].baudrate={{ s(gps.baud_rate) }} diff --git a/schema/service.gps.yml b/schema/service.gps.yml new file mode 100644 index 0000000..dc695d4 --- /dev/null +++ b/schema/service.gps.yml @@ -0,0 +1,18 @@ +description: + This section can be used to configure a GPS dongle +type: object +properties: + adjust-time: + description: + Adjust the systems clock upon a successful GPS lock. + type: boolean + default: false + baud-rate: + description: + The baudrate used by the attached GPS dongle + type: integer + enum: + - 2400 + - 4800 + - 9600 + - 19200 diff --git a/schema/service.yml b/schema/service.yml index 72c2de1..5f70d60 100644 --- a/schema/service.yml +++ b/schema/service.yml @@ -39,3 +39,5 @@ properties: $ref: 'https://ucentral.io/schema/v1/service/wireguard-overlay/' captive: $ref: 'https://ucentral.io/schema/v1/service/captive/' + gps: + $ref: 'https://ucentral.io/schema/v1/service/gps/' diff --git a/schemareader.uc b/schemareader.uc index 688956a..9d2db49 100644 --- a/schemareader.uc +++ b/schemareader.uc @@ -8106,6 +8106,47 @@ function instantiateServiceCaptive(location, value, errors) { return value; } +function instantiateServiceGps(location, value, errors) { + if (type(value) == "object") { + let obj = {}; + + function parseAdjustTime(location, value, errors) { + if (type(value) != "bool") + push(errors, [ location, "must be of type boolean" ]); + + return value; + } + + if (exists(value, "adjust-time")) { + obj.adjust_time = parseAdjustTime(location + "/adjust-time", value["adjust-time"], errors); + } + else { + obj.adjust_time = false; + } + + function parseBaudRate(location, value, errors) { + if (type(value) != "int") + push(errors, [ location, "must be of type integer" ]); + + if (!(value in [ 2400, 4800, 9600, 19200 ])) + push(errors, [ location, "must be one of 2400, 4800, 9600 or 19200" ]); + + return value; + } + + if (exists(value, "baud-rate")) { + obj.baud_rate = parseBaudRate(location + "/baud-rate", value["baud-rate"], errors); + } + + return obj; + } + + if (type(value) != "object") + push(errors, [ location, "must be of type object" ]); + + return value; +} + function instantiateService(location, value, errors) { if (type(value) == "object") { let obj = {}; @@ -8182,6 +8223,10 @@ function instantiateService(location, value, errors) { obj.captive = instantiateServiceCaptive(location + "/captive", value["captive"], errors); } + if (exists(value, "gps")) { + obj.gps = instantiateServiceGps(location + "/gps", value["gps"], errors); + } + return obj; } diff --git a/ucentral.schema.json b/ucentral.schema.json index 4ed01bf..ea54cf2 100644 --- a/ucentral.schema.json +++ b/ucentral.schema.json @@ -2892,6 +2892,24 @@ } ] }, + "service.gps": { + "type": "object", + "properties": { + "adjust-time": { + "type": "boolean", + "default": false + }, + "baud-rate": { + "type": "integer", + "enum": [ + 2400, + 4800, + 9600, + 19200 + ] + } + } + }, "service": { "type": "object", "properties": { @@ -2948,6 +2966,9 @@ }, "captive": { "$ref": "#/$defs/service.captive" + }, + "gps": { + "$ref": "#/$defs/service.gps" } } },