Class DJISerial
Defined in File dji_serial.hpp
Nested Relationships
Nested Types
Inheritance Relationships
Derived Type
public tap::communication::serial::RefSerial
(Class RefSerial)
Class Documentation
-
class DJISerial
A serial handler that implements a specific protocol to be used for communicating with the referee system. Also used for our personal communication with the xavier.
Extend this class and implement messageReceiveCallback if you want to use this serial protocol on a serial line.
Structure of a Serial Message:
Byte Number
Byte Description
Frame Header
0
Frame Head Byte (0xA5)
1
Frame Data Length, LSB
2
Frame Data Length, MSB
3
Frame Sequence Number
4
CRC8 of the frame, (bytes 0 - 3)
5
Message Type, LSB
6
Message Type, MSB
Body - Data Length bytes
Message CRC
7 + Data Length
CRC16 of header and frame, LSB (bytes 0 - 6 + Data Length)
8 + Data Length
CRC16 of header and frame, MSB
Subclassed by tap::communication::serial::RefSerial
Public Types
-
using ReceivedSerialMessage = SerialMessage<SERIAL_RX_BUFF_SIZE>
Public Functions
-
DJISerial(Drivers *drivers, Uart::UartPort port, bool isRxCRCEnforcementEnabled = true)
Construct a Serial object.
- Parameters:
port – [in] serial port to work on.
isRxCRCEnforcementEnabled – [in]
true
to enable Rx CRC Enforcement.
-
~DJISerial() = default
-
void initialize()
Initialize serial. In particular, initializes the hardware serial specified upon construction.
See also
Uart
Note
currently, only uart ports 1, 2, and 6 are enabled. Be sure to add a serial port to
uart.hpp
if you want to use the serial. Also, if you add a new uart port to be generated in theproject.xml
file, you should add it to both theUart
class and this function.
-
void updateSerial()
Receive messages. Call periodically in order to receive all incoming messages.
Note
tested with a delay of 10 microseconds with referee system. The longer the timeout the more likely a message failure may occur.
-
virtual void messageReceiveCallback(const ReceivedSerialMessage &completeMessage) = 0
Called when a complete message is received. A derived class must implement this in order to handle incoming messages properly.
- Parameters:
completeMessage – [in] a reference to the full message that has just been received by this class.
Public Static Attributes
-
static const uint16_t SERIAL_RX_BUFF_SIZE = 1024
-
static const uint16_t SERIAL_HEAD_BYTE = 0xA5
Protected Attributes
-
Drivers *drivers
-
struct FrameHeader
The serial message’s frame header.
-
template<int DATA_SIZE>
struct SerialMessage A container for storing and sending message over serial.
Public Functions
-
inline explicit SerialMessage(uint8_t seq = 0)
Constructs a SerialMessage. In doing so this constructor configures the message header.
- Parameters:
seq – [in] Message sequence number, an optional parameter.
-
inline void setCRC16()
Sets the CRC16 value in the struct. This should be called after writing data to the message struct.
-
inline explicit SerialMessage(uint8_t seq = 0)
-
using ReceivedSerialMessage = SerialMessage<SERIAL_RX_BUFF_SIZE>