|
36 | 36 | #include <cstddef> |
37 | 37 | #include <cstdint> |
38 | 38 |
|
39 | | -#include "rosflight_structs.h" |
| 39 | +#include "board.h" |
40 | 40 |
|
41 | 41 | namespace rosflight_firmware |
42 | 42 | { |
| 43 | + |
| 44 | +typedef struct //__attribute__((__packed__)) |
| 45 | +{ |
| 46 | + uint64_t timestamp; // us, time of data read complete |
| 47 | + uint64_t complete; // |
| 48 | + uint16_t status; // device dependent |
| 49 | +} PacketHeader; |
| 50 | + |
| 51 | +typedef struct //__attribute__((__packed__)) |
| 52 | +{ |
| 53 | + PacketHeader header; |
| 54 | + float voltage; |
| 55 | + float current; |
| 56 | + float temperature; // STM32 temperature, not batter temperature |
| 57 | +} BatteryStruct; |
| 58 | + |
| 59 | +typedef struct //__attribute__((__packed__)) |
| 60 | +{ |
| 61 | + PacketHeader header; |
| 62 | + float accel[3]; // rad/s |
| 63 | + float gyro[3]; // rad/s |
| 64 | + float temperature; // K |
| 65 | +} ImuStruct; |
| 66 | + |
| 67 | +typedef struct //__attribute__((__packed__)) |
| 68 | +{ |
| 69 | + PacketHeader header; |
| 70 | + float pressure; // Pa |
| 71 | + float temperature; // K |
| 72 | + union |
| 73 | + { |
| 74 | + float altitude; |
| 75 | + float ias; //speed; |
| 76 | + }; |
| 77 | +} PressureStruct; |
| 78 | + |
| 79 | +enum class SensorRangeType // c.f., ROSFLIGHT_RANGE_TYPE |
| 80 | +{ |
| 81 | + ROSFLIGHT_RANGE_SONAR = 0, /* | */ |
| 82 | + ROSFLIGHT_RANGE_LIDAR = 1, /* | */ |
| 83 | + END = 2, /* | */ |
| 84 | +}; |
| 85 | + |
| 86 | +typedef struct //__attribute__((__packed__)) |
| 87 | +{ |
| 88 | + PacketHeader header; |
| 89 | + float range; // m |
| 90 | + float min_range; // m |
| 91 | + float max_range; // m |
| 92 | + SensorRangeType type; // ROSFLIGHT_RANGE_SONAR, ROSFLIGHT_RANGE_SONAR |
| 93 | +} RangeStruct; |
| 94 | + |
| 95 | +typedef struct //__attribute__((packed)) |
| 96 | +{ |
| 97 | + PacketHeader header; // |
| 98 | + float flux[3]; // T, magnetic flux density |
| 99 | + float temperature; // K |
| 100 | +} MagStruct; |
| 101 | + |
| 102 | +enum class GNSSFixType // quality from GGA |
| 103 | +{ |
| 104 | + GNSS_FIX_TYPE_NO_FIX = 0, |
| 105 | + GNSS_FIX_TYPE_DEAD_RECKONING_ONLY = 1, |
| 106 | + GNSS_FIX_TYPE_2D_FIX = 2, |
| 107 | + GNSS_FIX_TYPE_3D_FIX = 3, |
| 108 | + GNSS_FIX_TYPE_GNSS_PLUS_DEAD_RECKONING = 4, |
| 109 | + GNSS_FIX_TYPE_TIME_FIX_ONLY = 5, |
| 110 | + GNSS_FIX_RTK_FLOAT = 6, |
| 111 | + GNSS_FIX_RTK_FIXED = 7, |
| 112 | + END = 8 |
| 113 | +}; |
| 114 | + |
| 115 | +typedef struct //__attribute__((__packed__)) |
| 116 | +{ |
| 117 | + PacketHeader header; |
| 118 | + uint64_t pps; // most recent pps timestamp (us) |
| 119 | + int64_t unix_seconds; // Unix time, in seconds |
| 120 | + int32_t unix_nanos; |
| 121 | + uint8_t fix_type; |
| 122 | + uint8_t num_sat; |
| 123 | + double lon; |
| 124 | + double lat; |
| 125 | + float height_msl; |
| 126 | + float vel_n; |
| 127 | + float vel_e; |
| 128 | + float vel_d; |
| 129 | + float h_acc; |
| 130 | + float v_acc; |
| 131 | + float speed_accy; |
| 132 | +} GnssStruct; |
| 133 | + |
| 134 | +typedef struct |
| 135 | +{ |
| 136 | + bool imu; |
| 137 | + bool gnss; |
| 138 | + bool baro; |
| 139 | + bool mag; |
| 140 | + bool diff_pressure; |
| 141 | + bool sonar; |
| 142 | + bool battery; |
| 143 | +} got_flags; |
| 144 | + |
| 145 | +// 16 analog + 8 digital MUST BE > 14 (Mavlink message size is hardware to 14) |
| 146 | +#define RC_STRUCT_CHANNELS 24 |
| 147 | +typedef struct //__attribute__((packed)) |
| 148 | +{ |
| 149 | + PacketHeader header; |
| 150 | + uint8_t nChan; |
| 151 | + float chan[RC_STRUCT_CHANNELS]; |
| 152 | + bool frameLost; |
| 153 | + bool failsafeActivated; |
| 154 | +} RcStruct; |
| 155 | + |
| 156 | +typedef struct //__attribute__((__packed__)) |
| 157 | +{ |
| 158 | + PacketHeader header; |
| 159 | + float q[4]; // quaternions |
| 160 | + float rate[3]; |
| 161 | +} AttitudeStruct; |
| 162 | + |
43 | 163 | class Board |
44 | 164 | { |
45 | 165 | public: |
|
0 commit comments