Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
ref_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_REF_SERIAL_HPP_
25#define TAPROOT_REF_SERIAL_HPP_
26
27#include <cmath>
28#include <cstdint>
29#include <unordered_map>
30
32#include "tap/util_macros.hpp"
33
34#include "modm/container/deque.hpp"
35#include "modm/processing/protothread/semaphore.hpp"
36
37#include "dji_serial.hpp"
38#include "ref_serial_data.hpp"
39
40namespace tap
41{
42class Drivers;
43}
44
46{
62class RefSerial : public DJISerial, public RefSerialData
63{
64private:
68 static constexpr uint32_t TIME_OFFLINE_REF_DATA_MS = 1000;
69
70 // RX message constants
75 static constexpr uint16_t DPS_TRACKER_DEQUE_SIZE = 20;
76
77public:
88 {
92
96
110
112 // REF_MESSAGE_TYPE_CUSTOM_CONTROLLER_DATA_RECEIVE = 0x302,
113 // REF_MESSAGE_TYPE_SMALL_MAP_INTERACTION = 0x303,
114 // REF_MESSAGE_TYPE_VTM_INPUT_DATA = 0x304,
115 // REF_MESSAGE_TYPE_RADAR_MINIMAP = 0x305,
116 // REF_MESSAGE_TYPE_CUSTOM_CONTROLLER_DATA_SEND = 0x306,
117 // REF_MESSAGE_TYPE_SENTRY_SMALL_MAP = 0x307,
118 // REF_MESSAGE_TYPE_ROBOT_SMALL_MAP = 0x308,
119 // REF_MESSAGE_TYPE_ROBOT_CUSTOM_CONTROLLER_FEEDBACK = 0x309
120 };
121
130 mockable ~RefSerial() = default;
131
135 void messageReceiveCallback(const ReceivedSerialMessage& completeMessage) override;
136
138
142 mockable const Rx::RobotData& getRobotData() const;
143
147 mockable const Rx::GameData& getGameData() const;
148
156
158 uint16_t msgId,
160
167 {
168 if (transmissionDelayTimer.isExpired() || transmissionDelayTimer.isStopped())
169 {
170 return transmissionSemaphore.acquire();
171 }
172 return false;
173 }
174
175 mockable void releaseTransmissionSemaphore(uint32_t sentMsgLen)
176 {
177 transmissionSemaphore.release();
178 transmissionDelayTimer.restart(
179 std::ceil(sentMsgLen * 1000.0f / Tx::MAX_TRANSMIT_SPEED_BYTES_PER_S));
180 }
181
186 bool operatorBlinded() const;
187
192 static inline bool heatAndLimitValid(uint16_t heat, uint16_t heatLimit)
193 {
194 return heat != 0xffff && heatLimit != 0xffff && heatLimit != 0;
195 }
196
197private:
198 Rx::RobotData robotData;
199 Rx::GameData gameData;
200 modm::BoundedDeque<Rx::DamageEvent, DPS_TRACKER_DEQUE_SIZE> receivedDpsTracker;
201 arch::MilliTimeout refSerialOfflineTimeout;
202 std::unordered_map<uint16_t, RobotToRobotMessageHandler*> msgIdToRobotToRobotHandlerMap;
203 modm::pt::Semaphore transmissionSemaphore;
204 tap::arch::MilliTimeout transmissionDelayTimer;
205
210 bool decodeToGameStatus(const ReceivedSerialMessage& message);
214 bool decodeToGameResult(const ReceivedSerialMessage& message);
218 bool decodeToAllRobotHP(const ReceivedSerialMessage& message);
222 bool decodeToSiteEventData(const ReceivedSerialMessage& message);
226 bool decodeToProjectileSupplierAction(const ReceivedSerialMessage& message);
231 bool decodeToWarningData(const ReceivedSerialMessage& message);
235 bool decodeToDartInfo(const ReceivedSerialMessage& message);
240 bool decodeToRobotStatus(const ReceivedSerialMessage& message);
245 bool decodeToPowerAndHeat(const ReceivedSerialMessage& message);
250 bool decodeToRobotPosition(const ReceivedSerialMessage& message);
254 bool decodeToRobotBuffs(const ReceivedSerialMessage& message);
259 bool decodeToAerialEnergyStatus(const ReceivedSerialMessage& message);
264 bool decodeToDamageStatus(const ReceivedSerialMessage& message);
269 bool decodeToProjectileLaunch(const ReceivedSerialMessage& message);
274 bool decodeToBulletsRemain(const ReceivedSerialMessage& message);
278 bool decodeToRFIDStatus(const ReceivedSerialMessage& message);
282 bool decodeToDartStation(const ReceivedSerialMessage& message);
286 bool decodeToGroundPositions(const ReceivedSerialMessage& message);
290 bool decodeToRadarProgress(const ReceivedSerialMessage& message);
294 bool decodeToSentryInfo(const ReceivedSerialMessage& message);
298 bool decodeToRadarInfo(const ReceivedSerialMessage& message);
299
300 bool handleRobotToRobotCommunication(const ReceivedSerialMessage& message);
301
302 void updateReceivedDamage();
303 void processReceivedDamage(uint32_t timestamp, int32_t damageTaken);
304};
305
306} // namespace tap::communication::serial
307
308#endif // TAPROOT_REF_SERIAL_HPP_
Definition drivers.hpp:70
Definition timeout.hpp:44
void restart(uint32_t timeout)
Definition timeout.hpp:70
bool isExpired() const
Definition timeout.hpp:95
bool isStopped() const
Definition timeout.hpp:89
Definition dji_serial.hpp:80
Drivers * drivers
Definition dji_serial.hpp:219
SerialMessage< SERIAL_RX_BUFF_SIZE > ReceivedSerialMessage
Definition dji_serial.hpp:134
Definition ref_serial_data.hpp:87
Definition ref_serial_data.hpp:41
RobotId
Definition ref_serial_data.hpp:48
Definition ref_serial.hpp:63
bool operatorBlinded() const
Definition ref_serial.cpp:567
mockable const Rx::RobotData & getRobotData() const
Definition ref_serial.cpp:168
static bool heatAndLimitValid(uint16_t heat, uint16_t heatLimit)
Definition ref_serial.hpp:192
mockable void attachRobotToRobotMessageHandler(uint16_t msgId, RobotToRobotMessageHandler *handler)
Definition ref_serial.cpp:554
mockable bool acquireTransmissionSemaphore()
Definition ref_serial.hpp:166
void messageReceiveCallback(const ReceivedSerialMessage &completeMessage) override
Definition ref_serial.cpp:52
mockable const Rx::GameData & getGameData() const
Definition ref_serial.cpp:170
mockable RobotId getRobotIdBasedOnCurrentRobotTeam(RobotId id)
Definition ref_serial.cpp:536
mockable bool getRefSerialReceivingData() const
Definition ref_serial.cpp:47
MessageType
Definition ref_serial.hpp:88
@ REF_MESSAGE_TYPE_ROBOT_BUFF_STATUS
Definition ref_serial.hpp:100
@ REF_MESSAGE_TYPE_BULLETS_REMAIN
Definition ref_serial.hpp:103
@ REF_MESSAGE_TYPE_DART_STATION_INFO
Definition ref_serial.hpp:105
@ REF_MESSAGE_TYPE_DART_INFO
Definition ref_serial.hpp:95
@ REF_MESSAGE_TYPE_RECEIVE_DAMAGE
Definition ref_serial.hpp:101
@ REF_MESSAGE_TYPE_GAME_STATUS
Definition ref_serial.hpp:89
@ REF_MESSAGE_TYPE_CUSTOM_DATA
Definition ref_serial.hpp:111
@ REF_MESSAGE_TYPE_RADAR_PROGRESS
Definition ref_serial.hpp:107
@ REF_MESSAGE_TYPE_POWER_AND_HEAT
Definition ref_serial.hpp:98
@ REF_MESSAGE_TYPE_GAME_RESULT
Definition ref_serial.hpp:90
@ REF_MESSAGE_TYPE_WARNING_DATA
Definition ref_serial.hpp:94
@ REF_MESSAGE_TYPE_ROBOT_POSITION
Definition ref_serial.hpp:99
@ REF_MESSAGE_TYPE_ROBOT_STATUS
Definition ref_serial.hpp:97
@ REF_MESSAGE_TYPE_GROUND_ROBOT_POSITION
Definition ref_serial.hpp:106
@ REF_MESSAGE_TYPE_PROJECTILE_LAUNCH
Definition ref_serial.hpp:102
@ REF_MESSAGE_TYPE_RFID_STATUS
Definition ref_serial.hpp:104
@ REF_MESSAGE_TYPE_RADAR_INFO
Definition ref_serial.hpp:109
@ REF_MESSAGE_TYPE_ALL_ROBOT_HP
Definition ref_serial.hpp:91
@ REF_MESSAGE_TYPE_SITE_EVENT_DATA
Definition ref_serial.hpp:93
@ REF_MESSAGE_TYPE_SENTRY_INFO
Definition ref_serial.hpp:108
mockable void releaseTransmissionSemaphore(uint32_t sentMsgLen)
Definition ref_serial.hpp:175
Definition dji_serial.cpp:41
Definition ballistics.cpp:29
tap::Drivers Drivers
Definition drivers.hpp:11
#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