Gunnar Skjold 633671851e
Fixed Kamstrup timestamp parsing (#1011)
* Fixed kamstrup timestamp deviation

* Fixed check for time zone
2025-09-25 10:47:47 +02:00

28 lines
661 B
C++

/**
* @copyright Utilitech AS 2023
* License: Fair Source
*
*/
#include "Cosem.h"
#include "lwip/def.h"
#include <TimeLib.h>
time_t decodeCosemDateTime(CosemDateTime timestamp) {
tmElements_t tm;
uint16_t year = ntohs(timestamp.year);
if(year < 1970) return 0;
tm.Year = year - 1970;
tm.Month = timestamp.month;
tm.Day = timestamp.dayOfMonth;
tm.Hour = timestamp.hour;
tm.Minute = timestamp.minute;
tm.Second = timestamp.second;
time_t time = makeTime(tm);
int16_t deviation = ntohs(timestamp.deviation);
if(deviation >= -720 && deviation <= 720) {
time += deviation * 60;
}
return time;
}