serial dump recoded

This commit is contained in:
gemu2015 2021-02-25 14:36:37 +01:00
parent d600768d49
commit dc92fc6c61
1 changed files with 120 additions and 81 deletions

View File

@ -490,6 +490,8 @@ uint8_t smltbuf[MAX_METERS][SML_BSIZ];
#define METER_ID_SIZE 24 #define METER_ID_SIZE 24
char meter_id[MAX_METERS][METER_ID_SIZE]; char meter_id[MAX_METERS][METER_ID_SIZE];
#define VBUS_SYNC 0xaa
#define SML_SYNC 0x77
#define EBUS_SYNC 0xaa #define EBUS_SYNC 0xaa
#define EBUS_ESC 0xa9 #define EBUS_ESC 0xa9
@ -823,41 +825,44 @@ uint8_t Serial_peek() {
uint8_t sml_logindex; uint8_t sml_logindex;
char log_data[128]; char log_data[128];
#define SML_EBUS_SKIP_SYNC_DUMPS
void Dump2log(void) { void Dump2log(void) {
int16_t index=0,hcnt=0; int16_t index = 0, hcnt = 0;
uint32_t d_lastms; uint32_t d_lastms;
uint8_t dchars[16]; uint8_t dchars[16];
uint8_t type = meter_desc_p[(dump2log&7) - 1].type;
//if (!SML_SAVAILABLE) return; //if (!SML_SAVAILABLE) return;
if (dump2log&8) { if (dump2log&8) {
// combo mode // combo mode
while (SML_SAVAILABLE) { while (SML_SAVAILABLE) {
log_data[index]=':'; log_data[index] = ':';
index++; index++;
log_data[index]=' '; log_data[index] = ' ';
index++; index++;
d_lastms=millis(); d_lastms = millis();
while ((millis()-d_lastms)<40) { while ((millis() - d_lastms) < 40) {
if (SML_SAVAILABLE) { if (SML_SAVAILABLE) {
uint8_t c=SML_SREAD; uint8_t c = SML_SREAD;
sprintf(&log_data[index],"%02x ",c); sprintf(&log_data[index], "%02x ", c);
dchars[hcnt]=c; dchars[hcnt] = c;
index+=3; index += 3;
hcnt++; hcnt++;
if (hcnt>15) { if (hcnt > 15) {
// line complete, build asci chars // line complete, build asci chars
log_data[index]='='; log_data[index] = '=';
index++; index++;
log_data[index]='>'; log_data[index] = '>';
index++; index++;
log_data[index]=' '; log_data[index] = ' ';
index++; index++;
for (uint8_t ccnt=0; ccnt<16; ccnt++) { for (uint8_t ccnt = 0; ccnt < 16; ccnt++) {
if (isprint(dchars[ccnt])) { if (isprint(dchars[ccnt])) {
log_data[index]=dchars[ccnt]; log_data[index] = dchars[ccnt];
} else { } else {
log_data[index]=' '; log_data[index] = ' ';
} }
index++; index++;
} }
@ -865,89 +870,116 @@ void Dump2log(void) {
} }
} }
} }
if (index>0) { if (index > 0) {
log_data[index]=0; log_data[index] = 0;
AddLogData(LOG_LEVEL_INFO, log_data); AddLogData(LOG_LEVEL_INFO, log_data);
index=0; index = 0;
hcnt=0; hcnt = 0;
} }
} }
} else { } else {
if (meter_desc_p[(dump2log&7)-1].type=='o') { if (type == 'o') {
// obis // obis
while (SML_SAVAILABLE) { while (SML_SAVAILABLE) {
char c=SML_SREAD&0x7f; char c = SML_SREAD&0x7f;
if (c=='\n' || c=='\r') { if (c == '\n' || c == '\r') {
log_data[sml_logindex]=0; if (sml_logindex > 2) {
AddLogData(LOG_LEVEL_INFO, log_data); AddLogData(LOG_LEVEL_INFO, log_data);
sml_logindex=2; log_data[sml_logindex] = 0;
log_data[0]=':'; log_data[0] = ':';
log_data[1]=' '; log_data[1] = ' ';
break; sml_logindex = 2;
}
continue;
} }
log_data[sml_logindex]=c; log_data[sml_logindex] = c;
if (sml_logindex<sizeof(log_data)-2) { if (sml_logindex < sizeof(log_data) - 2) {
sml_logindex++; sml_logindex++;
} }
} }
} else { } else if (type == 'v') {
//while (SML_SAVAILABLE) { // vbus
index=0; uint8_t c;
log_data[index]=':'; while (SML_SAVAILABLE) {
index++; c = SML_SREAD;
log_data[index]=' '; if (c == VBUS_SYNC) {
index++; AddLogData(LOG_LEVEL_INFO, log_data);
d_lastms=millis(); log_data[0] = ':';
while ((millis()-d_lastms)<40) { log_data[1] = ' ';
if (SML_SAVAILABLE) { sml_logindex = 2;
unsigned char c; }
if (meter_desc_p[(dump2log&7)-1].type=='e') { sprintf(&log_data[sml_logindex], "%02x ", c);
// ebus if (sml_logindex < sizeof(log_data) - 7) {
c=SML_SREAD; sml_logindex += 3;
sprintf(&log_data[index],"%02x ",c);
index+=3;
if (c==EBUS_SYNC) {
#if SML_EBUS_SKIP_SYNC_DUMPS
index = index == 5 ? 0 : index;
#endif
break;
}
} else if (meter_desc_p[(dump2log&7)-1].type=='v') {
// vbus
c=SML_SREAD;
if (c==EBUS_SYNC) {
index = 0;
AddLogData(LOG_LEVEL_INFO, log_data);
}
sprintf(&log_data[index],"%02x ",c);
if (index<sizeof(log_data)-3) {
index+=3;
}
} else {
// sml
if (sml_start==0x77) {
sml_start=0;
} else {
c=SML_SPEAK;
if (c==0x77) {
sml_start=c;
break;
}
}
c=SML_SREAD;
sprintf(&log_data[index],"%02x ",c);
index+=3;
}
} }
} }
if (index>2 && (meter_desc_p[(dump2log&7)-1].type!='v')) { } else if (type == 'e') {
log_data[index]=0; // ebus
uint8_t c, p;
while (SML_SAVAILABLE) {
c = SML_SREAD;
if (c == EBUS_SYNC) {
p = SML_SPEAK;
if (p != EBUS_SYNC && sml_logindex > 5) {
// new packet, plot last one
AddLogData(LOG_LEVEL_INFO, log_data);
strcpy(&log_data[0], ": aa ");
sml_logindex = 5;
}
continue;
}
sprintf(&log_data[sml_logindex], "%02x ", c);
if (sml_logindex < sizeof(log_data) - 7) {
sml_logindex += 3;
}
}
} else if (type == 's') {
// sml
uint8_t c;
while (SML_SAVAILABLE) {
c = SML_SREAD;
if (c == SML_SYNC) {
AddLogData(LOG_LEVEL_INFO, log_data);
log_data[0] = ':';
log_data[1] = ' ';
sml_logindex = 2;
}
sprintf(&log_data[sml_logindex], "%02x ", c);
if (sml_logindex < sizeof(log_data) - 7) {
sml_logindex += 3;
}
}
} else {
// raw dump
d_lastms = millis();
log_data[0] = ':';
log_data[1] = ' ';
sml_logindex = 2;
while ((millis() - d_lastms) < 40) {
while (SML_SAVAILABLE) {
sprintf(&log_data[sml_logindex], "%02x ", SML_SREAD);
sml_logindex += 3;
}
}
if (sml_logindex > 2) {
AddLogData(LOG_LEVEL_INFO, log_data); AddLogData(LOG_LEVEL_INFO, log_data);
} }
} }
} }
} }
void Hexdump(uint8_t *sbuff, uint32_t slen) {
char cbuff[slen*3+10];
char *cp = cbuff;
*cp++ = '>';
*cp++ = ' ';
for (uint32_t cnt = 0; cnt < slen; cnt ++) {
sprintf(cp, "%02x ", sbuff[cnt]);
cp += 3;
}
AddLogData(LOG_LEVEL_INFO, cbuff);
}
#ifdef ED300L #ifdef ED300L
uint8_t sml_status[MAX_METERS]; uint8_t sml_status[MAX_METERS];
uint8_t g_mindex; uint8_t g_mindex;
@ -2733,6 +2765,13 @@ void SML_Send_Seq(uint32_t meter,char *seq) {
slen+=6; slen+=6;
} }
meter_ss[meter]->write(sbuff,slen); meter_ss[meter]->write(sbuff,slen);
if (dump2log) {
uint8_t type = meter_desc_p[(dump2log&7) - 1].type;
if (type == 'm' || type == 'M') {
Hexdump(sbuff, slen);
}
}
} }
#endif // USE_SCRIPT #endif // USE_SCRIPT