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