70 lines
1.6 KiB
C++
70 lines
1.6 KiB
C++
// Copyright (c) 2022 ChenJun
|
||
// Licensed under the MIT License.
|
||
|
||
#ifndef RM_SERIAL_DRIVER__PACKET_HPP_
|
||
#define RM_SERIAL_DRIVER__PACKET_HPP_
|
||
|
||
#include <algorithm>
|
||
#include <cstdint>
|
||
#include <vector>
|
||
|
||
namespace rm_serial
|
||
{
|
||
struct ReceivePacket
|
||
{
|
||
uint8_t header;
|
||
uint8_t robot_color:1;
|
||
uint8_t task_mode:2;
|
||
uint8_t game_progress:3; //<2F><><EFBFBD><EFBFBD>״̬ 3 <20><><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD> 4 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ 5 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
uint8_t reserved : 2;
|
||
|
||
float body_joint_state;//lidar_link to base_link
|
||
uint16_t outpost_hp;
|
||
float target_x,target_y;
|
||
uint16_t checksum = 0;
|
||
} __attribute__((packed));
|
||
|
||
struct SendPacket
|
||
{
|
||
// uint8_t header = 0xA5;
|
||
// bool findEnemy : 1;
|
||
// bool target_color : 1;
|
||
// uint8_t task_mode : 2;
|
||
// bool suggest_fire : 1;
|
||
// uint8_t reserve : 3;
|
||
// float pitch_cmd = 0;
|
||
// float yaw_cmd = 0;
|
||
// float cmd_vx= 0,cmd_vy= 0,cmd_wz= 0;
|
||
|
||
uint8_t header = 0xA5;
|
||
// bool tracking : 1;
|
||
// bool target_color : 1;
|
||
// uint8_t task_mode : 2;
|
||
// bool suggest_fire : 1;
|
||
uint8_t reserve ;
|
||
|
||
float cmd_vx= 0,cmd_vy= 0,cmd_wz= 0;
|
||
|
||
uint16_t checksum = 0;
|
||
} __attribute__((packed));
|
||
|
||
inline ReceivePacket fromVector(const std::vector<uint8_t> & data)
|
||
{
|
||
ReceivePacket packet;
|
||
std::copy(data.begin(), data.end(), reinterpret_cast<uint8_t *>(&packet));
|
||
return packet;
|
||
}
|
||
|
||
inline std::vector<uint8_t> toVector(const SendPacket & data)
|
||
{
|
||
std::vector<uint8_t> packet(sizeof(SendPacket));
|
||
std::copy(
|
||
reinterpret_cast<const uint8_t *>(&data),
|
||
reinterpret_cast<const uint8_t *>(&data) + sizeof(SendPacket), packet.begin());
|
||
return packet;
|
||
}
|
||
|
||
} // namespace rm_serial_driver
|
||
|
||
#endif // RM_SERIAL_DRIVER__PACKET_HPP_
|