From c5449a91a69d63d41a081344feccd27987047fac Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Sat, 2 Nov 2024 16:28:22 +0100 Subject: [PATCH] Fix for GPS and RTC see issue #79 and #88 --- lib/obp60task/OBP60Extensions.cpp | 3 ++- lib/obp60task/OBPSensorTask.cpp | 12 +++++++----- lib/obp60task/config.json | 14 ++++++++++++++ lib/obp60task/obp60task.cpp | 5 +++-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/obp60task/OBP60Extensions.cpp b/lib/obp60task/OBP60Extensions.cpp index 28ca085..5cd3175 100644 --- a/lib/obp60task/OBP60Extensions.cpp +++ b/lib/obp60task/OBP60Extensions.cpp @@ -234,7 +234,7 @@ void displayHeader(CommonData &commonData, GwApi::BoatValue *date, GwApi::BoatVa getdisplay().print("USB "); } double gpshdop = formatValue(hdop, commonData).value; - if(commonData.config->getString(commonData.config->useGPS) != "off" && gpshdop > 0.3){ + if(commonData.config->getString(commonData.config->useGPS) != "off" && gpshdop <= commonData.config->getInt(commonData.config->hdopAccuracy) && hdop->valid == true){ getdisplay().print("GPS"); } // Save old telegram counter @@ -265,6 +265,7 @@ void displayHeader(CommonData &commonData, GwApi::BoatValue *date, GwApi::BoatVa getdisplay().setTextColor(textcolor); getdisplay().setFont(&Ubuntu_Bold8pt7b); getdisplay().setCursor(230, 15); + // Show date and time if date present if(date->valid == true){ String acttime = formatValue(time, commonData).svalue; acttime = acttime.substring(0, 5); diff --git a/lib/obp60task/OBPSensorTask.cpp b/lib/obp60task/OBPSensorTask.cpp index 9326608..be9f1b1 100644 --- a/lib/obp60task/OBPSensorTask.cpp +++ b/lib/obp60task/OBPSensorTask.cpp @@ -147,6 +147,7 @@ void sensorTask(void *param){ // Settings for GPS sensors String gpsOn=api->getConfig()->getConfigItem(api->getConfig()->useGPS,true)->asString(); + uint hdopAccuracy = uint(api->getConfig()->getConfigItem(api->getConfig()->hdopAccuracy,true)->asInt()); if(String(gpsOn) == "NEO-6M"){ Serial2.begin(9600, SERIAL_8N1, OBP_GPS_RX, OBP_GPS_TX, false); // not inverted (false) if (!Serial2) { @@ -354,7 +355,8 @@ void sensorTask(void *param){ GwApi::BoatValue *gpsdays=new GwApi::BoatValue(GwBoatData::_GPSD); GwApi::BoatValue *gpsseconds=new GwApi::BoatValue(GwBoatData::_GPST); - GwApi::BoatValue *valueList[]={gpsdays, gpsseconds}; + GwApi::BoatValue *hdop=new GwApi::BoatValue(GwBoatData::_HDOP); + GwApi::BoatValue *valueList[]={gpsdays, gpsseconds, hdop}; // Sensor task loop runs with 100ms //#################################################################################### @@ -366,7 +368,7 @@ void sensorTask(void *param){ { starttime0 = millis(); // Send NMEA0183 GPS data on several bus systems all 100ms - if (GPS_ready == true) + if (GPS_ready == true && hdop->value <= hdopAccuracy) { SNMEA0183Msg NMEA0183Msg; while (NMEA0183.GetMessageCor(NMEA0183Msg)) @@ -381,8 +383,8 @@ void sensorTask(void *param){ if(millis() > starttime11 + 5*60*1000){ starttime11 = millis(); if(rtcOn == "DS1388" && RTC_ready == true && GPS_ready == true){ - api->getBoatDataValues(2,valueList); - if(gpsdays->valid && gpsseconds->valid){ + api->getBoatDataValues(3,valueList); + if(gpsdays->valid && gpsseconds->valid && hdop->valid){ long ts = tNMEA0183Msg::daysToTime_t(gpsdays->value - (30*365+7))+floor(gpsseconds->value); // Adjusted to reference year 2000 (-30 years and 7 days for switch years) // sample input: date = "Dec 26 2009", time = "12:34:56" // ds1388.adjust(DateTime("Dec 26 2009", "12:34:56")); @@ -421,7 +423,7 @@ void sensorTask(void *param){ // If GPS not ready or installed then send RTC time on bus all 500ms if(millis() > starttime12 + 500){ starttime12 = millis(); - if(rtcOn == "DS1388" && RTC_ready == true && GPS_ready == false){ + if((rtcOn == "DS1388" && RTC_ready == true && GPS_ready == false) || (rtcOn == "DS1388" && RTC_ready == true && GPS_ready == true && hdop->valid == false)){ // Convert RTC time to Unix system time // https://de.wikipedia.org/wiki/Unixzeit const short daysOfYear[12] = {0,31,59,90,120,151,181,212,243,273,304,334}; diff --git a/lib/obp60task/config.json b/lib/obp60task/config.json index 4c04804..9704d56 100644 --- a/lib/obp60task/config.json +++ b/lib/obp60task/config.json @@ -311,6 +311,20 @@ "obp60":"true" } }, + { + "name": "hdopAccuracy", + "label": "HDOP Accuracy [m]", + "type": "number", + "default": "20", + "check": "checkMinMax", + "min": 1, + "max": 50, + "description": "HDOP ccuracy in m for a valid GPS signal [1...50]", + "category": "OBP60 Hardware", + "capabilities": { + "obp60":"true" + } + }, { "name": "useEnvSensor", "label": "Env. Sensor", diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index 8185511..f47411f 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -432,6 +432,7 @@ void OBP60Task(GwApi *api){ uint brightness = 2.55 * uint(api->getConfig()->getConfigItem(api->getConfig()->blBrightness,true)->asInt()); bool uvoltage = api->getConfig()->getConfigItem(api->getConfig()->underVoltage,true)->asBoolean(); String cpuspeed = api->getConfig()->getConfigItem(api->getConfig()->cpuSpeed,true)->asString(); + uint hdopAccuracy = uint(api->getConfig()->getConfigItem(api->getConfig()->hdopAccuracy,true)->asInt()); // refreshmode defined in init section // displaycolor defined in init section @@ -498,11 +499,11 @@ void OBP60Task(GwApi *api){ commonData.data.maxpage = numPages; // If GPS fix then LED off (HDOP) - if(String(gpsFix) == "GPS Fix Lost" && date->valid == true){ + if(String(gpsFix) == "GPS Fix Lost" && hdop->value <= hdopAccuracy && hdop->valid == true){ setFlashLED(false); } // If missing GPS fix then LED on - if(String(gpsFix) == "GPS Fix Lost" && date->valid == false){ + if((String(gpsFix) == "GPS Fix Lost" && hdop->value > hdopAccuracy && hdop->valid == true) || (String(gpsFix) == "GPS Fix Lost" && hdop->valid == false)){ setFlashLED(true); }