Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow 0 without unit #58

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/dsmr/parser.h
Original file line number Diff line number Diff line change
@@ -213,10 +213,21 @@ 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 != '*')
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
// 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, num_end);
}

const char *unit_start = ++num_end; // skip *
while(num_end < end && *num_end != ')' && *unit) {
// Next character in units do not match?
@@ -337,8 +348,11 @@ struct P1Parser {
return check_res;

// Check CRC
if (check_res.result != crc)
if (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);
}

res = parse_data(data, data_start, data_end, unknown_error);
res.next = check_res.next;