Garmin Fleet Management Controller  2.19.0
GarminTransportLayer Class Reference

Transport layer in the OSI communication model. More...

#include <GarminTransportLayer.h>

+ Inheritance diagram for GarminTransportLayer:

Public Member Functions

virtual void addAppLayer (ApplicationLayer *aAppLayer)
 Add an app layer object to the callback list. More...
 
virtual void onTimer ()
 Periodic callback. More...
 
virtual void removeAppLayer (ApplicationLayer *aAppLayer)
 Remove an app layer object from the callback list. More...
 
virtual void retry ()
 Tries to resend the most recently sent packet. More...
 
void rx (Packet *aPacket)
 Packet receive callback. More...
 
virtual void tx (Packet *aPacket, bool aSendImmediate)
 Transmit a Packet. More...
 

Static Public Member Functions

static void destroyInstance ()
 Delete the one and only GarminTransportLayer instance. More...
 
static GarminTransportLayergetInstance ()
 Get the one and only GarminTransportLayer. More...
 

Protected Types

typedef std::list< ApplicationLayer * > AppLayerList
 A list of app layers that are connected to this link layer. More...
 

Protected Attributes

AppLayerList mAppLayers
 The application layer objects that send/receive using this GarminTransportLayer. More...
 

Private Types

typedef std::list< GarminPacket * > PacketList
 A list of packets. More...
 

Private Member Functions

 GarminTransportLayer ()
 Construct a GarminTransportLayer. More...
 
virtual ~GarminTransportLayer ()
 GarminTransportLayer destructor. More...
 
bool sendPacket ()
 Send a Packet. More...
 

Private Attributes

bool mCommError
 If true, a communication error has occurred (transmit is suspended) More...
 
GarminPacketmLastAckSent
 A copy of the most recently sent ACK. More...
 
GarminPacketmLastNakSent
 A copy of the most recently sent NAK. More...
 
GarminLinkLayermLinkLayer
 The link layer that frames are sent/received from. More...
 
PacketList mTransmitQueue
 Queue of packets being transmitted; the head of the queue may have been sent but is not ACKed. More...
 

Static Private Attributes

static GarminTransportLayersInstance = NULL
 The one and only instance of this class. More...
 

Detailed Description

Transport layer in the OSI communication model.

In the OSI model, the transport layer is responsible for the reliable delivery of packets to the partner device. For the Fleet Management Interface, this means forming data packets from the Garmin packet ID, payload size, and payload and passing them down to the GarminLinkLayer. The GarminTransportLayer also processes incoming ACK and NAK packets, and determines when the link has timed out. In this implementation, link timeouts are handled by sending an event to the UI, but a robust implementation might retry the packet or reset the link. Packets are maintained in a queue; each packet must be ACK'd by the client before the next packet is sent. The application layer may request that a packet be inserted at the head of the queue; this is necessary for FMI Enable packets and for ACK/NAK responses to incoming packets from the client, as these need to be sent before any other packets that may be in the queue.

Definition at line 42 of file GarminTransportLayer.h.

Member Typedef Documentation

typedef std::list<ApplicationLayer *> TransportLayer::AppLayerList
protectedinherited

A list of app layers that are connected to this link layer.

Definition at line 71 of file TransportLayer.h.

typedef std::list<GarminPacket *> GarminTransportLayer::PacketList
private

A list of packets.

Definition at line 47 of file GarminTransportLayer.h.

Constructor & Destructor Documentation

GarminTransportLayer::GarminTransportLayer ( )
private

Construct a GarminTransportLayer.

Definition at line 48 of file GarminTransportLayer.cpp.

References mCommError, mLinkLayer, and LinkLayer::setTransportLayer().

Referenced by getInstance().

GarminTransportLayer::~GarminTransportLayer ( )
privatevirtual

Member Function Documentation

void TransportLayer::addAppLayer ( ApplicationLayer app)
virtualinherited

Add an app layer object to the callback list.

Parameters
appThe ApplicationLayer to get packet notifications

Definition at line 32 of file TransportLayer.cpp.

References TransportLayer::mAppLayers, and TransportLayer::removeAppLayer().

Referenced by ApplicationLayer::ApplicationLayer(), and TransportLayer::~TransportLayer().

void GarminTransportLayer::destroyInstance ( )
static

Delete the one and only GarminTransportLayer instance.

Definition at line 39 of file GarminTransportLayer.cpp.

References sInstance.

Referenced by getInstance().

GarminTransportLayer * GarminTransportLayer::getInstance ( )
static

Get the one and only GarminTransportLayer.

Returns
The GarminTransportLayer.
Note
An server that connects to multiple client devices should have a GarminTransportLayer object for each device.

Definition at line 26 of file GarminTransportLayer.cpp.

References destroyInstance(), GarminTransportLayer(), and sInstance.

Referenced by FmiLogParser::resendPacket().

void GarminTransportLayer::onTimer ( )
virtual

Periodic callback.

The Transport Layer is responsible for timeout handling. This implementation posts an FMI_COMM_TIMEOUT event if more than 3 seconds have elapsed since the packet at the head of the transmit queue was last sent.

Note
A more robust implementation might retry the last packet several times, resend an enable, etc. Also, the 3 second timeout is based on the fact that the link is direct serial and thus low-latency, and it is expected that the client device is always powered.

Implements TimerListener.

Definition at line 192 of file GarminTransportLayer.cpp.

References COM_TIMEOUT, EVENT_COMM_TIMEOUT, mCommError, mTransmitQueue, and Event::post().

void TransportLayer::removeAppLayer ( ApplicationLayer app)
virtualinherited

Remove an app layer object from the callback list.

Parameters
appThe ApplicationLayer that should no longer get packet notifications

Definition at line 45 of file TransportLayer.cpp.

References TransportLayer::mAppLayers.

Referenced by TransportLayer::addAppLayer(), and ApplicationLayer::~ApplicationLayer().

void GarminTransportLayer::retry ( )
virtual

Tries to resend the most recently sent packet.

Implements TransportLayer.

Definition at line 212 of file GarminTransportLayer.cpp.

References mCommError, sendPacket(), and tx().

void GarminTransportLayer::rx ( Packet aPacket)
virtual

Packet receive callback.

This function is called by the GarminLinkLayer when a complete packet is received. It processes ACK and NAK packets, and passes any others up to the application layer. When an ACK is received, the next packet (if any) in the transmit queue is sent. When a NAK is received, the packet at the head of the queue (if any) is resent.

Parameters
aPacketThe received packet.

Implements TransportLayer.

Definition at line 104 of file GarminTransportLayer.cpp.

References ID_ACK_BYTE, ID_NAK_BYTE, TransportLayer::mAppLayers, mLastAckSent, mLastNakSent, GarminPacket::mPacketId, GarminPacket::mPayload, GarminPacket::mSender, mTransmitQueue, ApplicationLayer::onAck(), and sendPacket().

Referenced by ~GarminTransportLayer().

bool GarminTransportLayer::sendPacket ( )
private

Send a Packet.

This procedure sends the packet at the head of mTransmitQueue to the GarminLinkLayer.

Returns
TRUE if the packet was sent successfully, FALSE otherwise. Note that this does not mean the packet was ACKed, only that there wasn't a comm error on the server side.
Warning
This function assumes the packet is complete, but does not check.

Definition at line 296 of file GarminTransportLayer.cpp.

References ID_ACK_BYTE, ID_NAK_BYTE, mLastAckSent, mLastNakSent, mLinkLayer, mTransmitQueue, and GarminLinkLayer::tx().

Referenced by retry(), rx(), and tx().

void GarminTransportLayer::tx ( Packet aPacket,
bool  aSendNow 
)
virtual

Transmit a Packet.

This procedure builds a packet, adds it to the transmit queue, and, if appropriate, calls sendPacket to send it. If the transmitted packet is an ACK or NAK, this function does not leave the packet on the queue; otherwise the packet is kept on the queue for later matching to a received ACK packet. If send_now is false and mTransmitQueue is not empty, the packet is added to the queue instead of being sent. This is to comply with the requirement that only one packet be transmitted at a time.

Parameters
aPacketThe packet to send
aSendNowIf true, send the packet immediately; if false, queue the packet if another is waiting for an ACK. ACK, NAK, and Enable packets should have this set to TRUE.

Implements TransportLayer.

Definition at line 235 of file GarminTransportLayer.cpp.

References ID_ACK_BYTE, ID_NAK_BYTE, GarminPacket::mChecksum, mCommError, GarminPacket::mPacketId, GarminPacket::mPayload, GarminPacket::mPayloadSize, mTransmitQueue, and sendPacket().

Referenced by FmiLogParser::resendPacket(), and retry().

Member Data Documentation

AppLayerList TransportLayer::mAppLayers
protectedinherited

The application layer objects that send/receive using this GarminTransportLayer.

Definition at line 75 of file TransportLayer.h.

Referenced by TransportLayer::addAppLayer(), TransportLayer::removeAppLayer(), rx(), and ~GarminTransportLayer().

bool GarminTransportLayer::mCommError
private

If true, a communication error has occurred (transmit is suspended)

Definition at line 83 of file GarminTransportLayer.h.

Referenced by GarminTransportLayer(), onTimer(), retry(), and tx().

GarminPacket* GarminTransportLayer::mLastAckSent
private

A copy of the most recently sent ACK.

Definition at line 86 of file GarminTransportLayer.h.

Referenced by rx(), sendPacket(), and ~GarminTransportLayer().

GarminPacket* GarminTransportLayer::mLastNakSent
private

A copy of the most recently sent NAK.

Definition at line 89 of file GarminTransportLayer.h.

Referenced by rx(), sendPacket(), and ~GarminTransportLayer().

GarminLinkLayer* GarminTransportLayer::mLinkLayer
private

The link layer that frames are sent/received from.

Definition at line 76 of file GarminTransportLayer.h.

Referenced by GarminTransportLayer(), sendPacket(), and ~GarminTransportLayer().

PacketList GarminTransportLayer::mTransmitQueue
private

Queue of packets being transmitted; the head of the queue may have been sent but is not ACKed.

Definition at line 80 of file GarminTransportLayer.h.

Referenced by onTimer(), rx(), sendPacket(), tx(), and ~GarminTransportLayer().

GarminTransportLayer * GarminTransportLayer::sInstance = NULL
staticprivate

The one and only instance of this class.

Definition at line 73 of file GarminTransportLayer.h.

Referenced by destroyInstance(), and getInstance().


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