[59] | 1 | /// Purpose: This class decodes NMEA0183 data and can store them
|
---|
| 2 | /// in dbt files. It implements a thread which gets frames
|
---|
| 3 | /// from dataFrame class.
|
---|
| 4 | ///
|
---|
| 5 | /// @date created 2005/09/02 - 8:06
|
---|
| 6 | /// @author: Gerald Dherbomez
|
---|
| 7 | /// @version: $Id: gpsComponent.h 1277 2013-01-10 16:49:06Z bonnetst $
|
---|
| 8 | ///
|
---|
| 9 | /// @todo replace the static shared memory by the class ShMem
|
---|
| 10 |
|
---|
| 11 | #ifndef GPSCOMPONENT_H
|
---|
| 12 | #define GPSCOMPONENT_H
|
---|
| 13 |
|
---|
| 14 | #include "Pacpus/kernel/pacpus.h"
|
---|
| 15 | #include "Pacpus/kernel/ComponentBase.h"
|
---|
| 16 | #include "Pacpus/kernel/DbiteFile.h"
|
---|
| 17 | #include "../NMEA0183/include/nmea0183.h"
|
---|
| 18 |
|
---|
| 19 | #include "GpsFrames.h"
|
---|
| 20 |
|
---|
| 21 | #include <QSemaphore>
|
---|
| 22 | #include <QThread>
|
---|
[99] | 23 | #include <QByteArray>
|
---|
| 24 | #include <QString>
|
---|
[59] | 25 |
|
---|
| 26 | #ifdef WIN32
|
---|
| 27 | # include "../driver/win32SerialPort.h"
|
---|
| 28 | //# include "network/gpsServerSocket.h"
|
---|
[99] | 29 | #else
|
---|
[59] | 30 | # include "../driver/PosixSerialPort.h"
|
---|
| 31 | #endif
|
---|
| 32 | //#include "DbitePlayer/SensorTcpServer.h"
|
---|
| 33 | #include "Pacpus/PacpusTools/ShMem.h"
|
---|
| 34 |
|
---|
| 35 | // Export macro for PluginTest DLL for Windows only
|
---|
| 36 | #ifdef WIN32
|
---|
| 37 | # ifdef GPS_EXPORTS
|
---|
| 38 | // make DLL
|
---|
| 39 | # define GPS_API __declspec(dllexport)
|
---|
| 40 | # else
|
---|
| 41 | // use DLL
|
---|
| 42 | # define GPS_API __declspec(dllimport)
|
---|
| 43 | # endif
|
---|
| 44 | #else
|
---|
[99] | 45 | // On other platforms, simply ignore this
|
---|
[59] | 46 | # define GPS_API /* nothing */
|
---|
| 47 | #endif
|
---|
| 48 |
|
---|
| 49 | class QFile;
|
---|
| 50 |
|
---|
| 51 | namespace pacpus {
|
---|
| 52 |
|
---|
| 53 | /*!
|
---|
| 54 | * The definition of the GpsComponent class
|
---|
| 55 | */
|
---|
| 56 | class GPS_API GpsComponent
|
---|
| 57 | : public QThread
|
---|
| 58 | , public ComponentBase
|
---|
| 59 | , public GpsFrames
|
---|
| 60 | {
|
---|
| 61 | Q_OBJECT
|
---|
[99] | 62 |
|
---|
[59] | 63 | public:
|
---|
[99] | 64 | GpsComponent(QString name);
|
---|
| 65 | ~GpsComponent();
|
---|
| 66 |
|
---|
[59] | 67 | virtual void stopActivity(); /*!< to stop the processing thread */
|
---|
| 68 | virtual void startActivity(); /*!< to start the processing thread */
|
---|
[99] | 69 | virtual ComponentBase::COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config);
|
---|
[59] | 70 |
|
---|
| 71 |
|
---|
| 72 | void enableSocketServer(int portNumber); /*!< to enable the socket server interface on port portNumber*/
|
---|
| 73 | void disableSocketServer(); /*!< to disable the socket server interface */
|
---|
| 74 |
|
---|
[99] | 75 | void setPortCOM(const char * port);
|
---|
[59] | 76 |
|
---|
| 77 |
|
---|
[99] | 78 |
|
---|
| 79 | public slots:
|
---|
[59] | 80 | void unlockProcessing(int v); /*!< to unlock the processing thread */
|
---|
| 81 |
|
---|
| 82 | protected:
|
---|
| 83 | private:
|
---|
[99] | 84 | void run(); /*!< the main loop of the thread */
|
---|
| 85 | int frameType(const QByteArray& frame); /*!< to get the type of the frame */
|
---|
| 86 | int decodeFrame(int type); /*!< parse the string in the NMEA0183 class to get the frame informations */
|
---|
[59] | 87 | bool currentFrameIsPps(); /*!< checks if a frame is an out-of-band pps signal */
|
---|
[99] | 88 | bool analyzeFrame(); /*!< reconstruct the entire frame starting from the received pieces */
|
---|
[59] | 89 |
|
---|
| 90 | #ifdef WIN32
|
---|
| 91 | Win32SerialPort * serialPort;
|
---|
| 92 | //GpsServerSocket * serverSocket;
|
---|
| 93 | #else
|
---|
| 94 | PosixSerialPort * serialPort;
|
---|
| 95 | #endif
|
---|
| 96 | // a pointer to the TCP server that send data on the network
|
---|
| 97 | //SensorTcpServer * tcpServer_;
|
---|
| 98 |
|
---|
| 99 | static const int MAX_FRAMES = 9;
|
---|
| 100 |
|
---|
| 101 | struct FrameTypeMap {
|
---|
| 102 | char *code;
|
---|
| 103 | int type;
|
---|
| 104 | };
|
---|
| 105 |
|
---|
| 106 | static FrameTypeMap frameTypes[MAX_FRAMES];
|
---|
| 107 |
|
---|
[99] | 108 | NMEA0183 nmea0183_;
|
---|
| 109 | QSemaphore semaphore_;
|
---|
[59] | 110 |
|
---|
[99] | 111 | FRAME* currentFrame_;
|
---|
[59] | 112 |
|
---|
[99] | 113 | FRAME frameToDecode_;
|
---|
[59] | 114 |
|
---|
| 115 | road_time_t lastPpsTime_;
|
---|
| 116 |
|
---|
[99] | 117 | bool newFrameToDecode_;
|
---|
| 118 | bool startOfFrame_;
|
---|
| 119 | bool endOfFrame_;
|
---|
[59] | 120 | int nextByteToProcess_;
|
---|
| 121 |
|
---|
| 122 |
|
---|
| 123 | unsigned int ppsIndex_;
|
---|
[99] | 124 |
|
---|
[59] | 125 | DbiteFile ppshdFile; /*!< pointer to the pps dbt file */
|
---|
| 126 | DbiteFile ggahdFile; /*!< pointer to the gga dbt file */
|
---|
| 127 | DbiteFile gsahdFile; /*!< pointer to the gsa dbt file */
|
---|
| 128 | DbiteFile gsthdFile; /*!< pointer to the gst dbt file */
|
---|
| 129 | DbiteFile gsvhdFile; /*!< pointer to the gsv dbt file */
|
---|
| 130 | DbiteFile hdthdFile; /*!< pointer to the hdt dbt file */
|
---|
| 131 | DbiteFile rmchdFile; /*!< pointer to the rmc dbt file */
|
---|
| 132 | DbiteFile rothdFile; /*!< pointer to the rot dbt file */
|
---|
| 133 | DbiteFile vtghdFile; /*!< pointer to the vtg dbt file */
|
---|
| 134 | DbiteFile zdahdFile; /*!< pointer to the zda dbt file */
|
---|
| 135 |
|
---|
| 136 | DbiteFile gpsSynchroFile; /*!< pointer to the zda dbt file */
|
---|
| 137 |
|
---|
| 138 | QFile * file;
|
---|
| 139 |
|
---|
| 140 | bool ppsRecording;
|
---|
| 141 | bool ggaRecording;
|
---|
| 142 | bool gsaRecording;
|
---|
[99] | 143 | bool gstRecording;
|
---|
[59] | 144 | bool gsvRecording;
|
---|
| 145 | bool hdtRecording;
|
---|
[99] | 146 | bool rmcRecording;
|
---|
| 147 | bool rotRecording;
|
---|
| 148 | bool vtgRecording;
|
---|
| 149 | bool zdaRecording;
|
---|
[59] | 150 |
|
---|
[99] | 151 | QString portName_;
|
---|
| 152 |
|
---|
[59] | 153 | ShMem * shMem_;
|
---|
[99] | 154 |
|
---|
[59] | 155 | /// For the socket server
|
---|
| 156 | /* Qt3 version - 17/12/2007
|
---|
[99] | 157 | BOOL socketServerEnabled;
|
---|
| 158 | void *frameToSend;
|
---|
[59] | 159 | QCustomEvent *evt;
|
---|
| 160 | */
|
---|
[99] | 161 |
|
---|
| 162 | /*
|
---|
| 163 | * VC6 doesn't support out-of-class template defintions
|
---|
| 164 | * see on http://support.microsoft.com kb q243451 and more particulary 241949
|
---|
[59] | 165 | */
|
---|
| 166 | template<typename T>
|
---|
| 167 | void sendDataToServerSocket(T /*frame*/, int /*type*/)
|
---|
| 168 | {
|
---|
| 169 | /* Qt3 version - 17/12/2007
|
---|
| 170 | if (socketServerEnabled)
|
---|
| 171 | {
|
---|
[99] | 172 | frameToSend = new T;
|
---|
| 173 | *(T*)frameToSend = frame;
|
---|
| 174 | evt = new QCustomEvent(QEvent::User + type);
|
---|
| 175 | evt->setData(frameToSend);
|
---|
| 176 | postEvent(serverSocket,evt);
|
---|
[59] | 177 | }
|
---|
| 178 | */
|
---|
| 179 | }
|
---|
| 180 | };
|
---|
| 181 |
|
---|
| 182 | } // namespace pacpus
|
---|
| 183 |
|
---|
| 184 | #endif // GPSCOMPONENT_H
|
---|