mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-25 11:46:31 +00:00
optional prefix size and serial invert (#18717)
This commit is contained in:
parent
c1ec35a086
commit
e969bf0e0e
@ -166,7 +166,7 @@ class SML_ESP32_SERIAL : public Stream {
|
|||||||
public:
|
public:
|
||||||
SML_ESP32_SERIAL(uint32_t uart_index);
|
SML_ESP32_SERIAL(uint32_t uart_index);
|
||||||
virtual ~SML_ESP32_SERIAL();
|
virtual ~SML_ESP32_SERIAL();
|
||||||
bool begin(uint32_t speed, uint32_t smode, int32_t recpin, int32_t trxpin);
|
bool begin(uint32_t speed, uint32_t smode, int32_t recpin, int32_t trxpin, int32_t invert);
|
||||||
int32_t peek(void);
|
int32_t peek(void);
|
||||||
int read(void) override;
|
int read(void) override;
|
||||||
size_t write(uint8_t byte) override;
|
size_t write(uint8_t byte) override;
|
||||||
@ -226,7 +226,7 @@ void SML_ESP32_SERIAL::end(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SML_ESP32_SERIAL::begin(uint32_t speed, uint32_t smode, int32_t recpin, int32_t trxpin) {
|
bool SML_ESP32_SERIAL::begin(uint32_t speed, uint32_t smode, int32_t recpin, int32_t trxpin, int invert) {
|
||||||
if (!m_valid) { return false; }
|
if (!m_valid) { return false; }
|
||||||
|
|
||||||
m_buffer = 0;
|
m_buffer = 0;
|
||||||
@ -246,7 +246,7 @@ bool SML_ESP32_SERIAL::begin(uint32_t speed, uint32_t smode, int32_t recpin, int
|
|||||||
m_tx_pin = trxpin;
|
m_tx_pin = trxpin;
|
||||||
hws = new HardwareSerial(uart_index);
|
hws = new HardwareSerial(uart_index);
|
||||||
if (hws) {
|
if (hws) {
|
||||||
hws->begin(speed, cfgmode, m_rx_pin, m_tx_pin);
|
hws->begin(speed, cfgmode, m_rx_pin, m_tx_pin, invert);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -383,6 +383,15 @@ typedef union {
|
|||||||
};
|
};
|
||||||
} TRX_EN_TYPE;
|
} TRX_EN_TYPE;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
uint8_t data;
|
||||||
|
struct {
|
||||||
|
uint8_t SO_DWS74_BUG : 1;
|
||||||
|
uint8_t SO_OBIS_LINE : 1;
|
||||||
|
uint8_t SO_TRX_INVERT : 1;
|
||||||
|
};
|
||||||
|
} SO_FLAGS;
|
||||||
|
|
||||||
#ifndef TMSBSIZ
|
#ifndef TMSBSIZ
|
||||||
#define TMSBSIZ 256
|
#define TMSBSIZ 256
|
||||||
#endif
|
#endif
|
||||||
@ -391,19 +400,20 @@ typedef union {
|
|||||||
#define SML_STIMEOUT 1000
|
#define SML_STIMEOUT 1000
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SO_DWS74_BUG 1
|
|
||||||
#define SO_OBIS_LINE 2
|
|
||||||
|
|
||||||
#define METER_ID_SIZE 24
|
#define METER_ID_SIZE 24
|
||||||
|
|
||||||
#define SML_CRYPT_SIZE 16
|
#define SML_CRYPT_SIZE 16
|
||||||
|
|
||||||
|
#ifndef SML_PREFIX_SIZE
|
||||||
|
#define SML_PREFIX_SIZE 8
|
||||||
|
#endif
|
||||||
|
|
||||||
struct METER_DESC {
|
struct METER_DESC {
|
||||||
int8_t srcpin;
|
int8_t srcpin;
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint16_t flag;
|
uint16_t flag;
|
||||||
int32_t params;
|
int32_t params;
|
||||||
char prefix[8];
|
char prefix[SML_PREFIX_SIZE];
|
||||||
int8_t trxpin;
|
int8_t trxpin;
|
||||||
uint8_t tsecs;
|
uint8_t tsecs;
|
||||||
char *txmem;
|
char *txmem;
|
||||||
@ -419,7 +429,7 @@ struct METER_DESC {
|
|||||||
uint16_t sibsiz;
|
uint16_t sibsiz;
|
||||||
uint32_t lastms;
|
uint32_t lastms;
|
||||||
uint16_t tout_ms;
|
uint16_t tout_ms;
|
||||||
uint8_t so_flags;
|
SO_FLAGS so_flags;
|
||||||
char meter_id[METER_ID_SIZE];
|
char meter_id[METER_ID_SIZE];
|
||||||
#ifdef USE_SML_SPECOPT
|
#ifdef USE_SML_SPECOPT
|
||||||
uint32_t so_obis1;
|
uint32_t so_obis1;
|
||||||
@ -1018,7 +1028,7 @@ double dval;
|
|||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// signed 16 bit
|
// signed 16 bit
|
||||||
if (meter_desc[index].so_flags & SO_DWS74_BUG) {
|
if (meter_desc[index].so_flags.SO_DWS74_BUG) {
|
||||||
if (scaler == -2) {
|
if (scaler == -2) {
|
||||||
value = (uint32_t)uvalue;
|
value = (uint32_t)uvalue;
|
||||||
} else {
|
} else {
|
||||||
@ -1294,7 +1304,7 @@ void sml_shift_in(uint32_t meters, uint32_t shard) {
|
|||||||
switch (mp->type) {
|
switch (mp->type) {
|
||||||
case 'o':
|
case 'o':
|
||||||
// asci obis
|
// asci obis
|
||||||
if (!(mp->so_flags & SO_OBIS_LINE)) {
|
if (!(mp->so_flags.SO_OBIS_LINE)) {
|
||||||
mp->sbuff[mp->sbsiz - 1] = iob & 0x7f;
|
mp->sbuff[mp->sbsiz - 1] = iob & 0x7f;
|
||||||
} else {
|
} else {
|
||||||
iob &= 0x7f;
|
iob &= 0x7f;
|
||||||
@ -2619,7 +2629,7 @@ struct METER_DESC *mp = &meter_desc[mnum];
|
|||||||
break;
|
break;
|
||||||
case '2':
|
case '2':
|
||||||
cp += 2;
|
cp += 2;
|
||||||
mp->so_flags = strtol(cp, &cp, 16);
|
mp->so_flags.data = strtol(cp, &cp, 16);
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '3':
|
||||||
cp += 2;
|
cp += 2;
|
||||||
@ -2720,14 +2730,14 @@ void reset_sml_vars(uint16_t maxmeters) {
|
|||||||
mp->so_obis1 = 0;
|
mp->so_obis1 = 0;
|
||||||
mp->so_obis2 = 0;
|
mp->so_obis2 = 0;
|
||||||
#endif
|
#endif
|
||||||
mp->so_flags = 0;
|
mp->so_flags.data = 0;
|
||||||
// addresses a bug in meter DWS74
|
// addresses a bug in meter DWS74
|
||||||
#ifdef DWS74_BUG
|
#ifdef DWS74_BUG
|
||||||
mp->so_flags |= SO_DWS74_BUG;
|
mp->so_flags.SO_DWS74_BUG = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SML_OBIS_LINE
|
#ifdef SML_OBIS_LINE
|
||||||
mp->so_flags |= SO_OBIS_LINE;
|
mp->so_flags.SO_OBIS_LINE = 1;
|
||||||
#endif
|
#endif
|
||||||
if (mp->txmem) {
|
if (mp->txmem) {
|
||||||
free(mp->txmem);
|
free(mp->txmem);
|
||||||
@ -2931,8 +2941,8 @@ dddef_exit:
|
|||||||
mmp->params = strtol(lp, &lp, 10);
|
mmp->params = strtol(lp, &lp, 10);
|
||||||
if (*lp != ',') goto next_line;
|
if (*lp != ',') goto next_line;
|
||||||
lp++;
|
lp++;
|
||||||
mmp->prefix[7] = 0;
|
mmp->prefix[SML_PREFIX_SIZE - 1] = 0;
|
||||||
for (uint32_t cnt = 0; cnt < 8; cnt++) {
|
for (uint32_t cnt = 0; cnt < SML_PREFIX_SIZE; cnt++) {
|
||||||
if (*lp == SCRIPT_EOL || *lp == ',') {
|
if (*lp == SCRIPT_EOL || *lp == ',') {
|
||||||
mmp->prefix[cnt] = 0;
|
mmp->prefix[cnt] = 0;
|
||||||
break;
|
break;
|
||||||
@ -3208,12 +3218,14 @@ next_line:
|
|||||||
if (mp->meter_ss->hardwareSerial()) {
|
if (mp->meter_ss->hardwareSerial()) {
|
||||||
Serial.begin(mp->params, (SerialConfig)smode);
|
Serial.begin(mp->params, (SerialConfig)smode);
|
||||||
ClaimSerial();
|
ClaimSerial();
|
||||||
//Serial.setRxBufferSize(512);
|
if (mp->so_flags.SO_TRX_INVERT) {
|
||||||
|
U0C0 = U0C0 | BIT(UCRXI) | BIT(UCTXI); // Inverse RX, TX
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif // ESP8266
|
#endif // ESP8266
|
||||||
|
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
mp->meter_ss->begin(mp->params, smode, mp->srcpin, mp->trxpin);
|
mp->meter_ss->begin(mp->params, smode, mp->srcpin, mp->trxpin, mp->so_flags.SO_TRX_INVERT);
|
||||||
#ifdef USE_ESP32_SW_SERIAL
|
#ifdef USE_ESP32_SW_SERIAL
|
||||||
mp->meter_ss->setRxBufferSize(mp->sibsiz);
|
mp->meter_ss->setRxBufferSize(mp->sibsiz);
|
||||||
#endif
|
#endif
|
||||||
@ -3244,7 +3256,7 @@ next_line:
|
|||||||
struct METER_DESC *mp = &meter_desc[meters];
|
struct METER_DESC *mp = &meter_desc[meters];
|
||||||
char type = mp->type;
|
char type = mp->type;
|
||||||
|
|
||||||
if (!(mp->so_flags & SO_OBIS_LINE)) {
|
if (!(mp->so_flags.SO_OBIS_LINE)) {
|
||||||
mp->shift_mode = (type != 'e' && type != 'k' && type != 'm' && type != 'M' && type != 'p' && type != 'R' && type != 'v');
|
mp->shift_mode = (type != 'e' && type != 'k' && type != 'm' && type != 'M' && type != 'p' && type != 'R' && type != 'v');
|
||||||
} else {
|
} else {
|
||||||
mp->shift_mode = (type != 'o' && type != 'e' && type != 'k' && type != 'm' && type != 'M' && type != 'p' && type != 'R' && type != 'v');
|
mp->shift_mode = (type != 'o' && type != 'e' && type != 'k' && type != 'm' && type != 'M' && type != 'p' && type != 'R' && type != 'v');
|
||||||
@ -3337,7 +3349,7 @@ uint32_t SML_Write(int32_t meter, char *hstr) {
|
|||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
Serial.begin(baud, (SerialConfig)smode);
|
Serial.begin(baud, (SerialConfig)smode);
|
||||||
#else
|
#else
|
||||||
meter_desc[meter].meter_ss->begin(baud, smode, sml_globs.mp[meter].srcpin, sml_globs.mp[meter].trxpin);
|
meter_desc[meter].meter_ss->begin(baud, smode, sml_globs.mp[meter].srcpin, sml_globs.mp[meter].trxpin, sml_globs.mp[meter].so_flags.SO_TRX_INVERT);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@ -3616,7 +3628,9 @@ uint16_t sml_swap(uint16_t in) {
|
|||||||
void sml_tcp_send(uint32_t meter, uint8_t *sbuff, uint16_t slen) {
|
void sml_tcp_send(uint32_t meter, uint8_t *sbuff, uint16_t slen) {
|
||||||
MODBUS_TCP_HEADER tcph;
|
MODBUS_TCP_HEADER tcph;
|
||||||
|
|
||||||
tcph.T_ID = sml_swap(0x1234);
|
//tcph.T_ID = sml_swap(0x1234);
|
||||||
|
tcph.T_ID = random(0xffff);
|
||||||
|
|
||||||
tcph.P_ID = 0;
|
tcph.P_ID = 0;
|
||||||
tcph.SIZE = sml_swap(6);
|
tcph.SIZE = sml_swap(6);
|
||||||
tcph.U_ID = *sbuff;
|
tcph.U_ID = *sbuff;
|
||||||
@ -3990,6 +4004,7 @@ bool Xsns53(uint32_t function) {
|
|||||||
SML_Init();
|
SML_Init();
|
||||||
break;
|
break;
|
||||||
case FUNC_LOOP:
|
case FUNC_LOOP:
|
||||||
|
if (bitRead(Settings->rule_enabled, 0)) {
|
||||||
if (sml_globs.ready) {
|
if (sml_globs.ready) {
|
||||||
SML_Counter_Poll();
|
SML_Counter_Poll();
|
||||||
if (sml_globs.dump2log) {
|
if (sml_globs.dump2log) {
|
||||||
@ -3998,6 +4013,7 @@ bool Xsns53(uint32_t function) {
|
|||||||
SML_Poll();
|
SML_Poll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case FUNC_EVERY_100_MSECOND:
|
case FUNC_EVERY_100_MSECOND:
|
||||||
if (bitRead(Settings->rule_enabled, 0)) {
|
if (bitRead(Settings->rule_enabled, 0)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user