source: pacpussensors/trunk/Sick/SickLMSSensor.h@ 61

Last change on this file since 61 was 42, checked in by cfougera, 10 years ago

Last version

File size: 7.5 KB
Line 
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
39class QEvent;
40
41namespace pacpus {
42
43class ShMem;
44class 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 */
53class SICKLMS_API MessageLMS
54{
55public:
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 */
86class SickLMSSensor : public AbstractSickSensor
87{
88 Q_OBJECT
89public:
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 run() {}
107
108 void stopActivity(); /*!< To stop the processing thread. */
109 void startActivity(); /*!< To start the processing thread. */
110
111 /**
112 * @brief reconstituteMessage reconstitute a complete message from received packets
113 * @param packet Raw data coming from the sensor.
114 * @param length Length of the raw data received.
115 * @param time Time of the last received data.
116 *
117 * A message starts with a <STX> (0x02 in ASCII) char and ends with <ETX> (0x03 in ASCII).
118 * This function stores packets until a complete message is received. In this case, the
119 * message is added to the list of MessageLMS, msgList.
120 */
121 void reconstituteMessage(const char * packet, const int length, road_time_t time);
122
123 /**
124 * @brief processScanData Parse information and process every needed values.
125 * @param msg Carries a message. splitMessage field of MessageLMS must be filled.
126 * @return Not used for the moment.
127 */
128 int processScanData(MessageLMS *msg);
129
130 /**
131 * @brief isMessageComplete find the <ETX> character (corresponding to the end of a message).
132 * @param packets Raw data.
133 * @param size Size of raw data.
134 * @return The index of the <ETX> character.
135 */
136 int isMessageComplete(const char* packets, unsigned int size);
137
138public Q_SLOTS:
139 /**
140 * @brief customEvent allows to receive the incoming data and store them into known structures.
141 * @param e Event that carries the Ethernet packets and receiving time.
142 */
143 void customEvent(QEvent * e);
144
145 /**
146 * @brief Configure the object, not used for the moment.
147 */
148 void configure();
149
150public:
151 /**
152 * @brief S_socket, used to receive and send data to the remote sensor.
153 */
154 SickSocket * S_socket;
155
156private:
157 /// Name is used to recognize between several sensors and store data into .dbt and utc files.
158 QString name_;
159
160 /// The IP address of the remote Sick LDMRS sensor we are connected to.
161 QString ipaddr_;
162
163 /// The SickLDMRS port
164 int port_;
165
166 /// Enable storing in DBT + UTC files
167 bool recording_;
168
169 scanCfg mainCfg;
170
171 /// Append new data into the private MessagePacket @b pendingBytes.
172 void storePendingBytes(road_time_t time);
173
174 /** 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}
175 Data is parsed in customEvent slot.
176 */
177 void askScanCfg();
178
179 /**
180 * @brief findSTX looks for the first character of the message <STX>.
181 * @param packets Raw data received.
182 * @param size Size of the raw data array (\c packets).
183 * @return Index of the <STX> character in \c packets.
184 */
185 int findSTX(const char* packets, const unsigned int size );
186
187 /**
188 * @brief splitMessage Split message into arrays of string to parse.
189 * @param message Contains raw data and is modified to store the vector of strings.
190 * @return Size of the vector.
191 */
192 int splitMessage(MessageLMS* message);
193
194 /**
195 * @brief xstol convert hexadecimal values coded in ASCII to integer.
196 * @param str String to convert (Hexadecimal value)
197 * @return long integer value (to cast as needed)
198 */
199 long xstol(std::string str);
200
201 std::string kSickDbtFileName; //!< Name of the DBT file.
202 std::string kSickUtcFileName; //!< Name of the UTC file.
203
204 /// List of messages to process.
205 std::list<MessageLMS> msgList;
206
207 /// Received raw data is appended into this MessagePacket.
208 MessagePacket pendingBytes;
209
210 /**
211 * @brief Write data into .dbt + .utc files.
212 * @param msg
213 *
214 * SickLMS_dbt structure is filled and stored into the DBT file.
215 * The arrays of points' distance is then stored into the UTC file, depending on data received.
216 */
217 void writeData(MessageLMS &msg);
218
219 pacpus::DbiteFile dbtFile_; //!< DBT file.
220 std::ofstream dataFile_; //!< UTC file.
221
222#ifdef SickLMS_SH_MEM
223 ShMem * shmem_;
224 SickLMS_shMem sickData;
225#endif
226
227};
228
229} // namespace pacpus
230
231#endif // SICKLMSSENSOR_H
Note: See TracBrowser for help on using the repository browser.