Command.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 
24 // -- END LICENSE BLOCK ------------------------------------------------
25 
26 //----------------------------------------------------------------------
33 //----------------------------------------------------------------------
34 
35 #ifndef SICK_SAFETYSCANNERS_COLA2_COMMAND_H
36 #define SICK_SAFETYSCANNERS_COLA2_COMMAND_H
37 
38 #include <ros/ros.h>
39 
40 #include <vector>
41 
43 
46 
47 #include <boost/thread/mutex.hpp>
48 
49 namespace sick {
50 namespace cola2 {
51 
55 class Cola2Session;
56 
57 
61 class Command
62 {
63 public:
73  const uint16_t& command_type,
74  const uint16_t& command_mode);
75 
79  virtual ~Command() {}
80 
81 
85  void lockExecutionMutex();
86 
93  std::vector<uint8_t> constructTelegram(const std::vector<uint8_t>& telegram) const;
94 
102  void processReplyBase(const std::vector<uint8_t>& packet);
103 
104 
108  void waitForCompletion();
109 
110 
116  uint32_t getSessionID() const;
117 
118 
124  void setSessionID(const uint32_t& session_id);
125 
126 
132  bool wasSuccessful() const;
133 
134 
140  uint8_t getCommandType() const;
141 
147  void setCommandType(const uint8_t& command_type);
148 
154  uint8_t getCommandMode() const;
155 
161  void setCommandMode(const uint8_t& command_mode);
162 
168  uint16_t getRequestID() const;
169 
175  void setRequestID(const uint16_t& request_id);
176 
182  std::vector<uint8_t> getDataVector() const;
183 
189  void setDataVector(const std::vector<uint8_t>& data);
190 
191 protected:
193 
194  std::vector<uint8_t> expandTelegram(const std::vector<uint8_t>& telegram,
195  size_t additional_bytes) const;
196 
197 private:
198  std::shared_ptr<sick::data_processing::ParseTCPPacket> m_tcp_parser_ptr;
199 
200  boost::mutex m_execution_mutex;
201 
203 
204  uint8_t m_command_mode;
205  uint8_t m_command_type;
206 
207  uint32_t m_session_id;
208  uint16_t m_request_id;
209 
210  std::vector<uint8_t> m_data_vector;
211 
212  virtual bool processReply() = 0;
213  virtual std::vector<uint8_t> addTelegramData(const std::vector<uint8_t>& telegram) const = 0;
214 
215  std::vector<uint8_t> addTelegramHeader(const std::vector<uint8_t>& telegram) const;
216  std::vector<uint8_t> prepareHeader() const;
217  void writeCola2StxToDataPtr(std::vector<uint8_t>::iterator data_ptr) const;
218  void writeLengthToDataPtr(std::vector<uint8_t>::iterator data_ptr,
219  const std::vector<uint8_t>& telegram) const;
220  void writeCola2HubCntrToDataPtr(std::vector<uint8_t>::iterator data_ptr) const;
221  void writeCola2NoCToDataPtr(std::vector<uint8_t>::iterator data_ptr) const;
222  void writeSessionIdToDataPtr(std::vector<uint8_t>::iterator data_ptr) const;
223  void writeRequestIdToDataPtr(std::vector<uint8_t>::iterator data_ptr) const;
224  void writeCommandTypeToDataPtr(std::vector<uint8_t>::iterator data_ptr) const;
225  void writeCommandModeToDataPtr(std::vector<uint8_t>::iterator data_ptr) const;
226  void writeDataToDataPtr(std::vector<uint8_t>::iterator data_ptr,
227  const std::vector<uint8_t>& telegram) const;
228 };
229 
230 
231 } // namespace cola2
232 } // namespace sick
233 
234 
235 #endif // SICK_SAFETYSCANNERS_COLA2_COMMAND_H
void setCommandMode(const uint8_t &command_mode)
Sets the command mode.
Definition: Command.cpp:96
void setSessionID(const uint32_t &session_id)
Sets the session ID.
Definition: Command.cpp:106
void setDataVector(const std::vector< uint8_t > &data)
Sets the data vector.
Definition: Command.cpp:152
std::vector< uint8_t > constructTelegram(const std::vector< uint8_t > &telegram) const
Adds the data to the telegram and afterwards the header with the correct length.
Definition: Command.cpp:58
void writeRequestIdToDataPtr(std::vector< uint8_t >::iterator data_ptr) const
Definition: Command.cpp:200
std::vector< uint8_t > getDataVector() const
Returns the data vector.
Definition: Command.cpp:147
uint16_t getRequestID() const
Returns the request id of the command.
Definition: Command.cpp:111
void writeCola2NoCToDataPtr(std::vector< uint8_t >::iterator data_ptr) const
Definition: Command.cpp:189
void writeCommandTypeToDataPtr(std::vector< uint8_t >::iterator data_ptr) const
Definition: Command.cpp:205
boost::mutex m_execution_mutex
Definition: Command.h:200
uint8_t getCommandType() const
Returns the command type.
Definition: Command.cpp:81
void setRequestID(const uint16_t &request_id)
Sets the request ID of the command.
Definition: Command.cpp:116
data
void writeCommandModeToDataPtr(std::vector< uint8_t >::iterator data_ptr) const
Definition: Command.cpp:210
void setCommandType(const uint8_t &command_type)
Sets the command type.
Definition: Command.cpp:86
Base class for commands. Defines the base interface and does the common tasks.
Definition: Command.h:61
Command(sick::cola2::Cola2Session &session, const uint16_t &command_type, const uint16_t &command_mode)
Constructor of the command. Sets the common variables for a command to the sensor.
Definition: Command.cpp:43
uint32_t getSessionID() const
Returns the current session ID.
Definition: Command.cpp:101
std::vector< uint8_t > prepareHeader() const
Definition: Command.cpp:142
std::shared_ptr< sick::data_processing::ParseTCPPacket > m_tcp_parser_ptr
Definition: Command.h:198
void waitForCompletion()
Scooped call to the mutex, which will block until the reply was processed.
Definition: Command.cpp:71
void writeLengthToDataPtr(std::vector< uint8_t >::iterator data_ptr, const std::vector< uint8_t > &telegram) const
Definition: Command.cpp:176
uint32_t m_session_id
Definition: Command.h:207
std::vector< uint8_t > expandTelegram(const std::vector< uint8_t > &telegram, size_t additional_bytes) const
Definition: Command.cpp:121
void writeSessionIdToDataPtr(std::vector< uint8_t >::iterator data_ptr) const
Definition: Command.cpp:195
sick::cola2::Cola2Session & m_session
Definition: Command.h:192
void processReplyBase(const std::vector< uint8_t > &packet)
Parses the da incoming data package and then processes it with the inherited processReply. Afterwards the mutex will be unlocked to allow new commands to be send.
Definition: Command.cpp:64
uint8_t getCommandMode() const
Returns the command mode.
Definition: Command.cpp:91
void lockExecutionMutex()
Locks a mutex to prevent other commands being executed in parallel.
Definition: Command.cpp:53
void writeCola2HubCntrToDataPtr(std::vector< uint8_t >::iterator data_ptr) const
Definition: Command.cpp:183
void writeDataToDataPtr(std::vector< uint8_t >::iterator data_ptr, const std::vector< uint8_t > &telegram) const
Definition: Command.cpp:157
std::vector< uint8_t > addTelegramHeader(const std::vector< uint8_t > &telegram) const
Definition: Command.cpp:132
std::vector< uint8_t > m_data_vector
Definition: Command.h:210
uint8_t m_command_type
Definition: Command.h:205
Establishes a cola2 session with a sensor and enables execution of commands in this session...
Definition: Cola2Session.h:72
bool wasSuccessful() const
Returns if the command was successfully parsed.
Definition: Command.cpp:76
virtual ~Command()
We have virtual member functions, so a virtual destructor is needed.
Definition: Command.h:79
virtual bool processReply()=0
uint16_t m_request_id
Definition: Command.h:208
uint8_t m_command_mode
Definition: Command.h:204
virtual std::vector< uint8_t > addTelegramData(const std::vector< uint8_t > &telegram) const =0
void writeCola2StxToDataPtr(std::vector< uint8_t >::iterator data_ptr) const
Definition: Command.cpp:170


sick_safetyscanners
Author(s): Lennart Puck
autogenerated on Fri Apr 2 2021 02:45:41