1 | /*********************************************************************
|
---|
2 | // created: 2007/11/13 - 10:48
|
---|
3 | // filename: AlascaComponent.h
|
---|
4 | //
|
---|
5 | // author: Gerald Dherbomez & Sergio Rodriguez
|
---|
6 | // Copyright Heudiasyc UMR UTC/CNRS 6599
|
---|
7 | //
|
---|
8 | // version: $Id: $
|
---|
9 | //
|
---|
10 | // purpose: Definition of the AlascaComponent class
|
---|
11 | *********************************************************************/
|
---|
12 |
|
---|
13 | #ifndef ALASCACOMPONENT_H
|
---|
14 | #define ALASCACOMPONENT_H
|
---|
15 |
|
---|
16 | #include "Pacpus/kernel/ComponentBase.h"
|
---|
17 | #include "Pacpus/kernel/DbiteFile.h"
|
---|
18 | #include "AlascaData.h"
|
---|
19 |
|
---|
20 | #include <fstream>
|
---|
21 | #include <QThread>
|
---|
22 | #include <string>
|
---|
23 |
|
---|
24 | // Export macro for AlascaXT DLL for Windows only
|
---|
25 | #ifdef WIN32
|
---|
26 | # ifdef ALASCAXT_EXPORTS
|
---|
27 | // make DLL
|
---|
28 | # define ALASCAXT_API __declspec(dllexport)
|
---|
29 | # else
|
---|
30 | // use DLL
|
---|
31 | # define ALASCAXT_API __declspec(dllimport)
|
---|
32 | # endif
|
---|
33 | #else
|
---|
34 | // On other platforms, simply ignore this
|
---|
35 | # define ALASCAXT_API
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | class QEvent;
|
---|
39 |
|
---|
40 | namespace pacpus {
|
---|
41 |
|
---|
42 | class AlascaSocket;
|
---|
43 | class ShMem;
|
---|
44 |
|
---|
45 | struct ScanAlascaObject {
|
---|
46 | // todo...
|
---|
47 | };
|
---|
48 |
|
---|
49 | // see Manual_Alasca.pdf page 27
|
---|
50 | struct MessageHeader {
|
---|
51 | unsigned long magicWord;
|
---|
52 | unsigned long size;
|
---|
53 | unsigned long dataType;
|
---|
54 | unsigned long timestamp;
|
---|
55 | };
|
---|
56 |
|
---|
57 | // see Manual_Alasca.pdf page 28
|
---|
58 | struct ALASCAXT_API ScanHeader {
|
---|
59 | unsigned char version;
|
---|
60 | unsigned char scannerType;
|
---|
61 | unsigned char ecuId;
|
---|
62 | unsigned long timeStamp;
|
---|
63 | unsigned short startAngle;
|
---|
64 | unsigned short endAngle;
|
---|
65 | unsigned short scanCounter;
|
---|
66 | unsigned short numPoints;
|
---|
67 | };
|
---|
68 |
|
---|
69 | // the class containing Alasca message
|
---|
70 | class ALASCAXT_API Message
|
---|
71 | {
|
---|
72 | public:
|
---|
73 | /// Constructor.
|
---|
74 | Message()
|
---|
75 | {
|
---|
76 | time = 0;
|
---|
77 | timerange = 0;
|
---|
78 | memset(&hMsg,0,sizeof(hMsg));
|
---|
79 | memset(&hScan,0,sizeof(hScan));
|
---|
80 | memset(body,0,sizeof(body));
|
---|
81 | }
|
---|
82 |
|
---|
83 | /// Destructor.
|
---|
84 | ~Message(){}
|
---|
85 |
|
---|
86 | MessageHeader hMsg; // 16 bytes
|
---|
87 | ScanHeader hScan; // 16 bytes
|
---|
88 | unsigned char body[ 32 + MAX_SCAN_POINT * 12 ]; // 32 + 12N bytes where N <= 8648 - MH+SH+body
|
---|
89 | road_time_t time;
|
---|
90 | road_timerange_t timerange;
|
---|
91 | };
|
---|
92 |
|
---|
93 | // Structure used to stored alasca data between several decoding processes
|
---|
94 | struct MessagePacket {
|
---|
95 | road_time_t time;
|
---|
96 | std::string data;
|
---|
97 | bool previousData;
|
---|
98 | };
|
---|
99 |
|
---|
100 | class AlascaDataGenerator;
|
---|
101 |
|
---|
102 | class ALASCAXT_API AlascaComponent
|
---|
103 | : public QThread
|
---|
104 | , public ComponentBase
|
---|
105 | {
|
---|
106 | Q_OBJECT
|
---|
107 |
|
---|
108 | public:
|
---|
109 | AlascaComponent(QString name);
|
---|
110 | ~AlascaComponent();
|
---|
111 |
|
---|
112 | void run() {}
|
---|
113 |
|
---|
114 | virtual void stopActivity(); /*!< to stop the processing thread */
|
---|
115 | virtual void startActivity(); /*!< to start the processing thread */
|
---|
116 | virtual ComponentBase::COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config);
|
---|
117 |
|
---|
118 | // decoupe le paquet en messages et remplit la liste de 'Message'
|
---|
119 | // remplit le message header
|
---|
120 | // remplit le scan header
|
---|
121 | // détermine si le message est complet (isFull)
|
---|
122 | // renvoie le nombre de pending bytes
|
---|
123 | void splitPacket(const char * packet, const int length, road_time_t time);
|
---|
124 |
|
---|
125 | // decoupe le message en scan
|
---|
126 | // remplit la structure alascaData
|
---|
127 | // renvoie le nombre de scan (<=8 648)
|
---|
128 | unsigned long processMessage(Message & msg);
|
---|
129 |
|
---|
130 | // renvoie l'index du magicWord dans le message
|
---|
131 | // -1 si aucun magic word trouvé
|
---|
132 | long findMagicWord(const char * message, const unsigned length);
|
---|
133 |
|
---|
134 | // renvoie la taille du message = 32 + body size
|
---|
135 | // 0 si pas trouv�
|
---|
136 | long getMessageSize(const char * message, const unsigned length, const long magicWordIndex);
|
---|
137 |
|
---|
138 | /// @returns @b true if the message is complete, @b false otherwise
|
---|
139 | bool isMessageComplete(const unsigned length, const long size);
|
---|
140 |
|
---|
141 | public Q_SLOTS:
|
---|
142 | //Fonction qui permet de trier les données reçues et de les enregistrer dans une structure point, puis dans un fichier binaire .dbt
|
---|
143 | void customEvent(QEvent * e);
|
---|
144 |
|
---|
145 | public:
|
---|
146 | AlascaSocket * A_socket; //on déclare pointeur de socket
|
---|
147 | AlascaComponent * myParent;
|
---|
148 |
|
---|
149 | private:
|
---|
150 | std::list<Message> msgList;
|
---|
151 |
|
---|
152 | ScanAlascaData alascaData;
|
---|
153 | ScanAlascaObject alascaObjects;
|
---|
154 |
|
---|
155 | //char * pendingBytes;
|
---|
156 | MessagePacket pendingBytes;
|
---|
157 |
|
---|
158 | void storePendingBytes(road_time_t time);
|
---|
159 | void fillMessageHeader(Message & msg);
|
---|
160 | void fillScanHeader(Message & msg);
|
---|
161 | short din70000toCentimeters(short n);
|
---|
162 | float din70000toMeters(short n);
|
---|
163 | // write the data on the disk in the dbt file and the associated binary file
|
---|
164 | void writeData();
|
---|
165 |
|
---|
166 | // AlascaDataGenerator * generator;
|
---|
167 |
|
---|
168 | AlascaXT dbtData_;
|
---|
169 | pacpus::DbiteFile dbtFile_;
|
---|
170 | std::ofstream dataFile_;
|
---|
171 |
|
---|
172 | //ShMem * shmem_;
|
---|
173 |
|
---|
174 | // The alasca IP or hostname
|
---|
175 | QString host_;
|
---|
176 |
|
---|
177 | // The alasca port
|
---|
178 | int port_;
|
---|
179 | };
|
---|
180 |
|
---|
181 | } // namespace pacpus
|
---|
182 |
|
---|
183 | #endif // ALASCACOMPONENT_H
|
---|