aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Mork <bjorn@mork.no>2019-05-25 18:10:19 +0200
committerBjørn Mork <bjorn@mork.no>2019-05-25 18:10:19 +0200
commit230a6c779a9193e3d3a63eb6020808d3965d7709 (patch)
treee3689fd2eda0a00cc96fa0f713366a9ba68cbe37
parent8e23ba0dfdbaa015a05d9fb70ed9d2e148c6dba7 (diff)
change OBIS list format to simplify parsing
Signed-off-by: Bjørn Mork <bjorn@mork.no>
-rw-r--r--aidon_v0001.json76
-rw-r--r--kaifa_v0001.json75
-rw-r--r--kamstrup_v0001.json73
-rw-r--r--obinsectd.c44
4 files changed, 177 insertions, 91 deletions
diff --git a/aidon_v0001.json b/aidon_v0001.json
index 628c053..9c3f69d 100644
--- a/aidon_v0001.json
+++ b/aidon_v0001.json
@@ -1,21 +1,59 @@
{
- "1-1:0.2.129.255" : { "name" : "ListId", "value" : "AIDON_V0001" },
- "0-0:96.1.0.255" : { "name" : "SerialNumber" },
- "0-0:96.1.7.255" : { "name" : "Model" },
- "1-0:1.7.0.255" : { "name" : "Power", "unit" : "kW", "scale" : 0.001 },
- "1-0:2.7.0.255" : { "name" : "PowerExport", "unit" : "kW", "scale" : 0.001 },
- "1-0:3.7.0.255" : { "name" : "ReactivePower", "unit" : "kW", "scale" : 0.001 },
- "1-0:4.7.0.255" : { "name" : "ReactivePowerExport", "unit" : "kW", "scale" : 0.001 },
- "1-0:31.7.0.255" : { "name" : "CurrentL1", "unit" : "A", "scale" : 0.1 },
- "1-0:51.7.0.255" : { "name" : "CurrentL2", "unit" : "A", "scale" : 0.1 },
- "1-0:71.7.0.255" : { "name" : "CurrentL3", "unit" : "A", "scale" : 0.1 },
- "1-0:32.7.0.255" : { "name" : "VoltageL1", "unit" : "V", "scale" : 0.1 },
- "1-0:52.7.0.255" : { "name" : "VoltageL2", "unit" : "V", "scale" : 0.1 },
- "1-0:72.7.0.255" : { "name" : "VoltageL3", "unit" : "V", "scale" : 0.1 },
- "0-0:1.0.0.255" : { "name" : "MeterTime" },
- "1-0:1.8.0.255" : { "name" : "CumulativeEnergy", "unit" : "kWh", "scale" : 0.01 },
- "1-0:2.8.0.255" : { "name" : "CumulativeEnergyExport", "unit" : "kWh", "scale" : 0.01 },
- "1-0:3.8.0.255" : { "name" : "CumulativeReactiveEnergy", "unit" : "kVArh", "scale" : 0.01 },
- "1-0:4.8.0.255" : { "name" : "CumulativeReactiveEnergyExport", "unit" : "kVArh", "scale" : 0.01 }
+ "_metadata": {
+ "revision": 1
+ },
+ "AIDON_V0001":{
+ "alias":{
+ "1-1:0.2.129.255":"ListId",
+ "0-0:96.1.0.255":"SerialNumber",
+ "0-0:96.1.7.255":"Model",
+ "1-0:1.7.0.255":"Power",
+ "1-0:2.7.0.255":"PowerExport",
+ "1-0:3.7.0.255":"ReactivePower",
+ "1-0:4.7.0.255":"ReactivePowerExport",
+ "1-0:31.7.0.255":"CurrentL1",
+ "1-0:51.7.0.255":"CurrentL2",
+ "1-0:71.7.0.255":"CurrentL3",
+ "1-0:32.7.0.255":"VoltageL1",
+ "1-0:52.7.0.255":"VoltageL2",
+ "1-0:72.7.0.255":"VoltageL3",
+ "0-0:1.0.0.255":"MeterTime",
+ "1-0:1.8.0.255":"CumulativeEnergy",
+ "1-0:2.8.0.255":"CumulativeEnergyExport",
+ "1-0:3.8.0.255":"CumulativeReactiveEnergy",
+ "1-0:4.8.0.255":"CumulativeReactiveEnergyExport"
+ },
+ "unit":{
+ "1-0:1.7.0.255":"kW",
+ "1-0:2.7.0.255":"kW",
+ "1-0:3.7.0.255":"kW",
+ "1-0:4.7.0.255":"kW",
+ "1-0:31.7.0.255":"A",
+ "1-0:51.7.0.255":"A",
+ "1-0:71.7.0.255":"A",
+ "1-0:32.7.0.255":"V",
+ "1-0:52.7.0.255":"V",
+ "1-0:72.7.0.255":"V",
+ "1-0:1.8.0.255":"kWh",
+ "1-0:2.8.0.255":"kWh",
+ "1-0:3.8.0.255":"kVArh",
+ "1-0:4.8.0.255":"kVArh"
+ },
+ "scale":{
+ "1-0:1.7.0.255":0.001,
+ "1-0:2.7.0.255":0.001,
+ "1-0:3.7.0.255":0.001,
+ "1-0:4.7.0.255":0.001,
+ "1-0:31.7.0.255":0.1,
+ "1-0:51.7.0.255":0.1,
+ "1-0:71.7.0.255":0.1,
+ "1-0:32.7.0.255":0.1,
+ "1-0:52.7.0.255":0.1,
+ "1-0:72.7.0.255":0.1,
+ "1-0:1.8.0.255":0.01,
+ "1-0:2.8.0.255":0.01,
+ "1-0:3.8.0.255":0.01,
+ "1-0:4.8.0.255":0.01
+ }
+ }
}
-
diff --git a/kaifa_v0001.json b/kaifa_v0001.json
index b04957f..902129b 100644
--- a/kaifa_v0001.json
+++ b/kaifa_v0001.json
@@ -1,21 +1,60 @@
{
- "1-1:0.2.129.255" : { "name" : "ListId", "value" : "KFM_001" },
- "0-0:96.1.0.255" : { "name" : "SerialNumber" },
- "0-0:96.1.7.255" : { "name" : "Model" },
- "1-0:1.7.0.255" : { "name" : "Power", "unit" : "kW", "scale" : 0.001 },
- "1-0:2.7.0.255" : { "name" : "PowerExport", "unit" : "kW", "scale" : 0.001 },
- "1-0:3.7.0.255" : { "name" : "ReactivePower", "unit" : "kW", "scale" : 0.001 },
- "1-0:4.7.0.255" : { "name" : "ReactivePowerExport", "unit" : "kW", "scale" : 0.001 },
- "1-0:31.7.0.255" : { "name" : "CurrentL1", "unit" : "A", "scale" : 0.1 },
- "1-0:51.7.0.255" : { "name" : "CurrentL2", "unit" : "A", "scale" : 0.1 },
- "1-0:71.7.0.255" : { "name" : "CurrentL3", "unit" : "A", "scale" : 0.1 },
- "1-0:32.7.0.255" : { "name" : "VoltageL1", "unit" : "V", "scale" : 0.1 },
- "1-0:52.7.0.255" : { "name" : "VoltageL2", "unit" : "V", "scale" : 0.1 },
- "1-0:72.7.0.255" : { "name" : "VoltageL3", "unit" : "V", "scale" : 0.1 },
- "0-0:1.0.0.255" : { "name" : "MeterTime" },
- "1-0:1.8.0.255" : { "name" : "CumulativeEnergy", "unit" : "kWh", "scale" : 0.001 },
- "1-0:2.8.0.255" : { "name" : "CumulativeEnergyExport", "unit" : "kWh", "scale" : 0.001 },
- "1-0:3.8.0.255" : { "name" : "CumulativeReactiveEnergy", "unit" : "kVArh", "scale" : 0.001 },
- "1-0:4.8.0.255" : { "name" : "CumulativeReactiveEnergyExport", "unit" : "kVArh", "scale" : 0.001 }
+ "_metadata": {
+ "revision": 1
+ },
+ "KFM_001":{
+ "alias":{
+ "1-1:0.2.129.255":"ListId",
+ "0-0:96.1.0.255":"SerialNumber",
+ "0-0:96.1.7.255":"Model",
+ "1-0:1.7.0.255":"Power",
+ "1-0:2.7.0.255":"PowerExport",
+ "1-0:3.7.0.255":"ReactivePower",
+ "1-0:4.7.0.255":"ReactivePowerExport",
+ "1-0:31.7.0.255":"CurrentL1",
+ "1-0:51.7.0.255":"CurrentL2",
+ "1-0:71.7.0.255":"CurrentL3",
+ "1-0:32.7.0.255":"VoltageL1",
+ "1-0:52.7.0.255":"VoltageL2",
+ "1-0:72.7.0.255":"VoltageL3",
+ "0-0:1.0.0.255":"MeterTime",
+ "1-0:1.8.0.255":"CumulativeEnergy",
+ "1-0:2.8.0.255":"CumulativeEnergyExport",
+ "1-0:3.8.0.255":"CumulativeReactiveEnergy",
+ "1-0:4.8.0.255":"CumulativeReactiveEnergyExport"
+ },
+ "unit":{
+ "1-0:1.7.0.255":"kW",
+ "1-0:2.7.0.255":"kW",
+ "1-0:3.7.0.255":"kW",
+ "1-0:4.7.0.255":"kW",
+ "1-0:31.7.0.255":"A",
+ "1-0:51.7.0.255":"A",
+ "1-0:71.7.0.255":"A",
+ "1-0:32.7.0.255":"V",
+ "1-0:52.7.0.255":"V",
+ "1-0:72.7.0.255":"V",
+ "1-0:1.8.0.255":"kWh",
+ "1-0:2.8.0.255":"kWh",
+ "1-0:3.8.0.255":"kVArh",
+ "1-0:4.8.0.255":"kVArh"
+ },
+ "scale":{
+ "1-0:1.7.0.255":0.001,
+ "1-0:2.7.0.255":0.001,
+ "1-0:3.7.0.255":0.001,
+ "1-0:4.7.0.255":0.001,
+ "1-0:31.7.0.255":0.1,
+ "1-0:51.7.0.255":0.1,
+ "1-0:71.7.0.255":0.1,
+ "1-0:32.7.0.255":0.1,
+ "1-0:52.7.0.255":0.1,
+ "1-0:72.7.0.255":0.1,
+ "1-0:1.8.0.255":0.001,
+ "1-0:2.8.0.255":0.001,
+ "1-0:3.8.0.255":0.001,
+ "1-0:4.8.0.255":0.001
+ }
+ }
}
diff --git a/kamstrup_v0001.json b/kamstrup_v0001.json
index cb6282b..69202c0 100644
--- a/kamstrup_v0001.json
+++ b/kamstrup_v0001.json
@@ -1,20 +1,57 @@
{
- "1-1:0.2.129.255" : { "name" : "ListId", "value" : "Kamstrup_V0001" },
- "1-1:0.0.5.255" : { "name" : "SerialNumber" },
- "1-1:96.1.1.255" : { "name" : "Model" },
- "1-1:1.7.0.255" : { "name" : "Power", "unit" : "kW", "scale" : 0.001 },
- "1-1:2.7.0.255" : { "name" : "PowerExport", "unit" : "kW", "scale" : 0.001 },
- "1-1:3.7.0.255" : { "name" : "ReactivePower", "unit" : "kW", "scale" : 0.001 },
- "1-1:4.7.0.255" : { "name" : "ReactivePowerExport", "unit" : "kW", "scale" : 0.001 },
- "1-1:31.7.0.255" : { "name" : "CurrentL1", "unit" : "A", "scale" : 0.01 },
- "1-1:51.7.0.255" : { "name" : "CurrentL2", "unit" : "A", "scale" : 0.01 },
- "1-1:71.7.0.255" : { "name" : "CurrentL3", "unit" : "A", "scale" : 0.01 },
- "1-1:32.7.0.255" : { "name" : "VoltageL1", "unit" : "V" },
- "1-1:52.7.0.255" : { "name" : "VoltageL2", "unit" : "V" },
- "1-1:72.7.0.255" : { "name" : "VoltageL3", "unit" : "V" },
- "0-1:1.0.0.255" : { "name" : "MeterTime" },
- "1-1:1.8.0.255" : { "name" : "CumulativeEnergy", "unit" : "kWh", "scale" : 0.01 },
- "1-1:2.8.0.255" : { "name" : "CumulativeEnergyExport", "unit" : "kWh", "scale" : 0.01 },
- "1-1:3.8.0.255" : { "name" : "CumulativeReactiveEnergy", "unit" : "kVArh", "scale" : 0.01 },
- "1-1:4.8.0.255" : { "name" : "CumulativeReactiveEnergyExport", "unit" : "kVArh", "scale" : 0.01 }
+ "_metadata": {
+ "revision": 1
+ },
+ "Kamstrup_V0001":{
+ "alias":{
+ "1-1:0.2.129.255":"ListId",
+ "1-1:0.0.5.255":"SerialNumber",
+ "1-1:96.1.1.255":"Model",
+ "1-1:1.7.0.255":"Power",
+ "1-1:2.7.0.255":"PowerExport",
+ "1-1:3.7.0.255":"ReactivePower",
+ "1-1:4.7.0.255":"ReactivePowerExport",
+ "1-1:31.7.0.255":"CurrentL1",
+ "1-1:51.7.0.255":"CurrentL2",
+ "1-1:71.7.0.255":"CurrentL3",
+ "1-1:32.7.0.255":"VoltageL1",
+ "1-1:52.7.0.255":"VoltageL2",
+ "1-1:72.7.0.255":"VoltageL3",
+ "0-1:1.0.0.255":"MeterTime",
+ "1-1:1.8.0.255":"CumulativeEnergy",
+ "1-1:2.8.0.255":"CumulativeEnergyExport",
+ "1-1:3.8.0.255":"CumulativeReactiveEnergy",
+ "1-1:4.8.0.255":"CumulativeReactiveEnergyExport"
+ },
+ "unit":{
+ "1-1:1.7.0.255":"kW",
+ "1-1:2.7.0.255":"kW",
+ "1-1:3.7.0.255":"kW",
+ "1-1:4.7.0.255":"kW",
+ "1-1:31.7.0.255":"A",
+ "1-1:51.7.0.255":"A",
+ "1-1:71.7.0.255":"A",
+ "1-1:32.7.0.255":"V",
+ "1-1:52.7.0.255":"V",
+ "1-1:72.7.0.255":"V",
+ "1-1:1.8.0.255":"kWh",
+ "1-1:2.8.0.255":"kWh",
+ "1-1:3.8.0.255":"kVArh",
+ "1-1:4.8.0.255":"kVArh"
+ },
+ "scale":{
+ "1-1:1.7.0.255":0.001,
+ "1-1:2.7.0.255":0.001,
+ "1-1:3.7.0.255":0.001,
+ "1-1:4.7.0.255":0.001,
+ "1-1:31.7.0.255":0.01,
+ "1-1:51.7.0.255":0.01,
+ "1-1:71.7.0.255":0.01,
+ "1-1:1.8.0.255":0.01,
+ "1-1:2.8.0.255":0.01,
+ "1-1:3.8.0.255":0.01,
+ "1-1:4.8.0.255":0.01
+ }
+ }
+ }
}
diff --git a/obinsectd.c b/obinsectd.c
index 67d0348..2288e3c 100644
--- a/obinsectd.c
+++ b/obinsectd.c
@@ -1483,48 +1483,26 @@ static json_object *read_json_file(const char *fname, char *buf, size_t bufsize)
static json_object *parse_obisfile(json_object *lists, const char *fname, char *buf, size_t bufsize)
{
- json_object *tmp, *l, *alias, *unit, *scale;
- const char *listname = NULL;
- int i = 0;
+ json_object *tmp;
tmp = read_json_file(fname, buf, bufsize);
if (!tmp)
return NULL;
debug("parsed %s\n", fname);
-
- l = json_object_new_object();
- alias = json_object_new_object();
- unit = json_object_new_object();
- scale = json_object_new_object();
- json_object_object_add(l, "alias", alias);
- json_object_object_add(l, "unit", unit);
- json_object_object_add(l, "scale", scale);
-
- json_object_object_foreach(tmp, code, obisobject) {
- i++;
- json_object_object_foreach(obisobject, key, val) {
- if (!strncmp(key, "name", 4))
- json_object_object_add(alias, code, val);
- else if (!strncmp(key, "value", 5) && !strncmp(code, "1-1:0.2.129.255", 15))
- listname = json_object_get_string(val);
- else if (!strncmp(key, "unit", 4))
- json_object_object_add(unit, code, val);
- else if (!strncmp(key, "scale", 5))
- json_object_object_add(scale, code, val);
- }
+ json_object_object_foreach(tmp, key, val) {
+ /* FIXME: ignoring for now... */
+ if (!strcmp("_metadata", key))
+ continue;
+ json_object_object_add(lists, key, val);
}
- /* save parsed file in config */
- if (listname)
- json_object_object_add(lists, listname, l);
-
return tmp;
}
static json_object *read_config(const char *fname, char *buf, size_t bufsize)
{
- json_object *tmp, *obis, *list, *ret, *parsed;
+ json_object *tmp, *list, *ret;
const char *name;
int i ;
@@ -1534,18 +1512,12 @@ static json_object *read_config(const char *fname, char *buf, size_t bufsize)
/* read all the OBIS definitions so we can look up aliases */
if (json_object_object_get_ex(ret, "obisdefs", &tmp) && json_object_is_type(tmp, json_type_array)) {
- /* create an object for the parsed files */
- obis = json_object_new_object();
- json_object_object_add(ret, "obisfiles", obis);
-
list = json_object_new_object();
json_object_object_add(ret, "obislists", list);
for (i = 0; i < json_object_array_length(tmp); i++) {
name = json_object_get_string(json_object_array_get_idx(tmp, i));
- parsed = parse_obisfile(list, name, buf, bufsize);
- if (parsed)
- json_object_object_add(obis, name, parsed);
+ parse_obisfile(list, name, buf, bufsize);
}
}