Fixes after testing

This commit is contained in:
Gunnar Skjold
2021-11-18 19:06:33 +01:00
parent 580085f717
commit 5c38d1cf3e
5 changed files with 56 additions and 48 deletions

View File

@@ -15,7 +15,7 @@ void mbus_hexdump(const uint8_t* buf, int len) {
printf("]\n");
}
int HDLC_validate(const uint8_t* d, int len, HDLCConfig* config) {
int HDLC_validate(const uint8_t* d, int len, HDLCConfig* config, CosemDateTime* timestamp) {
//mbus_hexdump(d, len);
HDLCHeader* h = (HDLCHeader*) d;
@@ -74,13 +74,18 @@ int HDLC_validate(const uint8_t* d, int len, HDLCConfig* config) {
ptr += sizeof *adpu;
// ADPU timestamp
// TODO : extract and return
CosemData* dateTime = (CosemData*) ptr;
if(dateTime->base.type == CosemTypeOctetString) {
if(dateTime->base.length == 0x0C) {
memcpy(timestamp, ptr+1, dateTime->base.length);
}
ptr += 2 + dateTime->base.length;
} else if(dateTime->base.type == CosemTypeNull) {
ptr++;
} else if(dateTime->base.type == CosemTypeDateTime) {
memcpy(timestamp, ptr, dateTime->base.length);
} else if(dateTime->base.type == 0x0C) { // Kamstrup bug...
memcpy(timestamp, ptr, dateTime->base.length);
ptr += 13;
} else {
return -99;