blob: 051095e17ea5b440b8e06a0f119dcc3ff14df6b2 [file] [log] [blame]
Brian Silverman2df84412013-12-10 14:00:40 -08001// This isn't really a header file. It's designed to be #included directly into
2// other code (possibly in a namespace or whatever), so it doesn't have include
3// guards.
4// This means that it can not #include anything else because it (sometimes) gets
5// #included inside a namespace.
6// <stdint.h> must be #included by the containing file.
7// In the cape code, fill_packet.h #includes this file.
8// In the fitpc code, frc971/input/gyro_board_data.h #includes this file.
9
10#pragma pack(push, 1)
11// Be careful with declaration order in here. ARM doesn't like unaligned
12// accesses!
13struct DATA_STRUCT_NAME {
14 int64_t gyro_angle;
15
16 union {
17 struct {
18 // In us since the cape last reset.
19 uint64_t timestamp;
20
21 struct {
22 // If the current gyro_angle has been not updated because of a bad
23 // reading from the sensor.
24 uint8_t old_gyro_reading : 1;
25 // If we're not going to get any more good gyro_angles.
26 uint8_t bad_gyro : 1;
27 };
28 };
29 struct {
30 uint64_t header1, header2;
31 };
32 };
33
34 // We are 64-bit aligned at this point.
35
36 union {
37 struct {
38 int32_t left_drive;
39 int32_t right_drive;
40 int32_t shooter_angle;
41 int32_t shooter;
42 int32_t indexer;
43 int32_t wrist;
44
45 int32_t capture_top_rise;
46 int32_t capture_top_fall;
47 int32_t capture_bottom_fall_delay;
48 int32_t capture_wrist_rise;
49 int32_t capture_shooter_angle_rise;
50
51 uint16_t battery_voltage;
52 uint16_t left_drive_hall;
53 uint16_t right_drive_hall;
54
55 int8_t top_rise_count;
56
57 int8_t top_fall_count;
58
59 int8_t bottom_rise_count;
60
61 int8_t bottom_fall_delay_count;
62 int8_t bottom_fall_count;
63
64 int8_t wrist_rise_count;
65
66 int8_t shooter_angle_rise_count;
67
68 struct {
69 uint8_t wrist_hall_effect : 1;
70 uint8_t angle_adjust_bottom_hall_effect : 1;
71 uint8_t top_disc : 1;
72 uint8_t bottom_disc : 1;
73 uint8_t loader_top : 1;
74 uint8_t loader_bottom : 1;
75 };
76 } main;
77
78 struct {
79 union {
80 struct {
81 };
82 uint16_t booleans;
83 };
84 } bot3;
85 };
86} __attribute__((aligned(8)));
87#pragma pack(pop)
88
89// The number of bytes that we actually send (so it stays consistent) (including
90// the byte-stuffing overhead and the CRC on the end).
91#define DATA_STRUCT_SEND_SIZE 200
92
93#ifdef __cplusplus
94#define STATIC_ASSERT(cond, msg) static_assert(cond, #msg)
95#endif
96// 4 bytes of 0s at the beginning, 4 bytes of byte-stuffing overhead, and 4
97// bytes of CRC on the end.
98STATIC_ASSERT(
99 (sizeof(struct DATA_STRUCT_NAME) + 8 + 4) <= DATA_STRUCT_SEND_SIZE,
100 The_sensor_data_structure_is_too_big);
101// The byte-stuffing and CRC both work in chunks of 4 bytes, so it has to be a
102// multiple of that in size.
103STATIC_ASSERT((sizeof(struct DATA_STRUCT_NAME) % 4) == 0,
104 The_sensor_data_structure_is_not_a_multiple_of_4_bytes);
105#ifdef __cplusplus
106#undef STATIC_ASSERT
107#endif