8 #include "../tools/errorhandler.hpp" 9 #include "../tools/toolbox.hpp" 12 #include <sys/socket.h> 13 #include <arpa/inet.h> 54 bytesSent = ::send(*socketPtr, buffer, numberOfBytes, 0);
56 if (bytesSent != (
INT32)numberOfBytes)
58 printWarning(
"Tcp::write: Failed to send data to socket.");
114 std::string ipAdrStr;
118 bool result =
open(ipAdrStr, port, enableVerboseDebugOutput);
147 printError(
"Tcp::open: socket() failed, aborting.");
154 struct sockaddr_in addr;
155 struct hostent *server;
156 server = gethostbyname(ipAddress.c_str());
157 memset(&addr, 0,
sizeof(addr));
158 addr.sin_family = AF_INET;
159 bcopy((
char *)server->h_addr, (
char *)&addr.sin_addr.s_addr, server->h_length);
160 addr.sin_port = htons(port);
165 std::string text =
"Tcp::open: Failed to open TCP connection to " + ipAddress +
", aborting.";
202 else if (result == 0)
220 const UINT16 max_length = 8192;
221 UINT8 inBuffer[max_length];
222 INT32 recvMsgSize = 0;
227 printError(
"Tcp::readInputData: Connection is not open, aborting!");
236 printError(
"Tcp::readInputData: Failed to read data from socket, aborting!");
238 else if (recvMsgSize > 0)
255 for (
INT32 i = 0; i < recvMsgSize; i++)
261 else if (recvMsgSize == 0)
264 printInfoMessage(
"Tcp::readInputData: Read 0 bytes - connection is lost!",
true);
370 std::string outString;
371 const UINT16 maxStringLength = 8192;
395 printWarning(
"Receive-String has excessive length (" +
toString(
m_rxString.length()) +
" bytes). Clearing string. On serial devices, incorrect bitrate settings may cause this behaviour.");
407 if ((
m_beVerbose ==
true) && (outString.length() > 0))
UINT32 getNumReadableBytes()
void printError(std::string message)
std::string toString(const PositionWGS84::PositionWGS84SourceType &type)
bool m_longStringWarningPrinted
void(* DisconnectFunction)(void *obj)
#define printInfoMessage(a, b)
void * m_disconnectFunctionObjPtr
bool write(UINT8 *buffer, UINT32 numberOfBytes)
SickThread< Tcp,&Tcp::readThreadFunction > m_readThread
std::list< unsigned char > m_rxBuffer
void readThreadFunction(bool &endThread, UINT16 &waitTimeMs)
bool open(std::string ipAddress, UINT16 port, bool enableVerboseDebugOutput=false)
void * m_readFunctionObjPtr
ReadFunction m_readFunction
void(* ReadFunction)(void *obj, UINT8 *inputBuffer, UINT32 &numBytes)
DisconnectFunction m_disconnectFunction
std::string readString(UINT8 delimiter)
UINT32 read(UINT8 *buffer, UINT32 bufferLen)
void setReadCallbackFunction(ReadFunction readFunction, void *obj)
void setDisconnectCallbackFunction(DisconnectFunction discFunction, void *obj)
void printWarning(std::string message)