71 unsigned short portNumber,
141 if (success ==
false)
177 bool beVerboseHere =
false;
179 "SickScanCommonNw::readCallbackFunction(): Called with " +
toString(numOfBytes) +
" available bytes.",
184 UINT32 bytesToBeTransferred = numOfBytes;
185 if (remainingSpace < numOfBytes)
187 bytesToBeTransferred = remainingSpace;
197 if (bytesToBeTransferred > 0)
201 m_numberOfBytesInReceiveBuffer += bytesToBeTransferred;
215 printInfoMessage(
"SickScanCommonNw::readCallbackFunction(): No complete frame in input buffer, we are done.",
225 "SickScanCommonNw::readCallbackFunction(): Processing a frame of length " + ::
toString(frame.
size()) +
226 " bytes.", beVerboseHere);
273 if (i >= m_numberOfBytesInReceiveBuffer)
276 m_numberOfBytesInReceiveBuffer = 0;
281 UINT32 newLen = m_numberOfBytesInReceiveBuffer - i;
283 m_numberOfBytesInReceiveBuffer = newLen;
296 if (i >= m_numberOfBytesInReceiveBuffer)
318 if (magicWord != 0x02020202)
325 if (magicWord == 0x02020202)
343 memmove(&(m_receiveBuffer[0]), &(m_receiveBuffer[i]), bytesToMove);
352 printInfoMessage(
"SickScanCommonNw::findFrameInReceiveBuffer: Frame cannot be decoded yet, only " +
359 payloadlength = colab::getIntegerFromBuffer<UINT32>(
m_receiveBuffer, pos);
361 "SickScanCommonNw::findFrameInReceiveBuffer: Decoded payload length is " + ::
toString(payloadlength) +
365 if (payloadlength > (
sizeof(m_receiveBuffer) - 9))
369 "SickScanCommonNw::findFrameInReceiveBuffer: Frame too big for receive buffer. Frame discarded with length:" 378 "SickScanCommonNw::findFrameInReceiveBuffer: Frame not complete yet. Waiting for the rest of it (" +
384 frameLen = payloadlength + 9;
398 for (
UINT16 i = 8; i < (frameLen - 1); i++)
402 temp_xor = temp_xor ^ temp;
406 if (temp_xor != checkSum)
408 printWarning(
"SickScanCommonNw::findFrameInReceiveBuffer: Wrong checksum, Frame discarded.");
443 "SickScanCommonNw::processFrame: Calling processFrame_CoLa_A() with " + ::
toString(frame.
size()) +
" bytes.",
450 "SickScanCommonNw::processFrame: Calling processFrame_CoLa_B() with " + ::
toString(frame.
size()) +
" bytes.",
476 printError(
"SickScanCommonNw::copyFrameToResposeBuffer: Failed to copy frame (Length=" + ::
toString(frameLength) +
477 " bytes) to response buffer because the response buffer is too small (buffer size=" +
495 " bytes from the input buffer. New length is " + ::
toString(newLen) +
" bytes.",
m_beVerbose);
502 printInfoMessage(
"SickScanCommonNw::removeFrameFromReceiveBuffer: Done, no more data in input buffer.",
539 return payLoadLength;
551 std::string commandString;
556 commandString = std::string((
char *) &
m_buffer[2], 2);
559 commandString = std::string((
char *) &
m_buffer[9], 2);
562 return commandString;
575 BYTE *bufferPos = NULL;
599 BYTE *bufferPos = NULL;
620 printError(
"SopasEventMessage::getVariableIndex: Unknown protocol!");
void printError(std::string message)
std::string getCommandString() const
Returns two character long command.
void closeTcpConnection()
BYTE * getPayLoad()
contains 's' + command string(2 byte) + content(payload length - 3)
SopasEventMessage findFrameInReceiveBuffer()
bool init(std::string ipAddress, unsigned short portNumber, Tcp::DisconnectFunction disconnectFunction, void *obj)
void processFrame(SopasEventMessage &frame)
UINT8 m_responseBuffer[1024]
Receive buffer for everything except scan data and eval case data.
void sendCommandBuffer(UINT8 *buffer, UINT16 len)
UINT8 m_receiveBuffer[25000]
Low-Level receive buffer for all data (25000 should be enough for NAV300 Events)
UINT16 decodeUINT16(BYTE *buffer)
UINT32 getPayLoadLength() const
contains 's' + command string(2 byte) + content(payload length - 3)
void(* DisconnectFunction)(void *obj)
#define printInfoMessage(a, b)
bool setReadCallbackFunction(Tcp::ReadFunction readFunction, void *obj)
bool write(UINT8 *buffer, UINT32 numberOfBytes)
void copyFrameToResposeBuffer(UINT32 frameLength)
bool open(std::string ipAddress, UINT16 port, bool enableVerboseDebugOutput=false)
BYTE * getRawData()
get SOPAS raw data include header and CRC
bool isConnected()
Returns true if the tcp connection is established.
void(* ReadFunction)(void *obj, UINT8 *inputBuffer, UINT32 &numBytes)
UINT32 m_numberOfBytesInResponseBuffer
Number of bytes in buffer.
Object has been constructed. Use init() to go into CONNECTED state.
SopasEventMessage()
Default constructor.
Mutex m_receiveDataMutex
Access mutex for buffer.
Class that represents a message that was sent by a sensor. (Event message)
UINT32 m_numberOfBytesInReceiveBuffer
Number of bytes in buffer.
void removeFrameFromReceiveBuffer(UINT32 frameLength)
void readCallbackFunction(UINT8 *buffer, UINT32 &numOfBytes)
bool connect()
Connects to a sensor via tcp and reads the device name.
bool disconnect()
Closes the connection to the LMS. This is the opposite of init().
void setReadCallbackFunction(ReadFunction readFunction, void *obj)
void setDisconnectCallbackFunction(DisconnectFunction discFunction, void *obj)
static void readCallbackFunctionS(void *obj, UINT8 *buffer, UINT32 &numOfBytes)
Function that will be called on incomming data via tcp.
void printWarning(std::string message)
UINT16 decodeUINT16(BYTE *buffer)
INT32 getVariableIndex()
Returns the index of a variable (answer to read variable by index). In case of error a negative value...