Fix exception 28 on HRG15

Fix exception 28 on HRG15 (#14067)
This commit is contained in:
Theo Arends 2021-12-17 11:31:29 +01:00
parent cdab49cfdd
commit 776fa99ee6
1 changed files with 10 additions and 13 deletions

View File

@ -53,8 +53,7 @@ struct RG15 {
float rate = 0.0f; float rate = 0.0f;
} Rg15; } Rg15;
void Rg15Init(void) void Rg15Init(void) {
{
Rg15.ready = 0; Rg15.ready = 0;
if (PinUsed(GPIO_HRG15_RX) && PinUsed(GPIO_HRG15_TX)) { if (PinUsed(GPIO_HRG15_RX) && PinUsed(GPIO_HRG15_TX)) {
HydreonSerial = new TasmotaSerial(Pin(GPIO_HRG15_RX), Pin(GPIO_HRG15_TX)); HydreonSerial = new TasmotaSerial(Pin(GPIO_HRG15_RX), Pin(GPIO_HRG15_TX));
@ -92,8 +91,7 @@ bool Rg15Poll(void) {
while (HydreonSerial->available()) { while (HydreonSerial->available()) {
Rg15ReadLine(rg15_buffer); Rg15ReadLine(rg15_buffer);
AddLog(LOG_LEVEL_DEBUG_MORE,PSTR("%s:" D_JSON_SERIALRECEIVED " = %s"),"HRG", rg15_buffer); AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("HRG: Received '%s'"), rg15_buffer);
Rg15Process(rg15_buffer); Rg15Process(rg15_buffer);
} }
@ -102,11 +100,11 @@ bool Rg15Poll(void) {
return true; return true;
} }
bool Rg15ReadLine(char* buffer) bool Rg15ReadLine(char* buffer) {
{
char c; char c;
uint8_t i = 0; uint8_t i = 0;
uint32_t cmillis = millis(); uint32_t cmillis = millis();
buffer[0] = '\0';
while (1) { while (1) {
if (HydreonSerial->available()) { if (HydreonSerial->available()) {
@ -121,8 +119,7 @@ bool Rg15ReadLine(char* buffer)
return false; return false;
} }
} }
if (i > 1) { buffer[i-2] = '\0'; }
buffer[i-2] = '\0';
return true; return true;
} }
@ -163,14 +160,14 @@ bool Rg15Command(void) {
HydreonSerial->flush(); HydreonSerial->flush();
if (send[0] == 'k' || send[0] == 'K' || send[0] == 'o' || send[0] == 'O') { if (send[0] == 'k' || send[0] == 'K' || send[0] == 'o' || send[0] == 'O') {
ResponseCmndDone(); ResponseCmndDone();
return serviced; return serviced;
} }
char rg15_buffer[255]; char rg15_buffer[255];
if (Rg15ReadLine(rg15_buffer)) { if (Rg15ReadLine(rg15_buffer)) {
Response_P(PSTR("{\"" D_JSON_SERIALRECEIVED "\":%s\"}"), rg15_buffer); Response_P(PSTR("{\"" D_JSON_SERIALRECEIVED "\":\"%s\"}"), rg15_buffer);
Rg15Process(rg15_buffer); Rg15Process(rg15_buffer);
} }
} }
@ -184,7 +181,7 @@ void Rg15Show(bool json)
} }
if (json) { if (json) {
ResponseAppend_P(PSTR(",\"" RG15_NAME "\":{\"" D_JSON_ACTIVE "\":%2_f, \"" D_JSON_EVENT "\":%2_f, \"" D_JSON_TOTAL "\":%2_f, \"" D_JSON_FLOWRATE "\":%2_f}"), &Rg15.acc, &Rg15.event, &Rg15.total, &Rg15.rate); ResponseAppend_P(PSTR(",\"" RG15_NAME "\":{\"" D_JSON_ACTIVE "\":%2_f,\"" D_JSON_EVENT "\":%2_f,\"" D_JSON_TOTAL "\":%2_f,\"" D_JSON_FLOWRATE "\":%2_f}"), &Rg15.acc, &Rg15.event, &Rg15.total, &Rg15.rate);
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
} else { } else {
WSContentSend_PD(HTTP_RG15, &Rg15.acc, &Rg15.event, &Rg15.total, &Rg15.rate); WSContentSend_PD(HTTP_RG15, &Rg15.acc, &Rg15.event, &Rg15.total, &Rg15.rate);