Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
tap::communication::serial::RefSerial Class Reference

#include <ref_serial.hpp>

Inheritance diagram for tap::communication::serial::RefSerial:
Collaboration diagram for tap::communication::serial::RefSerial:

Public Types

enum  MessageType {
  REF_MESSAGE_TYPE_GAME_STATUS = 0x1 , REF_MESSAGE_TYPE_GAME_RESULT = 0x2 , REF_MESSAGE_TYPE_ALL_ROBOT_HP = 0x3 , REF_MESSAGE_TYPE_SITE_EVENT_DATA = 0x101 ,
  REF_MESSAGE_TYPE_WARNING_DATA = 0x104 , REF_MESSAGE_TYPE_DART_INFO = 0x105 , REF_MESSAGE_TYPE_ROBOT_STATUS = 0x201 , REF_MESSAGE_TYPE_POWER_AND_HEAT = 0x202 ,
  REF_MESSAGE_TYPE_ROBOT_POSITION = 0x203 , REF_MESSAGE_TYPE_ROBOT_BUFF_STATUS = 0x204 , REF_MESSAGE_TYPE_RECEIVE_DAMAGE = 0x206 , REF_MESSAGE_TYPE_PROJECTILE_LAUNCH = 0x207 ,
  REF_MESSAGE_TYPE_BULLETS_REMAIN = 0x208 , REF_MESSAGE_TYPE_RFID_STATUS = 0x209 , REF_MESSAGE_TYPE_DART_STATION_INFO = 0x20A , REF_MESSAGE_TYPE_GROUND_ROBOT_POSITION = 0x20B ,
  REF_MESSAGE_TYPE_RADAR_PROGRESS = 0x20C , REF_MESSAGE_TYPE_SENTRY_INFO = 0x20D , REF_MESSAGE_TYPE_RADAR_INFO = 0x20E , REF_MESSAGE_TYPE_CUSTOM_DATA = 0x301
}
 
- Public Types inherited from tap::communication::serial::DJISerial
using ReceivedSerialMessage = SerialMessage< SERIAL_RX_BUFF_SIZE >
 
- Public Types inherited from tap::communication::serial::RefSerialData
enum class  RobotId : uint16_t {
  INVALID = 0 , RED_HERO = 1 , RED_ENGINEER = 2 , RED_SOLDIER_1 = 3 ,
  RED_SOLDIER_2 = 4 , RED_SOLDIER_3 = 5 , RED_DRONE = 6 , RED_SENTINEL = 7 ,
  RED_DART = 8 , RED_RADAR_STATION = 9 , BLUE_HERO = 101 , BLUE_ENGINEER = 102 ,
  BLUE_SOLDIER_1 = 103 , BLUE_SOLDIER_2 = 104 , BLUE_SOLDIER_3 = 105 , BLUE_DRONE = 106 ,
  BLUE_SENTINEL = 107 , BLUE_DART = 108 , BLUE_RADAR_STATION = 109
}
 

Public Member Functions

 RefSerial (Drivers *drivers)
 
mockable ~RefSerial ()=default
 
void messageReceiveCallback (const ReceivedSerialMessage &completeMessage) override
 
mockable bool getRefSerialReceivingData () const
 
mockable const Rx::RobotData & getRobotData () const
 
mockable const Rx::GameData & getGameData () const
 
mockable RobotId getRobotIdBasedOnCurrentRobotTeam (RobotId id)
 
mockable void attachRobotToRobotMessageHandler (uint16_t msgId, RobotToRobotMessageHandler *handler)
 
mockable bool acquireTransmissionSemaphore ()
 
mockable void releaseTransmissionSemaphore (uint32_t sentMsgLen)
 
bool operatorBlinded () const
 
- Public Member Functions inherited from tap::communication::serial::DJISerial
 DJISerial (Drivers *drivers, Uart::UartPort port, bool isRxCRCEnforcementEnabled=true)
 
mockable ~DJISerial ()=default
 
mockable void initialize ()
 
mockable void updateSerial ()
 

Static Public Member Functions

static bool heatAndLimitValid (uint16_t heat, uint16_t heatLimit)
 
- Static Public Member Functions inherited from tap::communication::serial::RefSerialData
static bool isBlueTeam (RobotId id)
 

Additional Inherited Members

- Public Attributes inherited from tap::communication::serial::DJISerial
struct tap::communication::serial::DJISerial::FrameHeader modm_packed
 
struct tap::communication::serial::DJISerial::SerialMessage modm_packed
 
- Static Public Attributes inherited from tap::communication::serial::DJISerial
static const uint16_t SERIAL_RX_BUFF_SIZE = 1024
 
static const uint16_t SERIAL_HEAD_BYTE = 0xA5
 
- Protected Attributes inherited from tap::communication::serial::DJISerial
Driversdrivers
 

Detailed Description

A class designed to communicate with the 2021 version of the RoboMaster referee system. Supports decoding various referee serial message types. Also supports sending custom UI messages to the referee serial and sending custom robot to robot communication.

For information about the protocol that this serial parser/decoder uses, view RoboMaster's ref serial website: https://www.robomaster.com/en-US/products/components/referee (in the Document Download tab).

Note
use the instance stored in the Drivers to interact with this class (you shouldn't be declaring your own RefSerial object).

Receive information from the referee serial by continuously calling messageReceiveCallback. Access data sent by the referee serial by calling getRobotData or getGameData.

Member Enumeration Documentation

◆ MessageType

RX message type defines, referred to as "Command ID"s in the RoboMaster Ref System Protocol Appendix. Ignored message types commented out because they are not handled by this parser yet. They are values that are used in message headers to indicate the type of message we have received.

Current Ref Serial Version: 1.7.0 Updated March 2025.

Enumerator
REF_MESSAGE_TYPE_GAME_STATUS 
REF_MESSAGE_TYPE_GAME_RESULT 
REF_MESSAGE_TYPE_ALL_ROBOT_HP 
REF_MESSAGE_TYPE_SITE_EVENT_DATA 
REF_MESSAGE_TYPE_WARNING_DATA 
REF_MESSAGE_TYPE_DART_INFO 
REF_MESSAGE_TYPE_ROBOT_STATUS 
REF_MESSAGE_TYPE_POWER_AND_HEAT 
REF_MESSAGE_TYPE_ROBOT_POSITION 
REF_MESSAGE_TYPE_ROBOT_BUFF_STATUS 
REF_MESSAGE_TYPE_RECEIVE_DAMAGE 
REF_MESSAGE_TYPE_PROJECTILE_LAUNCH 
REF_MESSAGE_TYPE_BULLETS_REMAIN 
REF_MESSAGE_TYPE_RFID_STATUS 
REF_MESSAGE_TYPE_DART_STATION_INFO 
REF_MESSAGE_TYPE_GROUND_ROBOT_POSITION 
REF_MESSAGE_TYPE_RADAR_PROGRESS 
REF_MESSAGE_TYPE_SENTRY_INFO 
REF_MESSAGE_TYPE_RADAR_INFO 
REF_MESSAGE_TYPE_CUSTOM_DATA 

Constructor & Destructor Documentation

◆ RefSerial()

tap::communication::serial::RefSerial::RefSerial ( Drivers drivers)

Constructs a RefSerial class connected to bound_ports::REF_SERIAL_UART_PORT with CRC enforcement enabled.

See also
DjiSerial

◆ ~RefSerial()

mockable tap::communication::serial::RefSerial::~RefSerial ( )
default

Member Function Documentation

◆ acquireTransmissionSemaphore()

mockable bool tap::communication::serial::RefSerial::acquireTransmissionSemaphore ( )
inline

Used by RefSerialTransmitter. Attempts to acquire transmission semaphore.

Note
should be called only using RF_WAIT_UNTIL to block until acquiring semaphore.

◆ attachRobotToRobotMessageHandler()

void tap::communication::serial::RefSerial::attachRobotToRobotMessageHandler ( uint16_t  msgId,
RobotToRobotMessageHandler handler 
)

◆ getGameData()

const RefSerialData::Rx::GameData & tap::communication::serial::RefSerial::getGameData ( ) const

Returns a reference to the most up to date game data struct.

◆ getRefSerialReceivingData()

bool tap::communication::serial::RefSerial::getRefSerialReceivingData ( ) const

◆ getRobotData()

const RefSerialData::Rx::RobotData & tap::communication::serial::RefSerial::getRobotData ( ) const

Returns a reference to the most up to date robot data struct.

◆ getRobotIdBasedOnCurrentRobotTeam()

RefSerial::RobotId tap::communication::serial::RefSerial::getRobotIdBasedOnCurrentRobotTeam ( RobotId  id)

Returns a robot id that is of the same color of this robot's ID. This allows you to specify you want to send to one robot and then based on your team it will be sent to the correct robot (your team not the enemy team's robot).

◆ heatAndLimitValid()

static bool tap::communication::serial::RefSerial::heatAndLimitValid ( uint16_t  heat,
uint16_t  heatLimit 
)
inlinestatic
Returns
True if the specified heat and heatLimit values are "valid". These values are valid if they aren't 0xffff and if the heatLimit is not 0.

◆ messageReceiveCallback()

void tap::communication::serial::RefSerial::messageReceiveCallback ( const ReceivedSerialMessage completeMessage)
overridevirtual

Handles the types of messages defined above in the RX message handlers section.

Implements tap::communication::serial::DJISerial.

◆ operatorBlinded()

bool tap::communication::serial::RefSerial::operatorBlinded ( ) const
Returns
True if the robot operator is blinded, false otherwise. Also return false if the referee system is offline.

◆ releaseTransmissionSemaphore()

mockable void tap::communication::serial::RefSerial::releaseTransmissionSemaphore ( uint32_t  sentMsgLen)
inline

The documentation for this class was generated from the following files: