sick_scan_common_nw.h
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 //
3 // Created by michael on 1/22/18.
4 //
5 
6 #ifndef SICK_SCAN_SICK_SCAN_COMMON_NW_H
7 #define SICK_SCAN_SICK_SCAN_COMMON_NW_H
8 
10 #include "sick_scan/tcp/tcp.hpp"
11 #include <map> // for std::map
12 
13 //
14 // SickScanCommonNw.cpp
15 //
16 // Created on: 18.07.2011
17 // Author: sick
18 //
19 #include "sick_scan/tcp/tcp.hpp"
22 #include "sick_scan/tcp/Mutex.hpp"
23 
24 
25 #include <string>
26 
27 class SopasEventMessage;
28 
29 class SopasAnswer;
30 
32 {
36 };
37 
38 
40 {
41 public:
42 
43 
45 
47 
48  bool init(std::string ipAddress,
49  unsigned short portNumber,
50  Tcp::DisconnectFunction disconnectFunction,
51  void *obj);
52 
54  void *obj);
55 
57  bool connect();
58 
60  bool isConnected();
61 
69  bool disconnect();
70 
71  bool sendCommandBuffer(UINT8 *buffer, UINT16 len);
72 
73  // Returns a timestamp in nanoseconds of the last received tcp message (or 0 if no message received)
75 
76 private:
77  // TCP
78  bool openTcpConnection();
79 
80  void closeTcpConnection();
81 
83  static void readCallbackFunctionS(void *obj, UINT8 *buffer, UINT32 &numOfBytes);
84 
85  void readCallbackFunction(UINT8 *buffer, UINT32 &numOfBytes);
86 
88 
89  void processFrame(SopasEventMessage &frame);
90 
92 
93 
94  // Response buffer
98 
99  // Receive buffer
102 
103 
104 
105  // TCP
107  std::string m_ipAddress;
110 
111 
112  void copyFrameToResposeBuffer(UINT32 frameLength);
113 
114  void removeFrameFromReceiveBuffer(UINT32 frameLength);
115 
116 protected:
117  enum State
118  {
123  ,
127  // , RUNNING
128  };
129 
131 };
132 
135 {
136 public:
139 
142  {}
143 
151  SopasEventMessage(BYTE *buffer, SopasProtocol protocol, UINT32 frameLength);
152 
154  {
155  return m_protocol;
156  }
157 
158 
159  UINT32 size() const
160  {
161  return m_frameLength;
162  }
163 
165  UINT32 getPayLoadLength() const;
166 
167  std::string getCommandString() const;
168 
170  BYTE *getPayLoad();
171 
172  BYTE *getRawData();
173 
176 
178  std::string getVariableName();
179 
180  bool isValid() const
181  { return (m_buffer != NULL); }
182 
183 private:
184  void detectEncoding();
185 
186  void detectMessageType();
187 
188 private:
192 };
193 
196 {
197 public:
199  SopasAnswer(const BYTE *answer, UINT32 answerLength);
200 
202  ~SopasAnswer();
203 
205  { return m_answerBuffer; }
206 
208  { return m_answerLength; }
209 
210  bool isValid()
211  { return (m_answerBuffer != NULL); }
212 
213 private:
216 };
217 
218 #endif //SICK_SCAN_SICK_SCAN_COMMON_NW_H
UINT16
uint16_t UINT16
Definition: BasicDatatypes.hpp:73
UINT8
uint8_t UINT8
Definition: BasicDatatypes.hpp:75
SopasEventMessage::getPayLoad
BYTE * getPayLoad()
contains 's' + command string(2 byte) + content(payload length - 3)
Definition: sick_scan_common_nw.cpp:626
SopasEventMessage::getProtocolType
SopasProtocol getProtocolType() const
Definition: sick_scan_common_nw.h:153
SickScanCommonNw::sendCommandBuffer
bool sendCommandBuffer(UINT8 *buffer, UINT16 len)
Definition: sick_scan_common_nw.cpp:479
NULL
#define NULL
errorhandler.hpp
SickScanCommonNw::connect
bool connect()
Connects to a sensor via tcp and reads the device name.
Definition: sick_scan_common_nw.cpp:142
SickScanCommonNw::m_ipAddress
std::string m_ipAddress
Definition: sick_scan_common_nw.h:107
CoLa_Unknown
@ CoLa_Unknown
Unknown Command Language.
Definition: sick_scan_common_nw.h:35
SickScanCommonNw::m_beVerbose
bool m_beVerbose
Definition: sick_scan_common_nw.h:91
SickScanCommonNw
Interface for TCP/IP.
Definition: sick_scan_common_nw.h:39
BasicDatatypes.hpp
SickScanCommonNw::m_receiveDataMutex
Mutex m_receiveDataMutex
Access mutex for buffer.
Definition: sick_scan_common_nw.h:97
SickScanCommonNw::m_numberOfBytesInReceiveBuffer
UINT32 m_numberOfBytesInReceiveBuffer
Number of bytes in buffer.
Definition: sick_scan_common_nw.h:100
SickScanCommonNw::readCallbackFunction
void readCallbackFunction(UINT8 *buffer, UINT32 &numOfBytes)
Definition: sick_scan_common_nw.cpp:228
SickScanCommonNw::m_numberOfBytesInResponseBuffer
UINT32 m_numberOfBytesInResponseBuffer
Number of bytes in buffer.
Definition: sick_scan_common_nw.h:95
BYTE
unsigned char BYTE
SickScanCommonNw::disconnect
bool disconnect()
Closes the connection to the LMS. This is the opposite of init().
Definition: sick_scan_common_nw.cpp:102
SopasEventMessage::isValid
bool isValid() const
Definition: sick_scan_common_nw.h:180
SickScanCommonNw::~SickScanCommonNw
~SickScanCommonNw()
Definition: sick_scan_common_nw.cpp:88
Tcp::DisconnectFunction
void(* DisconnectFunction)(void *obj)
Definition: tcp.hpp:59
Tcp::ReadFunction
void(* ReadFunction)(void *obj, UINT8 *inputBuffer, UINT32 &numBytes)
Definition: tcp.hpp:55
SickScanCommonNw::removeFrameFromReceiveBuffer
void removeFrameFromReceiveBuffer(UINT32 frameLength)
Definition: sick_scan_common_nw.cpp:540
SopasEventMessage::m_protocol
SopasProtocol m_protocol
Definition: sick_scan_common_nw.h:190
SopasEventMessage::m_buffer
BYTE * m_buffer
Definition: sick_scan_common_nw.h:189
SickScanCommonNw::m_state
State m_state
Definition: sick_scan_common_nw.h:130
INT32
int32_t INT32
Definition: BasicDatatypes.hpp:71
SickScanCommonNw::m_tcp
Tcp m_tcp
Definition: sick_scan_common_nw.h:106
CoLa_A
@ CoLa_A
Command Language ASCI.
Definition: sick_scan_common_nw.h:33
SopasEventMessage::getRawData
BYTE * getRawData()
get SOPAS raw data include header and CRC
Definition: sick_scan_common_nw.cpp:650
SickScanCommonNw::SickScanCommonNw
SickScanCommonNw()
Definition: sick_scan_common_nw.cpp:81
SopasEventMessage::detectMessageType
void detectMessageType()
Mutex.hpp
SickScanCommonNw::readCallbackFunctionS
static void readCallbackFunctionS(void *obj, UINT8 *buffer, UINT32 &numOfBytes)
Function that will be called on incomming data via tcp.
Definition: sick_scan_common_nw.cpp:218
toolbox.hpp
SickScanCommonNw::m_receiveBuffer
UINT8 m_receiveBuffer[25000]
Low-Level receive buffer for all data (25000 should be enough for NAV300 Events)
Definition: sick_scan_common_nw.h:101
SopasAnswer::isValid
bool isValid()
Definition: sick_scan_common_nw.h:210
Mutex
Definition: Mutex.hpp:19
SickScanCommonNw::State
State
Definition: sick_scan_common_nw.h:117
SopasEventMessage::m_frameLength
UINT32 m_frameLength
Definition: sick_scan_common_nw.h:191
SopasEventMessage::getVariableName
std::string getVariableName()
Returns the name of a variable (answer to read variable by name). In case of error an empty value wil...
SickScanCommonNw::init
bool init(std::string ipAddress, unsigned short portNumber, Tcp::DisconnectFunction disconnectFunction, void *obj)
Definition: sick_scan_common_nw.cpp:116
SopasAnswer::size
UINT32 size()
Definition: sick_scan_common_nw.h:207
Tcp
Definition: tcp.hpp:36
SopasAnswer::~SopasAnswer
~SopasAnswer()
Destructor. Frees the memory for the copied buffer.
SopasAnswer::m_answerLength
UINT32 m_answerLength
Definition: sick_scan_common_nw.h:214
SickScanCommonNw::CONNECTED
@ CONNECTED
Definition: sick_scan_common_nw.h:124
SickScanCommonNw::m_responseBuffer
UINT8 m_responseBuffer[1024]
Receive buffer for everything except scan data and eval case data.
Definition: sick_scan_common_nw.h:96
SickScanCommonNw::m_portNumber
UINT16 m_portNumber
Definition: sick_scan_common_nw.h:108
SickScanCommonNw::findFrameInReceiveBuffer
SopasEventMessage findFrameInReceiveBuffer()
Definition: sick_scan_common_nw.cpp:302
SopasAnswer::getBuffer
BYTE * getBuffer()
Definition: sick_scan_common_nw.h:204
SickScanCommonNw::closeTcpConnection
void closeTcpConnection()
Definition: sick_scan_common_nw.cpp:207
SopasEventMessage::getPayLoadLength
UINT32 getPayLoadLength() const
contains 's' + command string(2 byte) + content(payload length - 3)
Definition: sick_scan_common_nw.cpp:578
SickScanCommonNw::setReadCallbackFunction
bool setReadCallbackFunction(Tcp::ReadFunction readFunction, void *obj)
Definition: sick_scan_common_nw.cpp:128
tcp.hpp
SickScanCommonNw::openTcpConnection
bool openTcpConnection()
Definition: sick_scan_common_nw.cpp:182
SopasProtocol
SopasProtocol
Definition: sick_scan_common_nw.h:31
sick_scan_base.h
SopasEventMessage::SopasEventMessage
SopasEventMessage()
Default constructor.
Definition: sick_scan_common_nw.cpp:565
SickScanCommonNw::processFrame
void processFrame(SopasEventMessage &frame)
Definition: sick_scan_common_nw.cpp:490
CoLa_B
@ CoLa_B
Command Language binary.
Definition: sick_scan_common_nw.h:34
SickScanCommonNw::isConnected
bool isConnected()
Returns true if the tcp connection is established.
Definition: sick_scan_common_nw.cpp:171
SickScanCommonNw::CONSTRUCTED
@ CONSTRUCTED
Object has been constructed. Use init() to go into CONNECTED state.
Definition: sick_scan_common_nw.h:120
SopasAnswer
Class that encapsulates a buffer that was sent as return to a sync call. (variable / method)
Definition: sick_scan_common_nw.h:195
SopasEventMessage::~SopasEventMessage
~SopasEventMessage()
Destructor.
Definition: sick_scan_common_nw.h:141
SopasAnswer::SopasAnswer
SopasAnswer(const BYTE *answer, UINT32 answerLength)
Constructor. Copies the content of the answer into the buffer of this object.
UINT32
uint32_t UINT32
Definition: BasicDatatypes.hpp:72
SopasEventMessage::size
UINT32 size() const
Definition: sick_scan_common_nw.h:159
SopasAnswer::m_answerBuffer
BYTE * m_answerBuffer
Definition: sick_scan_common_nw.h:215
SickScanCommonNw::m_protocol
SopasProtocol m_protocol
Definition: sick_scan_common_nw.h:109
SopasEventMessage::getVariableIndex
INT32 getVariableIndex()
Returns the index of a variable (answer to read variable by index). In case of error a negative value...
Definition: sick_scan_common_nw.cpp:658
SopasEventMessage::detectEncoding
void detectEncoding()
SopasEventMessage
Class that represents a message that was sent by a sensor. (Event message)
Definition: sick_scan_common_nw.h:134
SickScanCommonNw::getNanosecTimestampLastTcpMessageReceived
uint64_t getNanosecTimestampLastTcpMessageReceived(void)
Definition: sick_scan_common_nw.cpp:199
SopasEventMessage::getCommandString
std::string getCommandString() const
Returns two character long command.
Definition: sick_scan_common_nw.cpp:602
SickScanCommonNw::copyFrameToResposeBuffer
void copyFrameToResposeBuffer(UINT32 frameLength)
Definition: sick_scan_common_nw.cpp:515


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:10