OpenCPN / OpenCPN

A concise ChartPlotter/Navigator. A cross-platform ship-borne GUI application supporting * GPS/GPDS Postition Input * BSB Raster Chart Display * S57 Vector ENChart Display * AIS Input Decoding * Waypoint Autopilot Navigation
https://opencpn.org/
GNU General Public License v2.0
1.04k stars 495 forks source link

Wrong sunrise/sunset times are displayed in the dashboard widgets #4082

Open sebastien-rosset opened 1 month ago

sebastien-rosset commented 1 month ago

Describe the bug The displayed sunrise/sunset times are sometimes wrong. It seems to occur immediately after a GPS watchdog timeout.

To Reproduce Steps to reproduce the behavior:

  1. Go to Dashboard preferences.
  2. Add widgets: Sunrise/Sunset UTC, Sunrise/Sunset Local, Location, time.
  3. Notice sometimes the displayed sunrise/sunset times are wrong. For example, around San Francisco August 6th, 2024, the sunset is displayed as 18:01:00 Local time, which is wrong. The actual sunset is around 8:07PM.

Expected behavior The sunrise/sunset times should be displayed correctly. If the program is unable to calculate the time, it should not display an invalid date.

Screenshots

image

I've added some debugging to troubleshoot the problem. It looks like after a GPS watchdog timeout, the m_dt variable is set to January 1st 1970, and that causes sunrise/sunset calculation errors.

19:00:56.450 MESSAGE clock.cpp:542 CurrentDate: 2024-08-07T02:00:55, DayOfYear: 220, Sunrise: 2024-08-06T13:18:00 Sunset: 2024-08-06T03:09:00
19:00:56.450 MESSAGE clock.cpp:542 CurrentDate: 2024-08-07T02:00:55, DayOfYear: 220, Sunrise: 2024-08-06T13:18:00 Sunset: 2024-08-06T03:09:00
19:01:05.661 MESSAGE comm_bridge.cpp:188    ***GPS Watchdog timeout at Lat:37.4885   Lon: -122.181
19:01:06.449 MESSAGE clock.cpp:542 CurrentDate: 1970-01-01T00:00:00, DayOfYear: 1, Sunrise: 2024-08-06T15:23:00 Sunset: 2024-08-06T01:01:00
19:01:06.450 MESSAGE clock.cpp:542 CurrentDate: 1970-01-01T00:00:00, DayOfYear: 1, Sunrise: 2024-08-06T15:23:00 Sunset: 2024-08-06T01:01:00

Desktop (please complete the following information if applicable):

Additional Context: Here are some findings based on troubleshooting/debugging:

Immediately after a GPS watchdog time, the void DashboardInstrument_Sun::SetUtcTime(wxDateTime data) function is invoked with the epoch date/time. The code sets the m_dt variable to the epoch time, and that variable is used to calculate the sunrise/sunset.

https://github.com/OpenCPN/OpenCPN/blob/41173d9eb6d911472a3a1b1b76a454ce9f527f0c/plugins/dashboard_pi/src/clock.cpp#L328

The time is set to 1969-12-31T16:00:00 at this line after the GPS timeout: https://github.com/OpenCPN/OpenCPN/blob/41173d9eb6d911472a3a1b1b76a454ce9f527f0c/plugins/dashboard_pi/src/dashboard_pi.cpp#L3120

The m_fixtime is set to 0, with a code comment that states it "invalidates fix time". However 0 is a valid date, so wxDateTime.IsValid() returns true when the milliseconds since epoch is set to 0: https://github.com/OpenCPN/OpenCPN/blob/ba6e2330330c607dcfdacaa9119a7f476beb0d9e/gui/src/ocpn_frame.cpp#L5066

sebastien-rosset commented 1 month ago

In addition, the "Local GNSS Clock" is wrong after the GPS watchdog timemout. In the attached screenshot, the time is stuck at "18:00:00 LCL". It should display something like "---" or string showing GNSS date is not available.