Garmin Fleet Management Controller  2.19.0
SerialPort.h
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * HEADER NAME:
4 * SerialPort.h
5 *
6 * Copyright 2008-2016 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 #ifndef SerialPort_H
11 #define SerialPort_H
12 
13 class SerialPort;
14 class TcpIpPort;
15 
16 #include <list>
17 
18 #include "stdafx.h"
19 #include "garmin_types.h"
20 #include "TimerListener.h"
21 #include "PhysicalLayer.h"
22 
23 #define TCP_PORT_NAME "TCP_PORT_6000"
24 
25 class LinkLayer;
26 
27 //----------------------------------------------------------------------
29 //----------------------------------------------------------------------
30 class SerialPort : public PhysicalLayer, public TimerListener
31 {
32 public:
33  virtual ~SerialPort();
34 
35  static SerialPort * getInstance();
36  static void destroyInstance();
37  static void getPortList
38  (
39  std::list<CString> &aList
40  );
41 
42  static bool initSerialPort
43  (
44  const CString& aPortName
45  );
46 
47  bool init
48  (
49  const CString& aPortName
50  );
51 
52  virtual bool setBaudRate
53  (
54  uint32 aBaudRate
55  );
56 
57  virtual uint32 getBaudRate() const;
58 
59  const CString& getLastError() const;
60  virtual const CString& getPortName() const;
61 
62  virtual bool isOpen() const;
63 
64  void onTimer();
65 
66  virtual bool tx
67  (
68  uint8 * aData,
69  uint16 aSize
70  );
71 
72 protected:
73  static bool getPortListFromRegistry
74  (
75  std::list<CString> &aList
76  );
77 
78  static void getPortListEnum
79  (
80  std::list<CString> &aList
81  );
82 
83  SerialPort();
84 
85  void recordErrorText
86  (
87  const CString& aOperation
88  );
89 
90  virtual void pumpRx();
91 
92  virtual void close();
93 
96 
97  friend class TcpIpPort;
98 
99 private:
103 
106 
108  CString mPortName;
109 
113  CString mLastErrorText;
114 
117 };
118 
119 #endif
Physical layer implementation for a serial port.
Definition: TcpIpPort.h:29
Abstract base class for the physical layer.
Definition: PhysicalLayer.h:25
virtual bool setBaudRate(uint32 aBaudRate)
Set the baud rate.
Definition: SerialPort.cpp:504
void recordErrorText(const CString &aOperation)
Store a textual description of the last error that occurred.
Definition: SerialPort.cpp:456
CString mPortName
Display name of the serial port being used for communication.
Definition: SerialPort.h:108
virtual void close()
Close the COM port if one is in use.
Definition: SerialPort.cpp:191
static bool initSerialPort(const CString &aPortName)
Initializes the port passed in.
Definition: SerialPort.cpp:96
static void getPortListEnum(std::list< CString > &aList)
Find the COM ports on the system by opening each in turn.
Definition: SerialPort.cpp:382
virtual uint32 getBaudRate() const
Return the last successfully applied baud rate .
Definition: SerialPort.cpp:552
static SerialPort * sInstance
The one and only instance of this object.
Definition: SerialPort.h:95
HANDLE mComPortHandle
File handle for the com port that is open, or INVALID_HANDLE_VALUE if the port is not open...
Definition: SerialPort.h:102
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...
Definition: SerialPort.cpp:293
virtual const CString & getPortName() const
Get the name of the serial port that is open.
Definition: SerialPort.cpp:484
SerialPort()
Construct the SerialPort.
Definition: SerialPort.cpp:82
Abstract base class for link Layers in the OSI model.
Definition: LinkLayer.h:26
bool init(const CString &aPortName)
Initializes the port passed in.
Definition: SerialPort.cpp:124
virtual bool tx(uint8 *aData, uint16 aSize)
Transmit bytes on the serial port.
Definition: SerialPort.cpp:258
virtual ~SerialPort()
Destructor. Close the serial port.
Definition: SerialPort.cpp:442
const CString & getLastError() const
Return a description of the last error that occurred.
Definition: SerialPort.cpp:423
BOOL mHandleInitialized
If TRUE, mComPortHandle is initialized.
Definition: SerialPort.h:105
static SerialPort * getInstance()
Get the one and only serial port object.
Definition: SerialPort.cpp:36
static void getPortList(std::list< CString > &aList)
Get the list of serial ports.
Definition: SerialPort.cpp:60
unsigned short int uint16
16-bit unsigned integer
Definition: garmin_types.h:64
Abstract base class for objects that need to do something periodically.
Definition: TimerListener.h:21
unsigned char uint8
8-bit unsigned integer
Definition: garmin_types.h:62
CString mLastErrorText
String containing the last communication error.
Definition: SerialPort.h:113
virtual bool isOpen() const
Indicate whether the port is open.
Definition: SerialPort.cpp:493
virtual void pumpRx()
Receive and process any data.
Definition: SerialPort.cpp:204
unsigned long int uint32
32-bit unsigned integer
Definition: garmin_types.h:66
void onTimer()
Timer callback.
Definition: SerialPort.cpp:433
Physical layer implementation for a serial port.
Definition: SerialPort.h:30
uint32 mBaudRate
The last successfully applied baud rate.
Definition: SerialPort.h:116
static void destroyInstance()
Destroy the one and only serial port object.
Definition: SerialPort.cpp:50