-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet.hpp
67 lines (59 loc) · 1.42 KB
/
packet.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2022 ChenJun
// Licensed under the Apache-2.0 License.
#ifndef RM_SERIAL_DRIVER__PACKET_HPP_
#define RM_SERIAL_DRIVER__PACKET_HPP_
#include <algorithm>
#include <cstdint>
#include <vector>
namespace rm_serial_driver
{
struct ReceivePacket
{
uint8_t header = 0x5A;
uint8_t detect_color : 1; // 0-red 1-blue
bool reset_tracker : 1;
uint8_t reserved : 6;
float roll;
float pitch;
float yaw;
float aim_x;
float aim_y;
float aim_z;
uint16_t checksum = 0;
} __attribute__((packed));
struct SendPacket
{
uint8_t header = 0xA5;
bool tracking : 1;
uint8_t id : 3; // 0-outpost 6-guard 7-base
uint8_t armors_num : 3; // 2-balance 3-outpost 4-normal
uint8_t reserved : 1;
float x;
float y;
float z;
float yaw;
float vx;
float vy;
float vz;
float v_yaw;
float r1;
float r2;
float dz;
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_