Garmin Fleet Management Controller
2.19.0
|
Physical layer implementation for a serial port. More...
#include <SerialPort.h>
Public Member Functions | |
virtual | ~SerialPort () |
Destructor. Close the serial port. More... | |
virtual uint32 | getBaudRate () const |
Return the last successfully applied baud rate . More... | |
const CString & | getLastError () const |
Return a description of the last error that occurred. More... | |
virtual const CString & | getPortName () const |
Get the name of the serial port that is open. More... | |
bool | init (const CString &aPortName) |
Initializes the port passed in. More... | |
virtual bool | isOpen () const |
Indicate whether the port is open. More... | |
void | onTimer () |
Timer callback. More... | |
virtual bool | setBaudRate (uint32 aBaudRate) |
Set the baud rate. More... | |
virtual void | setLinkLayer (LinkLayer *aLinkLayer) |
Change the link layer that receives bytes from this SerialPort. More... | |
virtual bool | tx (uint8 *aData, uint16 aSize) |
Transmit bytes on the serial port. More... | |
Static Public Member Functions | |
static void | destroyInstance () |
Destroy the one and only serial port object. More... | |
static SerialPort * | getInstance () |
Get the one and only serial port object. More... | |
static void | getPortList (std::list< CString > &aList) |
Get the list of serial ports. More... | |
static bool | initSerialPort (const CString &aPortName) |
Initializes the port passed in. More... | |
Protected Member Functions | |
SerialPort () | |
Construct the SerialPort. More... | |
virtual void | close () |
Close the COM port if one is in use. 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... | |
Static Protected Member Functions | |
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... | |
Protected Attributes | |
LinkLayer * | mLinkLayer |
The link layer that is one level up from this serial port. More... | |
Static Protected Attributes | |
static SerialPort * | sInstance = NULL |
The one and only instance of this object. More... | |
Private Attributes | |
uint32 | mBaudRate |
The last successfully applied baud rate. More... | |
HANDLE | mComPortHandle |
File handle for the com port that is open, or INVALID_HANDLE_VALUE if the port is not open. More... | |
BOOL | mHandleInitialized |
If TRUE, mComPortHandle is initialized. More... | |
CString | mLastErrorText |
String containing the last communication error. More... | |
CString | mPortName |
Display name of the serial port being used for communication. More... | |
Friends | |
class | TcpIpPort |
Physical layer implementation for a serial port.
Definition at line 30 of file SerialPort.h.
|
virtual |
Destructor. Close the serial port.
Definition at line 442 of file SerialPort.cpp.
References close(), PhysicalLayer::mLinkLayer, recordErrorText(), and LinkLayer::setPhysicalLayer().
|
protected |
Construct the SerialPort.
Definition at line 82 of file SerialPort.cpp.
References initSerialPort(), mComPortHandle, and PhysicalLayer::mLinkLayer.
Referenced by getInstance(), and initSerialPort().
|
protectedvirtual |
Close the COM port if one is in use.
Close the handle for the com port. After this is called, init() must be called to resume communication.
Reimplemented in TcpIpPort.
Definition at line 191 of file SerialPort.cpp.
References isOpen(), mComPortHandle, and mPortName.
Referenced by getPortListEnum(), init(), initSerialPort(), TcpIpPort::initTcpPort(), setBaudRate(), and ~SerialPort().
|
static |
Destroy the one and only serial port object.
Definition at line 50 of file SerialPort.cpp.
References sInstance.
Referenced by getInstance().
|
virtual |
Return the last successfully applied baud rate .
Reimplemented in TcpIpPort.
Definition at line 552 of file SerialPort.cpp.
References mBaudRate.
|
static |
Get the one and only serial port object.
Definition at line 36 of file SerialPort.cpp.
References destroyInstance(), SerialPort(), and sInstance.
Referenced by GarminLinkLayer::GarminLinkLayer(), getPortListEnum(), CSelectCommPortDlg::OnBnClickedOk(), CLogViewerDlg::OnLbnSelchangeLog(), FmiApplicationLayer::rx(), and CFmiPcAppDlg::tryNextCommRate().
const CString & SerialPort::getLastError | ( | ) | const |
Return a description of the last error that occurred.
Definition at line 423 of file SerialPort.cpp.
References mLastErrorText.
|
static |
Get the list of serial ports.
aList | The list to store the port names. |
Definition at line 60 of file SerialPort.cpp.
References getPortListEnum(), getPortListFromRegistry(), and TCP_PORT_NAME.
Referenced by CSelectCommPortDlg::OnInitDialog().
|
staticprotected |
Find the COM ports on the system by opening each in turn.
aList | The list to append port names to. |
Definition at line 382 of file SerialPort.cpp.
References close(), and getInstance().
Referenced by getPortList(), and getPortListFromRegistry().
|
staticprotected |
Get the list of com ports on the system by enumerating the device map in the Windows registry.
aList | The list of port names to append to |
Definition at line 293 of file SerialPort.cpp.
References getPortListEnum().
Referenced by getPortList(), and tx().
|
virtual |
Get the name of the serial port that is open.
Reimplemented in TcpIpPort.
Definition at line 484 of file SerialPort.cpp.
References mPortName.
bool SerialPort::init | ( | const CString & | port | ) |
Initializes the port passed in.
port | Null-terminated string containing the friendly name of the port (e.g., "COM1") |
Definition at line 124 of file SerialPort.cpp.
References close(), DEFAULT_BAUD_RATE, mComPortHandle, mPortName, recordErrorText(), RX_QUEUE_SIZE, setBaudRate(), and TX_QUEUE_SIZE.
Referenced by initSerialPort().
|
static |
Initializes the port passed in.
port | Null-terminated string containing the friendly name of the port (e.g., "COM1") |
Definition at line 96 of file SerialPort.cpp.
References Logger::clearLog(), close(), GarminLinkLayer::getInstance(), init(), Logger::isLogOpen(), GarminLinkLayer::resetPhysicalLayer(), SerialPort(), and sInstance.
Referenced by CSelectCommPortDlg::OnBnClickedOk(), and SerialPort().
|
virtual |
Indicate whether the port is open.
Reimplemented in TcpIpPort.
Definition at line 493 of file SerialPort.cpp.
References mComPortHandle, and setBaudRate().
|
virtual |
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.
|
protectedvirtual |
Receive and process any data.
Reimplemented in TcpIpPort.
Definition at line 204 of file SerialPort.cpp.
References mComPortHandle, minval, PhysicalLayer::mLinkLayer, LinkLayer::rx(), and tx().
Referenced by onTimer().
|
protected |
Store a textual description of the last error that occurred.
aOperation | The name of the operation that caused the error |
Definition at line 456 of file SerialPort.cpp.
References mLastErrorText.
Referenced by init(), TcpIpPort::init(), TcpIpPort::initTcpPort(), TcpIpPort::pumpRx(), setBaudRate(), TcpIpPort::tx(), and ~SerialPort().
|
virtual |
Set the baud rate.
aBaudRate | The new baud rate for the port, in bps. \ |
Reimplemented in TcpIpPort.
Definition at line 504 of file SerialPort.cpp.
References close(), FALSE, mBaudRate, mComPortHandle, recordErrorText(), and TRUE.
Referenced by init(), isOpen(), FmiApplicationLayer::rx(), and CFmiPcAppDlg::tryNextCommRate().
|
virtualinherited |
Change the link layer that receives bytes from this SerialPort.
aLinkLayer | The 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().
Transmit bytes on the serial port.
aData | The bytes to transmit |
aSize | The number of bytes to transmit |
Implements PhysicalLayer.
Reimplemented in TcpIpPort.
Definition at line 258 of file SerialPort.cpp.
References getPortListFromRegistry(), and mComPortHandle.
Referenced by pumpRx().
|
friend |
Definition at line 97 of file SerialPort.h.
|
private |
The last successfully applied baud rate.
Definition at line 116 of file SerialPort.h.
Referenced by getBaudRate(), and setBaudRate().
|
private |
File handle for the com port that is open, or INVALID_HANDLE_VALUE if the port is not open.
Definition at line 102 of file SerialPort.h.
Referenced by close(), init(), isOpen(), pumpRx(), SerialPort(), setBaudRate(), and tx().
|
private |
If TRUE, mComPortHandle is initialized.
Definition at line 105 of file SerialPort.h.
|
private |
String containing the last communication error.
Definition at line 113 of file SerialPort.h.
Referenced by getLastError(), and recordErrorText().
|
protectedinherited |
The link layer that is one level up from this serial port.
Definition at line 47 of file PhysicalLayer.h.
Referenced by TcpIpPort::pumpRx(), pumpRx(), SerialPort(), PhysicalLayer::setLinkLayer(), ~SerialPort(), and TcpIpPort::~TcpIpPort().
|
private |
Display name of the serial port being used for communication.
Definition at line 108 of file SerialPort.h.
Referenced by close(), getPortName(), and init().
|
staticprotected |
The one and only instance of this object.
Definition at line 95 of file SerialPort.h.
Referenced by destroyInstance(), getInstance(), initSerialPort(), and TcpIpPort::initTcpPort().