libpandac  0.0.0
A library designed for a comm.ai Panda.
gps.h
1 /*
2  Author: Matt Bunting
3  Copyright (c) 2020 Arizona Board of Regents
4  All rights reserved.
5 
6  Permission is hereby granted, without written agreement and without
7  license or royalty fees, to use, copy, modify, and distribute this
8  software and its documentation for any purpose, provided that the
9  above copyright notice and the following two paragraphs appear in
10  all copies of this software.
11 
12  IN NO EVENT SHALL THE ARIZONA BOARD OF REGENTS BE LIABLE TO ANY PARTY
13  FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14  ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15  IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
16  SUCH DAMAGE.
17 
18  THE ARIZONA BOARD OF REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
19  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20  AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER
21  IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION
22  TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 
24  */
25 
26 #ifndef PANDA_GPS_H
27 #define PANDA_GPS_H
28 
29 #include <vector>
30 #include <map>
31 #include <fstream>
32 
33 #include "NMEAParser.h"
34 #include "mogi/thread.h"
35 
36 #include "panda/gps.h"
37 #include "panda/usb.h"
38 #include "panda/gpsdata.h"
39 
40 namespace Panda {
41 
42  class Gps;
43 
50  class GpsListener {
51  private:
52  friend class Gps;
53  protected:
60  virtual void newDataNotification(GpsData* gpsData) = 0;
61 
62  public:
63  virtual ~GpsListener() { };
64 
65  };
66 
74  class Gps : protected Mogi::Thread, public UsbListener, public CNMEAParser {
75  public:
76  Gps();
77  ~Gps();
78 
79  void initialize(); // needs USB device
80 
85  const GpsData& getData() const;
86 
91  void saveToFile(const char* filename);
92 
97  void saveToCsvFile(const char* filename);
98 
102  void setUsb( Panda::Usb* usbHandler );
103 
107  void addObserver( GpsListener* listener );
108 
112  bool isReady();
113 
117  void startParsing();
118 
122  void stopParsing();
123 
124  private:
125  GpsData state;
126 
127  bool currentlyReceiving = false;
128 
129  std::ofstream nmeaDump;
130  FILE* csvDump;
131 
132  void writeCsvToFile(GpsData& state);
133 
134  std::vector<GpsListener*> listeners;
135  Usb* usbHandler = NULL;
136 
137  // Overload from Mogi::Thread
138  void doAction();
139 
140  // Overload frum UsbListener
141  void notificationUartRead(char* buffer, size_t bufferLength);
142 
143  // NMEAParser overload:
144  virtual void OnError(CNMEAParserData::ERROR_E nError, char *pCmd);
145  // NMEAPArser overload:
146  virtual CNMEAParserData::ERROR_E ProcessRxCommand(char *pCmd, char *pData);
147  };
148 
149 }
150 
151 #endif
Handles USB communication and parsing with a comma.ai Panda.
Definition: can.h:38
Abstract class, handles a single thread. Features mutual exclusion and pause/resume.
Definition: thread.h:27
Definition: gpsdata.h:143
virtual void newDataNotification(GpsData *gpsData)=0
Called on a successful RMC message parse Overload this to get instant updates form freshly parsed NME...
A class that handles the GPS data.
Definition: gps.h:74
Definition: usb.h:80
Definition: usb.h:60
An abstract class for new data notifications for new GPS data.
Definition: gps.h:50