Skip to content

Commit

Permalink
Add ability to configure SML meter workarounds
Browse files Browse the repository at this point in the history
Make use of libsml's workaround options to apply a workaround for DZG
meters. This builds upon the changes from [libsml PR volkszaehler#133](volkszaehler/libsml#133).
  • Loading branch information
tanuva committed Oct 20, 2023
1 parent 35426c0 commit 297a9d5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
10 changes: 10 additions & 0 deletions etc/vzlogger_generic.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@
"type": "boolean",
"default": false,
"description": "use the local time for reading timestamp?"
},
"dzg_fix_negative_values": {
"type": "boolean",
"default": false,
"description": "work around wrongly encoded negative values on some DZG meters"
}
},
"required": ["protocol", "device", "baudrate", "parity"]
Expand Down Expand Up @@ -559,6 +564,11 @@
"type": "boolean",
"default": false,
"description": "use the local time for reading timestamp?"
},
"dzg_fix_negative_values": {
"type": "boolean",
"default": false,
"description": "work around wrongly encoded negative values on some DZG meters"
}
},
"required": ["protocol", "host", "baudrate", "parity"]
Expand Down
1 change: 1 addition & 0 deletions include/protocols/MeterSML.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class MeterSML : public vz::protocol::Protocol {
parity_type_t _parity;
std::string _pull;
bool _use_local_time;
sml_workarounds _sml_workarounds;

int _fd; /* file descriptor of port */
struct termios _old_tio; /* required to reset port */
Expand Down
12 changes: 10 additions & 2 deletions src/protocols/MeterSML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#define SML_BUFFER_LEN 8096

MeterSML::MeterSML(std::list<Option> options)
: Protocol("sml"), _host(""), _device(""), BUFFER_LEN(SML_BUFFER_LEN) {
: Protocol("sml"), _host(""), _device(""), _sml_workarounds(0), BUFFER_LEN(SML_BUFFER_LEN) {
OptionList optlist;

/* connection */
Expand Down Expand Up @@ -194,6 +194,14 @@ MeterSML::MeterSML(std::list<Option> options)
print(log_alert, "Failed to parse the parity", name().c_str());
throw;
}

try {
if (optlist.lookup_bool(options, "dzg_fix_negative_values")) {
_sml_workarounds |= SML_WORKAROUND_DZG_NEGATIVE;
}
} catch (vz::OptionNotFoundException &e) {
// Leave disabled if the option wasn't provided.
}
}

MeterSML::MeterSML(const MeterSML &proto) : Protocol(proto), _fd(ERR), BUFFER_LEN(SML_BUFFER_LEN) {}
Expand Down Expand Up @@ -279,7 +287,7 @@ ssize_t MeterSML::read(std::vector<Reading> &rds, size_t n) {
}

/* parse SML file & stripping escape sequences */
file = sml_file_parse(buffer + 8, bytes - 16);
file = sml_file_parse(buffer + 8, bytes - 16, _sml_workarounds);

/* obtain SML messagebody of type getResponseList */
for (short i = 0; i < file->messages_len; i++) {
Expand Down

0 comments on commit 297a9d5

Please sign in to comment.