From a234cf02c683ec833c838d9102944bf72c19dcfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20=C3=96hrstr=C3=B6m?= Date: Wed, 27 Apr 2022 18:51:51 +0200 Subject: [PATCH] Use wildcard for mfct/version/type when using secondary addressing for mbus. --- src/driver_piigth.cc | 3 ++- src/mbus_rawtty.cc | 13 +++++++++++++ src/meters.cc | 25 +++++++------------------ src/wmbus.h | 1 + 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/driver_piigth.cc b/src/driver_piigth.cc index 75ed977..ac35912 100644 --- a/src/driver_piigth.cc +++ b/src/driver_piigth.cc @@ -69,6 +69,7 @@ namespace .set(StorageNr(2)) ); + /* addNumericFieldWithExtractor( "relative_humidity", "The current relative humidity.", @@ -78,7 +79,7 @@ namespace FieldMatcher::build(). set(DifVifKey("02FB1A")) ); - + */ addStringFieldWithExtractor( "fabrication_no", "Fabrication number.", diff --git a/src/mbus_rawtty.cc b/src/mbus_rawtty.cc index f8b27da..b554510 100644 --- a/src/mbus_rawtty.cc +++ b/src/mbus_rawtty.cc @@ -100,6 +100,19 @@ LinkModeSet MBusRawTTY::getLinkModes() { void MBusRawTTY::deviceReset() { + // Send an NKE message that resets the communication with all meters connected to the mbus. + vector buf; + buf.resize(5); + buf[0] = 0x10; // Start + buf[1] = 0x40; // SND_NKE + buf[2] = 0x00; // address 0 + uchar cs = 0; + for (int i=1; i<3; ++i) cs += buf[i]; + buf[3] = cs; // checksum + buf[4] = 0x16; // Stop + + verbose("Sending NKE to mbus %s\n", busAlias().c_str()); + serial()->send(buf); } void MBusRawTTY::deviceSetLinkModes(LinkModeSet lms) diff --git a/src/meters.cc b/src/meters.cc index e4970b5..674b05d 100644 --- a/src/meters.cc +++ b/src/meters.cc @@ -1021,20 +1021,6 @@ void MeterCommonImplementation::poll(shared_ptr bus_manager) debug("(meter) Could not find bus from name \"%s\"\n", bus().c_str()); return; } - /* - Reset mbus... - vector buf; - buf[0] = 0x10; // Start - buf[1] = 0x40; // SND_NKE - buf[2] = 0x00; // address 0 - uchar cs = 0; - for (int i=1; i<3; ++i) cs += buf[i]; - buf[3] = cs; // checksum - buf[4] = 0x16; // Stop - dev->serial()->send(buf); - - sleep(2); - */ string id = ids().back(); if (id.length() != 2 && id.length() != 3 && id.length() != 8) @@ -1090,14 +1076,17 @@ void MeterCommonImplementation::poll(shared_ptr bus_manager) buf[4] = 0x73; // SND_UD buf[5] = 0xfd; // address 253 buf[6] = 0x52; // ci 52 + // Assuming we send id 12345678 buf[7] = idhex[3]; // id 78 buf[8] = idhex[2]; // id 56 buf[9] = idhex[1]; // id 34 buf[10] = idhex[0]; // id 12 - buf[11] = 0x29; // mfct 29 - buf[12] = 0x41; // mfct 41 2941 == PII - buf[13] = 0x01; // version/generation - buf[14] = 0x1b; // type/media/device + // Use wildcards instead of exact matching here. + // TODO add selection based on these values as well. + buf[11] = 0xff; // mfct + buf[12] = 0xff; // mfct + buf[13] = 0xff; // version/generation + buf[14] = 0xff; // type/media/device uchar cs = 0; for (int i=4; i<15; ++i) cs += buf[i]; diff --git a/src/wmbus.h b/src/wmbus.h index f05180f..9891ee1 100644 --- a/src/wmbus.h +++ b/src/wmbus.h @@ -635,6 +635,7 @@ struct WMBus // Remember how this device was detected. virtual void setDetected(Detected detected) = 0; virtual Detected *getDetected() = 0; + virtual ~WMBus() = 0; };