Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
dji_serial.hpp
Go to the documentation of this file.
1/*****************************************************************************/
2/********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/
3/*****************************************************************************/
4
5/*
6 * Copyright (c) 2020-2021 Advanced Robotics at the University of Washington <robomstr@uw.edu>
7 *
8 * This file is part of Taproot.
9 *
10 * Taproot is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Taproot is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Taproot. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef TAPROOT_DJI_SERIAL_HPP_
25#define TAPROOT_DJI_SERIAL_HPP_
26
27#include <cstdint>
28
31#include "tap/util_macros.hpp"
32
33namespace tap
34{
35class Drivers;
36}
37
39{
80{
81public:
86 {
87 uint8_t headByte;
88 uint16_t dataLength;
89 uint8_t seq;
90 uint8_t CRC8;
92
96 template <int DATA_SIZE>
98 {
104 explicit SerialMessage(uint8_t seq = 0)
105 {
106 header.headByte = 0xa5;
107 header.dataLength = sizeof(data);
108 header.seq = seq;
110 reinterpret_cast<uint8_t *>(&header),
111 sizeof(header) - 1);
112 }
113
118 void setCRC16()
119 {
121 reinterpret_cast<uint8_t *>(this),
122 sizeof(*this) - 2);
123 }
124
126 uint16_t messageType;
127 uint8_t data[DATA_SIZE];
128 uint16_t CRC16;
130
131 static const uint16_t SERIAL_RX_BUFF_SIZE = 1024;
132 static const uint16_t SERIAL_HEAD_BYTE = 0xA5;
133
135
142 DJISerial(Drivers *drivers, Uart::UartPort port, bool isRxCRCEnforcementEnabled = true);
144 mockable ~DJISerial() = default;
145
156 mockable void initialize();
157
165 mockable void updateSerial();
166
174 virtual void messageReceiveCallback(const ReceivedSerialMessage &completeMessage) = 0;
175
176private:
177 enum SerialRxState
178 {
179 SERIAL_HEADER_SEARCH,
180 PROCESS_FRAME_HEADER,
181 PROCESS_FRAME_DATA
182 };
183
185 Uart::UartPort port;
186
188 SerialRxState djiSerialRxState;
189
191 ReceivedSerialMessage newMessage;
192
194 ReceivedSerialMessage mostRecentMessage;
195
201 uint16_t frameCurrReadByte;
202
203 bool rxCrcEnabled;
204
213 inline bool verifyCRC8(uint8_t *message, uint32_t messageLength, uint8_t expectedCRC8)
214 {
215 return tap::algorithms::calculateCRC8(message, messageLength) == expectedCRC8;
216 }
217
218protected:
220};
221
222} // namespace tap::communication::serial
223
224#endif // TAPROOT_DJI_SERIAL_HPP_
Definition drivers.hpp:70
Definition dji_serial.hpp:80
Drivers * drivers
Definition dji_serial.hpp:219
static const uint16_t SERIAL_RX_BUFF_SIZE
Definition dji_serial.hpp:131
mockable void updateSerial()
Definition dji_serial.cpp:71
virtual void messageReceiveCallback(const ReceivedSerialMessage &completeMessage)=0
struct tap::communication::serial::DJISerial::FrameHeader modm_packed
mockable void initialize()
Definition dji_serial.cpp:53
SerialMessage< SERIAL_RX_BUFF_SIZE > ReceivedSerialMessage
Definition dji_serial.hpp:134
static const uint16_t SERIAL_HEAD_BYTE
Definition dji_serial.hpp:132
UartPort
Definition uart.hpp:51
uint16_t calculateCRC16(const uint8_t *message, uint32_t messageLength, uint16_t initCRC16)
Definition crc.cpp:87
uint8_t calculateCRC8(const uint8_t *message, uint32_t messageLength, uint8_t initCRC8)
Definition crc.cpp:73
Definition dji_serial.cpp:41
Definition ballistics.cpp:29
tap::Drivers Drivers
Definition drivers.hpp:11
uint8_t seq
Definition dji_serial.hpp:89
uint8_t CRC8
Definition dji_serial.hpp:90
uint8_t headByte
Definition dji_serial.hpp:87
uint16_t dataLength
Definition dji_serial.hpp:88
void setCRC16()
Definition dji_serial.hpp:118
uint8_t data[DATA_SIZE]
Definition dji_serial.hpp:127
uint16_t messageType
Definition dji_serial.hpp:126
uint16_t CRC16
Definition dji_serial.hpp:128
FrameHeader header
Definition dji_serial.hpp:125
SerialMessage(uint8_t seq=0)
Definition dji_serial.hpp:104
#define mockable
Wrap class functions that are not already virtual in this function if you wish to mock them.
Definition util_macros.hpp:38
#define DISALLOW_COPY_AND_ASSIGN(Typename)
Definition util_macros.hpp:27