Garmin Fleet Management Controller  2.19.0
TcpIpPort Class Reference

Physical layer implementation for a serial port. More...

#include <TcpIpPort.h>

+ Inheritance diagram for TcpIpPort:

Public Member Functions

virtual uint32 getBaudRate () const
 Return the last successfully applied baud rate . More...
 
virtual const CString & getPortName () const
 Get the name of the serial port that is open. More...
 
virtual bool isOpen () const
 Indicate whether the port is open. More...
 
virtual bool setBaudRate (uint32 aBaudRate)
 Set the baud rate. More...
 
virtual bool tx (uint8 *aData, uint16 aSize)
 Transmit bytes on the serial port. More...
 

Static Public Member Functions

static bool initTcpPort ()
 

Protected Member Functions

 TcpIpPort ()
 Constructor. More...
 
virtual ~TcpIpPort ()
 Destructor. Close the serial port. More...
 
virtual void close ()
 Close the TCP virtual COM port if one is in use. More...
 
const CString & getLastError () const
 Return a description of the last error that occurred. More...
 
bool init (const CString &aPortName)
 Initializes the port passed in. More...
 
bool init ()
 
void onTimer ()
 Timer callback. More...
 
virtual void pumpRx ()
 Receive and process any data. More...
 
void recordErrorText (const CString &aOperation)
 Store a textual description of the last error that occurred. More...
 
virtual void setLinkLayer (LinkLayer *aLinkLayer)
 Change the link layer that receives bytes from this SerialPort. More...
 

Static Protected Member Functions

static void destroyInstance ()
 Destroy the one and only serial port object. More...
 
static SerialPortgetInstance ()
 Get the one and only serial port object. More...
 
static void getPortList (std::list< CString > &aList)
 Get the list of serial ports. More...
 
static void getPortListEnum (std::list< CString > &aList)
 Find the COM ports on the system by opening each in turn. More...
 
static bool getPortListFromRegistry (std::list< CString > &aList)
 Get the list of com ports on the system by enumerating the device map in the Windows registry. More...
 
static bool initSerialPort (const CString &aPortName)
 Initializes the port passed in. More...
 

Protected Attributes

LinkLayermLinkLayer
 The link layer that is one level up from this serial port. More...
 

Static Protected Attributes

static SerialPortsInstance = NULL
 The one and only instance of this object. More...
 

Private Attributes

CSocket clientSocket
 
uint32 mBaudRate
 The last successfully applied baud rate. More...
 
CString mPortName
 Display name of the serial port being used for communication. More...
 
bool socketIsOpen
 

Detailed Description

Physical layer implementation for a serial port.

Definition at line 29 of file TcpIpPort.h.

Constructor & Destructor Documentation

TcpIpPort::TcpIpPort ( )
protected

Constructor.

Definition at line 68 of file TcpIpPort.cpp.

Referenced by initTcpPort().

TcpIpPort::~TcpIpPort ( )
protectedvirtual

Destructor. Close the serial port.

Definition at line 75 of file TcpIpPort.cpp.

References close(), PhysicalLayer::mLinkLayer, and LinkLayer::setPhysicalLayer().

Member Function Documentation

void TcpIpPort::close ( )
protectedvirtual

Close the TCP virtual COM port if one is in use.

Reimplemented from SerialPort.

Definition at line 125 of file TcpIpPort.cpp.

References clientSocket, isOpen(), socketIsOpen, and tx().

Referenced by pumpRx(), tx(), and ~TcpIpPort().

void SerialPort::destroyInstance ( )
staticinherited

Destroy the one and only serial port object.

Definition at line 50 of file SerialPort.cpp.

References SerialPort::sInstance.

Referenced by SerialPort::getInstance().

uint32 TcpIpPort::getBaudRate ( ) const
virtual

Return the last successfully applied baud rate .

Reimplemented from SerialPort.

Definition at line 198 of file TcpIpPort.cpp.

References mBaudRate.

SerialPort * SerialPort::getInstance ( )
staticinherited

Get the one and only serial port object.

Returns
The serial port
Note
SerialPort is a singleton because this application is designed to communicate with a single client device. In a server-based application, there must be one serial port per connected client.

Definition at line 36 of file SerialPort.cpp.

References SerialPort::destroyInstance(), SerialPort::SerialPort(), and SerialPort::sInstance.

Referenced by GarminLinkLayer::GarminLinkLayer(), SerialPort::getPortListEnum(), CSelectCommPortDlg::OnBnClickedOk(), CLogViewerDlg::OnLbnSelchangeLog(), FmiApplicationLayer::rx(), and CFmiPcAppDlg::tryNextCommRate().

const CString & SerialPort::getLastError ( ) const
inherited

Return a description of the last error that occurred.

Definition at line 423 of file SerialPort.cpp.

References SerialPort::mLastErrorText.

void SerialPort::getPortList ( std::list< CString > &  aList)
staticinherited

Get the list of serial ports.

Parameters
aListThe list to store the port names.

Definition at line 60 of file SerialPort.cpp.

References SerialPort::getPortListEnum(), SerialPort::getPortListFromRegistry(), and TCP_PORT_NAME.

Referenced by CSelectCommPortDlg::OnInitDialog().

void SerialPort::getPortListEnum ( std::list< CString > &  aList)
staticprotectedinherited

Find the COM ports on the system by opening each in turn.

Parameters
aListThe list to append port names to.

Definition at line 382 of file SerialPort.cpp.

References SerialPort::close(), and SerialPort::getInstance().

Referenced by SerialPort::getPortList(), and SerialPort::getPortListFromRegistry().

bool SerialPort::getPortListFromRegistry ( std::list< CString > &  aList)
staticprotectedinherited

Get the list of com ports on the system by enumerating the device map in the Windows registry.

Parameters
aListThe list of port names to append to
Returns
TRUE if successful, FALSE otherwise. Note that a return value of FALSE does not mean aList is untouched; aList will have all of the port names that were found.
Note
May require administrative privileges to open the registry

Definition at line 293 of file SerialPort.cpp.

References SerialPort::getPortListEnum().

Referenced by SerialPort::getPortList(), and SerialPort::tx().

const CString & TcpIpPort::getPortName ( ) const
virtual

Get the name of the serial port that is open.

Returns
The name of the serial port that is open, or an empty string if the port is closed.

Reimplemented from SerialPort.

Definition at line 167 of file TcpIpPort.cpp.

References mPortName.

bool SerialPort::init ( const CString &  port)
inherited

Initializes the port passed in.

Parameters
portNull-terminated string containing the friendly name of the port (e.g., "COM1")
Returns
TRUE if the port was successfully opened and initialized, FALSE otherwise

Definition at line 124 of file SerialPort.cpp.

References SerialPort::close(), DEFAULT_BAUD_RATE, SerialPort::mComPortHandle, SerialPort::mPortName, SerialPort::recordErrorText(), RX_QUEUE_SIZE, SerialPort::setBaudRate(), and TX_QUEUE_SIZE.

Referenced by SerialPort::initSerialPort().

bool TcpIpPort::init ( )
protected

Definition at line 48 of file TcpIpPort.cpp.

References clientSocket, SerialPort::recordErrorText(), and socketIsOpen.

bool SerialPort::initSerialPort ( const CString &  port)
staticinherited

Initializes the port passed in.

Parameters
portNull-terminated string containing the friendly name of the port (e.g., "COM1")
Returns
TRUE if the port was successfully opened and initialized, FALSE otherwise

Definition at line 96 of file SerialPort.cpp.

References Logger::clearLog(), SerialPort::close(), GarminLinkLayer::getInstance(), SerialPort::init(), Logger::isLogOpen(), GarminLinkLayer::resetPhysicalLayer(), SerialPort::SerialPort(), and SerialPort::sInstance.

Referenced by CSelectCommPortDlg::OnBnClickedOk(), and SerialPort::SerialPort().

bool TcpIpPort::isOpen ( ) const
virtual

Indicate whether the port is open.

Returns
true if the serial port is open, false otherwise.

Reimplemented from SerialPort.

Definition at line 176 of file TcpIpPort.cpp.

References setBaudRate(), and socketIsOpen.

Referenced by close().

void SerialPort::onTimer ( )
virtualinherited

Timer callback.

If the serial port is open, receive (and process) anything that is ready to receive.

Implements TimerListener.

Definition at line 433 of file SerialPort.cpp.

References SerialPort::isOpen(), and SerialPort::pumpRx().

void TcpIpPort::pumpRx ( )
protectedvirtual

Receive and process any data.

Reimplemented from SerialPort.

Definition at line 87 of file TcpIpPort.cpp.

References clientSocket, close(), PhysicalLayer::mLinkLayer, SerialPort::recordErrorText(), LinkLayer::rx(), RX_BUFFER_SIZE, and socketIsOpen.

void SerialPort::recordErrorText ( const CString &  aOperation)
protectedinherited

Store a textual description of the last error that occurred.

Parameters
aOperationThe name of the operation that caused the error

Definition at line 456 of file SerialPort.cpp.

References SerialPort::mLastErrorText.

Referenced by SerialPort::init(), init(), initTcpPort(), pumpRx(), SerialPort::setBaudRate(), tx(), and SerialPort::~SerialPort().

bool TcpIpPort::setBaudRate ( uint32  aBaudRate)
virtual

Set the baud rate.

Parameters
aBaudRateThe new baud rate for the port, in bps. \

Reimplemented from SerialPort.

Definition at line 187 of file TcpIpPort.cpp.

References mBaudRate.

Referenced by isOpen().

void PhysicalLayer::setLinkLayer ( LinkLayer aLinkLayer)
virtualinherited

Change the link layer that receives bytes from this SerialPort.

Parameters
aLinkLayerThe LinkLayer object that receives bytes, or NULL if no LinkLayer should receive data from this port.

Definition at line 19 of file PhysicalLayer.cpp.

References PhysicalLayer::mLinkLayer.

Referenced by GarminLinkLayer::GarminLinkLayer(), GarminLinkLayer::resetPhysicalLayer(), and LinkLayer::~LinkLayer().

bool TcpIpPort::tx ( uint8 aData,
uint16  aSize 
)
virtual

Transmit bytes on the serial port.

Parameters
aDataThe bytes to transmit
aSizeThe number of bytes to transmit
Returns
true if the bytes were transmitted, false otherwise

Reimplemented from SerialPort.

Definition at line 141 of file TcpIpPort.cpp.

References clientSocket, close(), SerialPort::recordErrorText(), and socketIsOpen.

Referenced by close().

Member Data Documentation

CSocket TcpIpPort::clientSocket
private

Definition at line 69 of file TcpIpPort.h.

Referenced by close(), init(), pumpRx(), and tx().

uint32 TcpIpPort::mBaudRate
private

The last successfully applied baud rate.

Definition at line 67 of file TcpIpPort.h.

Referenced by getBaudRate(), and setBaudRate().

LinkLayer* PhysicalLayer::mLinkLayer
protectedinherited

The link layer that is one level up from this serial port.

Definition at line 47 of file PhysicalLayer.h.

Referenced by pumpRx(), SerialPort::pumpRx(), SerialPort::SerialPort(), PhysicalLayer::setLinkLayer(), SerialPort::~SerialPort(), and ~TcpIpPort().

CString TcpIpPort::mPortName
private

Display name of the serial port being used for communication.

Definition at line 64 of file TcpIpPort.h.

Referenced by getPortName().

SerialPort * SerialPort::sInstance = NULL
staticprotectedinherited

The one and only instance of this object.

Definition at line 95 of file SerialPort.h.

Referenced by SerialPort::destroyInstance(), SerialPort::getInstance(), SerialPort::initSerialPort(), and initTcpPort().

bool TcpIpPort::socketIsOpen
private

Definition at line 71 of file TcpIpPort.h.

Referenced by close(), init(), isOpen(), pumpRx(), and tx().


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