Skip to content

Commit 6336718

Browse files
authored
Fixed Kamstrup timestamp parsing (#1011)
* Fixed kamstrup timestamp deviation * Fixed check for time zone
1 parent 69da9f9 commit 6336718

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

lib/AmsDecoder/src/Cosem.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ time_t decodeCosemDateTime(CosemDateTime timestamp) {
1919
tm.Minute = timestamp.minute;
2020
tm.Second = timestamp.second;
2121

22-
//Serial.printf("\nY: %d, M: %d, D: %d, h: %d, m: %d, s: %d, deviation: 0x%2X, status: 0x%1X\n", tm.Year, tm.Month, tm.Day, tm.Hour, tm.Minute, tm.Second, timestamp.deviation, timestamp.status);
23-
2422
time_t time = makeTime(tm);
2523
int16_t deviation = ntohs(timestamp.deviation);
2624
if(deviation >= -720 && deviation <= 720) {

lib/MeterCommunicators/include/IEC6205675.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include "AmsConfiguration.h"
1212
#include "DataParser.h"
1313
#include "Cosem.h"
14+
#if defined(AMS_REMOTE_DEBUG)
15+
#include "RemoteDebug.h"
16+
#endif
1417

1518
#define NOVALUE 0xFFFFFFFF
1619

@@ -21,7 +24,11 @@ struct AmsOctetTimestamp {
2124

2225
class IEC6205675 : public AmsData {
2326
public:
24-
IEC6205675(const char* payload, uint8_t useMeterType, MeterConfig* meterConfig, DataParserContext &ctx, AmsData &state);
27+
#if defined(AMS_REMOTE_DEBUG)
28+
IEC6205675(const char* payload, uint8_t useMeterType, MeterConfig* meterConfig, DataParserContext &ctx, AmsData &state, RemoteDebug* debugger);
29+
#else
30+
IEC6205675(const char* payload, uint8_t useMeterType, MeterConfig* meterConfig, DataParserContext &ctx, AmsData &state, Stream* debugger);
31+
#endif
2532

2633
private:
2734
CosemData* getCosemDataAt(uint8_t index, const char* ptr);

lib/MeterCommunicators/src/IEC6205675.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
#include "Uptime.h"
1212
#include "hexutils.h"
1313

14-
IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterConfig, DataParserContext &ctx, AmsData &state) {
14+
#if defined(AMS_REMOTE_DEBUG)
15+
IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterConfig, DataParserContext &ctx, AmsData &state, RemoteDebug* debugger) {
16+
#else
17+
IEC6205675::IEC6205675(const char* payload, uint8_t useMeterType, MeterConfig* meterConfig, DataParserContext &ctx, AmsData &state, Stream* debugger) {
18+
#endif
1519
float val;
1620
char str[64];
1721

@@ -635,12 +639,6 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterCo
635639
}
636640
}
637641

638-
if(this->packageTimestamp > 0) {
639-
if(meterType == AmsTypeKamstrup) {
640-
this->packageTimestamp = this->packageTimestamp - 3600;
641-
}
642-
}
643-
644642
uint8_t str_len = 0;
645643
str_len = getString(AMS_OBIS_VERSION, sizeof(AMS_OBIS_VERSION), ((char *) (d)), str);
646644
if(str_len > 0) {
@@ -741,8 +739,12 @@ IEC6205675::IEC6205675(const char* d, uint8_t useMeterType, MeterConfig* meterCo
741739
if(meterTs != NULL) {
742740
AmsOctetTimestamp* amst = (AmsOctetTimestamp*) meterTs;
743741
time_t ts = decodeCosemDateTime(amst->dt);
744-
if(amst->dt.deviation == 0x8000) { // Deviation not specified, adjust from localtime to UTC
742+
int16_t deviation = ntohs(amst->dt.deviation);
743+
if(deviation < -720 || deviation > 720) { // Deviation not specified, adjust from localtime to UTC
745744
meterTimestamp = tz.toUTC(ts);
745+
if(ctx.timestamp > 0) {
746+
this->packageTimestamp = tz.toUTC(ctx.timestamp);
747+
}
746748
} else if(meterType == AmsTypeAidon) {
747749
meterTimestamp = ts - 3600; // 21.09.24, the clock is now correct
748750
} else {

lib/MeterCommunicators/src/PassiveMeterCommunicator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ AmsData* PassiveMeterCommunicator::getData(AmsData& meterState) {
278278
#endif
279279
debugger->printf_P(PSTR("DLMS\n"));
280280
// TODO: Split IEC6205675 into DataParserKaifa and DataParserObis. This way we can add other means of parsing, for those other proprietary formats
281-
data = new IEC6205675(payload, meterState.getMeterType(), &meterConfig, ctx, meterState);
281+
data = new IEC6205675(payload, meterState.getMeterType(), &meterConfig, ctx, meterState, debugger);
282282
}
283283
} else if(ctx.type == DATA_TAG_DSMR) {
284284
data = new IEC6205621(payload, tz, &meterConfig);

0 commit comments

Comments
 (0)