replace vars in descriptor + line (#21622)

This commit is contained in:
gemu 2024-06-14 10:14:44 +02:00 committed by GitHub
parent 95f6032d86
commit cbff86695f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 63 additions and 53 deletions

View File

@ -3156,28 +3156,38 @@ void SML_Init(void) {
// add descriptor +1,1,c,0,10,H20 // add descriptor +1,1,c,0,10,H20
//toLogEOL(">>",lp); //toLogEOL(">>",lp);
lp++; lp++;
index = *lp & 7; char *lp1;
lp += 2; #ifdef SML_REPLACE_VARS
char dstbuf[SML_SRCBSIZE*2];
Replace_Cmd_Vars(lp, 1, dstbuf, sizeof(dstbuf));
lp += SML_getlinelen(lp);
lp1 = dstbuf;
#else
lp1 = lp;
lp += SML_getlinelen(lp);
#endif
index = *lp1 & 7;
lp1 += 2;
if (index < 1 || index > sml_globs.meters_used) { if (index < 1 || index > sml_globs.meters_used) {
AddLog(LOG_LEVEL_INFO, PSTR("illegal meter number!")); AddLog(LOG_LEVEL_INFO, PSTR("illegal meter number!"));
goto next_line; goto next_line;
} }
index--; index--;
mmp = &meter_desc[index]; mmp = &meter_desc[index];
if (*lp == '[') { if (*lp1 == '[') {
// sign TCP mode // sign TCP mode
srcpin = TCP_MODE_FLG; srcpin = TCP_MODE_FLG;
lp++; lp1++;
char str[32]; char str[32];
uint8_t cnt; uint8_t cnt;
for (cnt = 0; cnt < sizeof(str) - 1; cnt++) { for (cnt = 0; cnt < sizeof(str) - 1; cnt++) {
if (!*lp || *lp == '\n' || *lp == ']') { if (!*lp1 || *lp1 == '\n' || *lp1 == ']') {
break; break;
} }
str[cnt] = *lp++; str[cnt] = *lp1++;
} }
str[cnt] = 0; str[cnt] = 0;
lp++; lp1++;
#ifdef USE_SML_TCP #ifdef USE_SML_TCP
#ifdef USE_SML_TCP_IP_STR #ifdef USE_SML_TCP_IP_STR
strcpy(mmp->ip_addr, str); strcpy(mmp->ip_addr, str);
@ -3186,7 +3196,7 @@ void SML_Init(void) {
#endif #endif
#endif #endif
} else { } else {
srcpin = strtol(lp, &lp, 10); srcpin = strtol(lp1, &lp1, 10);
if (Gpio_used(abs(srcpin))) { if (Gpio_used(abs(srcpin))) {
AddLog(LOG_LEVEL_INFO, PSTR("SML: Error: Duplicate GPIO %d defined. Not usable for RX in meter number %d"), abs(srcpin), index + 1); AddLog(LOG_LEVEL_INFO, PSTR("SML: Error: Duplicate GPIO %d defined. Not usable for RX in meter number %d"), abs(srcpin), index + 1);
dddef_exit: dddef_exit:
@ -3196,53 +3206,53 @@ dddef_exit:
} }
} }
mmp->srcpin = srcpin; mmp->srcpin = srcpin;
if (*lp != ',') goto next_line; if (*lp1 != ',') goto next_line;
lp++; lp1++;
mmp->type = *lp; mmp->type = *lp1;
lp++; lp1++;
if (*lp != ',') { if (*lp1 != ',') {
switch (*lp) { switch (*lp1) {
case 'N': case 'N':
lp++; lp1++;
mmp->sopt = 0x10 | (*lp & 3); mmp->sopt = 0x10 | (*lp1 & 3);
lp++; lp1++;
break; break;
case 'E': case 'E':
lp++; lp1++;
mmp->sopt = 0x20 | (*lp & 3); mmp->sopt = 0x20 | (*lp1 & 3);
lp++; lp1++;
break; break;
case 'O': case 'O':
lp++; lp1++;
mmp->sopt = 0x30 | (*lp & 3); mmp->sopt = 0x30 | (*lp1 & 3);
lp++; lp1++;
break; break;
default: default:
mmp->sopt = *lp&7; mmp->sopt = *lp1&7;
lp++; lp1++;
} }
} else { } else {
mmp->sopt = 0; mmp->sopt = 0;
} }
lp++; lp1++;
mmp->flag = strtol(lp, &lp, 10); mmp->flag = strtol(lp1, &lp1, 10);
if (*lp != ',') goto next_line; if (*lp1 != ',') goto next_line;
lp++; lp1++;
mmp->params = strtol(lp, &lp, 10); mmp->params = strtol(lp1, &lp1, 10);
if (*lp != ',') goto next_line; if (*lp1 != ',') goto next_line;
lp++; lp1++;
mmp->prefix[SML_PREFIX_SIZE - 1] = 0; mmp->prefix[SML_PREFIX_SIZE - 1] = 0;
for (uint32_t cnt = 0; cnt < SML_PREFIX_SIZE; cnt++) { for (uint32_t cnt = 0; cnt < SML_PREFIX_SIZE; cnt++) {
if (*lp == SCRIPT_EOL || *lp == ',') { if (*lp1 == SCRIPT_EOL || *lp1 == ',') {
mmp->prefix[cnt] = 0; mmp->prefix[cnt] = 0;
break; break;
} }
mmp->prefix[cnt] = *lp++; mmp->prefix[cnt] = *lp1++;
} }
if (*lp == ',') { if (*lp1 == ',') {
lp++; lp1++;
// get TRX pin // get TRX pin
mmp->trxpin = strtol(lp, &lp, 10); mmp->trxpin = strtol(lp1, &lp1, 10);
if (mmp->srcpin != TCP_MODE_FLG) { if (mmp->srcpin != TCP_MODE_FLG) {
if (Gpio_used(mmp->trxpin)) { if (Gpio_used(mmp->trxpin)) {
AddLog(LOG_LEVEL_INFO, PSTR("SML: Error: Duplicate GPIO %d defined. Not usable for TX in meter number %d"), meter_desc[index].trxpin, index + 1); AddLog(LOG_LEVEL_INFO, PSTR("SML: Error: Duplicate GPIO %d defined. Not usable for TX in meter number %d"), meter_desc[index].trxpin, index + 1);
@ -3250,19 +3260,19 @@ dddef_exit:
} }
} }
// optional transmit enable pin // optional transmit enable pin
if (*lp == '(') { if (*lp1 == '(') {
lp++; lp1++;
if (*lp == 'i') { if (*lp1 == 'i') {
lp++; lp1++;
mmp->trx_en.trxenpol = 1; mmp->trx_en.trxenpol = 1;
} else { } else {
mmp->trx_en.trxenpol = 0; mmp->trx_en.trxenpol = 0;
} }
mmp->trx_en.trxenpin = strtol(lp, &lp, 10); mmp->trx_en.trxenpin = strtol(lp1, &lp1, 10);
if (*lp != ')') { if (*lp1 != ')') {
goto dddef_exit; goto dddef_exit;
} }
lp++; lp1++;
if (Gpio_used(mmp->trx_en.trxenpin)) { if (Gpio_used(mmp->trx_en.trxenpin)) {
AddLog(LOG_LEVEL_INFO, PSTR("SML: Error: Duplicate GPIO %d defined. Not usable for TX enable in meter number %d"), meter_desc[index].trx_en.trxenpin, index + 1); AddLog(LOG_LEVEL_INFO, PSTR("SML: Error: Duplicate GPIO %d defined. Not usable for TX enable in meter number %d"), meter_desc[index].trx_en.trxenpin, index + 1);
goto dddef_exit; goto dddef_exit;
@ -3273,15 +3283,15 @@ dddef_exit:
} else { } else {
mmp->trx_en.trxen = 0; mmp->trx_en.trxen = 0;
} }
if (*lp != ',') goto next_line; if (*lp1 != ',') goto next_line;
lp++; lp1++;
mmp->tsecs = strtol(lp, &lp, 10); mmp->tsecs = strtol(lp1, &lp1, 10);
if (*lp == ',') { if (*lp1 == ',') {
lp++; lp1++;
// look ahead // look ahead
uint16_t txlen = 0; uint16_t txlen = 0;
uint16_t tx_entries = 1; uint16_t tx_entries = 1;
char *txp = lp; char *txp = lp1;
while (*txp) { while (*txp) {
if (*txp == ',') tx_entries++; if (*txp == ',') tx_entries++;
if (*txp == SCRIPT_EOL) { if (*txp == SCRIPT_EOL) {
@ -3303,7 +3313,7 @@ dddef_exit:
memory += txlen + 2; memory += txlen + 2;
if (mmp->txmem) { if (mmp->txmem) {
// now copy send blocks // now copy send blocks
char *txp = lp; char *txp = lp1;
uint16_t tind = 0; uint16_t tind = 0;
for (uint32_t cnt = 0; cnt < txlen; cnt++) { for (uint32_t cnt = 0; cnt < txlen; cnt++) {
if (*txp == SCRIPT_EOL) { if (*txp == SCRIPT_EOL) {
@ -3318,11 +3328,11 @@ dddef_exit:
mmp->index = 0; mmp->index = 0;
mmp->max_index = tx_entries; mmp->max_index = tx_entries;
sml_globs.sml_send_blocks++; sml_globs.sml_send_blocks++;
lp += txlen; lp1 += txlen;
} }
} }
} }
if (*lp == SCRIPT_EOL) lp--; if (*lp1 == SCRIPT_EOL) lp1--;
goto next_line; goto next_line;
} }
char *lp1; char *lp1;