CreateSession.cpp
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 
36 
39 
40 namespace sick {
41 namespace cola2 {
42 
44  : Command(session, 0x4F, 0x58) // see cola2 manual 0x4F = O, 0x58 = X
45 {
46 }
47 
48 std::vector<uint8_t> CreateSession::addTelegramData(const std::vector<uint8_t>& telegram) const
49 {
50  auto output = expandTelegram(telegram, 5);
51  // Add new values after telegram
52  auto new_data_offset_it = output.begin() + telegram.size();
53  writeHeartbeatTimeoutToDataPtr(new_data_offset_it);
54  writeClientIdToDataPtr(new_data_offset_it);
55  return output;
56 }
57 
59 {
60  return true;
61 }
62 
64 {
65  bool result = false;
66  if ((getCommandType() == 'O' && getCommandMode() == 'A') ||
67  (getCommandType() == 0x4F && getCommandMode() == 0x41))
68  {
70  ROS_INFO("Successfully opened Cola2 session with sessionID: %u", m_session.getSessionID());
71  result = true;
72  }
73  else
74  {
75  ROS_WARN("Could not open Cola2 session");
76  }
77  return result;
78 }
79 
80 void CreateSession::writeHeartbeatTimeoutToDataPtr(std::vector<uint8_t>::iterator it) const
81 {
82  uint8_t heart_beat_time_out_seconds = 60;
83  read_write_helper::writeUint8BigEndian(it + 0, heart_beat_time_out_seconds);
84 }
85 
86 void CreateSession::writeClientIdToDataPtr(std::vector<uint8_t>::iterator it) const
87 {
88  uint32_t client_id = 1; // can be any random number
89  read_write_helper::writeUint32BigEndian(it + 1, client_id);
90 }
91 
92 } // namespace cola2
93 } // namespace sick
bool processReply()
Processes the return from the sensor. Checks if the request was successful.
void writeUint32BigEndian(std::vector< uint8_t >::iterator it, const uint32_t v)
Writes an unsigned 32-bit integer to a buffer at offset in big endian encoding.
void writeUint8BigEndian(std::vector< uint8_t >::iterator it, const uint8_t v)
Writes an unsigned 8-bit integer to a buffer at offset in big endian encoding.
uint8_t getCommandType() const
Returns the command type.
Definition: Command.cpp:81
Base class for commands. Defines the base interface and does the common tasks.
Definition: Command.h:61
#define ROS_WARN(...)
uint32_t getSessionID() const
Returns the current session ID.
Definition: Command.cpp:101
void writeClientIdToDataPtr(std::vector< uint8_t >::iterator it) const
std::vector< uint8_t > expandTelegram(const std::vector< uint8_t > &telegram, size_t additional_bytes) const
Definition: Command.cpp:121
#define ROS_INFO(...)
sick::cola2::Cola2Session & m_session
Definition: Command.h:192
uint8_t getCommandMode() const
Returns the command mode.
Definition: Command.cpp:91
void setSessionID(const uint32_t &session_id)
Sets the current session ID.
bool canBeExecutedWithoutSessionID() const
Returns true since creating a new session is possible without a session ID.
uint32_t getSessionID() const
Returns the current session ID.
std::vector< uint8_t > addTelegramData(const std::vector< uint8_t > &telegram) const
Adds the data to the telegram.
Establishes a cola2 session with a sensor and enables execution of commands in this session...
Definition: Cola2Session.h:72
void writeHeartbeatTimeoutToDataPtr(std::vector< uint8_t >::iterator it) const
CreateSession(Cola2Session &session)
Constructor to create a new command to set up a new session.


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