1 | /*********************************************************************
|
---|
2 | // created: 2014/02/11 - 10:48
|
---|
3 | // filename: SickLMSSensor.h
|
---|
4 | //
|
---|
5 | // author: Cyril Fougeray
|
---|
6 | // Copyright Heudiasyc UMR UTC/CNRS 6599
|
---|
7 | //
|
---|
8 | // version: $Id: $
|
---|
9 | //
|
---|
10 | // purpose: Definition of the SickLMSSensor class
|
---|
11 | *********************************************************************/
|
---|
12 |
|
---|
13 | #ifndef SICKLMSSENSOR_H
|
---|
14 | #define SICKLMSSENSOR_H
|
---|
15 |
|
---|
16 | #include "Pacpus/kernel/ComponentBase.h"
|
---|
17 | #include "Pacpus/kernel/DbiteFile.h"
|
---|
18 |
|
---|
19 | #include "AbstractSickSensor.h"
|
---|
20 | #include "SickLMSData.h"
|
---|
21 |
|
---|
22 | #include <fstream>
|
---|
23 | #include <string>
|
---|
24 |
|
---|
25 | // Export macro for SickLMS DLL for Windows only
|
---|
26 | #ifdef WIN32
|
---|
27 | # ifdef SICKLMS_EXPORTS
|
---|
28 | // make DLL
|
---|
29 | # define SICKLMS_API __declspec(dllexport)
|
---|
30 | # else
|
---|
31 | // use DLL
|
---|
32 | # define SICKLMS_API __declspec(dllimport)
|
---|
33 | # endif
|
---|
34 | #else
|
---|
35 | // On other platforms, simply ignore this
|
---|
36 | # define SICKLMS_API
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | class QEvent;
|
---|
40 |
|
---|
41 | namespace pacpus {
|
---|
42 |
|
---|
43 | class ShMem;
|
---|
44 | class SickComponent;
|
---|
45 |
|
---|
46 |
|
---|
47 | /// The class carrying Sick LMS message.
|
---|
48 | /** This class is used so that we can store every information sent by a Sick LMS sensor.
|
---|
49 | * First, the raw data is stored in \c body. Then, if the message is relevant, \c splitMessage is instanciated in order
|
---|
50 | * to parse easily information from the sensor.
|
---|
51 | * These data are then decoded and stored in the scanData structure.
|
---|
52 | */
|
---|
53 | class SICKLMS_API MessageLMS
|
---|
54 | {
|
---|
55 | public:
|
---|
56 | /// Constructor.
|
---|
57 | MessageLMS()
|
---|
58 | {
|
---|
59 | time = 0;
|
---|
60 | timerange = 0;
|
---|
61 | memset(&data,0,sizeof(data));
|
---|
62 | }
|
---|
63 |
|
---|
64 | /// Destructor.
|
---|
65 | ~MessageLMS(){}
|
---|
66 |
|
---|
67 | scanData data; //!< Every needed information about the scan (general info + scan points).
|
---|
68 |
|
---|
69 | long msgSize; //!< Size of the message
|
---|
70 |
|
---|
71 | std::vector<std::string>* splitMessage; //!< The message is split into an array of string in order to be processed easily.
|
---|
72 | char* body; //!< Raw data
|
---|
73 | road_time_t time; //!< Time when the first packet of the message is received.
|
---|
74 | road_timerange_t timerange; //!< Timerange : roughly, time between measurement of a point and the processing step (not implemented).
|
---|
75 | };
|
---|
76 |
|
---|
77 |
|
---|
78 | //! The class implenting receiving, decoding and storing process of Sick LMS data.
|
---|
79 | /**
|
---|
80 | * This class can be used as a particular thread to acquire data from Sick LDMRS sensors.
|
---|
81 | * The Ethernet interface is used to get data from the sensor. Thus, the goal of this class is to
|
---|
82 | * get packets and decode them. Also, it offers the possibility to store all relevant information in
|
---|
83 | * two files (.dbt and .utc).
|
---|
84 | * It can be managed by SickComponent objects.
|
---|
85 | */
|
---|
86 | class SickLMSSensor : public AbstractSickSensor
|
---|
87 | {
|
---|
88 | Q_OBJECT
|
---|
89 | public:
|
---|
90 | /// Constructor
|
---|
91 | SickLMSSensor(QObject *parent);
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * @brief SickLMSSensor constructor.
|
---|
95 | * @param parent Basically, a SickComponent object.
|
---|
96 | * @param name Name of the sensor in order to write on .dbt and .utc files and to recognize every sensors used.
|
---|
97 | * @param ip The IP address of the remote Sick LMS sensor.
|
---|
98 | * @param port The port of the remote Sick LMS sensor.
|
---|
99 | * @param recording If \c true, data is recorded into dbt + utc files. Data is not recorded otherwise.
|
---|
100 | */
|
---|
101 | SickLMSSensor(QObject *parent, QString name, QString ip, int port, int recording);
|
---|
102 |
|
---|
103 | /// Destructor
|
---|
104 | ~SickLMSSensor();
|
---|
105 |
|
---|
106 | void stopActivity(); /*!< To stop the processing thread. */
|
---|
107 | void startActivity(); /*!< To start the processing thread. */
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * @brief reconstituteMessage reconstitute a complete message from received packets
|
---|
111 | * @param packet Raw data coming from the sensor.
|
---|
112 | * @param length Length of the raw data received.
|
---|
113 | * @param time Time of the last received data.
|
---|
114 | *
|
---|
115 | * A message starts with a <STX> (0x02 in ASCII) char and ends with <ETX> (0x03 in ASCII).
|
---|
116 | * This function stores packets until a complete message is received. In this case, the
|
---|
117 | * message is added to the list of MessageLMS, msgList.
|
---|
118 | */
|
---|
119 | void reconstituteMessage(const char * packet, const int length, road_time_t time);
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * @brief processScanData Parse information and process every needed values.
|
---|
123 | * @param msg Carries a message. splitMessage field of MessageLMS must be filled.
|
---|
124 | * @return Not used for the moment.
|
---|
125 | */
|
---|
126 | int processScanData(MessageLMS *msg);
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * @brief isMessageComplete find the <ETX> character (corresponding to the end of a message).
|
---|
130 | * @param packets Raw data.
|
---|
131 | * @param size Size of raw data.
|
---|
132 | * @return The index of the <ETX> character.
|
---|
133 | */
|
---|
134 | int isMessageComplete(const char* packets, unsigned int size);
|
---|
135 |
|
---|
136 | public Q_SLOTS:
|
---|
137 | /**
|
---|
138 | * @brief customEvent allows to receive the incoming data and store them into known structures.
|
---|
139 | * @param e Event that carries the Ethernet packets and receiving time.
|
---|
140 | */
|
---|
141 | void customEvent(QEvent * e);
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * @brief Configure the object, not used for the moment.
|
---|
145 | */
|
---|
146 | void configure();
|
---|
147 |
|
---|
148 | public:
|
---|
149 | /**
|
---|
150 | * @brief S_socket, used to receive and send data to the remote sensor.
|
---|
151 | */
|
---|
152 | SickSocket * S_socket;
|
---|
153 |
|
---|
154 | private:
|
---|
155 | /// Name is used to recognize between several sensors and store data into .dbt and utc files.
|
---|
156 | QString name_;
|
---|
157 |
|
---|
158 | /// The IP address of the remote Sick LDMRS sensor we are connected to.
|
---|
159 | QString ipaddr_;
|
---|
160 |
|
---|
161 | /// The SickLDMRS port
|
---|
162 | int port_;
|
---|
163 |
|
---|
164 | /// Enable storing in DBT + UTC files
|
---|
165 | bool recording_;
|
---|
166 |
|
---|
167 | scanCfg mainCfg;
|
---|
168 |
|
---|
169 | /// Append new data into the private MessagePacket @b pendingBytes.
|
---|
170 | void storePendingBytes(road_time_t time);
|
---|
171 |
|
---|
172 | /** Ask for scan configuration (frequency and angular resolution) . [See §5.2 of the documentation : telegrams]{TL_LMS1xx_5xx_TiM3xx_JEF300_JEF500_en_8014631_20120508.pdf}
|
---|
173 | Data is parsed in customEvent slot.
|
---|
174 | */
|
---|
175 | void askScanCfg();
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * @brief findSTX looks for the first character of the message <STX>.
|
---|
179 | * @param packets Raw data received.
|
---|
180 | * @param size Size of the raw data array (\c packets).
|
---|
181 | * @return Index of the <STX> character in \c packets.
|
---|
182 | */
|
---|
183 | int findSTX(const char* packets, const unsigned int size );
|
---|
184 |
|
---|
185 | /**
|
---|
186 | * @brief splitMessage Split message into arrays of string to parse.
|
---|
187 | * @param message Contains raw data and is modified to store the vector of strings.
|
---|
188 | * @return Size of the vector.
|
---|
189 | */
|
---|
190 | int splitMessage(MessageLMS* message);
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * @brief xstol convert hexadecimal values coded in ASCII to integer.
|
---|
194 | * @param str String to convert (Hexadecimal value)
|
---|
195 | * @return long integer value (to cast as needed)
|
---|
196 | */
|
---|
197 | long xstol(std::string str);
|
---|
198 |
|
---|
199 | std::string kSickDbtFileName; //!< Name of the DBT file.
|
---|
200 | std::string kSickUtcFileName; //!< Name of the UTC file.
|
---|
201 |
|
---|
202 | /// List of messages to process.
|
---|
203 | std::list<MessageLMS> msgList;
|
---|
204 |
|
---|
205 | /// Received raw data is appended into this MessagePacket.
|
---|
206 | MessagePacket pendingBytes;
|
---|
207 |
|
---|
208 | /**
|
---|
209 | * @brief Write data into .dbt + .utc files.
|
---|
210 | * @param msg
|
---|
211 | *
|
---|
212 | * SickLMS_dbt structure is filled and stored into the DBT file.
|
---|
213 | * The arrays of points' distance is then stored into the UTC file, depending on data received.
|
---|
214 | */
|
---|
215 | void writeData(MessageLMS &msg);
|
---|
216 |
|
---|
217 | pacpus::DbiteFile dbtFile_; //!< DBT file.
|
---|
218 | std::ofstream dataFile_; //!< UTC file.
|
---|
219 |
|
---|
220 | #ifdef SickLMS_SH_MEM
|
---|
221 | ShMem * shmem_;
|
---|
222 | SickLMS_shMem sickData;
|
---|
223 | #endif
|
---|
224 |
|
---|
225 | };
|
---|
226 |
|
---|
227 | } // namespace pacpus
|
---|
228 |
|
---|
229 | #endif // SICKLMSSENSOR_H
|
---|