71 unsigned short portNumber,
145 if (success ==
false)
182 bool beVerboseHere =
false;
183 printInfoMessage(
"SickScanCommonNw::readCallbackFunction(): Called with " +
toString(numOfBytes) +
" available bytes.", beVerboseHere);
187 UINT32 bytesToBeTransferred = numOfBytes;
188 if (remainingSpace < numOfBytes)
190 bytesToBeTransferred = remainingSpace;
200 if (bytesToBeTransferred > 0)
204 m_numberOfBytesInReceiveBuffer += bytesToBeTransferred;
218 printInfoMessage(
"SickScanCommonNw::readCallbackFunction(): No complete frame in input buffer, we are done.", beVerboseHere);
226 printInfoMessage(
"SickScanCommonNw::readCallbackFunction(): Processing a frame of length " + ::
toString(frame.
size()) +
" bytes.", beVerboseHere);
274 if (i >= m_numberOfBytesInReceiveBuffer)
277 m_numberOfBytesInReceiveBuffer = 0;
282 UINT32 newLen = m_numberOfBytesInReceiveBuffer - i;
284 m_numberOfBytesInReceiveBuffer = newLen;
297 if (i >= m_numberOfBytesInReceiveBuffer)
319 if (magicWord != 0x02020202)
326 if (magicWord == 0x02020202)
344 memmove(&(m_receiveBuffer[0]), &(m_receiveBuffer[i]), bytesToMove);
353 printInfoMessage(
"SickScanCommonNw::findFrameInReceiveBuffer: Frame cannot be decoded yet, only " +
360 payloadlength = colab::getIntegerFromBuffer<UINT32>(
m_receiveBuffer, pos);
364 if (payloadlength > (
sizeof(m_receiveBuffer) - 9))
367 printWarning(
"SickScanCommonNw::findFrameInReceiveBuffer: Frame too big for receive buffer. Frame discarded with length:" 375 printInfoMessage(
"SickScanCommonNw::findFrameInReceiveBuffer: Frame not complete yet. Waiting for the rest of it (" +
381 frameLen = payloadlength + 9;
395 for (
UINT16 i = 8; i < (frameLen - 1); i++)
399 temp_xor = temp_xor ^ temp;
403 if (temp_xor != checkSum)
405 printWarning(
"SickScanCommonNw::findFrameInReceiveBuffer: Wrong checksum, Frame discarded.");
472 printError(
"SickScanCommonNw::copyFrameToResposeBuffer: Failed to copy frame (Length=" + ::
toString(frameLength) +
473 " bytes) to response buffer because the response buffer is too small (buffer size=" +
492 " bytes from the input buffer. New length is " + ::
toString(newLen) +
" bytes.",
m_beVerbose);
537 return payLoadLength;
549 std::string commandString;
554 commandString = std::string((
char*) &
m_buffer[2], 2);
557 commandString = std::string((
char*) &
m_buffer[9], 2);
560 return commandString;
574 BYTE* bufferPos = NULL;
598 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...