add hex to asci id option

This commit is contained in:
gemu2015 2022-09-08 14:35:04 +02:00
parent c1f8ef6909
commit 693309965c

View File

@ -1630,7 +1630,7 @@ void sml_shift_in(uint32_t meters,uint32_t shard) {
if (meter_spos[meters] >= SML_BSIZ) { if (meter_spos[meters] >= SML_BSIZ) {
meter_spos[meters] = 0; meter_spos[meters] = 0;
} }
if (iob == 0x0a) { if ((iob == 0x0a) || (iob == 0x0d)) {
SML_Decode(meters); SML_Decode(meters);
meter_spos[meters] = 0; meter_spos[meters] = 0;
} }
@ -2433,7 +2433,12 @@ void SML_Show(boolean json) {
tststr: tststr:
if (*cp=='#') { if (*cp=='#') {
// meter id // meter id
if (*(cp + 1) == 'x') {
// convert hex to asci
sml_hex_asci(mindex, tpowstr);
} else {
sprintf(tpowstr,"\"%s\"",&meter_id[mindex][0]); sprintf(tpowstr,"\"%s\"",&meter_id[mindex][0]);
}
mid=1; mid=1;
} else if (*cp=='(') { } else if (*cp=='(') {
if (meter_desc_p[mindex].type=='o') { if (meter_desc_p[mindex].type=='o') {
@ -3343,7 +3348,6 @@ uint32_t ctime=millis();
sml_counters[cindex].sml_cnt_updated = 0; sml_counters[cindex].sml_cnt_updated = 0;
} }
} }
cindex++; cindex++;
} }
@ -3412,6 +3416,21 @@ void SML_Check_Send(void) {
} }
} }
void sml_hex_asci(uint32_t mindex, char *tpowstr) {
char *cp = &meter_id[mindex][0];
uint16_t slen = strlen(cp);
slen &= 0xfffe;
uint16_t cnt;
*tpowstr++ = '"';
for (cnt = 0; cnt < slen; cnt += 2) {
uint8_t iob = (sml_hexnibble(cp[cnt]) << 4) | sml_hexnibble(cp[cnt + 1]);
*tpowstr++ = iob;
}
*tpowstr++ = '"';
*tpowstr = 0;
}
uint8_t sml_hexnibble(char chr) { uint8_t sml_hexnibble(char chr) {
uint8_t rVal = 0; uint8_t rVal = 0;
if (isdigit(chr)) { if (isdigit(chr)) {