diff --git a/others/src/additions/additions.cpp b/others/src/additions/additions.cpp index 2661127..6325ec0 100644 --- a/others/src/additions/additions.cpp +++ b/others/src/additions/additions.cpp @@ -30,27 +30,18 @@ extern ArmorFinder armorFinder; extern Energy energy; void uartReceive(Serial *pSerial) { - char buffer[20]; - int cnt = 0; + char buffer[30]; LOGM(STR_CTR(WORD_LIGHT_WHITE, "data receive start!")); while (true) { char byte = 0; memset(buffer, 0, sizeof(buffer)); - while (pSerial->ReadData((uint8_t *) &byte, 1) && byte != '\n') { - buffer[cnt++] = byte; - if (cnt >= sizeof(buffer)) { -// LOGE("data receive over flow!"); - cnt = 0; - } - } - if (cnt == 0 && byte == '\n') { - LOGM("%d", cnt); - } - if (cnt == sizeof(mcuData)) { + pSerial->ReadData((uint8_t *) &byte, sizeof(mcuData)+1); + if (buffer[sizeof(mcuData)] == '\n') { memcpy(&mcuData, buffer, sizeof(mcuData)); LOGM("Get, state:%c, mark:%d!", mcuData.state, (int) mcuData.mark); + }else{ + LOGW("corrupt data!"); } - cnt = 0; } } diff --git a/others/src/serial/serial.cpp b/others/src/serial/serial.cpp index 5192001..a2fe4ec 100644 --- a/others/src/serial/serial.cpp +++ b/others/src/serial/serial.cpp @@ -191,7 +191,7 @@ Serial::Serial(int nSpeed, char nEvent, int nBits, int nStop) : nSpeed(nSpeed), nEvent(nEvent), nBits(nBits), nStop(nStop) { if (wait_uart) { LOGM("Wait for serial be ready!"); - while (InitPort(nSpeed, nEvent, nBits, nStop) == false); + while (!InitPort(nSpeed, nEvent, nBits, nStop)); LOGM("Port set successfully!"); } else { if (InitPort(nSpeed, nEvent, nBits, nStop)) {