file name: gpsbase.hpp, gpsbase.cpp
classification: simulation
contents: class ACGps, class CGpsTemplate
derived from: class CNeedInterrupt
use: provides the base class for handling the data from the
GPS receiver, plus the template class that is used for obtaining an object
of the currently used interface class (hardware or software)
global items used by ACGps:
local items defined in the implementation file:
const INT32
GpsNotHealthy: a mask for the bit in the macrostamp MSGPS that contains
the status of the GPS receiver (the bit is 1 if the receiver is not healthy).
member variables of ACGps:
int area_:
the area of the associated clock
default: set to parameter area of the ctor
CClockInterface
*clock_: the associated clock that is influenced by the GPS receiver.
default: set to parameter clock of the ctor
INT8
enableMask_: for every GPS receiver that is connected to a GPU and
is enabled, the corresponding bit in the bit mask is set to 1
default: 0
INT8
statusMask_: for every GPS receiver that is connected to a GPU and
is healthy, the corresponding bit in the bit mask is set to 1
default: 0
member functions of ACGps:
ACGps (CClockInterface
*clock, int area): Stores the clock that is connected to the GPS receiver
and its area and sets all members to their default values. If clock
is NULL, an assert fails.
virtual
~ACGps (): If enableMask is not zero, an assert fails.
virtual
void ClearGpsInterrupt(): pure virtual
Should clear the interrupt that was triggered after the GPS time information
was available.
virtual
void DisableGps (int area, INT8 gpu): pure virtual
The function should disable the interrupt that is generated by the
GPS receiver when the time information is available.
virtual
void EnableGps (int area, INT8 gpu): pure virtual
The function should enable the interrupt that is generated by the GPS
receiver when the time information is available.
void GetClockGps
(EGpsUnit gpu, CNtpTime& clockTime): Reads the MSGPS and TSGPS
registers of the GPU specified in parameter gpu. The values of
the registers are stored in clockTime. In the case of MSGPS, the
checksum (but not the GPS health bit) is masked out before the value is
stored. If clock::GetClock() returns NULL, or if gpu
is greater or equal to EGpsUnitCount, an assert
fails.
virtual
EGpsUnit GetGpsNumber(): pure virtual
Should return the number of the GPU to which the receiver that has
raised the interrupt is connected. Since two GPS receivers may share the
same interrupt vector and thus the same ISR, the number of the GPS unit
cannot be stored in advance, but must be found out.
virtual
void GetGpsTime (CNtpTime& time): pure virtual
Should obtain the NTP time from the GPS receiver and modify time
accordingly.
EBool GpsEnabled():
returns True if at least one GPS receiver is enabled (enableMask
is not zero), else False.
virtual
void isr(): The ISR is called if the time information from the GPS
receiver is available and clears that interrupt calling ClearGpsInterrupt().
It then reads the GPS time using function GetGpsTime() and compares
it to the clock value read by GetClockGps(). If the values are
not equal, GPS is healthy and the difference between the clock values is
greater than GpsEpsilon, the clock is prompted
to amortize the time difference and an event is sent to report the update.
Otherwise, the clock value is not changed.
In any case, the health bit (bit 31) of register MSGPS is checked and
SetGpsStatus() is called accordingly.
virtual
void ReportEvent (SEvent *event): Sets the module to Clock
and the event type to GpsEvent, then passes the event
to clock. If event is NULL, an assert fails.
virtual
void SetGpsStatus (EGpsUnit gpu, EBool status): You should set status
to True if the GPS receiver is healthy, to False if it is not. If status
is True, the bit in statusMask corresponding to gpu is
set, otherwise it is cleared. If enableMask and statusMask
are equal (all enabled GPS receivers are healthy), clock::gpsStatus
is set to True, else it is set to False. If the receiver corresponding
to gpu is not enabled, an assert fails.
global items used by CGpsTemplate:
member functions of CGpsTemplate:
Note: gpsTemplate (template.hpp) is instantiated in gpsbase.cpp.
virtual
ACGps *NewGPS (CClockInterface *clock): The function should return
a new object of the currently used GPS interface class. The implementation
of the function is left to the programmer of the class.