Aria  2.8.0
ArDeviceConnection Class Referenceabstract

Base class for device connections. More...

#include <ArDeviceConnection.h>

Inherited by ArLogFileConnection, ArSerialConnection, and ArTcpConnection.

Public Types

enum  Status {
  STATUS_NEVER_OPENED = 1, STATUS_OPEN, STATUS_OPEN_FAILED, STATUS_CLOSED_NORMALLY,
  STATUS_CLOSED_ERROR
}
 

Public Member Functions

 ArDeviceConnection ()
 constructor More...
 
virtual bool close (void)
 Closes the connection. More...
 
void debugBytesRead (int bytesRead)
 Notifies the device connection that some bytes were read (should call with 0 if it read but got no bytes)
 
void debugEndPacket (bool goodPacket, int type=0)
 Notifies the device connection that the end of a packet was read, which will cause log messages if set to do so.
 
void debugStartPacket (void)
 Notifies the device connection that the start of a packet is trying to be read.
 
const char * getDeviceName (void) const
 Gets the device type (what this is connecting to)
 
virtual const char * getOpenMessage (int messageNumber)=0
 Gets the string of the message associated with opening the device. More...
 
const char * getPortName (void) const
 Gets the port name.
 
const char * getPortType (void) const
 Gets the port type.
 
virtual int getStatus (void)=0
 Gets the status of the connection, which is one of the enum status. More...
 
const char * getStatusMessage (int messageNumber) const
 Gets the description string associated with the status. More...
 
virtual ArTime getTimeRead (int index)=0
 Gets the time data was read in. More...
 
virtual bool isTimeStamping (void)=0
 sees if timestamping is really going on or not More...
 
virtual bool openSimple (void)=0
 Opens the connection again, using the values from setLocation or.
 
virtual int read (const char *data, unsigned int size, unsigned int msWait=0)=0
 Reads data from connection. More...
 
void setDeviceName (const char *deviceName)
 Sets the device type (what this is connecting to)
 
virtual int write (const char *data, unsigned int size)=0
 Writes data to connection. More...
 
virtual int writePacket (ArBasePacket *packet)
 Writes data to connection. More...
 
virtual ~ArDeviceConnection ()
 destructor also forces a close on the connection
 

Static Public Member Functions

static bool debugShouldLog (bool shouldLog)
 Makes all device connections so that they'll dump data.
 

Protected Member Functions

void buildStrMap (void)
 
void setPortName (const char *portName)
 Sets the port name.
 
void setPortType (const char *portType)
 Sets the port type.
 

Protected Attributes

int myDCDebugBytesRead
 
ArTime myDCDebugFirstByteTime
 
ArTime myDCDebugLastByteTime
 
long long myDCDebugNumBadPackets
 
long long myDCDebugNumGoodPackets
 
bool myDCDebugPacketStarted
 
ArTime myDCDebugStartTime
 
int myDCDebugTimesRead
 
std::string myDCDeviceName
 
std::string myDCPortName
 
std::string myDCPortType
 

Static Protected Attributes

static ArTime ourDCDebugFirstTime
 
static bool ourDCDebugShouldLog = false
 
static ArStrMap ourStrMap
 
static bool ourStrMapInited = false
 

Detailed Description

Base class for device connections.

Base class for device connections, this is mostly for connections to the robot or simulator but could also be used for a connection to a laser or other device

Note that this is mostly a base class, so if you'll want to use one of the classes which inherit from this one... also note that in those classes is where you'll find setPort which sets the place the device connection will try to connect to... the inherited classes also have an open which returns more detailed information about the open attempt, and which takes the parameters for where to connect

Member Enumeration Documentation

◆ Status

Enumerator
STATUS_NEVER_OPENED 

Never opened.

STATUS_OPEN 

Currently open.

STATUS_OPEN_FAILED 

Tried to open, but failed.

STATUS_CLOSED_NORMALLY 

Closed by a close call.

STATUS_CLOSED_ERROR 

Closed because of error.

Constructor & Destructor Documentation

◆ ArDeviceConnection()

ArDeviceConnection::ArDeviceConnection ( )

constructor

Subclasses of this connection type should call setDCPortType in their constructor, then setDCPortName in their openPort.

Classes that use a device connection should call setDCDeviceName with the device the connection is attached too (usually in setDeviceConnection on the device)...

Things that read the port should call debugStartPacket whenever they are starting reading a packet... Then debugBytesRead with the byte count whenever they read or fail a read (0 if a read is failed)... Then debugEndPacket with a boolean for if the packet was a good one or a bad one and an integer that's postive for the type of packet (if successful) or negative to express why the read failed (if not successful). For the 'why the read failed' the values should be negative, and should all be unique (anywhere a read can return), preferably with a gap between the values, so that if more debugging is needed there are values in between the ones already there. Generally this information isn't used or computed, unless the global member ArDeviceConnection::debugShouldLog is called to turn it on.

Member Function Documentation

◆ close()

virtual bool ArDeviceConnection::close ( void  )
inlinevirtual

Closes the connection.

Returns
whether the close succeeded or not

◆ getOpenMessage()

virtual const char* ArDeviceConnection::getOpenMessage ( int  messageNumber)
pure virtual

Gets the string of the message associated with opening the device.

Each class inherited from this one has an open method which returns 0 for success or an integer which can be passed into this function to obtain a string describing the reason for failure

Parameters
messageNumberthe number returned from the open
Returns
the error description associated with the messageNumber

◆ getStatus()

virtual int ArDeviceConnection::getStatus ( void  )
pure virtual

Gets the status of the connection, which is one of the enum status.

Gets the status of the connection, which is one of the enum status. If you want to get a string to go along with the number, use getStatusMessage

Returns
the status of the connection
See also
getStatusMessage

◆ getStatusMessage()

const char * ArDeviceConnection::getStatusMessage ( int  messageNumber) const

Gets the description string associated with the status.

Parameters
messageNumberthe int from getStatus you want the string for
Returns
the description associated with the status
See also
getStatus

◆ getTimeRead()

virtual ArTime ArDeviceConnection::getTimeRead ( int  index)
pure virtual

Gets the time data was read in.

Parameters
indexlooks like this is the index back in the number of bytes last read in
Returns
the time the last read data was read in

◆ isTimeStamping()

virtual bool ArDeviceConnection::isTimeStamping ( void  )
pure virtual

sees if timestamping is really going on or not

Returns
true if real timestamping is happening, false otherwise

◆ read()

virtual int ArDeviceConnection::read ( const char *  data,
unsigned int  size,
unsigned int  msWait = 0 
)
pure virtual

Reads data from connection.

Reads data from connection

Parameters
datapointer to a character array to read the data into
sizemaximum number of bytes to read
msWaitread blocks for this many milliseconds (not at all for == 0)
Returns
number of bytes read, or -1 for failure
See also
write, writePacket

◆ write()

virtual int ArDeviceConnection::write ( const char *  data,
unsigned int  size 
)
pure virtual

Writes data to connection.

Writes data to connection

Parameters
datapointer to a character array to write the data from
sizenumber of bytes to write
Returns
number of bytes read, or -1 for failure
See also
read, writePacket

◆ writePacket()

virtual int ArDeviceConnection::writePacket ( ArBasePacket packet)
inlinevirtual

Writes data to connection.

Writes data to connection from a packet

Parameters
packetpointer to a packet to write the data from
Returns
number of bytes written, or -1 for failure
See also
read, write

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