Public Member Functions | Static Public Attributes | Protected Attributes | Static Protected Attributes | Private Attributes | List of all members
cTCPSerial Class Reference

Low-level communication class to access a CAN port. More...

#include <tcpserial.h>

Inheritance diagram for cTCPSerial:
Inheritance graph
[legend]

Public Member Functions

void Close (void)
 Close the previously opened CAN ESD interface port. More...
 
 cTCPSerial (char const *_tcp_adr, int _tcp_port, double _timeout)
 
virtual tErrorCode GetErrorNumber ()
 
bool IsOpen (void) throw ()
 Return true if interface to CAN ESD is open. More...
 
void Open (void)
 
ssize_t Read (void *data, ssize_t size, long timeout_us, bool return_on_less_data)
 
void SetTimeout (double _timeout)
 set the timeout for next readline() calls (negative value means: no timeout, wait for ever) More...
 
int write (char const *ptr, int len=0)
 Write data to a previously opened port. More...
 
- Public Member Functions inherited from cSerialBase
 cSerialBase ()
 ctor More...
 
virtual char const * GetErrorMessage (tErrorCode dw)
 
char const * GetLastErrorMessage (void)
 return the last error message as string. The string returned will be overwritten by the next call to the function More...
 
virtual double GetTimeout ()
 get the timeout for next readline() calls (negative value means: no timeout, wait for ever) More...
 
virtual char * readline (char *line, int size, char const *eol="\n", bool return_on_less_data=false)
 Read a line from the device. More...
 
virtual bool UseCRC16 ()
 
virtual ~cSerialBase (void)
 dtor More...
 

Static Public Attributes

static double const TIMEOUT_RETURN_IMMEDITELY_S = 0.0
 
static long const TIMEOUT_RETURN_IMMEDITELY_US = 0
 
static double const TIMEOUT_WAIT_FOR_EVER_S = -1.0
 
static long const TIMEOUT_WAIT_FOR_EVER_US = -1
 

Protected Attributes

int fd
 the file descriptor of the socket More...
 
std::string tcp_adr
 
int tcp_port
 the TCP port to use More...
 
- Protected Attributes inherited from cSerialBase
double timeout
 timeout in seconds More...
 
char ungetch
 an already read data byte of the next line More...
 
bool ungetch_valid
 Flag, true if ungetch is valid. More...
 

Static Protected Attributes

static const int INVALID_SOCKET = -1
 

Private Attributes

struct timeval timeout_timeval
 timeout for setsockopt More...
 
long timeout_us
 cached timeout in us for read() More...
 

Additional Inherited Members

- Public Types inherited from cSerialBase
typedef int tErrorCode
 type of the error code, DWORD on windows and int on Linux/cygwin More...
 
- Public Attributes inherited from cSerialBase
cDBG dbg
 A stream object to print colored debug messages. More...
 

Detailed Description

Low-level communication class to access a CAN port.

Definition at line 88 of file tcpserial.h.

Constructor & Destructor Documentation

cTCPSerial::cTCPSerial ( char const *  _tcp_adr,
int  _tcp_port,
double  _timeout 
)

Constructor: constructs an object to communicate with an SDH via TCP on _tcp_adr and _tcp_port.

Parameters
_tcp_adr- a string describing the hostname or IP address of the SDH
_tcp_port- the port number on the SDH
_timeout- the timeout when receiving / sending data:
  • < 0.0 : no timeout = wait for ever
  • == 0.0 : zero timeout = return immediately
  • > 0.0 : timeout in seconds

Definition at line 116 of file tcpserial.cpp.

Member Function Documentation

void cTCPSerial::Close ( void  )
virtual

Close the previously opened CAN ESD interface port.

Implements cSerialBase.

Definition at line 198 of file tcpserial.cpp.

virtual tErrorCode cTCPSerial::GetErrorNumber ( )
inlinevirtual

Overloaded helper function that returns the last TCP error number.

Reimplemented from cSerialBase.

Definition at line 167 of file tcpserial.h.

bool cTCPSerial::IsOpen ( void  )
throw (
)
virtual

Return true if interface to CAN ESD is open.

Implements cSerialBase.

Definition at line 190 of file tcpserial.cpp.

void cTCPSerial::Open ( void  )
virtual

Open the device as configured by the parameters given to the constructor

Implements cSerialBase.

Definition at line 137 of file tcpserial.cpp.

ssize_t cTCPSerial::Read ( void *  data,
ssize_t  size,
long  timeout_us,
bool  return_on_less_data 
)
virtual

Read data from device. This function waits until max_time_us us passed or the expected number of bytes are received via serial line. if (return_on_less_data is true (default value), the number of bytes that have been received are returned and the data is stored in data If the return_on_less_data is false, data is only read from serial line, if at least size bytes are available.

Implements cSerialBase.

Definition at line 240 of file tcpserial.cpp.

void cTCPSerial::SetTimeout ( double  _timeout)
virtual

set the timeout for next readline() calls (negative value means: no timeout, wait for ever)

Reimplemented from cSerialBase.

Definition at line 331 of file tcpserial.cpp.

int cTCPSerial::write ( char const *  ptr,
int  len = 0 
)
virtual

Write data to a previously opened port.

Write len bytes from *ptr to the CAN device

Parameters
ptr- pointer the byte array to send in memory
len- number of bytes to send
Returns
the number of bytes actually written

Implements cSerialBase.

Definition at line 214 of file tcpserial.cpp.

Member Data Documentation

int cTCPSerial::fd
protected

the file descriptor of the socket

Definition at line 102 of file tcpserial.h.

const int cTCPSerial::INVALID_SOCKET = -1
staticprotected

Definition at line 103 of file tcpserial.h.

std::string cTCPSerial::tcp_adr
protected

Definition at line 93 of file tcpserial.h.

int cTCPSerial::tcp_port
protected

the TCP port to use

Definition at line 96 of file tcpserial.h.

double const cTCPSerial::TIMEOUT_RETURN_IMMEDITELY_S = 0.0
static

Definition at line 113 of file tcpserial.h.

long const cTCPSerial::TIMEOUT_RETURN_IMMEDITELY_US = 0
static

Definition at line 115 of file tcpserial.h.

struct timeval cTCPSerial::timeout_timeval
private

timeout for setsockopt

Definition at line 107 of file tcpserial.h.

long cTCPSerial::timeout_us
private

cached timeout in us for read()

Definition at line 109 of file tcpserial.h.

double const cTCPSerial::TIMEOUT_WAIT_FOR_EVER_S = -1.0
static

Definition at line 112 of file tcpserial.h.

long const cTCPSerial::TIMEOUT_WAIT_FOR_EVER_US = -1
static

Definition at line 114 of file tcpserial.h.


The documentation for this class was generated from the following files:


sdhlibrary_cpp
Author(s): Dirk Osswald
autogenerated on Sun Aug 18 2019 03:42:21