gps: add support to the data model

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2023-01-27 13:25:39 +01:00
parent f41e47e48b
commit 242a1a18cb
5 changed files with 97 additions and 0 deletions

View File

@@ -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) }}

18
schema/service.gps.yml Normal file
View File

@@ -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

View File

@@ -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/'

View File

@@ -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;
}

View File

@@ -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"
}
}
},