SafeVisionaryControl.cpp
Go to the documentation of this file.
1 // -- BEGIN LICENSE BLOCK ----------------------------------------------
20 // -- END LICENSE BLOCK ------------------------------------------------
21 
32 #include <cassert>
33 
34 namespace visionary {
36 
38 
39 bool SafeVisionaryControl::open(const std::string& hostname, uint8_t sessionTimeout_s)
40 {
41  m_pProtocolHandler = nullptr;
42  m_pTransport = nullptr;
43 
44  std::unique_ptr<TcpSocket> pTransport(new TcpSocket());
45 
46  if (pTransport->connect(hostname, htons(COLA_2)) != 0)
47  {
48  return false;
49  }
50 
51  std::unique_ptr<IProtocolHandler> pProtocolHandler;
52  pProtocolHandler = std::unique_ptr<IProtocolHandler>(new CoLa2ProtocolHandler(*pTransport));
53 
54  if (!pProtocolHandler->openSession(sessionTimeout_s))
55  {
56  pTransport->shutdown();
57  return false;
58  }
59 
60  std::unique_ptr<ControlSession> pControlSession;
61  pControlSession = std::unique_ptr<ControlSession>(new ControlSession(*pProtocolHandler));
62 
63  std::unique_ptr<IAuthentication> pAuthentication;
64  pAuthentication = std::unique_ptr<IAuthentication>(new AuthenticationSecure(*this));
65 
66  m_pTransport = std::move(pTransport);
67  m_pProtocolHandler = std::move(pProtocolHandler);
68  m_pControlSession = std::move(pControlSession);
69  m_pAuthentication = std::move(pAuthentication);
70 
71  return true;
72 }
73 
75 {
77  {
78  (void)m_pAuthentication->logout();
79  m_pAuthentication = nullptr;
80  }
82  {
83  m_pProtocolHandler->closeSession();
84  m_pProtocolHandler = nullptr;
85  }
86  if (m_pTransport)
87  {
88  m_pTransport->shutdown();
89  m_pTransport = nullptr;
90  }
92  {
93  m_pControlSession = nullptr;
94  }
95 }
96 
97 bool SafeVisionaryControl::login(IAuthentication::UserLevel userLevel, const std::string password)
98 {
99  return m_pAuthentication->login(userLevel, password);
100 }
101 
103 {
104  return m_pAuthentication->logout();
105 }
106 
108 {
110 
111  CoLaCommand response = m_pControlSession->send(command);
112  if (response.getError() == CoLaError::OK)
113  {
114  return CoLaParameterReader(response).readFlexString();
115  }
116  else
117  {
118  return "";
119  }
120 }
121 
123 {
124  return m_pControlSession->send(command);
125 }
126 
127 } // namespace visionary
visionary::SafeVisionaryControl::COLA_2
@ COLA_2
Definition: SafeVisionaryControl.h:41
visionary::IAuthentication::UserLevel
UserLevel
Available CoLa user levels.
Definition: IAuthentication.h:31
visionary::SafeVisionaryControl::m_pAuthentication
std::unique_ptr< IAuthentication > m_pAuthentication
Definition: SafeVisionaryControl.h:95
VisionaryEndian.h
TcpSocket.h
visionary::CoLaParameterReader
Class for reading data from a CoLaCommand.
Definition: CoLaParameterReader.h:33
visionary::SafeVisionaryControl::login
bool login(IAuthentication::UserLevel userLevel, const std::string password)
Definition: SafeVisionaryControl.cpp:97
visionary
Definition: AuthenticationLegacy.h:25
visionary::SafeVisionaryControl::close
void close()
Definition: SafeVisionaryControl.cpp:74
AuthenticationSecure.h
visionary::CoLaParameterWriter
Builder for constructing CoLaCommands.
Definition: CoLaParameterWriter.h:35
visionary::CoLaCommand
Definition: CoLaCommand.h:32
visionary::SafeVisionaryControl::getDeviceIdent
std::string getDeviceIdent()
Get device information by calling the "DeviceIdent" method on the device.
Definition: SafeVisionaryControl.cpp:107
visionary::CoLaError::OK
@ OK
No error.
Definition: CoLaError.h:35
visionary::CoLaCommand::getError
CoLaError::Enum getError()
Get error.
Definition: CoLaCommand.cpp:113
visionary::SafeVisionaryControl::logout
bool logout()
Logout from the device.
Definition: SafeVisionaryControl.cpp:102
CoLaParameterWriter.h
CoLa2ProtocolHandler.h
ControlSession.h
visionary::ControlSession
Definition: ControlSession.h:29
visionary::CoLaCommandType::READ_VARIABLE
@ READ_VARIABLE
Definition: CoLaCommandType.h:32
visionary::SafeVisionaryControl::~SafeVisionaryControl
~SafeVisionaryControl()
Definition: SafeVisionaryControl.cpp:37
visionary::SafeVisionaryControl::sendCommand
CoLaCommand sendCommand(CoLaCommand &command)
Send a CoLaBCommand to the device and waits for the result.
Definition: SafeVisionaryControl.cpp:122
SafeVisionaryControl.h
visionary::SafeVisionaryControl::open
bool open(const std::string &hostname, uint8_t sessionTimeout_s=kSessionTimeout_s)
Definition: SafeVisionaryControl.cpp:39
visionary::SafeVisionaryControl::m_pProtocolHandler
std::unique_ptr< IProtocolHandler > m_pProtocolHandler
Definition: SafeVisionaryControl.h:94
visionary::SafeVisionaryControl::SafeVisionaryControl
SafeVisionaryControl()
Definition: SafeVisionaryControl.cpp:35
visionary::SafeVisionaryControl::m_pTransport
std::unique_ptr< TcpSocket > m_pTransport
Definition: SafeVisionaryControl.h:93
visionary::SafeVisionaryControl::m_pControlSession
std::unique_ptr< ControlSession > m_pControlSession
Definition: SafeVisionaryControl.h:96
CoLaBProtocolHandler.h
visionary::AuthenticationSecure
Definition: AuthenticationSecure.h:38
CoLaParameterReader.h
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