mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-17 07:46:31 +00:00
parent
fa6d18a505
commit
03cadd29f3
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
struct DataParserContext {
|
struct DataParserContext {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
|
uint8_t flags;
|
||||||
uint16_t length;
|
uint16_t length;
|
||||||
time_t timestamp;
|
time_t timestamp;
|
||||||
uint8_t system_title[8];
|
uint8_t system_title[8];
|
||||||
|
@ -36,13 +36,19 @@ int8_t GCMParser::parse(uint8_t *d, DataParserContext &ctx) {
|
|||||||
int len = 0;
|
int len = 0;
|
||||||
int headersize = 2 + systemTitleLength;
|
int headersize = 2 + systemTitleLength;
|
||||||
ptr += systemTitleLength;
|
ptr += systemTitleLength;
|
||||||
if(((*ptr) & 0xFF) == 0x81) {
|
|
||||||
|
if (ctx.flags & 1) {
|
||||||
|
len = *ptr;
|
||||||
|
ptr++;
|
||||||
|
headersize++;
|
||||||
|
} else {
|
||||||
|
if(((*ptr) & 0xFF) == 0x81) {
|
||||||
ptr++;
|
ptr++;
|
||||||
len = *ptr;
|
len = *ptr;
|
||||||
// 1-byte payload length
|
// 1-byte payload length
|
||||||
ptr++;
|
ptr++;
|
||||||
headersize += 2;
|
headersize += 2;
|
||||||
} else if(((*ptr) & 0xFF) == 0x82) {
|
} else if(((*ptr) & 0xFF) == 0x82) {
|
||||||
GCMSizeDef* h = (GCMSizeDef*) ptr;
|
GCMSizeDef* h = (GCMSizeDef*) ptr;
|
||||||
|
|
||||||
// 2-byte payload length
|
// 2-byte payload length
|
||||||
@ -50,14 +56,19 @@ int8_t GCMParser::parse(uint8_t *d, DataParserContext &ctx) {
|
|||||||
|
|
||||||
ptr += 3;
|
ptr += 3;
|
||||||
headersize += 3;
|
headersize += 3;
|
||||||
} else if(((*ptr) & 0xFF) == 0x4f) {
|
} else if(((*ptr) & 0xFF) == 0x4f) {
|
||||||
// ???????? single frame did only decode with this compare
|
// ???????? single frame did only decode with this compare
|
||||||
ptr++;
|
ptr++;
|
||||||
headersize++;
|
headersize++;
|
||||||
} else if(((*ptr) & 0xFF) == 0x5e) {
|
} else if(((*ptr) & 0xFF) == 0x5e) {
|
||||||
// ???????? single frame did only decode with this compare
|
// ???????? single frame did only decode with this compare
|
||||||
ptr++;
|
ptr++;
|
||||||
headersize++;
|
headersize++;
|
||||||
|
} else {
|
||||||
|
len = *ptr;
|
||||||
|
ptr++;
|
||||||
|
headersize++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(len + headersize > ctx.length)
|
if(len + headersize > ctx.length)
|
||||||
return DATA_PARSE_INCOMPLETE;
|
return DATA_PARSE_INCOMPLETE;
|
||||||
|
@ -44,7 +44,7 @@ int16_t Han_Parser::serial_readBytes(uint8_t *buf, uint16_t size) {
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Han_Parser::readHanPort(uint8_t **out, uint16_t *size) {
|
bool Han_Parser::readHanPort(uint8_t **out, uint16_t *size, uint8_t flags) {
|
||||||
|
|
||||||
if (!serial_available()) return false;
|
if (!serial_available()) return false;
|
||||||
|
|
||||||
@ -56,6 +56,7 @@ bool Han_Parser::readHanPort(uint8_t **out, uint16_t *size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DataParserContext ctx = {0};
|
DataParserContext ctx = {0};
|
||||||
|
ctx.flags = flags;
|
||||||
int pos = DATA_PARSE_INCOMPLETE;
|
int pos = DATA_PARSE_INCOMPLETE;
|
||||||
// For each byte received, check if we have a complete frame we can handle
|
// For each byte received, check if we have a complete frame we can handle
|
||||||
while (serial_available() && pos == DATA_PARSE_INCOMPLETE) {
|
while (serial_available() && pos == DATA_PARSE_INCOMPLETE) {
|
||||||
|
@ -18,7 +18,7 @@ class Han_Parser
|
|||||||
public:
|
public:
|
||||||
Han_Parser(uint16_t (*)(uint8_t, uint8_t), uint8_t, uint8_t *, uint8_t *);
|
Han_Parser(uint16_t (*)(uint8_t, uint8_t), uint8_t, uint8_t *, uint8_t *);
|
||||||
~Han_Parser(void);
|
~Han_Parser(void);
|
||||||
bool readHanPort(uint8_t **out, uint16_t *size);
|
bool readHanPort(uint8_t **out, uint16_t *size, uint8_t flags);
|
||||||
int16_t unwrapData(uint8_t *buf, DataParserContext &context);
|
int16_t unwrapData(uint8_t *buf, DataParserContext &context);
|
||||||
void printHanReadError(int16_t pos);
|
void printHanReadError(int16_t pos);
|
||||||
uint8_t encryptionKey[16];
|
uint8_t encryptionKey[16];
|
||||||
|
@ -186,6 +186,10 @@ on esp8266 2 filter masks
|
|||||||
9:
|
9:
|
||||||
on esp32 1 filter
|
on esp32 1 filter
|
||||||
on esp8266 6 filters
|
on esp8266 6 filters
|
||||||
|
|
||||||
|
A:
|
||||||
|
decryption flags (8 bits)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//#define MODBUS_DEBUG
|
//#define MODBUS_DEBUG
|
||||||
@ -490,6 +494,7 @@ struct METER_DESC {
|
|||||||
|
|
||||||
#ifdef USE_SML_DECRYPT
|
#ifdef USE_SML_DECRYPT
|
||||||
bool use_crypt = false;
|
bool use_crypt = false;
|
||||||
|
uint8_t crypflags;
|
||||||
uint8_t last_iob;
|
uint8_t last_iob;
|
||||||
uint8_t key[SML_CRYPT_SIZE];
|
uint8_t key[SML_CRYPT_SIZE];
|
||||||
Han_Parser *hp;
|
Han_Parser *hp;
|
||||||
@ -753,7 +758,7 @@ void dump2log(void) {
|
|||||||
d_lastms = millis();
|
d_lastms = millis();
|
||||||
uint16_t logsiz;
|
uint16_t logsiz;
|
||||||
uint8_t *payload;
|
uint8_t *payload;
|
||||||
if (mp->hp->readHanPort(&payload, &logsiz)) {
|
if (mp->hp->readHanPort(&payload, &logsiz, mp->crypflags)) {
|
||||||
if (logsiz > mp->sbsiz) {
|
if (logsiz > mp->sbsiz) {
|
||||||
logsiz = mp->sbsiz;
|
logsiz = mp->sbsiz;
|
||||||
}
|
}
|
||||||
@ -1408,7 +1413,7 @@ void sml_shift_in(uint32_t meters, uint32_t shard) {
|
|||||||
mp->lastms = millis();
|
mp->lastms = millis();
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
uint8_t *payload;
|
uint8_t *payload;
|
||||||
if (mp->hp->readHanPort(&payload, &len)) {
|
if (mp->hp->readHanPort(&payload, &len, mp->crypflags)) {
|
||||||
if (len > mp->sbsiz) {
|
if (len > mp->sbsiz) {
|
||||||
len = mp->sbsiz;
|
len = mp->sbsiz;
|
||||||
}
|
}
|
||||||
@ -2868,6 +2873,10 @@ struct METER_DESC *mp = &meter_desc[mnum];
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif // USE_SML_AUTHKEY
|
#endif // USE_SML_AUTHKEY
|
||||||
|
case 'A':
|
||||||
|
cp += 2;
|
||||||
|
mp->crypflags = strtol(cp, &cp, 10);
|
||||||
|
break;
|
||||||
#endif // USE_SML_DECRYPT
|
#endif // USE_SML_DECRYPT
|
||||||
case '6':
|
case '6':
|
||||||
cp += 2;
|
cp += 2;
|
||||||
@ -3633,6 +3642,7 @@ next_line:
|
|||||||
#else
|
#else
|
||||||
mp->hp = new Han_Parser(serial_dispatch, meters, mp->key, nullptr);
|
mp->hp = new Han_Parser(serial_dispatch, meters, mp->key, nullptr);
|
||||||
#endif
|
#endif
|
||||||
|
mp->crypflags = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user