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