Garmin Fleet Management Controller
2.19.0
|
Transport layer in the OSI communication model. More...
#include <GarminTransportLayer.h>
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 GarminTransportLayer * | getInstance () |
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... | |
GarminPacket * | mLastAckSent |
A copy of the most recently sent ACK. More... | |
GarminPacket * | mLastNakSent |
A copy of the most recently sent NAK. More... | |
GarminLinkLayer * | mLinkLayer |
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 GarminTransportLayer * | sInstance = NULL |
The one and only instance of this class. More... | |
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.
|
protectedinherited |
A list of app layers that are connected to this link layer.
Definition at line 71 of file TransportLayer.h.
|
private |
A list of packets.
Definition at line 47 of file GarminTransportLayer.h.
|
private |
Construct a GarminTransportLayer.
Definition at line 48 of file GarminTransportLayer.cpp.
References mCommError, mLinkLayer, and LinkLayer::setTransportLayer().
Referenced by getInstance().
|
privatevirtual |
GarminTransportLayer destructor.
Empty the transmit queue
Definition at line 61 of file GarminTransportLayer.cpp.
References TransportLayer::mAppLayers, mLastAckSent, mLastNakSent, mLinkLayer, mTransmitQueue, rx(), and LinkLayer::setTransportLayer().
|
virtualinherited |
Add an app layer object to the callback list.
app | The 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().
|
static |
Delete the one and only GarminTransportLayer instance.
Definition at line 39 of file GarminTransportLayer.cpp.
References sInstance.
Referenced by getInstance().
|
static |
Get the one and only GarminTransportLayer.
Definition at line 26 of file GarminTransportLayer.cpp.
References destroyInstance(), GarminTransportLayer(), and sInstance.
Referenced by FmiLogParser::resendPacket().
|
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.
Implements TimerListener.
Definition at line 192 of file GarminTransportLayer.cpp.
References COM_TIMEOUT, EVENT_COMM_TIMEOUT, mCommError, mTransmitQueue, and Event::post().
|
virtualinherited |
Remove an app layer object from the callback list.
app | The 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().
|
virtual |
Tries to resend the most recently sent packet.
Implements TransportLayer.
Definition at line 212 of file GarminTransportLayer.cpp.
References mCommError, sendPacket(), and tx().
|
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.
aPacket | The 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().
|
private |
Send a Packet.
This procedure sends the packet at the head of mTransmitQueue to the GarminLinkLayer.
Definition at line 296 of file GarminTransportLayer.cpp.
References ID_ACK_BYTE, ID_NAK_BYTE, mLastAckSent, mLastNakSent, mLinkLayer, mTransmitQueue, and GarminLinkLayer::tx().
|
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.
aPacket | The packet to send |
aSendNow | If 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().
|
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().
|
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().
|
private |
A copy of the most recently sent ACK.
Definition at line 86 of file GarminTransportLayer.h.
Referenced by rx(), sendPacket(), and ~GarminTransportLayer().
|
private |
A copy of the most recently sent NAK.
Definition at line 89 of file GarminTransportLayer.h.
Referenced by rx(), sendPacket(), and ~GarminTransportLayer().
|
private |
The link layer that frames are sent/received from.
Definition at line 76 of file GarminTransportLayer.h.
Referenced by GarminTransportLayer(), sendPacket(), and ~GarminTransportLayer().
|
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().
|
staticprivate |
The one and only instance of this class.
Definition at line 73 of file GarminTransportLayer.h.
Referenced by destroyInstance(), and getInstance().