diff options
author | Bjørn Mork <bjorn@mork.no> | 2019-05-30 09:03:28 +0200 |
---|---|---|
committer | Bjørn Mork <bjorn@mork.no> | 2019-05-30 09:03:28 +0200 |
commit | e4ceeec4ce86fe64181f200ae3453ce22fe82f1c (patch) | |
tree | 55db2af1447e68b99b80235879b4908884b826f0 | |
parent | 875565ff01885de3e5a0a68ca50bc736a6705cd8 (diff) |
map the parts of the unit enum we know
Signed-off-by: Bjørn Mork <bjorn@mork.no>
-rw-r--r-- | obinsectd.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/obinsectd.c b/obinsectd.c index 0a64c6a..61059a5 100644 --- a/obinsectd.c +++ b/obinsectd.c @@ -522,6 +522,25 @@ static time_t decode_datetime(unsigned char *buf) return mktime(&t); } +/* + * Ref BS EN 62056-6-2:2013, page 30, "Table 3 – Enumerated values for physical units". + * according to "Hårek" + */ +static char *cosem_unit_enum(unsigned char e) +{ + static char ret[17]; /* "unknown-unit-255" is 16 bytes */ + switch (e) { + case 27: return "W"; + case 28: return "VA"; + case 29: return "VAr"; + case 33: return "A"; + case 35: return "V"; + default: + sprintf(ret, "unknown-unit-%u", e); + return ret; + } +} + static char *cosem_typestr(unsigned char type) { /* ref DLMS Blue-Book-Ed-122-Excerpt.pdf section 4.1.5 "Common data types" */ @@ -682,8 +701,8 @@ static int parse_cosem(unsigned char *buf, size_t buflen, int lvl, json_object * *ret = cosem_object_new_int(buf, len++, false); break; case 22: // enum - len = 1; - *ret = cosem_object_new_int(buf, len++, false); + len = 2; + *ret = json_object_new_string(cosem_unit_enum(buf[1])); break; case 25: // date-time len = 1 + 12; |