OpenCPN-low-energy/diagram-approach

Jump to: navigation, search

A diagram approach

Diagrams are the best way to really visualize what's going on when a program is running.

In which files we have to look

We have established a list of files that are linked to what we are interesting to do. This list have been set up by firstly seek for files we absolutely don't need (for example the options window). Then we have narrow down the list to classes and functionality that we can modify (we can't modify the collision system because it's obviously too dangerous). To be very specific, we kept only files with timers because we looked for actions that occurred every X seconds. At the end the list of files is :

  • chart1.cpp
  • chcanv.cpp
  • ais.cpp (In the current version : AIS_Decoder.cpp)

How the main window is refreshed ?

We managed to find the piece of code that refresh the main window in the file chart1.cpp. The refreshing action is done every 5 seconds. Actions aren't located in a loop but triggered by the timer event FrameTimer1. The actions done when the timer emit a timerEvent are : Reload the chart quilt if needed (the ship have traveled out of the current quilt) Print the ship on the chart Print ships fetched by the AIS on the chart Look for possible anchor alerts Update watchdogs for various navigation indicators Log the position in the opencpn.log file every 30 minutes

Detailed diagram of the OnFrameTimer1 function :

Flow diagram of the function

What is done by the AIS ?

Like the main window refreshing action, the AIS data fetching rely on a timer (TimerAIS) which trigger the AIS_Decoder::OnTimerAIS() function every 995 ms. The actions done by this method are mostly about fetching the AIS data and remove old AIS targets. The collision detection system is also implemented in this method. The collision is defined by a ship too close of your ship's position. If a collision might happen, a collision alert window pop-up and a sound is played (this is an option).

Detailed diagram of the OnTimerAIS function :

Flow diagram of the function

What is done in the initialization?

The program starts with OnInit() function in Chart1.cpp, which is needed by wxWidgets. This function initializes in roughly five steps :

  • Preparing configuration
  • Preparing UI
  • Load Data
  • Start timers
  • Show UI

Timers deals with chart refreshing and in course up mode with chart rotating. Tide and current are not refreshed with the main chart refreshing timer, but have their own timer.

Flow diagram for init

Rotation and tide and current timers

These timers do simple actions: rotation timer computes angle and refresh, and current and tide timer ask update of its data setting a boolean.

Flow diagram for rotation Flow diagram for tide and current