multi trx lines (#22056)

This commit is contained in:
gemu 2024-09-07 15:29:27 +02:00 committed by GitHub
parent 8956b25de4
commit 2c5e8749e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 46 additions and 34 deletions

View File

@ -119,6 +119,10 @@
#endif #endif
#ifndef SML_TRX_BUFF_SIZE
#define SML_TRX_BUFF_SIZE 1024
#endif
#ifdef USE_SML_CANBUS #ifdef USE_SML_CANBUS
#ifdef ESP8266 #ifdef ESP8266
@ -443,6 +447,7 @@ typedef union {
uint8_t SO_DWS74_BUG : 1; uint8_t SO_DWS74_BUG : 1;
uint8_t SO_OBIS_LINE : 1; uint8_t SO_OBIS_LINE : 1;
uint8_t SO_TRX_INVERT : 1; uint8_t SO_TRX_INVERT : 1;
uint8_t SO_DISS_PULL : 1;
}; };
} SO_FLAGS; } SO_FLAGS;
@ -3286,50 +3291,51 @@ dddef_exit:
if (*lp1 != ',') goto next_line; if (*lp1 != ',') goto next_line;
lp1++; lp1++;
mmp->tsecs = strtol(lp1, &lp1, 10); mmp->tsecs = strtol(lp1, &lp1, 10);
// optional values to send
if (*lp1 == ',') { if (*lp1 == ',') {
lp1++; lp1++;
// look ahead // look ahead, lp points to next line
uint16_t txlen = 0; char *txbuff = (char *)malloc(SML_TRX_BUFF_SIZE);
uint16_t tx_entries = 1; if (!txbuff) {
goto dddef_exit;
}
char *txb1 = txbuff;
char *txp = lp1; char *txp = lp1;
while (*txp) { uint16_t tx_entries = 1;
if (*txp == ',') tx_entries++; uint16_t txlen = 0;
if (*txp == SCRIPT_EOL) { while (1) {
if (tx_entries > 1) { if (!*lp1 || (*lp1 == SCRIPT_EOL)) {
if (*(txp - 1) != ',' ) { if (*(lp1 - 1) == ',') {
break; // line ends with comma, add another line
} while (*lp == SCRIPT_EOL) lp++;
// line ends with , #ifdef SML_REPLACE_VARS
Replace_Cmd_Vars(lp, 1, dstbuf, sizeof(dstbuf));
lp += SML_getlinelen(lp);
lp1 = dstbuf;
#else
lp1 = lp;
lp += SML_getlinelen(lp);
#endif
} else { } else {
// single entry
break; break;
} }
} }
txp++; if (*lp1 == ',') tx_entries++;
*txb1++ = *lp1++;
txlen++; txlen++;
} if (txlen >= SML_TRX_BUFF_SIZE - 2) {
if (txlen) { break;
mmp->txmem = (char*)calloc(txlen + 2, 1);
memory += txlen + 2;
if (mmp->txmem) {
// now copy send blocks
char *txp = lp1;
uint16_t tind = 0;
for (uint32_t cnt = 0; cnt < txlen; cnt++) {
if (*txp == SCRIPT_EOL) {
txp++;
} else {
mmp->txmem[tind] = *txp++;
tind++;
}
}
} }
//AddLog(LOG_LEVEL_INFO, PSTR(">>> %s - %d"), meter_desc[index].txmem, txlen);
mmp->index = 0;
mmp->max_index = tx_entries;
sml_globs.sml_send_blocks++;
lp1 += txlen;
} }
// tx lines complete
*txb1 = 0;
//AddLog(LOG_LEVEL_INFO, PSTR("SML: >>> %s - %d - %d"), txbuff, txlen, tx_entries);
mmp->txmem = (char*)realloc(txbuff, txlen + 2);
memory += txlen + 2;
mmp->index = 0;
mmp->max_index = tx_entries;
sml_globs.sml_send_blocks++;
// end collect transmit values
} }
} }
if (*lp1 == SCRIPT_EOL) lp1--; if (*lp1 == SCRIPT_EOL) lp1--;
@ -3639,6 +3645,9 @@ next_line:
#ifdef ESP32 #ifdef ESP32
mp->meter_ss->begin(mp->params, smode, mp->srcpin, mp->trxpin, mp->so_flags.SO_TRX_INVERT); mp->meter_ss->begin(mp->params, smode, mp->srcpin, mp->trxpin, mp->so_flags.SO_TRX_INVERT);
if (mp->so_flags.SO_DISS_PULL) {
gpio_pullup_dis((gpio_num_t)mp->srcpin);
}
#ifdef USE_ESP32_SW_SERIAL #ifdef USE_ESP32_SW_SERIAL
mp->meter_ss->setRxBufferSize(mp->sibsiz); mp->meter_ss->setRxBufferSize(mp->sibsiz);
#endif #endif
@ -3770,6 +3779,9 @@ uint32_t SML_Write(int32_t meter, char *hstr) {
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, sml_globs.mp[meter].so_flags.SO_TRX_INVERT); 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);
if (sml_globs.mp[meter].so_flags.SO_DISS_PULL) {
gpio_pullup_dis((gpio_num_t)sml_globs.mp[meter].srcpin);
}
#endif #endif
} }
return 1; return 1;