Garmin Fleet Management Controller
2.19.0
|
Link Layer in the OSI model. More...
#include <GarminLinkLayer.h>
Classes | |
struct | fifo_type |
A circular FIFO buffer for processing received bytes into packets. More... | |
Public Member Functions | |
void | resetPhysicalLayer (PhysicalLayer *aPort) |
Reset the physical layer. More... | |
virtual void | rx (uint8 const *const aData, uint32 const aSize) |
Copy Data to FIFO. More... | |
void | setPhysicalLayer (PhysicalLayer *aPort) |
Set the physical layer. More... | |
void | setTransportLayer (TransportLayer *aTransport) |
Set the transport layer. More... | |
virtual bool | tx (Packet *aPacket) |
Transmit a packet. More... | |
Static Public Member Functions | |
static void | destroyInstance () |
Delete the one and only link layer object. More... | |
static GarminLinkLayer * | getInstance () |
Get the one and only link layer object. More... | |
Protected Attributes | |
PhysicalLayer * | mPhysicalLayer |
The serial port that this link layer communicates with. More... | |
TransportLayer * | mTransportLayer |
The transport layer that this link layer communicates with. More... | |
Private Member Functions | |
GarminLinkLayer () | |
Construct a new GarminLinkLayer. More... | |
void | getDataFromFifo (uint8 *aData, uint32 aSize) |
Get Data From FIFO. More... | |
bool | getPacketFromFifo () |
Frame Packet. More... | |
void | incrementHead (uint32 aIncrement) |
Increment FIFO head. More... | |
int | numBytesInFifo () |
Calculate the number of bytes in the FIFO buffer. More... | |
Private Attributes | |
fifo_type | mFifo |
FIFO (First-In, First-Out) buffer used to store bytes received from the client until they are parsed into packets. More... | |
Static Private Attributes | |
static GarminLinkLayer * | sInstance = NULL |
The one and only instance of this class. More... | |
Link Layer in the OSI model.
In the OSI model, the Data Link layer provides encapsulation of data packets into frames, frame synchronization, and error control. For Fleet Management, encapsulation means adding the frame header, frame footer, and sequencing and DLE-stuffing the elements of the packet before transmitting a packet as a frame, and removing the DLE stuffing and verifying the checksum on incoming frames. Frame synchronization is performed by receiving bytes from the serial port into a FIFO buffer, then searching the data received to find valid frames (starting with DLE and ending with DLE-ETX), and sending any valid frames received up to the TransportLayer. Error control means responding to each received frame with either ACK or NAK, depending on whether the frame was received correctly.
Definition at line 39 of file GarminLinkLayer.h.
|
private |
Construct a new GarminLinkLayer.
Construct and initialize the link layer.
Definition at line 49 of file GarminLinkLayer.cpp.
References FIFO_SIZE, SerialPort::getInstance(), GarminLinkLayer::fifo_type::head, mFifo, LinkLayer::mPhysicalLayer, resetPhysicalLayer(), PhysicalLayer::setLinkLayer(), LinkLayer::setPhysicalLayer(), GarminLinkLayer::fifo_type::size, and GarminLinkLayer::fifo_type::tail.
Referenced by getInstance().
|
static |
Delete the one and only link layer object.
Definition at line 40 of file GarminLinkLayer.cpp.
References sInstance.
Referenced by getInstance().
Get Data From FIFO.
This procedure copies data from the FIFO and places it into a persistent buffer. It does not advance the pointers (i.e., the data remains in the buffer).
aData | The data buffer to write to |
aSize | The number of bytes to retrieve. |
Definition at line 318 of file GarminLinkLayer.cpp.
References GarminLinkLayer::fifo_type::buffer, GarminLinkLayer::fifo_type::head, incrementHead(), mFifo, and GarminLinkLayer::fifo_type::size.
Referenced by getPacketFromFifo().
|
static |
Get the one and only link layer object.
Definition at line 27 of file GarminLinkLayer.cpp.
References destroyInstance(), GarminLinkLayer(), and sInstance.
Referenced by SerialPort::initSerialPort(), and TcpIpPort::initTcpPort().
|
private |
Frame Packet.
This procedure processes raw data in the FIFO into Garmin packets, and adds the packets to the rx_queue for processing. While doing so, it also sends ACK/NAK link-level responses as appropriate, and logs the packets that are received.
Each invocation of getPacketFromFifo will add at most one packet to the rx_queue.
Definition at line 155 of file GarminLinkLayer.cpp.
References GarminLinkLayer::fifo_type::buffer, header_type::dle, footer_type::dle, footer_type::etx, FALSE, FIFO_SIZE, getDataFromFifo(), GarminLinkLayer::fifo_type::head, header_type::id, ID_ACK_BYTE, ID_DLE_BYTE, ID_ETX_BYTE, ID_NAK_BYTE, incrementHead(), Logger::logRawData(), GarminPacket::mChecksum, mFifo, GarminPacket::mFrame, GarminPacket::mFrameSize, MIN_PACKET_SIZE, GarminPacket::mPacketId, GarminPacket::mPayload, GarminPacket::mPayloadSize, LinkLayer::mTransportLayer, numBytesInFifo(), TransportLayer::rx(), GarminLinkLayer::fifo_type::size, header_type::size, SIZE_OF_FOOTER, SIZE_OF_HEADER, GarminLinkLayer::fifo_type::tail, TRUE, and TransportLayer::tx().
Referenced by rx().
|
private |
Increment FIFO head.
This procedure increments the receive FIFO's head by the amount requested, effectively removing the data from the FIFO. It will not increment the head beyond the tail, and it also accounts for wrapping.
aIncrement | The number of bytes to remove from the FIFO. |
Definition at line 349 of file GarminLinkLayer.cpp.
References GarminLinkLayer::fifo_type::head, mFifo, GarminLinkLayer::fifo_type::size, GarminLinkLayer::fifo_type::tail, and tx().
Referenced by getDataFromFifo(), and getPacketFromFifo().
|
private |
Calculate the number of bytes in the FIFO buffer.
This procedure calculates the number of bytes between the head and tail of the receive FIFO.
Definition at line 124 of file GarminLinkLayer.cpp.
References GarminLinkLayer::fifo_type::head, mFifo, GarminLinkLayer::fifo_type::size, and GarminLinkLayer::fifo_type::tail.
Referenced by getPacketFromFifo().
void GarminLinkLayer::resetPhysicalLayer | ( | PhysicalLayer * | aPort | ) |
Reset the physical layer.
The existing physical layer is removed and replaced with a new physical layer.
Definition at line 65 of file GarminLinkLayer.cpp.
References FIFO_SIZE, GarminLinkLayer::fifo_type::head, mFifo, LinkLayer::mPhysicalLayer, rx(), PhysicalLayer::setLinkLayer(), LinkLayer::setPhysicalLayer(), GarminLinkLayer::fifo_type::size, and GarminLinkLayer::fifo_type::tail.
Referenced by GarminLinkLayer(), SerialPort::initSerialPort(), and TcpIpPort::initTcpPort().
Copy Data to FIFO.
This procedure appends data (from the PC's com port) to a local rx FIFO, then calls getPacketFromFifo.
aData | Buffer containing the bytes to add to the FIFO |
aSize | Number of bytes to add |
Implements LinkLayer.
Definition at line 94 of file GarminLinkLayer.cpp.
References GarminLinkLayer::fifo_type::buffer, getPacketFromFifo(), mFifo, GarminLinkLayer::fifo_type::size, and GarminLinkLayer::fifo_type::tail.
Referenced by resetPhysicalLayer().
|
inherited |
Set the physical layer.
Set the physical layer that this LinkLayer sends bytes to and receives bytes from.
aPort | The physical layer, or NULL if none. |
Definition at line 41 of file LinkLayer.cpp.
References LinkLayer::mPhysicalLayer, and LinkLayer::setTransportLayer().
Referenced by GarminLinkLayer(), resetPhysicalLayer(), LinkLayer::~LinkLayer(), SerialPort::~SerialPort(), and TcpIpPort::~TcpIpPort().
|
inherited |
Set the transport layer.
Set the transport layer that this LinkLayer sends packets to and receives packets from.
aTransport | The physical layer, or NULL if none. |
Definition at line 55 of file LinkLayer.cpp.
References LinkLayer::mTransportLayer.
Referenced by GarminTransportLayer::GarminTransportLayer(), LinkLayer::setPhysicalLayer(), and GarminTransportLayer::~GarminTransportLayer().
|
virtual |
Transmit a packet.
Build a packet into a raw frame and call the physical layer to transmit it.
aPacket | The packet to build into a frame |
Implements LinkLayer.
Definition at line 400 of file GarminLinkLayer.cpp.
References ID_DLE_BYTE, ID_ETX_BYTE, Logger::logRawData(), GarminPacket::mChecksum, GarminPacket::mFrame, GarminPacket::mFrameSize, GarminPacket::mPacketId, GarminPacket::mPayload, GarminPacket::mPayloadSize, LinkLayer::mPhysicalLayer, and PhysicalLayer::tx().
Referenced by incrementHead(), and GarminTransportLayer::sendPacket().
|
private |
FIFO (First-In, First-Out) buffer used to store bytes received from the client until they are parsed into packets.
Definition at line 93 of file GarminLinkLayer.h.
Referenced by GarminLinkLayer(), getDataFromFifo(), getPacketFromFifo(), incrementHead(), numBytesInFifo(), resetPhysicalLayer(), and rx().
|
protectedinherited |
The serial port that this link layer communicates with.
Definition at line 74 of file LinkLayer.h.
Referenced by GarminLinkLayer(), resetPhysicalLayer(), LinkLayer::setPhysicalLayer(), tx(), and LinkLayer::~LinkLayer().
|
protectedinherited |
The transport layer that this link layer communicates with.
Definition at line 77 of file LinkLayer.h.
Referenced by getPacketFromFifo(), and LinkLayer::setTransportLayer().
|
staticprivate |
The one and only instance of this class.
Definition at line 89 of file GarminLinkLayer.h.
Referenced by destroyInstance(), and getInstance().