Program Listing for File sick_scan_common_nw.h
↰ Return to documentation for file (include/sick_scan/sick_scan_common_nw.h
)
#include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
//
// Created by michael on 1/22/18.
//
#ifndef SICK_SCAN_SICK_SCAN_COMMON_NW_H
#define SICK_SCAN_SICK_SCAN_COMMON_NW_H
#include "sick_scan/tcp/BasicDatatypes.hpp"
#include "sick_scan/tcp/tcp.hpp"
#include <map> // for std::map
//
// SickScanCommonNw.cpp
//
// Created on: 18.07.2011
// Author: sick
//
#include "sick_scan/tcp/tcp.hpp"
#include "sick_scan/tcp/errorhandler.hpp"
#include "sick_scan/tcp/toolbox.hpp"
#include "sick_scan/tcp/Mutex.hpp"
#include <string>
class SopasEventMessage;
class SopasAnswer;
enum SopasProtocol
{
CoLa_A,
CoLa_B,
CoLa_Unknown
};
class SickScanCommonNw
{
public:
SickScanCommonNw();
~SickScanCommonNw();
bool init(std::string ipAddress,
unsigned short portNumber,
Tcp::DisconnectFunction disconnectFunction,
void *obj);
bool setReadCallbackFunction(Tcp::ReadFunction readFunction,
void *obj);
bool connect();
bool isConnected();
bool disconnect();
bool sendCommandBuffer(UINT8 *buffer, UINT16 len);
// Returns a timestamp in nanoseconds of the last received tcp message (or 0 if no message received)
uint64_t getNanosecTimestampLastTcpMessageReceived(void);
private:
// TCP
bool openTcpConnection();
void closeTcpConnection();
static void readCallbackFunctionS(void *obj, UINT8 *buffer, UINT32 &numOfBytes);
void readCallbackFunction(UINT8 *buffer, UINT32 &numOfBytes);
SopasEventMessage findFrameInReceiveBuffer();
void processFrame(SopasEventMessage &frame);
bool m_beVerbose;
// Response buffer
UINT32 m_numberOfBytesInResponseBuffer;
UINT8 m_responseBuffer[1024];
Mutex m_receiveDataMutex;
// Receive buffer
UINT32 m_numberOfBytesInReceiveBuffer;
UINT8 m_receiveBuffer[25000];
// TCP
Tcp m_tcp;
std::string m_ipAddress;
UINT16 m_portNumber;
SopasProtocol m_protocol;
void copyFrameToResposeBuffer(UINT32 frameLength);
void removeFrameFromReceiveBuffer(UINT32 frameLength);
protected:
enum State
{
CONSTRUCTED
,
CONNECTED
// , RUNNING
};
State m_state;
};
class SopasEventMessage
{
public:
SopasEventMessage();
~SopasEventMessage()
{}
SopasEventMessage(BYTE *buffer, SopasProtocol protocol, UINT32 frameLength);
SopasProtocol getProtocolType() const
{
return m_protocol;
}
UINT32 size() const
{
return m_frameLength;
}
UINT32 getPayLoadLength() const;
std::string getCommandString() const;
BYTE *getPayLoad();
BYTE *getRawData();
INT32 getVariableIndex();
std::string getVariableName();
bool isValid() const
{ return (m_buffer != NULL); }
private:
void detectEncoding();
void detectMessageType();
private:
BYTE *m_buffer;
SopasProtocol m_protocol;
UINT32 m_frameLength;
};
class SopasAnswer
{
public:
SopasAnswer(const BYTE *answer, UINT32 answerLength);
~SopasAnswer();
BYTE *getBuffer()
{ return m_answerBuffer; }
UINT32 size()
{ return m_answerLength; }
bool isValid()
{ return (m_answerBuffer != NULL); }
private:
UINT32 m_answerLength;
BYTE *m_answerBuffer;
};
#endif //SICK_SCAN_SICK_SCAN_COMMON_NW_H