GPS Library  0.1
GPS driver and NMEA parser
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
GPSHandler.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  *
3  * Project: Ducktor Navi - my navigation software
4  * Purpose: Generic GPS Driver
5  * Author: György Kövesdi (kgy@teledigit.eu)
6  * License: GPL (see file 'COPYING' in the project root for more details)
7  * Comments:
8  *
9  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
10 
11 #ifndef __SRC_DRIVER_GPSHANDLER_H_INCLUDED__
12 #define __SRC_DRIVER_GPSHANDLER_H_INCLUDED__
13 
14 #include <GPS/I_GPSHandler.h>
15 #include <GPS/Driver/I_GPSDriver.h>
16 #include <GPS/Interpreter/I_GPSInterpreter.h>
17 #include <GPS/Data/GPSData.h>
18 #include <Threads/Threads.h>
19 #include <Threads/Mutex.h>
20 
21 #include <stack>
22 
23 namespace GPS
24 {
25  class GPSHandler: public I_GPSHandler, public Threads::Thread
26  {
27  MAKE_AUTON_FRIEND(GPSHandler, I_GPSHandler);
28 
29  friend class GPS::GPSData;
30 
31  GPSHandler(void);
32  virtual ~GPSHandler();
33 
34  virtual void GotGPSData(const void * data, int length, I_GPSDriver * driver = nullptr) override;
35  virtual I_GPSData & GetGPSData(void) override;
36  virtual float GetLastTimeElapsed(void) const override;
37  virtual int GotNewGPSTime(const GPS::Time & time) override;
38 
39  virtual int main(void) override;
40 
42  {
43  Threads::Lock _l(gps_driver_mutex);
44  if (gps_drivers.empty()) {
45  return GPSDriverPtr();
46  }
47  return gps_drivers.top();
48  }
49 
50  void RemoveGPSDriver(void)
51  {
52  Threads::Lock _l(gps_driver_mutex);
53  ASSERT(!gps_drivers.empty(), "no GPS driver to remove");
54  gps_drivers.pop();
55  }
56 
57  SYS_DEFINE_CLASS_NAME("GPSHandler");
58 
60 
62 
64 
67  SYS::TimeDelay last_localtime;
68 
70 
74  SYS::TimeDelay next_localtime;
75 
77 
81 
83  std::stack<GPSDriverPtr> gps_drivers;
84 
85  Threads::Mutex gps_driver_mutex;
86 
87  public:
89  {
90  Threads::Lock _l(gps_driver_mutex);
91  gps_drivers.push(driver);
92  }
93 
94  }; // class GPS::GPSHandler
95 
96 } // namespace GPS
97 
98 #endif /* __SRC_DRIVER_GPSHANDLER_H_INCLUDED__ */
99 
100 /* * * * * * * * * * * * * End - of - File * * * * * * * * * * * * * * */