mirror of https://github.com/arendst/Tasmota.git
fix modbus-tcp, add U32,U64 etc (#19063)
This commit is contained in:
parent
8ce7cb4ccd
commit
d9d9ca2651
|
@ -1388,6 +1388,7 @@ void sml_shift_in(uint32_t meters, uint32_t shard) {
|
|||
uint8_t tlen = (mp->sbuff[4] << 8) | mp->sbuff[5];
|
||||
if (mp->spos == 6 + tlen) {
|
||||
mp->spos = 0;
|
||||
memmove(&mp->sbuff[0], &mp->sbuff[6], mp->sbsiz - 6);
|
||||
SML_Decode(meters);
|
||||
if (mp->client) {
|
||||
mp->client->flush();
|
||||
|
@ -1863,9 +1864,29 @@ void SML_Decode(uint8_t index) {
|
|||
cp += skip;
|
||||
}
|
||||
}
|
||||
} else if (!strncmp(mp, "U64", 3)) {
|
||||
uint32_t valh = (cp[0]<<24) | (cp[1]<<16) | (cp[2]<<8) | (cp[3]<<0);
|
||||
uint32_t vall = (cp[4]<<24) | (cp[5]<<16) | (cp[6]<<8) | (cp[7]<<0);
|
||||
uint64_t val = ((uint64_t)valh<<32) | vall;
|
||||
mp += 3;
|
||||
cp += 8;
|
||||
ebus_dval = val;
|
||||
mbus_dval = val;
|
||||
} else if (!strncmp(mp, "u64", 3)) {
|
||||
uint64_t valh = (cp[1]<<24) | (cp[0]<<16) | (cp[3]<<8) | (cp[2]<<0);
|
||||
uint64_t vall = (cp[5]<<24) | (cp[4]<<16) | (cp[7]<<8) | (cp[6]<<0);
|
||||
uint64_t val = ((uint64_t)valh<<32) | vall;
|
||||
mp += 3;
|
||||
cp += 8;
|
||||
ebus_dval = val;
|
||||
mbus_dval = val;
|
||||
} else if (!strncmp(mp, "U32", 3)) {
|
||||
mp += 3;
|
||||
goto U32_do;
|
||||
} else if (!strncmp(mp, "UUuuUUuu", 8)) {
|
||||
uint32_t val = (cp[0]<<24) | (cp[1]<<16) | (cp[2]<<8) | (cp[3]<<0);
|
||||
mp += 8;
|
||||
U32_do:
|
||||
uint32_t val = (cp[0]<<24) | (cp[1]<<16) | (cp[2]<<8) | (cp[3]<<0);
|
||||
cp += 4;
|
||||
if (*mp == 's') {
|
||||
mp++;
|
||||
|
@ -1874,9 +1895,13 @@ void SML_Decode(uint8_t index) {
|
|||
}
|
||||
ebus_dval = val;
|
||||
mbus_dval = val;
|
||||
} else if (!strncmp(mp, "u32", 3)) {
|
||||
mp += 3;
|
||||
goto u32_do;
|
||||
} else if (!strncmp(mp, "uuUUuuUU", 8)) {
|
||||
uint32_t val = (cp[1]<<24) | (cp[0]<<16) | (cp[3]<<8) | (cp[2]<<0);
|
||||
mp += 8;
|
||||
u32_do:
|
||||
uint32_t val = (cp[1]<<24) | (cp[0]<<16) | (cp[3]<<8) | (cp[2]<<0);
|
||||
cp += 4;
|
||||
if (*mp == 's') {
|
||||
mp++;
|
||||
|
@ -1891,9 +1916,13 @@ void SML_Decode(uint8_t index) {
|
|||
ebus_dval = val;
|
||||
mp += 4;
|
||||
cp += 2;
|
||||
} else if (!strncmp(mp, "S32", 3)) {
|
||||
mp += 3;
|
||||
goto S32_do;
|
||||
} else if (!strncmp(mp, "SSssSSss", 8)) {
|
||||
int32_t val = (cp[0]<<24) | (cp[1]<<16) | (cp[2]<<8) | (cp[3]<<0);
|
||||
mp += 8;
|
||||
S32_do:
|
||||
int32_t val = (cp[0]<<24) | (cp[1]<<16) | (cp[2]<<8) | (cp[3]<<0);
|
||||
cp += 4;
|
||||
if (*mp == 's') {
|
||||
mp++;
|
||||
|
@ -1902,9 +1931,13 @@ void SML_Decode(uint8_t index) {
|
|||
}
|
||||
ebus_dval = val;
|
||||
mbus_dval = val;
|
||||
} else if (!strncmp(mp, "s32", 3)) {
|
||||
mp += 3;
|
||||
goto s32_do;
|
||||
} else if (!strncmp(mp, "ssSSssSS", 8)) {
|
||||
int32_t val = (cp[1]<<24) | (cp[0]<<16) | (cp[3]<<8) | (cp[2]<<0);
|
||||
mp += 8;
|
||||
s32_do:
|
||||
int32_t val = (cp[1]<<24) | (cp[0]<<16) | (cp[3]<<8) | (cp[2]<<0);
|
||||
cp += 4;
|
||||
if (*mp == 's') {
|
||||
mp++;
|
||||
|
@ -2203,11 +2236,13 @@ void SML_Decode(uint8_t index) {
|
|||
dval = mbus_dval;
|
||||
mp++;
|
||||
} else {
|
||||
uint16_t pos = meter_desc[mindex].sbuff[2] + 3;
|
||||
if (pos > (meter_desc[mindex].sbsiz - 2)) pos = meter_desc[mindex].sbsiz - 2;
|
||||
uint16_t crc = MBUS_calculateCRC(&meter_desc[mindex].sbuff[0], pos, 0xFFFF);
|
||||
if (lowByte(crc) != meter_desc[mindex].sbuff[pos]) goto nextsect;
|
||||
if (highByte(crc) != meter_desc[mindex].sbuff[pos + 1]) goto nextsect;
|
||||
if (meter_desc[mindex].srcpin != TCP_MODE_FLG) {
|
||||
uint16_t pos = meter_desc[mindex].sbuff[2] + 3;
|
||||
if (pos > (meter_desc[mindex].sbsiz - 2)) pos = meter_desc[mindex].sbsiz - 2;
|
||||
uint16_t crc = MBUS_calculateCRC(&meter_desc[mindex].sbuff[0], pos, 0xFFFF);
|
||||
if (lowByte(crc) != meter_desc[mindex].sbuff[pos]) goto nextsect;
|
||||
if (highByte(crc) != meter_desc[mindex].sbuff[pos + 1]) goto nextsect;
|
||||
}
|
||||
dval = mbus_dval;
|
||||
//AddLog(LOG_LEVEL_INFO, PSTR(">> %s"),mp);
|
||||
mp++;
|
||||
|
@ -3620,7 +3655,7 @@ typedef struct {
|
|||
} MODBUS_TCP_HEADER;
|
||||
|
||||
uint16_t sml_swap(uint16_t in) {
|
||||
return (in << 8) || in >> 8;
|
||||
return (in << 8) | in >> 8;
|
||||
}
|
||||
|
||||
// send modbus TCP frame with payload
|
||||
|
|
Loading…
Reference in New Issue