Skip to content

Commit

Permalink
Fixed autodetect
Browse files Browse the repository at this point in the history
  • Loading branch information
gskjold committed Nov 6, 2024
1 parent fa5985f commit 118c633
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/MeterCommunicators/include/KmpCommunicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class KmpCommunicator : public PassiveMeterCommunicator {
AmsData* getData(AmsData& meterState);
int getLastError();
bool isConfigChanged() { return false; }
void ackConfigChanged() {}
void getCurrentConfig(MeterConfig& meterConfig) {
meterConfig = this->meterConfig;
}
Expand Down
1 change: 1 addition & 0 deletions lib/MeterCommunicators/include/MeterCommunicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class MeterCommunicator {
virtual AmsData* getData(AmsData& meterState);
virtual int getLastError();
virtual bool isConfigChanged();
virtual void ackConfigChanged();
virtual void getCurrentConfig(MeterConfig& meterConfig);
};

Expand Down
1 change: 1 addition & 0 deletions lib/MeterCommunicators/include/PassiveMeterCommunicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PassiveMeterCommunicator : public MeterCommunicator {
AmsData* getData(AmsData& meterState);
int getLastError();
bool isConfigChanged();
void ackConfigChanged();
void getCurrentConfig(MeterConfig& meterConfig);
void setPassthroughMqttHandler(PassthroughMqttHandler*);

Expand Down
1 change: 1 addition & 0 deletions lib/MeterCommunicators/include/PulseMeterCommunicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class PulseMeterCommunicator : public MeterCommunicator {
AmsData* getData(AmsData& meterState);
int getLastError();
bool isConfigChanged();
void ackConfigChanged();
void getCurrentConfig(MeterConfig& meterConfig);

void onPulse(uint8_t pulses);
Expand Down
7 changes: 5 additions & 2 deletions lib/MeterCommunicators/src/PassiveMeterCommunicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,14 @@ bool PassiveMeterCommunicator::isConfigChanged() {
return configChanged;
}

void PassiveMeterCommunicator::ackConfigChanged() {
configChanged = false;
}

void PassiveMeterCommunicator::getCurrentConfig(MeterConfig& meterConfig) {
meterConfig = this->meterConfig;
}


int16_t PassiveMeterCommunicator::unwrapData(uint8_t *buf, DataParserContext &context) {
int16_t ret = 0;
bool doRet = false;
Expand Down Expand Up @@ -578,7 +581,7 @@ void PassiveMeterCommunicator::setupHanPort(uint32_t baud, uint8_t parityOrdinal
int8_t txpin = passive ? -1 : meterConfig.txPin;

if(baud == 0) {
baud = 2400;
autodetectBaud = baud = 2400;
}

#if defined(AMS_REMOTE_DEBUG)
Expand Down
4 changes: 4 additions & 0 deletions lib/MeterCommunicators/src/PulseMeterCommunicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ bool PulseMeterCommunicator::isConfigChanged() {
return this->configChanged;
}

void PulseMeterCommunicator::ackConfigChanged() {
configChanged = false;
}

void PulseMeterCommunicator::getCurrentConfig(MeterConfig& meterConfig) {
meterConfig = this->meterConfig;
}
Expand Down
2 changes: 2 additions & 0 deletions src/AmsToMqttBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,7 @@ bool readHanPort() {
if(mc->isConfigChanged()) {
mc->getCurrentConfig(meterConfig);
config.setMeterConfig(meterConfig);
mc->ackConfigChanged();
}
meterState.setLastError(mc->getLastError());

Expand Down Expand Up @@ -1667,6 +1668,7 @@ void configFileParse() {
meter.baud = String(buf+10).toInt();
} else if(strncmp_P(buf, PSTR("meterParity "), 12) == 0) {
if(!lMeter) { config.getMeterConfig(meter); lMeter = true; };
meter.parity = 0;
if(strncmp_P(buf+12, PSTR("7N1"), 3) == 0) meter.parity = 2;
if(strncmp_P(buf+12, PSTR("8N1"), 3) == 0) meter.parity = 3;
if(strncmp_P(buf+12, PSTR("8N2"), 3) == 0) meter.parity = 7;
Expand Down

0 comments on commit 118c633

Please sign in to comment.