From 663c3ecd1afb235bd60e0b53ed1034fffd09a1c8 Mon Sep 17 00:00:00 2001 From: Bascy Date: Wed, 5 Mar 2025 21:27:04 +0100 Subject: [PATCH 1/2] made enable pin optional --- src/dsmr/reader.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/dsmr/reader.h b/src/dsmr/reader.h index 61b8742..ae0b1e9 100644 --- a/src/dsmr/reader.h +++ b/src/dsmr/reader.h @@ -39,6 +39,8 @@ namespace dsmr { +#define NO_PIN 0xff + /** * Controls the request pin on the P1 port to enable (periodic) * transmission of messages and reads those messages. @@ -69,10 +71,12 @@ class P1Reader { * output, the Stream is assumed to be already set up (e.g. baud * rate configured). */ - P1Reader(Stream *stream, uint8_t req_pin) + P1Reader(Stream *stream, uint8_t req_pin = NO_PIN) : stream(stream), req_pin(req_pin), once(false), state(State::DISABLED_STATE) { - pinMode(req_pin, OUTPUT); - digitalWrite(req_pin, LOW); + if (req_pin != NO_PIN) { + pinMode(req_pin, OUTPUT); + digitalWrite(req_pin, LOW); + } } /** @@ -84,7 +88,8 @@ class P1Reader { * periodically. */ void enable(bool once) { - digitalWrite(this->req_pin, HIGH); + if (req_pin != NO_PIN) + digitalWrite(this->req_pin, HIGH); this->state = State::WAITING_STATE; this->once = once; } @@ -95,9 +100,10 @@ class P1Reader { * clear() is called. */ void disable() { - digitalWrite(this->req_pin, LOW); + if (req_pin != NO_PIN) + digitalWrite(this->req_pin, LOW); this->state = State::DISABLED_STATE; - if (!this->_available) + if (!this->_available) this->buffer = ""; // Clear any pending bytes while(this->stream->read() >= 0) /* nothing */; @@ -121,7 +127,7 @@ class P1Reader { if (state == State::CHECKSUM_STATE) { // Let the Stream buffer the CRC bytes. Convert to size_t to // prevent unsigned vs signed comparison - if ((size_t)this->stream->available() < CrcParser::CRC_LEN) + if ((size_t)this->stream->available() < CrcParser::CRC_LEN) return false; char buf[CrcParser::CRC_LEN]; @@ -138,7 +144,7 @@ class P1Reader { this->_available = true; if (once) - this->disable(); + this->disable(); return true; } From 498bfcc97005d13d684cadd066e000c7c62b242a Mon Sep 17 00:00:00 2001 From: Bascy Date: Wed, 5 Mar 2025 21:31:35 +0100 Subject: [PATCH 2/2] Restore unneeded format changes --- src/dsmr/reader.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dsmr/reader.h b/src/dsmr/reader.h index ae0b1e9..569ca23 100644 --- a/src/dsmr/reader.h +++ b/src/dsmr/reader.h @@ -103,7 +103,7 @@ class P1Reader { if (req_pin != NO_PIN) digitalWrite(this->req_pin, LOW); this->state = State::DISABLED_STATE; - if (!this->_available) + if (!this->_available) this->buffer = ""; // Clear any pending bytes while(this->stream->read() >= 0) /* nothing */; @@ -127,7 +127,7 @@ class P1Reader { if (state == State::CHECKSUM_STATE) { // Let the Stream buffer the CRC bytes. Convert to size_t to // prevent unsigned vs signed comparison - if ((size_t)this->stream->available() < CrcParser::CRC_LEN) + if ((size_t)this->stream->available() < CrcParser::CRC_LEN) return false; char buf[CrcParser::CRC_LEN];