From 10ebfbfa21064bdfd234c0c1317d52a9ad537843 Mon Sep 17 00:00:00 2001 From: Bascy Date: Sat, 1 Mar 2025 13:09:02 +0100 Subject: [PATCH 1/4] Allow fields without units when vallue = 0 --- src/dsmr/parser.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/dsmr/parser.h b/src/dsmr/parser.h index 69beca6..513c3e2 100644 --- a/src/dsmr/parser.h +++ b/src/dsmr/parser.h @@ -215,8 +215,14 @@ struct NumParser { // If a unit was passed, check that the unit in the messages // messages the unit passed. if (unit && *unit) { - if (num_end >= end || *num_end != '*') - return res.fail(F("Missing unit"), num_end); + + if (num_end >= end || *num_end != '*') { + if (value != 0) + return res.fail(F("Missing unit"), num_end); + else + return res.succeed(value).until(num_end + 1); // Skip ) + } + const char *unit_start = ++num_end; // skip * while(num_end < end && *num_end != ')' && *unit) { // Next character in units do not match? @@ -337,8 +343,10 @@ struct P1Parser { return check_res; // Check CRC - if (check_res.result != crc) + if (check_res.result != crc) { + Serial.printf("Checksum mismatch %x != %x\n", check_res.result, crc); return res.fail(F("Checksum mismatch"), data_end + 1); + } res = parse_data(data, data_start, data_end, unknown_error); res.next = check_res.next; From ccc5baad6f80fddc096ed1e71730606c572e918c Mon Sep 17 00:00:00 2001 From: Bascy Date: Wed, 5 Mar 2025 22:00:02 +0100 Subject: [PATCH 2/4] Allow missing unit when value is 0 --- src/dsmr/parser.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/dsmr/parser.h b/src/dsmr/parser.h index 513c3e2..55eaca0 100644 --- a/src/dsmr/parser.h +++ b/src/dsmr/parser.h @@ -213,14 +213,19 @@ struct NumParser { value *= 10; // If a unit was passed, check that the unit in the messages - // messages the unit passed. + // matches the unit passed. if (unit && *unit) { if (num_end >= end || *num_end != '*') { if (value != 0) return res.fail(F("Missing unit"), num_end); else - return res.succeed(value).until(num_end + 1); // Skip ) + // if no unit after value 0, then the ) must still be there + if (*num_end == ')') + return res.succeed(value).until(num_end + 1) // Skip ) + else + // something else + return res.fail((const __FlashStringHelper*)INVALID_UNIT, unit_start); } const char *unit_start = ++num_end; // skip * From 466bde4a40c471adea445f7660ef09d7c0c9ec89 Mon Sep 17 00:00:00 2001 From: Bascy Date: Wed, 5 Mar 2025 22:03:15 +0100 Subject: [PATCH 3/4] Added comment to optional log of checksum --- src/dsmr/parser.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dsmr/parser.h b/src/dsmr/parser.h index 55eaca0..33b9bae 100644 --- a/src/dsmr/parser.h +++ b/src/dsmr/parser.h @@ -349,7 +349,8 @@ struct P1Parser { // Check CRC if (check_res.result != crc) { - Serial.printf("Checksum mismatch %x != %x\n", check_res.result, crc); + // log expected checksum, convenient for creating test data + // Serial.printf("Checksum mismatch %x != %x\n", check_res.result, crc); return res.fail(F("Checksum mismatch"), data_end + 1); } From 7dbea35676d80203f570cfba7c9e32944cf6ffe3 Mon Sep 17 00:00:00 2001 From: Bascy Date: Fri, 7 Mar 2025 21:45:26 +0100 Subject: [PATCH 4/4] Fixed missing ; --- src/dsmr/parser.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dsmr/parser.h b/src/dsmr/parser.h index 33b9bae..5c70e7d 100644 --- a/src/dsmr/parser.h +++ b/src/dsmr/parser.h @@ -222,10 +222,10 @@ struct NumParser { else // if no unit after value 0, then the ) must still be there if (*num_end == ')') - return res.succeed(value).until(num_end + 1) // Skip ) + return res.succeed(value).until(num_end + 1); // Skip ) else // something else - return res.fail((const __FlashStringHelper*)INVALID_UNIT, unit_start); + return res.fail((const __FlashStringHelper*)INVALID_UNIT, num_end); } const char *unit_start = ++num_end; // skip *