sick_scan_common_nw.h
Go to the documentation of this file.
1 //
2 // Created by michael on 1/22/18.
3 //
4 
5 #ifndef SICK_SCAN_SICK_SCAN_COMMON_NW_H
6 #define SICK_SCAN_SICK_SCAN_COMMON_NW_H
7 
9 #include "sick_scan/tcp/tcp.hpp"
10 #include <map> // for std::map
11 
12 //
13 // SickScanCommonNw.cpp
14 //
15 // Created on: 18.07.2011
16 // Author: sick
17 //
18 #include "sick_scan/tcp/tcp.hpp"
21 #include "sick_scan/tcp/Mutex.hpp"
22 
23 
24 #include <string>
25 
26 class SopasEventMessage;
27 
28 class SopasAnswer;
29 
31 {
35 };
36 
37 
39 {
40 public:
41 
42 
44 
46 
47  bool init(std::string ipAddress,
48  unsigned short portNumber,
49  Tcp::DisconnectFunction disconnectFunction,
50  void *obj);
51 
53  void *obj);
54 
56  bool connect();
57 
59  bool isConnected();
60 
68  bool disconnect();
69 
70  void sendCommandBuffer(UINT8 *buffer, UINT16 len);
71 
72 private:
73  // TCP
74  bool openTcpConnection();
75 
76  void closeTcpConnection();
77 
79  static void readCallbackFunctionS(void *obj, UINT8 *buffer, UINT32 &numOfBytes);
80 
81  void readCallbackFunction(UINT8 *buffer, UINT32 &numOfBytes);
82 
84 
85  void processFrame(SopasEventMessage &frame);
86 
88 
89 
90  // Response buffer
94 
95  // Receive buffer
98 
99 
100 
101  // TCP
103  std::string m_ipAddress;
106 
107 
108  void copyFrameToResposeBuffer(UINT32 frameLength);
109 
110  void removeFrameFromReceiveBuffer(UINT32 frameLength);
111 
112 protected:
113  enum State
114  {
119  ,
123  // , RUNNING
124  };
125 
127 };
128 
131 {
132 public:
135 
138  {}
139 
147  SopasEventMessage(BYTE *buffer, SopasProtocol protocol, UINT32 frameLength);
148 
150  {
151  return m_protocol;
152  }
153 
154 
155  UINT32 size() const
156  {
157  return m_frameLength;
158  }
159 
161  UINT32 getPayLoadLength() const;
162 
163  std::string getCommandString() const;
164 
166  BYTE *getPayLoad();
167 
168  BYTE *getRawData();
169 
172 
174  std::string getVariableName();
175 
176  bool isValid() const
177  { return (m_buffer != NULL); }
178 
179 private:
180  void detectEncoding();
181 
182  void detectMessageType();
183 
184 private:
188 };
189 
192 {
193 public:
195  SopasAnswer(const BYTE *answer, UINT32 answerLength);
196 
198  ~SopasAnswer();
199 
201  { return m_answerBuffer; }
202 
204  { return m_answerLength; }
205 
206  bool isValid()
207  { return (m_answerBuffer != NULL); }
208 
209 private:
212 };
213 
214 #endif //SICK_SCAN_SICK_SCAN_COMMON_NW_H
UINT16
uint16_t UINT16
Definition: BasicDatatypes.hpp:27
UINT8
uint8_t UINT8
Definition: BasicDatatypes.hpp:29
SopasEventMessage::getPayLoad
BYTE * getPayLoad()
contains 's' + command string(2 byte) + content(payload length - 3)
Definition: sick_scan_common_nw.cpp:573
SopasEventMessage::getProtocolType
SopasProtocol getProtocolType() const
Definition: sick_scan_common_nw.h:149
errorhandler.hpp
SickScanCommonNw::connect
bool connect()
Connects to a sensor via tcp and reads the device name.
Definition: sick_scan_common_nw.cpp:96
SickScanCommonNw::m_ipAddress
std::string m_ipAddress
Definition: sick_scan_common_nw.h:103
CoLa_Unknown
@ CoLa_Unknown
Unknown Command Language.
Definition: sick_scan_common_nw.h:34
SickScanCommonNw::m_beVerbose
bool m_beVerbose
Definition: sick_scan_common_nw.h:87
SickScanCommonNw
Interface for TCP/IP.
Definition: sick_scan_common_nw.h:38
BasicDatatypes.hpp
SickScanCommonNw::m_receiveDataMutex
Mutex m_receiveDataMutex
Access mutex for buffer.
Definition: sick_scan_common_nw.h:93
SickScanCommonNw::m_numberOfBytesInReceiveBuffer
UINT32 m_numberOfBytesInReceiveBuffer
Number of bytes in buffer.
Definition: sick_scan_common_nw.h:96
SickScanCommonNw::readCallbackFunction
void readCallbackFunction(UINT8 *buffer, UINT32 &numOfBytes)
Definition: sick_scan_common_nw.cpp:175
SickScanCommonNw::m_numberOfBytesInResponseBuffer
UINT32 m_numberOfBytesInResponseBuffer
Number of bytes in buffer.
Definition: sick_scan_common_nw.h:91
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:56
SopasEventMessage::isValid
bool isValid() const
Definition: sick_scan_common_nw.h:176
SickScanCommonNw::~SickScanCommonNw
~SickScanCommonNw()
Definition: sick_scan_common_nw.cpp:42
Tcp::DisconnectFunction
void(* DisconnectFunction)(void *obj)
Definition: tcp.hpp:53
Tcp::ReadFunction
void(* ReadFunction)(void *obj, UINT8 *inputBuffer, UINT32 &numBytes)
Definition: tcp.hpp:49
SickScanCommonNw::removeFrameFromReceiveBuffer
void removeFrameFromReceiveBuffer(UINT32 frameLength)
Definition: sick_scan_common_nw.cpp:487
SopasEventMessage::m_protocol
SopasProtocol m_protocol
Definition: sick_scan_common_nw.h:186
SopasEventMessage::m_buffer
BYTE * m_buffer
Definition: sick_scan_common_nw.h:185
SickScanCommonNw::m_state
State m_state
Definition: sick_scan_common_nw.h:126
INT32
int32_t INT32
Definition: BasicDatatypes.hpp:25
SickScanCommonNw::m_tcp
Tcp m_tcp
Definition: sick_scan_common_nw.h:102
CoLa_A
@ CoLa_A
Command Language ASCI.
Definition: sick_scan_common_nw.h:32
SopasEventMessage::getRawData
BYTE * getRawData()
get SOPAS raw data include header and CRC
Definition: sick_scan_common_nw.cpp:597
SickScanCommonNw::SickScanCommonNw
SickScanCommonNw()
Definition: sick_scan_common_nw.cpp:35
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:165
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:97
SopasAnswer::isValid
bool isValid()
Definition: sick_scan_common_nw.h:206
Mutex
Definition: Mutex.hpp:15
SickScanCommonNw::State
State
Definition: sick_scan_common_nw.h:113
SopasEventMessage::m_frameLength
UINT32 m_frameLength
Definition: sick_scan_common_nw.h:187
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:70
SopasAnswer::size
UINT32 size()
Definition: sick_scan_common_nw.h:203
Tcp
Definition: tcp.hpp:30
SopasAnswer::~SopasAnswer
~SopasAnswer()
Destructor. Frees the memory for the copied buffer.
SopasAnswer::m_answerLength
UINT32 m_answerLength
Definition: sick_scan_common_nw.h:210
SickScanCommonNw::sendCommandBuffer
void sendCommandBuffer(UINT8 *buffer, UINT16 len)
Definition: sick_scan_common_nw.cpp:426
SickScanCommonNw::CONNECTED
@ CONNECTED
Definition: sick_scan_common_nw.h:120
SickScanCommonNw::m_responseBuffer
UINT8 m_responseBuffer[1024]
Receive buffer for everything except scan data and eval case data.
Definition: sick_scan_common_nw.h:92
SickScanCommonNw::m_portNumber
UINT16 m_portNumber
Definition: sick_scan_common_nw.h:104
SickScanCommonNw::findFrameInReceiveBuffer
SopasEventMessage findFrameInReceiveBuffer()
Definition: sick_scan_common_nw.cpp:249
SopasAnswer::getBuffer
BYTE * getBuffer()
Definition: sick_scan_common_nw.h:200
SickScanCommonNw::closeTcpConnection
void closeTcpConnection()
Definition: sick_scan_common_nw.cpp:154
SopasEventMessage::getPayLoadLength
UINT32 getPayLoadLength() const
contains 's' + command string(2 byte) + content(payload length - 3)
Definition: sick_scan_common_nw.cpp:525
SickScanCommonNw::setReadCallbackFunction
bool setReadCallbackFunction(Tcp::ReadFunction readFunction, void *obj)
Definition: sick_scan_common_nw.cpp:82
tcp.hpp
SickScanCommonNw::openTcpConnection
bool openTcpConnection()
Definition: sick_scan_common_nw.cpp:136
SopasProtocol
SopasProtocol
Definition: sick_scan_common_nw.h:30
SopasEventMessage::SopasEventMessage
SopasEventMessage()
Default constructor.
Definition: sick_scan_common_nw.cpp:512
SickScanCommonNw::processFrame
void processFrame(SopasEventMessage &frame)
Definition: sick_scan_common_nw.cpp:437
CoLa_B
@ CoLa_B
Command Language binary.
Definition: sick_scan_common_nw.h:33
SickScanCommonNw::isConnected
bool isConnected()
Returns true if the tcp connection is established.
Definition: sick_scan_common_nw.cpp:125
SickScanCommonNw::CONSTRUCTED
@ CONSTRUCTED
Object has been constructed. Use init() to go into CONNECTED state.
Definition: sick_scan_common_nw.h:116
SopasAnswer
Class that encapsulates a buffer that was sent as return to a sync call. (variable / method)
Definition: sick_scan_common_nw.h:191
SopasEventMessage::~SopasEventMessage
~SopasEventMessage()
Destructor.
Definition: sick_scan_common_nw.h:137
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:26
SopasEventMessage::size
UINT32 size() const
Definition: sick_scan_common_nw.h:155
SopasAnswer::m_answerBuffer
BYTE * m_answerBuffer
Definition: sick_scan_common_nw.h:211
SickScanCommonNw::m_protocol
SopasProtocol m_protocol
Definition: sick_scan_common_nw.h:105
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:605
SopasEventMessage::detectEncoding
void detectEncoding()
SopasEventMessage
Class that represents a message that was sent by a sensor. (Event message)
Definition: sick_scan_common_nw.h:130
SopasEventMessage::getCommandString
std::string getCommandString() const
Returns two character long command.
Definition: sick_scan_common_nw.cpp:549
SickScanCommonNw::copyFrameToResposeBuffer
void copyFrameToResposeBuffer(UINT32 frameLength)
Definition: sick_scan_common_nw.cpp:462


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Thu Sep 8 2022 02:30:19