Go to the documentation of this file.00001
00002
00003
00004
00005 #ifndef SICK_SCAN_SICK_SCAN_COMMON_NW_H
00006 #define SICK_SCAN_SICK_SCAN_COMMON_NW_H
00007
00008 #include "sick_scan/tcp/BasicDatatypes.hpp"
00009 #include "sick_scan/tcp/tcp.hpp"
00010 #include <map>
00011
00012
00013
00014
00015
00016
00017
00018 #include "sick_scan/tcp/tcp.hpp"
00019 #include "sick_scan/tcp/errorhandler.hpp"
00020 #include "sick_scan/tcp/toolbox.hpp"
00021 #include "sick_scan/tcp/Mutex.hpp"
00022
00023
00024 #include <string>
00025 class SopasEventMessage;
00026 class SopasAnswer;
00027
00028 enum SopasProtocol
00029 {
00030 CoLa_A,
00031 CoLa_B,
00032 CoLa_Unknown
00033 };
00034
00035
00036 class SickScanCommonNw
00037 {
00038 public:
00039
00040
00041
00042 SickScanCommonNw();
00043 ~SickScanCommonNw();
00044 bool init(std::string ipAddress,
00045 unsigned short portNumber,
00046 Tcp::DisconnectFunction disconnectFunction,
00047 void* obj);
00048 bool setReadCallbackFunction(Tcp::ReadFunction readFunction,
00049 void* obj);
00050
00052 bool connect();
00053
00055 bool isConnected();
00056
00064 bool disconnect();
00065 void sendCommandBuffer(UINT8* buffer, UINT16 len);
00066
00067 private:
00068
00069 bool openTcpConnection();
00070 void closeTcpConnection();
00071
00073 static void readCallbackFunctionS(void* obj, UINT8* buffer, UINT32& numOfBytes);
00074 void readCallbackFunction(UINT8* buffer, UINT32& numOfBytes);
00075
00076 SopasEventMessage findFrameInReceiveBuffer();
00077 void processFrame(SopasEventMessage& frame);
00078
00079 bool m_beVerbose;
00080
00081
00082
00083
00084
00085
00086 UINT32 m_numberOfBytesInResponseBuffer;
00087 UINT8 m_responseBuffer[1024];
00088 Mutex m_receiveDataMutex;
00089
00090
00091 UINT32 m_numberOfBytesInReceiveBuffer;
00092 UINT8 m_receiveBuffer[25000];
00093
00094
00095
00096
00097 Tcp m_tcp;
00098 std::string m_ipAddress;
00099 UINT16 m_portNumber;
00100 SopasProtocol m_protocol;
00101
00102
00103 void copyFrameToResposeBuffer(UINT32 frameLength);
00104 void removeFrameFromReceiveBuffer(UINT32 frameLength);
00105 protected:
00106 enum State
00107 {
00109 CONSTRUCTED
00112 ,
00113 CONNECTED
00116
00117 };
00118
00119 State m_state;
00120 };
00121
00123 class SopasEventMessage
00124 {
00125 public:
00127 SopasEventMessage();
00128
00130 ~SopasEventMessage() {}
00131
00139 SopasEventMessage(BYTE* buffer, SopasProtocol protocol, UINT32 frameLength);
00140
00141 SopasProtocol getProtocolType() const
00142 {
00143 return m_protocol;
00144 }
00145
00146
00147 UINT32 size() const
00148 {
00149 return m_frameLength;
00150 }
00151
00153 UINT32 getPayLoadLength() const;
00154
00155 std::string getCommandString() const;
00156
00158 BYTE* getPayLoad();
00159
00160 BYTE* getRawData();
00162 INT32 getVariableIndex();
00163
00165 std::string getVariableName();
00166
00167 bool isValid() const { return (m_buffer != NULL); }
00168
00169 private:
00170 void detectEncoding();
00171
00172 void detectMessageType();
00173
00174 private:
00175 BYTE* m_buffer;
00176 SopasProtocol m_protocol;
00177 UINT32 m_frameLength;
00178 };
00179
00181 class SopasAnswer
00182 {
00183 public:
00185 SopasAnswer(const BYTE* answer, UINT32 answerLength);
00186
00188 ~SopasAnswer();
00189
00190 BYTE* getBuffer() { return m_answerBuffer; }
00191
00192 UINT32 size() { return m_answerLength; }
00193
00194 bool isValid() { return (m_answerBuffer != NULL); }
00195
00196 private:
00197 UINT32 m_answerLength;
00198 BYTE* m_answerBuffer;
00199 };
00200
00201 #endif //SICK_SCAN_SICK_SCAN_COMMON_NW_H