diff --git a/lib/obp60task/ObpNmea0183.h b/lib/obp60task/ObpNmea0183.h new file mode 100644 index 0000000..56a5db6 --- /dev/null +++ b/lib/obp60task/ObpNmea0183.h @@ -0,0 +1,54 @@ +#pragma once +#include "NMEA0183.h" +#include "GwNmea0183Msg.h" + +class ObpNmea0183 : public tNMEA0183 +{ +public: + bool GetMessageCor(SNMEA0183Msg &NMEA0183Msg) + { + if (!IsOpen()) + return false; + + bool result = false; + + while (port->available() > 0 && !result) + { + int NewByte = port->read(); + if (NewByte == '$' || NewByte == '!') + { // Message start + MsgInStarted = true; + MsgInPos = 0; + MsgInBuf[MsgInPos] = NewByte; + MsgInPos++; + } + else if (MsgInStarted) + { + MsgInBuf[MsgInPos] = NewByte; + if (NewByte == '*') + MsgCheckSumStartPos = MsgInPos; + MsgInPos++; + if (MsgCheckSumStartPos != SIZE_MAX and MsgCheckSumStartPos + 3 == MsgInPos) + { // We have full checksum and so full message + MsgInBuf[MsgInPos] = 0; // add null termination + if (NMEA0183Msg.SetMessageCor(MsgInBuf)) + { + NMEA0183Msg.SourceID = SourceID; + result = true; + } + MsgInStarted = false; + MsgInPos = 0; + MsgCheckSumStartPos = SIZE_MAX; + } + if (MsgInPos >= MAX_NMEA0183_MSG_BUF_LEN) + { // Too may chars in message. Start from beginning + MsgInStarted = false; + MsgInPos = 0; + MsgCheckSumStartPos = SIZE_MAX; + } + } + } + + return result; + } +}; diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index 106bead..97634a2 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -28,8 +28,12 @@ #include "Logo_OBP_400x300_sw.h" // OBP Logo #include "OBP60QRWiFi.h" // Functions lib for WiFi QR code +#include "ObpNmea0183.h" +#include "GwNmea0183Msg.h" + tNMEA0183Msg NMEA0183Msg; -tNMEA0183 NMEA0183; +ObpNmea0183 NMEA0183; // Fixed Lib for NMEA0183 +// tNMEA0183 NMEA0183; // Old lib with problems for NMEA0183 Adafruit_BME280 bme280; // Evironment sensor BME280 Adafruit_BMP280 bmp280; // Evironment sensor BMEP280 @@ -520,6 +524,7 @@ void OBP60Task(GwApi *api){ long starttime6 = millis(); // Environment sensor update all 1s while (true){ + delay(10); // Fixed the problem with NMEA0183 and GPS sentences Timer1.update(); // Update for Timer1 Timer2.update(); // Update for Timer2 if(millis() > starttime0 + 100){