Skip to content

Commit cbff866

Browse files
authored
replace vars in descriptor + line (#21622)
1 parent 95f6032 commit cbff866

File tree

1 file changed

+63
-53
lines changed

1 file changed

+63
-53
lines changed

tasmota/tasmota_xsns_sensor/xsns_53_sml.ino

Lines changed: 63 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3156,28 +3156,38 @@ void SML_Init(void) {
31563156
// add descriptor +1,1,c,0,10,H20
31573157
//toLogEOL(">>",lp);
31583158
lp++;
3159-
index = *lp & 7;
3160-
lp += 2;
3159+
char *lp1;
3160+
#ifdef SML_REPLACE_VARS
3161+
char dstbuf[SML_SRCBSIZE*2];
3162+
Replace_Cmd_Vars(lp, 1, dstbuf, sizeof(dstbuf));
3163+
lp += SML_getlinelen(lp);
3164+
lp1 = dstbuf;
3165+
#else
3166+
lp1 = lp;
3167+
lp += SML_getlinelen(lp);
3168+
#endif
3169+
index = *lp1 & 7;
3170+
lp1 += 2;
31613171
if (index < 1 || index > sml_globs.meters_used) {
31623172
AddLog(LOG_LEVEL_INFO, PSTR("illegal meter number!"));
31633173
goto next_line;
31643174
}
31653175
index--;
31663176
mmp = &meter_desc[index];
3167-
if (*lp == '[') {
3177+
if (*lp1 == '[') {
31683178
// sign TCP mode
31693179
srcpin = TCP_MODE_FLG;
3170-
lp++;
3180+
lp1++;
31713181
char str[32];
31723182
uint8_t cnt;
31733183
for (cnt = 0; cnt < sizeof(str) - 1; cnt++) {
3174-
if (!*lp || *lp == '\n' || *lp == ']') {
3184+
if (!*lp1 || *lp1 == '\n' || *lp1 == ']') {
31753185
break;
31763186
}
3177-
str[cnt] = *lp++;
3187+
str[cnt] = *lp1++;
31783188
}
31793189
str[cnt] = 0;
3180-
lp++;
3190+
lp1++;
31813191
#ifdef USE_SML_TCP
31823192
#ifdef USE_SML_TCP_IP_STR
31833193
strcpy(mmp->ip_addr, str);
@@ -3186,7 +3196,7 @@ void SML_Init(void) {
31863196
#endif
31873197
#endif
31883198
} else {
3189-
srcpin = strtol(lp, &lp, 10);
3199+
srcpin = strtol(lp1, &lp1, 10);
31903200
if (Gpio_used(abs(srcpin))) {
31913201
AddLog(LOG_LEVEL_INFO, PSTR("SML: Error: Duplicate GPIO %d defined. Not usable for RX in meter number %d"), abs(srcpin), index + 1);
31923202
dddef_exit:
@@ -3196,73 +3206,73 @@ dddef_exit:
31963206
}
31973207
}
31983208
mmp->srcpin = srcpin;
3199-
if (*lp != ',') goto next_line;
3200-
lp++;
3201-
mmp->type = *lp;
3202-
lp++;
3203-
if (*lp != ',') {
3204-
switch (*lp) {
3209+
if (*lp1 != ',') goto next_line;
3210+
lp1++;
3211+
mmp->type = *lp1;
3212+
lp1++;
3213+
if (*lp1 != ',') {
3214+
switch (*lp1) {
32053215
case 'N':
3206-
lp++;
3207-
mmp->sopt = 0x10 | (*lp & 3);
3208-
lp++;
3216+
lp1++;
3217+
mmp->sopt = 0x10 | (*lp1 & 3);
3218+
lp1++;
32093219
break;
32103220
case 'E':
3211-
lp++;
3212-
mmp->sopt = 0x20 | (*lp & 3);
3213-
lp++;
3221+
lp1++;
3222+
mmp->sopt = 0x20 | (*lp1 & 3);
3223+
lp1++;
32143224
break;
32153225
case 'O':
3216-
lp++;
3217-
mmp->sopt = 0x30 | (*lp & 3);
3218-
lp++;
3226+
lp1++;
3227+
mmp->sopt = 0x30 | (*lp1 & 3);
3228+
lp1++;
32193229
break;
32203230
default:
3221-
mmp->sopt = *lp&7;
3222-
lp++;
3231+
mmp->sopt = *lp1&7;
3232+
lp1++;
32233233
}
32243234
} else {
32253235
mmp->sopt = 0;
32263236
}
3227-
lp++;
3228-
mmp->flag = strtol(lp, &lp, 10);
3229-
if (*lp != ',') goto next_line;
3230-
lp++;
3231-
mmp->params = strtol(lp, &lp, 10);
3232-
if (*lp != ',') goto next_line;
3233-
lp++;
3237+
lp1++;
3238+
mmp->flag = strtol(lp1, &lp1, 10);
3239+
if (*lp1 != ',') goto next_line;
3240+
lp1++;
3241+
mmp->params = strtol(lp1, &lp1, 10);
3242+
if (*lp1 != ',') goto next_line;
3243+
lp1++;
32343244
mmp->prefix[SML_PREFIX_SIZE - 1] = 0;
32353245
for (uint32_t cnt = 0; cnt < SML_PREFIX_SIZE; cnt++) {
3236-
if (*lp == SCRIPT_EOL || *lp == ',') {
3246+
if (*lp1 == SCRIPT_EOL || *lp1 == ',') {
32373247
mmp->prefix[cnt] = 0;
32383248
break;
32393249
}
3240-
mmp->prefix[cnt] = *lp++;
3250+
mmp->prefix[cnt] = *lp1++;
32413251
}
3242-
if (*lp == ',') {
3243-
lp++;
3252+
if (*lp1 == ',') {
3253+
lp1++;
32443254
// get TRX pin
3245-
mmp->trxpin = strtol(lp, &lp, 10);
3255+
mmp->trxpin = strtol(lp1, &lp1, 10);
32463256
if (mmp->srcpin != TCP_MODE_FLG) {
32473257
if (Gpio_used(mmp->trxpin)) {
32483258
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);
32493259
goto dddef_exit;
32503260
}
32513261
}
32523262
// optional transmit enable pin
3253-
if (*lp == '(') {
3254-
lp++;
3255-
if (*lp == 'i') {
3256-
lp++;
3263+
if (*lp1 == '(') {
3264+
lp1++;
3265+
if (*lp1 == 'i') {
3266+
lp1++;
32573267
mmp->trx_en.trxenpol = 1;
32583268
} else {
32593269
mmp->trx_en.trxenpol = 0;
32603270
}
3261-
mmp->trx_en.trxenpin = strtol(lp, &lp, 10);
3262-
if (*lp != ')') {
3271+
mmp->trx_en.trxenpin = strtol(lp1, &lp1, 10);
3272+
if (*lp1 != ')') {
32633273
goto dddef_exit;
32643274
}
3265-
lp++;
3275+
lp1++;
32663276
if (Gpio_used(mmp->trx_en.trxenpin)) {
32673277
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);
32683278
goto dddef_exit;
@@ -3273,15 +3283,15 @@ dddef_exit:
32733283
} else {
32743284
mmp->trx_en.trxen = 0;
32753285
}
3276-
if (*lp != ',') goto next_line;
3277-
lp++;
3278-
mmp->tsecs = strtol(lp, &lp, 10);
3279-
if (*lp == ',') {
3280-
lp++;
3286+
if (*lp1 != ',') goto next_line;
3287+
lp1++;
3288+
mmp->tsecs = strtol(lp1, &lp1, 10);
3289+
if (*lp1 == ',') {
3290+
lp1++;
32813291
// look ahead
32823292
uint16_t txlen = 0;
32833293
uint16_t tx_entries = 1;
3284-
char *txp = lp;
3294+
char *txp = lp1;
32853295
while (*txp) {
32863296
if (*txp == ',') tx_entries++;
32873297
if (*txp == SCRIPT_EOL) {
@@ -3303,7 +3313,7 @@ dddef_exit:
33033313
memory += txlen + 2;
33043314
if (mmp->txmem) {
33053315
// now copy send blocks
3306-
char *txp = lp;
3316+
char *txp = lp1;
33073317
uint16_t tind = 0;
33083318
for (uint32_t cnt = 0; cnt < txlen; cnt++) {
33093319
if (*txp == SCRIPT_EOL) {
@@ -3318,11 +3328,11 @@ dddef_exit:
33183328
mmp->index = 0;
33193329
mmp->max_index = tx_entries;
33203330
sml_globs.sml_send_blocks++;
3321-
lp += txlen;
3331+
lp1 += txlen;
33223332
}
33233333
}
33243334
}
3325-
if (*lp == SCRIPT_EOL) lp--;
3335+
if (*lp1 == SCRIPT_EOL) lp1--;
33263336
goto next_line;
33273337
}
33283338
char *lp1;

0 commit comments

Comments
 (0)