Skip to content

Commit

Permalink
replace vars in meter def
Browse files Browse the repository at this point in the history
  • Loading branch information
gemu2015 committed May 16, 2024
1 parent 3c20e25 commit 1605975
Showing 1 changed file with 63 additions and 53 deletions.
116 changes: 63 additions & 53 deletions tasmota/tasmota_xsns_sensor/xsns_53_sml.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3145,28 +3145,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);
Expand All @@ -3175,7 +3185,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:
Expand All @@ -3185,73 +3195,73 @@ 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);
goto 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;
Expand All @@ -3262,15 +3272,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) {
Expand All @@ -3292,7 +3302,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) {
Expand All @@ -3307,11 +3317,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;
Expand Down

0 comments on commit 1605975

Please sign in to comment.