mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-04-24 19:40:33 +00:00
Merge branch 'master' into dev-v2.2
This commit is contained in:
@@ -10,7 +10,7 @@ enum AmsType {
|
|||||||
AmsTypeKaifa = 0x02,
|
AmsTypeKaifa = 0x02,
|
||||||
AmsTypeKamstrup = 0x03,
|
AmsTypeKamstrup = 0x03,
|
||||||
AmsTypeIskra = 0x08,
|
AmsTypeIskra = 0x08,
|
||||||
AmsTypeLandis = 0x09,
|
AmsTypeLandisGyr = 0x09,
|
||||||
AmsTypeSagemcom = 0x0A,
|
AmsTypeSagemcom = 0x0A,
|
||||||
AmsTypeLng = 0x0B,
|
AmsTypeLng = 0x0B,
|
||||||
AmsTypeCustom = 0x88,
|
AmsTypeCustom = 0x88,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
uint16_t crc16(const uint8_t* p, int len);
|
||||||
uint16_t crc16_x25(const uint8_t* p, int len);
|
uint16_t crc16_x25(const uint8_t* p, int len);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
#include "DsmrParser.h"
|
#include "DsmrParser.h"
|
||||||
|
#include "crc.h"
|
||||||
|
#include "hexutils.h"
|
||||||
|
#include "lwip/def.h"
|
||||||
|
|
||||||
int8_t DSMRParser::parse(uint8_t *buf, DataParserContext &ctx, bool verified) {
|
int8_t DSMRParser::parse(uint8_t *buf, DataParserContext &ctx, bool verified) {
|
||||||
uint16_t crcPos = 0;
|
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;
|
if(!reachedEnd) return DATA_PARSE_INCOMPLETE;
|
||||||
buf[ctx.length+1] = '\0';
|
buf[ctx.length+1] = '\0';
|
||||||
if(crcPos > 0) {
|
if(crcPos > 0) {
|
||||||
// TODO: CRC
|
uint16_t crc_calc = crc16(buf, crcPos);
|
||||||
Serial.printf("CRC: %s\n", 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;
|
return DATA_PARSE_OK;
|
||||||
}
|
}
|
||||||
@@ -10,3 +10,20 @@ uint16_t crc16_x25(const uint8_t* p, int len)
|
|||||||
|
|
||||||
return (~crc << 8) | (~crc >> 8 & 0xff);
|
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;
|
||||||
|
}
|
||||||
@@ -854,7 +854,7 @@ var fetch = function() {
|
|||||||
$('.jmt').html("Iskra");
|
$('.jmt').html("Iskra");
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
$('.jmt').html("Landis");
|
$('.jmt').html("Landis+Gyr");
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
$('.jmt').html("Sagemcom");
|
$('.jmt').html("Sagemcom");
|
||||||
|
|||||||
@@ -329,7 +329,7 @@ void AmsWebServer::configMeterHtml() {
|
|||||||
case AmsTypeIskra:
|
case AmsTypeIskra:
|
||||||
manufacturer = F("Iskra");
|
manufacturer = F("Iskra");
|
||||||
break;
|
break;
|
||||||
case AmsTypeLandis:
|
case AmsTypeLandisGyr:
|
||||||
manufacturer = F("Landis+Gyr");
|
manufacturer = F("Landis+Gyr");
|
||||||
break;
|
break;
|
||||||
case AmsTypeSagemcom:
|
case AmsTypeSagemcom:
|
||||||
|
|||||||
@@ -1463,6 +1463,7 @@ void MQTT_connect() {
|
|||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
if(mqttSecureClient) {
|
if(mqttSecureClient) {
|
||||||
|
time_t epoch = time(nullptr);
|
||||||
debugD("Setting NTP time %lu for secure MQTT connection", epoch);
|
debugD("Setting NTP time %lu for secure MQTT connection", epoch);
|
||||||
mqttSecureClient->setX509Time(epoch);
|
mqttSecureClient->setX509Time(epoch);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
#include "IEC6205621.h"
|
#include "IEC6205621.h"
|
||||||
#include "crc.h"
|
|
||||||
|
|
||||||
IEC6205621::IEC6205621(const char* p) {
|
IEC6205621::IEC6205621(const char* p) {
|
||||||
if(strlen(p) < 16)
|
if(strlen(p) < 16)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String payload(p+1);
|
String payload(p+1);
|
||||||
int crc_pos = payload.lastIndexOf("!");
|
|
||||||
String crc = payload.substring(crc_pos+1, crc_pos+5);
|
|
||||||
//uint16_t crc_calc = crc16_x25((uint8_t*) (payload.startsWith("/") ? p+1 : p), crc_pos);
|
|
||||||
|
|
||||||
//Serial.printf("CRC %s :: %04X\n", crc.c_str(), crc_calc);
|
|
||||||
|
|
||||||
lastUpdateMillis = millis();
|
lastUpdateMillis = millis();
|
||||||
listId = payload.substring(payload.startsWith("/") ? 1 : 0, payload.indexOf("\n"));
|
listId = payload.substring(payload.startsWith("/") ? 1 : 0, payload.indexOf("\n"));
|
||||||
@@ -28,11 +22,14 @@ IEC6205621::IEC6205621(const char* p) {
|
|||||||
meterType = AmsTypeIskra;
|
meterType = AmsTypeIskra;
|
||||||
listId = listId.substring(0,5);
|
listId = listId.substring(0,5);
|
||||||
} else if(listId.startsWith("XMX")) {
|
} else if(listId.startsWith("XMX")) {
|
||||||
meterType = AmsTypeLandis;
|
meterType = AmsTypeLandisGyr;
|
||||||
listId = listId.substring(0,6);
|
listId = listId.substring(0,6);
|
||||||
} else if(listId.startsWith("Ene") || listId.startsWith("EST")) {
|
} else if(listId.startsWith("Ene") || listId.startsWith("EST")) {
|
||||||
meterType = AmsTypeSagemcom;
|
meterType = AmsTypeSagemcom;
|
||||||
listId = listId.substring(0,4);
|
listId = listId.substring(0,4);
|
||||||
|
} else if(listId.startsWith("LGF")) {
|
||||||
|
meterType = AmsTypeLandisGyr;
|
||||||
|
listId = listId.substring(0,4);
|
||||||
} else {
|
} else {
|
||||||
meterType = AmsTypeUnknown;
|
meterType = AmsTypeUnknown;
|
||||||
listId = listId.substring(0,4);
|
listId = listId.substring(0,4);
|
||||||
@@ -136,6 +133,9 @@ IEC6205621::IEC6205621(const char* p) {
|
|||||||
l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
|
l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (l1activeImportPower > 0 || l2activeImportPower > 0 || l3activeImportPower > 0 || l1activeExportPower > 0 || l2activeExportPower > 0 || l3activeExportPower > 0)
|
||||||
|
listType = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
String IEC6205621::extract(String payload, String obis) {
|
String IEC6205621::extract(String payload, String obis) {
|
||||||
|
|||||||
Reference in New Issue
Block a user