Class SopasBase

Class Documentation

class SopasBase

Class SopasBase encapsuls the communication to a sensor via SopasProtocol. It offers the functions:

  • invokeMethode

  • readVariable

  • writeVariable

  • (un)registerEvent

Callback functions are used to inform you about incoming events (scans or eval cases).

Public Types

enum SopasProtocol

Values:

enumerator CoLa_A

Command Language ASCI.

enumerator CoLa_B

Command Language binary.

enum SopasEncoding

Values:

enumerator ByName

read/write variable, invoke methods by name

enumerator ByIndex

read/write variable, invoke methods by index (indexes will be generated !!!)

enum SopasMessageType

types of answers of the sensor

Values:

enumerator MSG_UNKNOWN

Unknown message.

enumerator MSG_SEND_EVENT

Send Event.

enumerator MSG_READ_VARIABLE_ANSWER

Read Variable Answer.

enumerator MSG_WRITE_VARIABLE_ANSWER

Write Variable Answer.

enumerator MSG_INVOKE_METHOD_ANSWER

Invoke Method Answer.

enumerator MSG_METHOD_RESULT_ANSWER

Method Result Answer.

enumerator MSG_REGISTER_EVENT_ANSWER

Register Event Answer.

enumerator MSG_EVENT_ACKNOWLEDGE

Event Acknowledge -Answer to register event.

enumerator MSG_ERROR

Error.

typedef void (*DecoderFunction)(SopasEventMessage &frame)

Public Functions

SopasBase()

Default constructor.

virtual ~SopasBase()

Destructor.

virtual bool init(SopasProtocol protocol, std::string ipAddress, UINT16 portNumber, bool weWantScanData, bool weWantFieldData, bool readOnlyMode, Tcp::DisconnectFunction disconnectFunction, void *obj)

Initialization.

Parameters:
  • protocol

  • ipAddress – IP-address 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

Returns:

bool connect()

Connects to a sensor via tcp and reads the device name.

bool isConnected()

Returns true if the tcp connection is established.

bool 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.

Returns:

True if the device is now in the CONSTRUCTED state

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.

Returns:

true if no errors occurred.

void setReadOnlyMode(bool mode)
bool isReadOnly()
bool invokeMethod(const std::string &methodeName, BYTE *parameters, UINT16 parametersLength, SopasAnswer *&answer)

Invoke a method on the sensor.

Parameters:
  • 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 !!!)

Returns:

true if no errors occurred.

bool invokeMethod(UINT16 index, BYTE *parameters, UINT16 parametersLength, SopasAnswer *&answer)

Invoke a method on the sensor.

Parameters:
  • 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 !!!)

Returns:

true if no errors occurred.

bool readVariable(const std::string &variableName, SopasAnswer *&answer)

Reads a variable from the sensor by name.

Parameters:
  • variableName – name of the variable

  • answer – pointer to an answer message (NOTE: memory for this object will be allocated - free this after usage !!!)

Returns:

true if no errors occurred.

bool readVariable(UINT16 index, SopasAnswer *&answer)

Reads a variable from the sensor by index.

Parameters:
  • index – of the variable

  • answer

Returns:

true if no errors occurred.

bool writeVariable(const std::string &variableName, BYTE *parameters, UINT16 parametersLength)

Write a variable to the sensor by name.

Parameters:
  • 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

Returns:

true if no errors occurred.

bool writeVariable(UINT16 index, BYTE *parameters, UINT16 parametersLength)

Write a variable to the sensor by index.

Parameters:
  • 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

Returns:

true if no errors occurred.

bool registerEvent(const std::string &eventName)

Registers an event by name.

Parameters:

eventName – name of the event

Returns:

true if no errors occurred.

bool registerEvent(UINT16 index)

Registers an event by index.

Parameters:

index – of the event.

Returns:

true if no errors occurred.

bool unregisterEvent(const std::string &eventName)

Unregisters an event by name.

Parameters:

eventName – name of the event

Returns:

true if no errors occurred.

bool unregisterEvent(UINT16 index)

Unregisters an event by index.

Parameters:

index – of the event

Returns:

true if no errors occurred.

inline void setEventCallbackFunction(DecoderFunction decoderFunction, const std::string &eventName)
Parameters:
  • decoderFunction

  • eventName

inline void setEventCallbackFunction(DecoderFunction decoderFunction, UINT16 eventIndex)
Parameters:
  • decoderFunction

  • eventIndex

double makeAngleValid(double angle)
inline const std::string &getScannerName() const
inline const std::string &getScannerVersion() const
uint64_t getNanosecTimestampLastTcpMessageReceived(void)

Public Static Functions

static std::string convertSopasErrorCodeToText(UINT16 errorCode)

Public Static Attributes

static const std::string EVENTNAME_SUBSCRIBE_EVALCASES
static const std::string EVENTNAME_SUBSCRIBE_SCANS
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_DEVICEIDENT
static const std::string VARIABLENAME_SCANCONFIG
static const std::string VARIABLENAME_DATAOUTPUTRANGE
static const std::string VARIABLENAME_SCANDATACONFIG
static const std::string COMMAND_Read_Variable_ByIndex
static const std::string COMMAND_Write_Variable_ByIndex
static const std::string COMMAND_Invoke_Method_ByIndex
static const std::string COMMAND_Method_Result_ByIndex
static const std::string COMMAND_Register_Event_ByIndex
static const std::string COMMAND_Send_Event_ByIndex
static const std::string COMMAND_Read_Variable_Answer
static const std::string COMMAND_Write_Variable_Answer
static const std::string COMMAND_Invoke_Method_Answer
static const std::string COMMAND_Method_Result_Answer
static const std::string COMMAND_Register_Event_Answer
static const std::string COMMAND_Event_Acknowledge
static const std::string COMMAND_Read_Variable_ByName
static const std::string COMMAND_Write_Variable_ByName
static const std::string COMMAND_Invoke_Method_ByName
static const std::string COMMAND_Method_Result_ByName
static const std::string COMMAND_Register_Event_ByName
static const std::string COMMAND_Send_Event_ByName
static const UINT16 INDEX_DEVICE_IDENT

Protected Types

enum SopasCommand

Values:

enumerator CMD_UNKNOWN

Unknown command.

enumerator RI

Read Variable.

enumerator WI

Write Variable.

enumerator MI

Invoke Method.

enumerator AI

Method Result.

enumerator EI

Register Event.

enumerator SI

Send Event.

enumerator RA

Read Variable Answer.

enumerator WA

Write Variable Answer.

enumerator MA

Invoke Method Answer.

enumerator AA

Method Result Answer.

enumerator EA

Register Event Answer.

enumerator SA

Event Acknowledge.

enumerator RN

Read Variable (by name)

enumerator AN

Method Result (ny name)

enumerator SN

Send Event (by name, receive)

enumerator FA

Error.

enum State

Values:

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.

enumerator CONNECTED

Object is connected and emitting data. Use stop() to go back into CONNECTED, or disconnect() to go back into CONSTRUCTED state.

Protected Functions

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.

Parameters:
  • 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.

Returns:

true if no error occurred.

bool receiveAnswer_CoLa_A(SopasCommand cmd, std::string name, UINT32 timeout, SopasAnswer *&answer)
bool receiveAnswer_CoLa_B(SopasCommand cmd, std::string name, UINT32 timeout, SopasAnswer *&answer)
bool receiveAnswer(SopasCommand cmd, UINT16 index, UINT32 timeout, SopasAnswer *&answer)
bool receiveAnswer_CoLa_A(SopasCommand cmd, UINT16 index, UINT32 timeout, SopasAnswer *&answer)
bool receiveAnswer_CoLa_B(SopasCommand cmd, UINT16 index, UINT32 timeout, SopasAnswer *&answer)
bool sendCommandBuffer(UINT8 *buffer, UINT16 len)

Sends the content of the buffer via TCP to the sensor.

Parameters:
  • buffer – pointer to the buffer

  • len – length of buffer to be sent.

SopasCommand colaA_decodeCommand(std::string *rxData)
SopasCommand stringToSopasCommand(const std::string &cmdString)

Converts strings in sopas answer buffer to SopasCommand enum.

std::string sopasCommandToString(SopasCommand cmd)
virtual void evalCaseResultDecoder(SopasEventMessage &msg) = 0
virtual void scanDataDecoder(SopasEventMessage &msg) = 0

Protected Attributes

bool m_scanEventIsRegistered
bool m_fieldEventIsRegistered
bool m_weWantScanData

Flag to enable/disable scan data reception.

bool m_weWantFieldData

Flag to enable/disable protection field data reception.

State m_state

Device info.

std::string m_scannerName

Read from scanner.

std::string m_scannerVersion

Read from scanner.

bool m_beVerbose
bool m_isLoggedIn