VisionaryControl.cpp
Go to the documentation of this file.
1 // -- BEGIN LICENSE BLOCK ----------------------------------------------
20 // -- END LICENSE BLOCK ------------------------------------------------
21 
31 #include <cassert>
32 
33 namespace visionary {
34 
36 
38 
40  const std::string& hostname,
41  uint8_t sessionTimeout_s)
42 {
43  m_pProtocolHandler = nullptr;
44  m_pTransport = nullptr;
45 
46  std::unique_ptr<TcpSocket> pTransport(new TcpSocket());
47 
48  if (pTransport->connect(hostname, htons(type)) != 0)
49  {
50  return false;
51  }
52 
53  std::unique_ptr<IProtocolHandler> pProtocolHandler;
54 
55  switch (type)
56  {
57  case COLA_B:
58  pProtocolHandler = std::unique_ptr<IProtocolHandler>(new CoLaBProtocolHandler(*pTransport));
59  break;
60  case COLA_2:
61  pProtocolHandler = std::unique_ptr<IProtocolHandler>(new CoLa2ProtocolHandler(*pTransport));
62  break;
63  default:
64  assert(false /* unsupported protocol*/);
65  return false;
66  }
67 
68  if (!pProtocolHandler->openSession(sessionTimeout_s))
69  {
70  pTransport->shutdown();
71  return false;
72  }
73 
74  std::unique_ptr<ControlSession> pControlSession;
75  pControlSession = std::unique_ptr<ControlSession>(new ControlSession(*pProtocolHandler));
76 
77  std::unique_ptr<IAuthentication> pAuthentication;
78  pAuthentication = std::unique_ptr<IAuthentication>(new AuthenticationLegacy(*this));
79 
80  m_pTransport = std::move(pTransport);
81  m_pProtocolHandler = std::move(pProtocolHandler);
82  m_pControlSession = std::move(pControlSession);
83  m_pAuthentication = std::move(pAuthentication);
84 
85  return true;
86 }
87 
89 {
91  {
92  (void)m_pAuthentication->logout();
93  m_pAuthentication = nullptr;
94  }
96  {
97  m_pProtocolHandler->closeSession();
98  m_pProtocolHandler = nullptr;
99  }
100  if (m_pTransport)
101  {
102  m_pTransport->shutdown();
103  m_pTransport = nullptr;
104  }
105  if (m_pControlSession)
106  {
107  m_pControlSession = nullptr;
108  }
109 }
110 
111 bool VisionaryControl::login(IAuthentication::UserLevel userLevel, const std::string password)
112 {
113  return m_pAuthentication->login(userLevel, password);
114 }
115 
117 {
118  return m_pAuthentication->logout();
119 }
120 
122 {
124 
125  CoLaCommand response = m_pControlSession->send(command);
126  if (response.getError() == CoLaError::OK)
127  {
128  return CoLaParameterReader(response).readFlexString();
129  }
130  else
131  {
132  return "";
133  }
134 }
135 
137 {
138  CoLaCommand command =
140 
141  CoLaCommand response = m_pControlSession->send(command);
142 
143  return response.getError() == CoLaError::OK;
144 }
145 
147 {
149  CoLaCommand response = m_pControlSession->send(command);
150 
151  return response.getError() == CoLaError::OK;
152 }
153 
155 {
157  CoLaCommand response = m_pControlSession->send(command);
158 
159  return response.getError() == CoLaError::OK;
160 }
161 
163 {
164  CoLaCommand command =
166  CoLaCommand response = m_pControlSession->send(command);
167 
168  return response.getError() == CoLaError::OK;
169 }
170 
172 {
173  return m_pControlSession->send(command);
174 }
175 
176 } // namespace visionary
VisionaryControl.h
visionary::IAuthentication::UserLevel
UserLevel
Available CoLa user levels.
Definition: IAuthentication.h:31
VisionaryEndian.h
TcpSocket.h
visionary::CoLaParameterReader
Class for reading data from a CoLaCommand.
Definition: CoLaParameterReader.h:33
visionary::VisionaryControl::startAcquisition
bool startAcquisition()
Start streaming the data by calling the "PLAYSTART" method on the device. Works only when acquisition...
Definition: VisionaryControl.cpp:136
visionary
Definition: AuthenticationLegacy.h:25
visionary::CoLaParameterWriter
Builder for constructing CoLaCommands.
Definition: CoLaParameterWriter.h:35
visionary::CoLaCommand
Definition: CoLaCommand.h:32
visionary::VisionaryControl::~VisionaryControl
~VisionaryControl()
Definition: VisionaryControl.cpp:37
visionary::CoLaError::OK
@ OK
No error.
Definition: CoLaError.h:35
visionary::VisionaryControl::VisionaryControl
VisionaryControl()
Definition: VisionaryControl.cpp:35
visionary::CoLaCommand::getError
CoLaError::Enum getError()
Get error.
Definition: CoLaCommand.cpp:113
visionary::VisionaryControl::getDataStreamConfig
bool getDataStreamConfig()
Tells the device that there is a streaming channel by invoking a method named GetBlobClientConfig.
Definition: VisionaryControl.cpp:162
visionary::VisionaryControl::ProtocolType
ProtocolType
The numbers used for the protocols are the port numbers.
Definition: VisionaryControl.h:39
visionary::VisionaryControl::getDeviceIdent
std::string getDeviceIdent()
Get device information by calling the "DeviceIdent" method on the device.
Definition: VisionaryControl.cpp:121
visionary::VisionaryControl::COLA_B
@ COLA_B
Definition: VisionaryControl.h:43
CoLaParameterWriter.h
CoLa2ProtocolHandler.h
visionary::VisionaryControl::m_pControlSession
std::unique_ptr< ControlSession > m_pControlSession
Definition: VisionaryControl.h:132
ControlSession.h
visionary::ControlSession
Definition: ControlSession.h:29
visionary::CoLaCommandType::READ_VARIABLE
@ READ_VARIABLE
Definition: CoLaCommandType.h:32
visionary::VisionaryControl::stopAcquisition
bool stopAcquisition()
Stops the data stream. Works always, also when acquisition is already stopped before.
Definition: VisionaryControl.cpp:154
visionary::VisionaryControl::m_pProtocolHandler
std::unique_ptr< IProtocolHandler > m_pProtocolHandler
Definition: VisionaryControl.h:130
visionary::AuthenticationLegacy
Definition: AuthenticationLegacy.h:27
visionary::VisionaryControl::login
bool login(IAuthentication::UserLevel userLevel, const std::string password)
Definition: VisionaryControl.cpp:111
visionary::VisionaryControl::COLA_2
@ COLA_2
Definition: VisionaryControl.h:44
visionary::CoLaBProtocolHandler
Definition: CoLaBProtocolHandler.h:29
visionary::VisionaryControl::m_pTransport
std::unique_ptr< TcpSocket > m_pTransport
Definition: VisionaryControl.h:129
visionary::CoLaCommandType::METHOD_INVOCATION
@ METHOD_INVOCATION
Definition: CoLaCommandType.h:36
visionary::VisionaryControl::sendCommand
CoLaCommand sendCommand(CoLaCommand &command)
Send a CoLaBCommand to the device and waits for the result.
Definition: VisionaryControl.cpp:171
visionary::VisionaryControl::logout
bool logout()
Logout from the device.
Definition: VisionaryControl.cpp:116
visionary::VisionaryControl::open
bool open(ProtocolType type, const std::string &hostname, uint8_t sessionTimeout_s=kSessionTimeout_s)
Definition: VisionaryControl.cpp:39
visionary::VisionaryControl::close
void close()
Definition: VisionaryControl.cpp:88
visionary::VisionaryControl::stepAcquisition
bool stepAcquisition()
Trigger a single image on the device. Works only when acquisition is stopped.
Definition: VisionaryControl.cpp:146
CoLaBProtocolHandler.h
CoLaParameterReader.h
visionary::VisionaryControl::m_pAuthentication
std::unique_ptr< IAuthentication > m_pAuthentication
Definition: VisionaryControl.h:131
visionary::CoLaParameterReader::readFlexString
std::string readFlexString()
Read a flex string, and advance position according to string size.
Definition: CoLaParameterReader.cpp:105
visionary::TcpSocket
Definition: TcpSocket.h:50
AuthenticationLegacy.h
visionary::CoLa2ProtocolHandler
Definition: CoLa2ProtocolHandler.h:29
visionary::CoLaParameterWriter::build
const CoLaCommand build()
Definition: CoLaParameterWriter.cpp:198


sick_safevisionary_base
Author(s):
autogenerated on Sat Oct 21 2023 02:24:26