source: pacpussensors/trunk/Sick/SickSocket.h@ 118

Last change on this file since 118 was 42, checked in by cfougera, 11 years ago

Last version

File size: 3.1 KB
RevLine 
[37]1/*********************************************************************
2// created: 2014/02/02
3// filename: SickSocket.h
4//
[42]5// author: Gerald Dherbomez
6// Modified by Cyril Fougeray
[37]7// Copyright Heudiasyc UMR UTC/CNRS 6599
8//
9// version: $Id: $
10//
11// purpose: Defintion of the SickSocket class
12// Management of the socket connection with Sick sensors
13*********************************************************************/
14
15#ifndef _SICKSOCKET_H_
16#define _SICKSOCKET_H_
17
18#include <cmath>
19#include <QObject>
20#include <QTcpSocket>
21#include <QMutex>
22#include <QEvent>
23
24#include "Pacpus/kernel/road_time.h"
25
26namespace pacpus {
27
28class AbstractSickSensor;
29
30// Sensors classes :
31class SickLDMRSSensor;
32class SickLMSSensor;
33
[42]34/**
35 * @brief The SickFrame class
36 */
[37]37class SickFrame
38{
39public:
[42]40 /**
41 * @brief SickFrame constructor
42 */
[37]43 SickFrame()
44 {
45 size = 0;
46 time = 0;
47 msg = NULL;
48 }
49
[42]50 /// Destructor
[37]51 ~SickFrame()
52 {
53 delete[] msg; // check for NULL is not necessary
54 }
55
[42]56 qint64 size; //!< Size of incoming packet.
57 road_time_t time; //!< Time when packet is received.
58 char * msg; //!< Packet (raw data).
[37]59};
60
[42]61/**
62 * @brief The SickFrameEvent class
63 * QEvent that encapsulates packets.
64 */
[37]65class SickFrameEvent
66 : public QEvent
67{
68public:
[42]69 /// Constructor
[37]70 SickFrameEvent()
71 : QEvent((QEvent::Type)(QEvent::User + 522))
72 {}
73
[42]74 /// Destructor
[37]75 ~SickFrameEvent()
76 {}
77
[42]78 /// Packet data
[37]79 SickFrame * frame;
80};
81
[42]82/**
83 * @brief The SickSocket class
84 * Handles the ethernet connection with the remote sensor.
85 */
[37]86class SickSocket
87 : public QObject
88{
89 Q_OBJECT
90
91public:
[42]92 /// Constructor
[37]93 SickSocket(AbstractSickSensor * parent);
[42]94
95 /// Destructor
[37]96 ~SickSocket();
97
98public Q_SLOTS:
[42]99 /// Enable the connection to the server
[37]100 void connectToServer(QString host, int port);
101
[42]102 /// Warns about connection of the socket and launch configuration of the socket.
[37]103 int socketConnected();
104
[42]105 /** Called when incoming data is received. Create an event and send it to the sensor's handler. @see AbstractSickComponent */
[37]106 void socketReadyRead();
107
[42]108 /// Close the connection with the server
[37]109 void closeSocket() { socket->close(); }
110
[42]111 /**
112 * @brief sendToServer Sends data to the remote lidar.
113 * @param data Data to be sent, translated in ASCII.
114 */
[37]115 void sendToServer(QString data);
116Q_SIGNALS:
[42]117 /// Asked for configuring sensor.
[37]118 void configuration();
119
120protected slots:
[42]121 /// Says to the user the connection is closed.
[37]122 void socketConnectionClosed();
123
[42]124 /// Warns the user an error occured
[37]125 void socketError(QAbstractSocket::SocketError e);
126
127private:
[42]128 /// Socket
[37]129 QTcpSocket *socket;
[42]130
131 /// Mutex to use socket resource.
[37]132 QMutex mutex;
133
[42]134 /// Parent (contains slots to connect to in order to pass the received data).
[37]135 AbstractSickSensor *myParent;
136};
137
138} // namespace pacpus
139
140#endif // _SICKSOCKET_H_
Note: See TracBrowser for help on using the repository browser.