mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2026-02-24 20:53:07 +01:00
Fix iRTC time for N2K bus
This commit is contained in:
@@ -104,8 +104,21 @@ void GwWifi::loop(){
|
|||||||
if (lastConnectStart > now || (lastConnectStart + RETRY_MILLIS) < now)
|
if (lastConnectStart > now || (lastConnectStart + RETRY_MILLIS) < now)
|
||||||
{
|
{
|
||||||
LOG_DEBUG(GwLog::LOG,"wifiClient: retry connect to %s", wifiSSID->asCString());
|
LOG_DEBUG(GwLog::LOG,"wifiClient: retry connect to %s", wifiSSID->asCString());
|
||||||
WiFi.disconnect();
|
|
||||||
|
//+++++++++ Old part +++++++++++++++++++++
|
||||||
|
// WiFi.disconnect();
|
||||||
|
// connectInternal();
|
||||||
|
//++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
|
//+++++++++ New part +++++++++++++++++++++
|
||||||
|
WiFi.disconnect(true);
|
||||||
|
delay(300);
|
||||||
|
esp_wifi_stop();
|
||||||
|
delay(100);
|
||||||
|
esp_wifi_start();
|
||||||
connectInternal();
|
connectInternal();
|
||||||
|
//++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|||||||
@@ -371,7 +371,7 @@ void sensorTask(void *param){
|
|||||||
GwApi::BoatValue *hdop=new GwApi::BoatValue(GwBoatData::_HDOP);
|
GwApi::BoatValue *hdop=new GwApi::BoatValue(GwBoatData::_HDOP);
|
||||||
GwApi::BoatValue *valueList[]={gpsdays, gpsseconds, hdop};
|
GwApi::BoatValue *valueList[]={gpsdays, gpsseconds, hdop};
|
||||||
|
|
||||||
// Internal RTC with NTP init
|
// Internal iRTC with NTP init
|
||||||
ESP32Time rtc(0);
|
ESP32Time rtc(0);
|
||||||
if (api->getConfig()->getString(api->getConfig()->timeSource) == "iRTC") {
|
if (api->getConfig()->getString(api->getConfig()->timeSource) == "iRTC") {
|
||||||
GwApi::Status status;
|
GwApi::Status status;
|
||||||
@@ -432,17 +432,17 @@ void sensorTask(void *param){
|
|||||||
|
|
||||||
iRTC RTC GPS N2K
|
iRTC RTC GPS N2K
|
||||||
0 0 0 (1)
|
0 0 0 (1)
|
||||||
0 0 (1) (X)
|
0 0 (1) X
|
||||||
0 (1) 0 (X)
|
0 (1) 0 X
|
||||||
0 1 <-(1) (X)
|
0 1 <-(1) X
|
||||||
(1) 0 0 (X)
|
(1) 0 0 X
|
||||||
1 0 (1) (X)
|
1 0 (1) X
|
||||||
1 ->(1) 0 (X)
|
1 ->(1) 0 X
|
||||||
1 1 <-(1) (X)
|
1 1 <-(1) X
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// If RTC DS1388 ready, then copy iRTC and GPS data to RTC all 1min
|
// If RTC DS1388 ready, then copy iRTC and GPS data to RTC all 1 min
|
||||||
if(millis() > starttime11 + 1*60*1000){
|
if(millis() > starttime11 + 1*60*1000){
|
||||||
starttime11 = millis();
|
starttime11 = millis();
|
||||||
// Set RTC chip via iRTC (NTP)
|
// Set RTC chip via iRTC (NTP)
|
||||||
@@ -475,7 +475,7 @@ void sensorTask(void *param){
|
|||||||
// Adjust RTC time as unix time value
|
// Adjust RTC time as unix time value
|
||||||
ds1388.adjust(adjusttime);
|
ds1388.adjust(adjusttime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set RTC chip via N2K or 183 in case the internal GPS is off (only one time)
|
// Set RTC chip via N2K or 183 in case the internal GPS is off (only one time)
|
||||||
@@ -524,7 +524,7 @@ void sensorTask(void *param){
|
|||||||
// N2K sysTime is double in n2klib
|
// N2K sysTime is double in n2klib
|
||||||
double sysTime = (dt.hour() * 3600) + (dt.minute() * 60) + dt.second();
|
double sysTime = (dt.hour() * 3600) + (dt.minute() * 60) + dt.second();
|
||||||
if(!isnan(daysAt1970) && !isnan(sysTime)){
|
if(!isnan(daysAt1970) && !isnan(sysTime)){
|
||||||
//api->getLogger()->logDebug(GwLog::LOG,"RTC time: %04d/%02d/%02d %02d:%02d:%02d",sensors.rtcTime.tm_year+1900,sensors.rtcTime.tm_mon, sensors.rtcTime.tm_mday, sensors.rtcTime.tm_hour, sensors.rtcTime.tm_min, sensors.rtcTime.tm_sec);
|
//api->getLogger()->logDebug(GwLog::LOG,"RTC time: %04d/%02d/%02d %02d:%02d:%02d",sensors.rtcTime.tm_year+1900,sensors.rtcTime.tm_mon+1, sensors.rtcTime.tm_mday, sensors.rtcTime.tm_hour, sensors.rtcTime.tm_min, sensors.rtcTime.tm_sec);
|
||||||
//api->getLogger()->logDebug(GwLog::LOG,"Send PGN126992: %10d %10d",daysAt1970, (uint16_t)sysTime);
|
//api->getLogger()->logDebug(GwLog::LOG,"Send PGN126992: %10d %10d",daysAt1970, (uint16_t)sysTime);
|
||||||
SetN2kPGN126992(N2kMsg,0,daysAt1970,sysTime,N2ktimes_LocalCrystalClock);
|
SetN2kPGN126992(N2kMsg,0,daysAt1970,sysTime,N2ktimes_LocalCrystalClock);
|
||||||
api->sendN2kMessage(N2kMsg);
|
api->sendN2kMessage(N2kMsg);
|
||||||
@@ -533,25 +533,26 @@ void sensorTask(void *param){
|
|||||||
}
|
}
|
||||||
// Send date and time from software RTC (iRTC)
|
// Send date and time from software RTC (iRTC)
|
||||||
if (iRTC_ready == true && RTC_ready == false && GPS_ready == false) {
|
if (iRTC_ready == true && RTC_ready == false && GPS_ready == false) {
|
||||||
// Use internal RTC feature
|
sensors.rtcTime = rtc.getTimeStruct();
|
||||||
sensors.rtcTime = rtc.getTimeStruct(); // Save software RTC values in SensorData
|
|
||||||
// TODO implement daysAt1970 and sysTime as methods of DateTime
|
|
||||||
const short daysOfYear[12] = {0,31,59,90,120,151,181,212,243,273,304,334};
|
const short daysOfYear[12] = {0,31,59,90,120,151,181,212,243,273,304,334};
|
||||||
uint16_t switchYear = ((sensors.rtcTime.tm_year-1)-1968)/4 - ((sensors.rtcTime.tm_year-1)-1900)/100 + ((sensors.rtcTime.tm_year-1)-1600)/400;
|
int year = sensors.rtcTime.tm_year + 1900;
|
||||||
long daysAt1970 = (sensors.rtcTime.tm_year-1970)*365 + switchYear + daysOfYear[sensors.rtcTime.tm_mon-1] + sensors.rtcTime.tm_mday-1;
|
int month = sensors.rtcTime.tm_mon;
|
||||||
// If switch year then add one day
|
int day = sensors.rtcTime.tm_mday;
|
||||||
if ((sensors.rtcTime.tm_mon > 2) && (sensors.rtcTime.tm_year % 4 == 0 && (sensors.rtcTime.tm_year % 100 != 0 || sensors.rtcTime.tm_year % 400 == 0))) {
|
uint16_t switchYear = ((year - 1) - 1968) / 4 - ((year - 1) - 1900) / 100 + ((year - 1) - 1600) / 400;
|
||||||
|
long daysAt1970 = (year - 1970) * 365L + switchYear + daysOfYear[month] + day - 1;
|
||||||
|
|
||||||
|
// Leap day add if date is after Feb (i.e. month >= March)
|
||||||
|
if (month >= 2 && (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))) {
|
||||||
daysAt1970 += 1;
|
daysAt1970 += 1;
|
||||||
}
|
}
|
||||||
// N2K sysTime is double in n2klib
|
double sysTime = sensors.rtcTime.tm_hour * 3600.0 + sensors.rtcTime.tm_min * 60.0 + sensors.rtcTime.tm_sec;
|
||||||
double sysTime = (sensors.rtcTime.tm_hour * 3600) + (sensors.rtcTime.tm_min * 60) + sensors.rtcTime.tm_sec;
|
//api->getLogger()->logDebug(GwLog::LOG, "iRTC time: %04d/%02d/%02d %02d:%02d:%02d", year, month + 1, day, sensors.rtcTime.tm_hour, sensors.rtcTime.tm_min, sensors.rtcTime.tm_sec);
|
||||||
if(!isnan(daysAt1970) && !isnan(sysTime)){
|
//api->getLogger()->logDebug(GwLog::LOG,"Send PGN126992: %10d %10d",daysAt1970, (uint16_t)sysTime);
|
||||||
//api->getLogger()->logDebug(GwLog::LOG,"RTC time: %04d/%02d/%02d %02d:%02d:%02d",sensors.rtcTime.tm_year+1900,sensors.rtcTime.tm_mon, sensors.rtcTime.tm_mday, sensors.rtcTime.tm_hour, sensors.rtcTime.tm_min, sensors.rtcTime.tm_sec);
|
SetN2kPGN126992(N2kMsg, 0, daysAt1970, sysTime, N2ktimes_LocalCrystalClock);
|
||||||
//api->getLogger()->logDebug(GwLog::LOG,"Send PGN126992: %10d %10d",daysAt1970, (uint16_t)sysTime);
|
api->sendN2kMessage(N2kMsg);
|
||||||
SetN2kPGN126992(N2kMsg,0,daysAt1970,sysTime,N2ktimes_LocalCrystalClock);
|
|
||||||
api->sendN2kMessage(N2kMsg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send 1Wire data for all temperature sensors to N2K all 2s
|
// Send 1Wire data for all temperature sensors to N2K all 2s
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ class PageAutopilot : public Page
|
|||||||
// if ( x_test > 390)
|
// if ( x_test > 390)
|
||||||
// x_test = 320;
|
// x_test = 320;
|
||||||
|
|
||||||
displayRudderPosition(DataValue[ShowRPOS], 20, 200, 160, commonData->fgcolor, commonData->bgcolor);
|
displayRudderPosition(DataValue[ShowSOG], 20, 200, 160, commonData->fgcolor, commonData->bgcolor);
|
||||||
|
|
||||||
return PAGE_UPDATE;
|
return PAGE_UPDATE;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1245,8 +1245,8 @@
|
|||||||
"name": "timeSource",
|
"name": "timeSource",
|
||||||
"label": "Status Time Source",
|
"label": "Status Time Source",
|
||||||
"type": "list",
|
"type": "list",
|
||||||
"default": "GPS",
|
"default": "iRTC",
|
||||||
"description": "Data source for date and time display in status line [RTC|iRTC|GPS]",
|
"description": "Data source for date and time display in status line [iRTC|RTC|GPS]",
|
||||||
"list": [
|
"list": [
|
||||||
{"l":"Internal real time clock (iRTC)","v":"iRTC"},
|
{"l":"Internal real time clock (iRTC)","v":"iRTC"},
|
||||||
{"l":"External real time clock (RTC)","v":"RTC"},
|
{"l":"External real time clock (RTC)","v":"RTC"},
|
||||||
|
|||||||
@@ -1235,8 +1235,9 @@
|
|||||||
"label": "Status Time Source",
|
"label": "Status Time Source",
|
||||||
"type": "list",
|
"type": "list",
|
||||||
"default": "GPS",
|
"default": "GPS",
|
||||||
"description": "Data source for date and time display in status line [RTC|GPS]",
|
"description": "Data source for date and time display in status line [iRTC|RTC|GPS]",
|
||||||
"list": [
|
"list": [
|
||||||
|
{"l":"Internal real time clock (iRTC)","v":"iRTC"},
|
||||||
{"l":"Real time clock (RTC)","v":"RTC"},
|
{"l":"Real time clock (RTC)","v":"RTC"},
|
||||||
{"l":"Time via bus (GPS)","v":"GPS"}
|
{"l":"Time via bus (GPS)","v":"GPS"}
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user