Merge branch 'master' into dev-v2.2

This commit is contained in:
Gunnar Skjold
2023-01-04 18:55:38 +01:00
8 changed files with 39 additions and 12 deletions

View File

@@ -10,7 +10,7 @@ enum AmsType {
AmsTypeKaifa = 0x02,
AmsTypeKamstrup = 0x03,
AmsTypeIskra = 0x08,
AmsTypeLandis = 0x09,
AmsTypeLandisGyr = 0x09,
AmsTypeSagemcom = 0x0A,
AmsTypeLng = 0x0B,
AmsTypeCustom = 0x88,

View File

@@ -4,6 +4,7 @@
#include "Arduino.h"
#include <stdint.h>
uint16_t crc16(const uint8_t* p, int len);
uint16_t crc16_x25(const uint8_t* p, int len);
#endif

View File

@@ -1,4 +1,7 @@
#include "DsmrParser.h"
#include "crc.h"
#include "hexutils.h"
#include "lwip/def.h"
int8_t DSMRParser::parse(uint8_t *buf, DataParserContext &ctx, bool verified) {
uint16_t crcPos = 0;
@@ -14,8 +17,13 @@ int8_t DSMRParser::parse(uint8_t *buf, DataParserContext &ctx, bool verified) {
if(!reachedEnd) return DATA_PARSE_INCOMPLETE;
buf[ctx.length+1] = '\0';
if(crcPos > 0) {
// TODO: CRC
Serial.printf("CRC: %s\n", buf+crcPos);
uint16_t crc_calc = crc16(buf, crcPos);
uint16_t crc = 0x0000;
fromHex((uint8_t*) &crc, String((char*) buf+crcPos), 2);
crc = ntohs(crc);
if(crc != crc_calc)
return DATA_PARSE_FOOTER_CHECKSUM_ERROR;
}
return DATA_PARSE_OK;
}

View File

@@ -10,3 +10,20 @@ uint16_t crc16_x25(const uint8_t* p, int len)
return (~crc << 8) | (~crc >> 8 & 0xff);
}
uint16_t crc16 (const uint8_t *p, int len) {
uint16_t crc = 0;
while (len--) {
int i;
crc ^= *p++;
for (i = 0 ; i < 8 ; ++i) {
if (crc & 1)
crc = (crc >> 1) ^ 0xa001;
else
crc = (crc >> 1);
}
}
return crc;
}

View File

@@ -854,7 +854,7 @@ var fetch = function() {
$('.jmt').html("Iskra");
break;
case 9:
$('.jmt').html("Landis");
$('.jmt').html("Landis+Gyr");
break;
case 10:
$('.jmt').html("Sagemcom");

View File

@@ -329,7 +329,7 @@ void AmsWebServer::configMeterHtml() {
case AmsTypeIskra:
manufacturer = F("Iskra");
break;
case AmsTypeLandis:
case AmsTypeLandisGyr:
manufacturer = F("Landis+Gyr");
break;
case AmsTypeSagemcom: