#include <SopasBase.hpp>
Public Types | |
typedef void(* | DecoderFunction) (SopasEventMessage &frame) |
enum | SopasEncoding { ByName, ByIndex } |
enum | SopasMessageType { MSG_UNKNOWN, MSG_SEND_EVENT, MSG_READ_VARIABLE_ANSWER, MSG_WRITE_VARIABLE_ANSWER, MSG_INVOKE_METHOD_ANSWER, MSG_METHOD_RESULT_ANSWER, MSG_REGISTER_EVENT_ANSWER, MSG_EVENT_ACKNOWLEDGE, MSG_ERROR } |
types of answers of the sensor More... | |
enum | SopasProtocol { CoLa_A, CoLa_B } |
Public Member Functions | |
bool | action_getScannerTypeAndVersion () |
Reads the scanner type and version variable from the sensor and stores it in the member variables. This is done always by name. More... | |
bool | connect () |
Connects to a sensor via tcp and reads the device name. More... | |
bool | disconnect () |
Closes the connection to the LMS. This is the opposite of init(). More... | |
const std::string & | getScannerName () const |
const std::string & | getScannerVersion () const |
virtual bool | init (SopasProtocol protocol, std::string ipAddress, UINT16 portNumber, bool weWantScanData, bool weWantFieldData, bool readOnlyMode, Tcp::DisconnectFunction disconnectFunction, void *obj) |
Initialization. More... | |
bool | invokeMethod (const std::string &methodeName, BYTE *parameters, UINT16 parametersLength, SopasAnswer *&answer) |
Invoke a method on the sensor. More... | |
bool | invokeMethod (UINT16 index, BYTE *parameters, UINT16 parametersLength, SopasAnswer *&answer) |
Invoke a method on the sensor. More... | |
bool | isConnected () |
Returns true if the tcp connection is established. More... | |
bool | isReadOnly () |
double | makeAngleValid (double angle) |
bool | readVariable (const std::string &variableName, SopasAnswer *&answer) |
Reads a variable from the sensor by name. More... | |
bool | readVariable (UINT16 index, SopasAnswer *&answer) |
Reads a variable from the sensor by index. More... | |
bool | registerEvent (const std::string &eventName) |
Registers an event by name. More... | |
bool | registerEvent (UINT16 index) |
Registers an event by index. More... | |
void | setEventCallbackFunction (DecoderFunction decoderFunction, const std::string &eventName) |
void | setEventCallbackFunction (DecoderFunction decoderFunction, UINT16 eventIndex) |
void | setReadOnlyMode (bool mode) |
SopasBase () | |
Default constructor. More... | |
bool | unregisterEvent (const std::string &eventName) |
Unregisters an event by name. More... | |
bool | unregisterEvent (UINT16 index) |
Unregisters an event by index. More... | |
bool | writeVariable (const std::string &variableName, BYTE *parameters, UINT16 parametersLength) |
Write a variable to the sensor by name. More... | |
bool | writeVariable (UINT16 index, BYTE *parameters, UINT16 parametersLength) |
Write a variable to the sensor by index. More... | |
virtual | ~SopasBase () |
Destructor. More... | |
Static Public Member Functions | |
static std::string | convertSopasErrorCodeToText (UINT16 errorCode) |
Static Public Attributes | |
static const std::string | COMMAND_Event_Acknowledge |
static const std::string | COMMAND_Invoke_Method_Answer |
static const std::string | COMMAND_Invoke_Method_ByIndex |
static const std::string | COMMAND_Invoke_Method_ByName |
static const std::string | COMMAND_Method_Result_Answer |
static const std::string | COMMAND_Method_Result_ByIndex |
static const std::string | COMMAND_Method_Result_ByName |
static const std::string | COMMAND_Read_Variable_Answer |
static const std::string | COMMAND_Read_Variable_ByIndex |
static const std::string | COMMAND_Read_Variable_ByName |
static const std::string | COMMAND_Register_Event_Answer |
static const std::string | COMMAND_Register_Event_ByIndex |
static const std::string | COMMAND_Register_Event_ByName |
static const std::string | COMMAND_Send_Event_ByIndex |
static const std::string | COMMAND_Send_Event_ByName |
static const std::string | COMMAND_Write_Variable_Answer |
static const std::string | COMMAND_Write_Variable_ByIndex |
static const std::string | COMMAND_Write_Variable_ByName |
static const std::string | EVENTNAME_SUBSCRIBE_EVALCASES |
static const std::string | EVENTNAME_SUBSCRIBE_SCANS |
static const UINT16 | INDEX_DEVICE_IDENT = 0 |
static const std::string | METHODNAME_LOGIN |
static const std::string | METHODNAME_LOGOUT |
static const std::string | METHODNAME_SET_SCANCONFIG |
static const std::string | METHODNAME_START_MEASURE |
static const std::string | METHODNAME_STOP_MEASURE |
static const std::string | VARIABLENAME_DATAOUTPUTRANGE |
static const std::string | VARIABLENAME_DEVICEIDENT |
static const std::string | VARIABLENAME_SCANCONFIG |
static const std::string | VARIABLENAME_SCANDATACONFIG |
Protected Types | |
enum | SopasCommand { CMD_UNKNOWN = 0, RI = 1, WI = 2, MI = 3, AI = 4, EI = 5, SI = 6, RA = 7, WA = 8, MA = 9, AA = 10, EA = 11, SA = 12, RN = 20, AN = 21, SN = 22, FA = 50 } |
enum | State { CONSTRUCTED, CONNECTED } |
Protected Member Functions | |
SopasCommand | colaA_decodeCommand (std::string *rxData) |
virtual void | evalCaseResultDecoder (SopasEventMessage &msg)=0 |
bool | receiveAnswer (SopasCommand cmd, std::string name, UINT32 timeout, SopasAnswer *&answer) |
Take answer from read thread and decode it. Waits for a certain answer by name. Event data (scans) are filtered and processed by read thread. More... | |
bool | receiveAnswer (SopasCommand cmd, UINT16 index, UINT32 timeout, SopasAnswer *&answer) |
bool | receiveAnswer_CoLa_A (SopasCommand cmd, std::string name, UINT32 timeout, SopasAnswer *&answer) |
bool | receiveAnswer_CoLa_A (SopasCommand cmd, UINT16 index, UINT32 timeout, SopasAnswer *&answer) |
bool | receiveAnswer_CoLa_B (SopasCommand cmd, std::string name, UINT32 timeout, SopasAnswer *&answer) |
bool | receiveAnswer_CoLa_B (SopasCommand cmd, UINT16 index, UINT32 timeout, SopasAnswer *&answer) |
virtual void | scanDataDecoder (SopasEventMessage &msg)=0 |
void | sendCommandBuffer (UINT8 *buffer, UINT16 len) |
Sends the content of the buffer via TCP to the sensor. More... | |
std::string | sopasCommandToString (SopasCommand cmd) |
SopasCommand | stringToSopasCommand (const std::string &cmdString) |
Converts strings in sopas answer buffer to SopasCommand enum. More... | |
Protected Attributes | |
bool | m_beVerbose |
bool | m_fieldEventIsRegistered |
bool | m_isLoggedIn |
bool | m_scanEventIsRegistered |
std::string | m_scannerName |
Read from scanner. More... | |
std::string | m_scannerVersion |
Read from scanner. More... | |
State | m_state |
Device info. More... | |
bool | m_weWantFieldData |
Flag to enable/disable protection field data reception. More... | |
bool | m_weWantScanData |
Flag to enable/disable scan data reception. More... | |
Private Types | |
typedef std::map< UINT16, DecoderFunction > | DecoderFunctionMapByIndex |
typedef std::map< std::string, DecoderFunction > | DecoderFunctionMapByName |
typedef std::map< UINT16, std::string > | IndexToNameMap |
Private Member Functions | |
void | closeTcpConnection () |
void | colaA_decodeScannerTypeAndVersion (std::string *rxData) |
void | colaB_decodeScannerTypeAndVersion (UINT8 *buffer, UINT16 pos) |
void | copyFrameToResposeBuffer (UINT32 frameLength) |
SopasEventMessage | findFrameInReceiveBuffer () |
Depending on the protocol the start and end of a frame will be found. More... | |
bool | openTcpConnection () |
void | processFrame (SopasEventMessage &frame) |
Reads one frame from receive buffer and decodes it. More... | |
void | processFrame_CoLa_A (SopasEventMessage &frame) |
void | processFrame_CoLa_B (SopasEventMessage &frame) |
void | readCallbackFunction (UINT8 *buffer, UINT32 &numOfBytes) |
void | removeFrameFromReceiveBuffer (UINT32 frameLength) |
Static Private Member Functions | |
static void | readCallbackFunctionS (void *obj, UINT8 *buffer, UINT32 &numOfBytes) |
Function that will be called on incomming data via tcp. More... | |
Private Attributes | |
DecoderFunctionMapByIndex | m_decoderFunctionMapByIndex |
DecoderFunctionMapByName | m_decoderFunctionMapByName |
SopasEncoding | m_encoding |
ByName or ByIndex. More... | |
IndexToNameMap | m_indexToNameMap |
std::string | m_ipAddress |
UINT32 | m_numberOfBytesInReceiveBuffer |
Number of bytes in buffer. More... | |
UINT32 | m_numberOfBytesInResponseBuffer |
Number of bytes in buffer. More... | |
UINT16 | m_portNumber |
SopasProtocol | m_protocol |
Used protocol (ColaA oder ColaB) More... | |
bool | m_readOnlyMode |
UINT8 | m_receiveBuffer [25000] |
Low-Level receive buffer for all data (25000 should be enough for NAV300 Events) More... | |
Mutex | m_receiveDataMutex |
Access mutex for buffer. More... | |
UINT8 | m_responseBuffer [1024] |
Receive buffer for everything except scan data and eval case data. More... | |
Tcp | m_tcp |
Class SopasBase encapsuls the communication to a sensor via SopasProtocol. It offers the functions:
Callback functions are used to inform you about incoming events (scans or eval cases).
Definition at line 35 of file SopasBase.hpp.
typedef void(* devices::SopasBase::DecoderFunction) (SopasEventMessage &frame) |
Definition at line 106 of file SopasBase.hpp.
|
private |
Definition at line 387 of file SopasBase.hpp.
|
private |
Definition at line 386 of file SopasBase.hpp.
|
private |
Definition at line 394 of file SopasBase.hpp.
|
protected |
Definition at line 276 of file SopasBase.hpp.
Enumerator | |
---|---|
ByName |
read/write variable, invoke methods by name |
ByIndex |
read/write variable, invoke methods by index (indexes will be generated !!!) |
Definition at line 80 of file SopasBase.hpp.
types of answers of the sensor
Definition at line 87 of file SopasBase.hpp.
Enumerator | |
---|---|
CoLa_A |
Command Language ASCI. |
CoLa_B |
Command Language binary. |
Definition at line 74 of file SopasBase.hpp.
|
protected |
Enumerator | |
---|---|
CONSTRUCTED |
Object has been constructed. Use init() to go into CONNECTED state. Object is now connected. Use run() to go into RUNNING state, or disconnect() to go back into CONSTRUCTED state. |
CONNECTED |
Object is connected and emitting data. Use stop() to go back into CONNECTED, or disconnect() to go back into CONSTRUCTED state. |
Definition at line 298 of file SopasBase.hpp.
devices::SopasBase::SopasBase | ( | ) |
Default constructor.
Definition at line 57 of file SopasBase.cpp.
|
virtual |
Destructor.
Definition at line 67 of file SopasBase.cpp.
bool devices::SopasBase::action_getScannerTypeAndVersion | ( | ) |
Reads the scanner type and version variable from the sensor and stores it in the member variables. This is done always by name.
Get scanner type and version string Also used as connection check.
true: Information was read, false if an error occured
Definition at line 1548 of file SopasBase.cpp.
|
private |
Definition at line 238 of file SopasBase.cpp.
|
protected |
Read command bytes from buffer (2 bytes followed by space) and convert string to enum value accordingly. The command string is removed from input.
Definition at line 1368 of file SopasBase.cpp.
|
private |
Decode answer for action_getScannerTypeAndVersion
Definition at line 1596 of file SopasBase.cpp.
Definition at line 1626 of file SopasBase.cpp.
bool devices::SopasBase::connect | ( | ) |
Connects to a sensor via tcp and reads the device name.
Definition at line 122 of file SopasBase.cpp.
|
static |
Definition at line 916 of file SopasBase.cpp.
|
private |
Definition at line 1315 of file SopasBase.cpp.
bool devices::SopasBase::disconnect | ( | ) |
Closes the connection to the LMS. This is the opposite of init().
Switches this device from the CONNECTED state back in the CONSTRUCTED state.
Definition at line 185 of file SopasBase.cpp.
|
protectedpure virtual |
|
private |
Depending on the protocol the start and end of a frame will be found.
Definition at line 331 of file SopasBase.cpp.
|
inline |
Definition at line 268 of file SopasBase.hpp.
|
inline |
Definition at line 269 of file SopasBase.hpp.
|
virtual |
Initialization.
protocol | |
ipAddress | IP-adress of the Scanner |
portNumber | port for SOPAS comunication |
weWantScanData | |
weWantFieldData | |
readOnlyMode | |
disconnectFunction | Function to be called on disconnect events. |
obj | = pointer to the object that holds the disconnectFunction |
Definition at line 94 of file SopasBase.cpp.
bool devices::SopasBase::invokeMethod | ( | const std::string & | methodeName, |
BYTE * | parameters, | ||
UINT16 | parametersLength, | ||
SopasAnswer *& | answer | ||
) |
Invoke a method on the sensor.
methodeName | name of the method to call |
parameters | byte buffer with parameter (NOTE: you have to fill this buffer with the correct protocol - cola-a or cola-b) |
parametersLength | length of the byte buffer |
answer | pointer to an answer message (NOTE: memory for this object will be allocated - free this after usage !!!) |
Definition at line 1648 of file SopasBase.cpp.
bool devices::SopasBase::invokeMethod | ( | UINT16 | index, |
BYTE * | parameters, | ||
UINT16 | parametersLength, | ||
SopasAnswer *& | answer | ||
) |
Invoke a method on the sensor.
index | index of the method to call |
parameters | byte buffer with parameter (NOTE: you have to fill this buffer with the correct protocol - cola-a or cola-b) |
parametersLength | length of the byte buffer |
answer | pointer to an answer message (NOTE: memory for this object will be allocated - free this after usage !!!) |
Definition at line 1705 of file SopasBase.cpp.
bool devices::SopasBase::isConnected | ( | ) |
Returns true if the tcp connection is established.
Definition at line 177 of file SopasBase.cpp.
bool devices::SopasBase::isReadOnly | ( | ) |
Definition at line 207 of file SopasBase.cpp.
double devices::SopasBase::makeAngleValid | ( | double | angle | ) |
Map angle to range ]PI..-PI]
Definition at line 2146 of file SopasBase.cpp.
|
private |
Open TCP-connection to endpoint (usually IP-address and port)
true = Connected, false = no connection
Definition at line 219 of file SopasBase.cpp.
|
private |
Reads one frame from receive buffer and decodes it.
Reads one frame from receive buffer and decodes it. Switches directly to the decoder of the protocol.
Definition at line 1123 of file SopasBase.cpp.
|
private |
Definition at line 1145 of file SopasBase.cpp.
|
private |
Definition at line 1234 of file SopasBase.cpp.
Read callback. Diese Funktion wird aufgerufen, sobald Daten auf der Schnittstelle hereingekommen sind.
Definition at line 259 of file SopasBase.cpp.
|
staticprivate |
Function that will be called on incomming data via tcp.
Definition at line 249 of file SopasBase.cpp.
bool devices::SopasBase::readVariable | ( | const std::string & | variableName, |
SopasAnswer *& | answer | ||
) |
Reads a variable from the sensor by name.
variableName | name of the variable |
answer | pointer to an answer message (NOTE: memory for this object will be allocated - free this after usage !!!) |
Definition at line 1754 of file SopasBase.cpp.
bool devices::SopasBase::readVariable | ( | UINT16 | index, |
SopasAnswer *& | answer | ||
) |
Reads a variable from the sensor by index.
index | of the variable |
answer |
Definition at line 1796 of file SopasBase.cpp.
|
protected |
Take answer from read thread and decode it. Waits for a certain answer by name. Event data (scans) are filtered and processed by read thread.
cmd | Waits for the answer to this command. |
name | name of the method/variable. |
timeout | in [ms] |
answer | Pointer to answer. Will be filled if answer contains parameter. |
Take answer from read thread and decode it. Waits for a certain answer by name. Event data (scans) are filtered and processed by read thread.
By Name: name = "<Name>" timeout: Number of cycles to check for an answer (approx. 1ms per cycle)
Definition at line 539 of file SopasBase.cpp.
|
protected |
Take answer from read thread and decode it. Waits for a certain answer by index. Event data (scans) are filtered and processed by read thread.
By Name: index = "<Index>" timeout: Number of cycles to check for an answer (approx. 1ms per cycle)
Definition at line 566 of file SopasBase.cpp.
|
protected |
Definition at line 685 of file SopasBase.cpp.
|
protected |
Definition at line 587 of file SopasBase.cpp.
|
protected |
Definition at line 781 of file SopasBase.cpp.
|
protected |
Definition at line 984 of file SopasBase.cpp.
bool devices::SopasBase::registerEvent | ( | const std::string & | eventName | ) |
Registers an event by name.
eventName | name of the event |
Definition at line 1961 of file SopasBase.cpp.
bool devices::SopasBase::registerEvent | ( | UINT16 | index | ) |
Registers an event by index.
index | of the event. |
Definition at line 2005 of file SopasBase.cpp.
|
private |
Definition at line 1341 of file SopasBase.cpp.
|
protectedpure virtual |
Sends the content of the buffer via TCP to the sensor.
buffer | pointer to the buffer |
len | length of buffer to be sent. |
Send contents of buffer to scanner using according framing.
Send buffer is limited to 1024 byte!
Definition at line 505 of file SopasBase.cpp.
|
inline |
decoderFunction | |
eventName |
Definition at line 250 of file SopasBase.hpp.
|
inline |
decoderFunction | |
eventIndex |
Definition at line 260 of file SopasBase.hpp.
void devices::SopasBase::setReadOnlyMode | ( | bool | mode | ) |
Definition at line 200 of file SopasBase.cpp.
|
protected |
Definition at line 1460 of file SopasBase.cpp.
|
protected |
Converts strings in sopas answer buffer to SopasCommand enum.
Definition at line 1375 of file SopasBase.cpp.
bool devices::SopasBase::unregisterEvent | ( | const std::string & | eventName | ) |
Unregisters an event by name.
eventName | name of the event |
Definition at line 2102 of file SopasBase.cpp.
bool devices::SopasBase::unregisterEvent | ( | UINT16 | index | ) |
Unregisters an event by index.
index | of the event |
Definition at line 2053 of file SopasBase.cpp.
bool devices::SopasBase::writeVariable | ( | const std::string & | variableName, |
BYTE * | parameters, | ||
UINT16 | parametersLength | ||
) |
Write a variable to the sensor by name.
variableName | name of the variable. |
parameters | byte buffer with parameter (NOTE: you have to fill this buffer with the correct protocol - cola-a or cola-b) |
parametersLength | length of the byte buffer |
Definition at line 1834 of file SopasBase.cpp.
Write a variable to the sensor by index.
index | of the variable |
parameters | byte buffer with parameter (NOTE: you have to fill this buffer with the correct protocol - cola-a or cola-b) |
parametersLength | length of the byte buffer |
Definition at line 1905 of file SopasBase.cpp.
|
static |
Definition at line 63 of file SopasBase.hpp.
|
static |
Definition at line 60 of file SopasBase.hpp.
|
static |
Definition at line 53 of file SopasBase.hpp.
|
static |
Definition at line 67 of file SopasBase.hpp.
|
static |
Definition at line 61 of file SopasBase.hpp.
|
static |
Definition at line 54 of file SopasBase.hpp.
|
static |
Definition at line 68 of file SopasBase.hpp.
|
static |
Definition at line 58 of file SopasBase.hpp.
|
static |
Definition at line 51 of file SopasBase.hpp.
|
static |
Definition at line 65 of file SopasBase.hpp.
|
static |
Definition at line 62 of file SopasBase.hpp.
|
static |
Definition at line 55 of file SopasBase.hpp.
|
static |
Definition at line 69 of file SopasBase.hpp.
|
static |
Definition at line 56 of file SopasBase.hpp.
|
static |
Definition at line 70 of file SopasBase.hpp.
|
static |
Definition at line 59 of file SopasBase.hpp.
|
static |
Definition at line 52 of file SopasBase.hpp.
|
static |
Definition at line 66 of file SopasBase.hpp.
|
static |
Definition at line 38 of file SopasBase.hpp.
|
static |
Definition at line 39 of file SopasBase.hpp.
|
static |
Definition at line 72 of file SopasBase.hpp.
|
protected |
Definition at line 356 of file SopasBase.hpp.
|
private |
Definition at line 389 of file SopasBase.hpp.
|
private |
Definition at line 388 of file SopasBase.hpp.
|
private |
ByName or ByIndex.
Definition at line 381 of file SopasBase.hpp.
|
protected |
Definition at line 347 of file SopasBase.hpp.
|
private |
Definition at line 395 of file SopasBase.hpp.
|
private |
Definition at line 408 of file SopasBase.hpp.
|
protected |
Definition at line 358 of file SopasBase.hpp.
|
private |
Number of bytes in buffer.
Definition at line 403 of file SopasBase.hpp.
|
private |
Number of bytes in buffer.
Definition at line 398 of file SopasBase.hpp.
|
private |
Definition at line 409 of file SopasBase.hpp.
|
private |
Used protocol (ColaA oder ColaB)
Definition at line 380 of file SopasBase.hpp.
|
private |
Definition at line 411 of file SopasBase.hpp.
|
private |
Low-Level receive buffer for all data (25000 should be enough for NAV300 Events)
Definition at line 404 of file SopasBase.hpp.
|
private |
Access mutex for buffer.
Definition at line 400 of file SopasBase.hpp.
|
private |
Receive buffer for everything except scan data and eval case data.
Definition at line 399 of file SopasBase.hpp.
|
protected |
Definition at line 346 of file SopasBase.hpp.
|
protected |
Read from scanner.
Definition at line 353 of file SopasBase.hpp.
|
protected |
Read from scanner.
Definition at line 354 of file SopasBase.hpp.
|
protected |
Device info.
Definition at line 352 of file SopasBase.hpp.
|
private |
Definition at line 407 of file SopasBase.hpp.
|
protected |
Flag to enable/disable protection field data reception.
Definition at line 349 of file SopasBase.hpp.
|
protected |
Flag to enable/disable scan data reception.
Definition at line 348 of file SopasBase.hpp.
|
static |
Definition at line 40 of file SopasBase.hpp.
|
static |
Definition at line 41 of file SopasBase.hpp.
|
static |
Definition at line 42 of file SopasBase.hpp.
|
static |
Definition at line 43 of file SopasBase.hpp.
|
static |
Definition at line 44 of file SopasBase.hpp.
|
static |
Definition at line 47 of file SopasBase.hpp.
|
static |
Definition at line 45 of file SopasBase.hpp.
|
static |
Definition at line 46 of file SopasBase.hpp.
|
static |
Definition at line 48 of file SopasBase.hpp.