GCC Code Coverage Report


Directory: ../../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 7 / 0 / 7
Functions: 100.0% 1 / 0 / 1
Branches: -% 0 / 0 / 0

mod/telemetry/telemetry.h
Line Branch Exec Source
1 /**
2 ******************************************************************************
3 * @file : telemetry.h
4 * @brief : Definitions for the telemetry data structures.
5 ******************************************************************************
6 * @copyright
7 *
8 * Copyright (c) 2025 Sun Devil Rocketry.
9 * All rights reserved.
10 *
11 * This software is licensed under terms that can be found in the LICENSE
12 * file in the root directory of this software component.
13 * If no LICENSE file comes with this software, it is covered under the
14 * BSD-3-Clause.
15 *
16 * https://opensource.org/license/bsd-3-clause
17 *
18 ******************************************************************************
19 */
20
21 /* Define to prevent recursive inclusion -------------------------------------*/
22 #ifndef __TELEM_H
23 #define __TELEM_H
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 /*------------------------------------------------------------------------------
30 Standard Includes
31 ------------------------------------------------------------------------------*/
32
33
34 /*------------------------------------------------------------------------------
35 Project Includes
36 ------------------------------------------------------------------------------*/
37 #include "error_sdr.h"
38 #include "commands.h"
39 #include "main.h"
40
41 #ifndef F1_TESTBED
42 #include "stm32h7xx_hal.h"
43 #include "sensor.h"
44 #endif
45
46 /*------------------------------------------------------------------------------
47 Constants
48 ------------------------------------------------------------------------------*/
49 #define LORA_INTERNAL_HEADER_SIZE 8U
50 #define LORA_PAYLOAD_SIZE 40U
51 #define TELEMETRY_MESSAGE_SIZE (LORA_INTERNAL_HEADER_SIZE + LORA_PAYLOAD_SIZE)
52
53 /*------------------------------------------------------------------------------
54 Typedefs
55 ------------------------------------------------------------------------------*/
56
57 /* Aliased types if it doesn't exist on this platform */
58 #ifndef FLIGHT_COMPUTER
59 typedef uint8_t FLIGHT_COMP_STATE_TYPE;
60
61 /* opaque structs to allow FC dependencies to be used on non-FC platforms*/
62 #ifdef F1_TESTBED
63 typedef struct {
64 float imu_offset[ 6 ];
65 } IMU_OFFSET;
66
67 typedef struct {
68 float baro_preset[ 2 ];
69 } BARO_PRESET;
70
71 typedef struct {
72 uint8_t servo_preset[ 4 ];
73 } SERVO_PRESET;
74 #endif /* F1_TESTBED */
75 #endif
76
77 typedef uint32_t VERSION_INFO_TYPE; /* hw version : fw version : fw patch : fw prerelease */
78 /* msb lsb */
79
80 typedef enum _TELEMETRY_MESSAGE_TYPES
81 {
82 TELEMETRY_MSG_VEHICLE_ID = 0x00000001,
83 TELEMETRY_MSG_DASHBOARD_DATA = 0x00000002,
84 TELEMETRY_MSG_CALIBRATION = 0x00000003,
85 __TELEMETRY_MSG_FORCE_32BIT = 0xFFFFFFFF /* used to force this type size to 32 bits */
86 } TELEMETRY_MESSAGE_TYPES;
87 _Static_assert( sizeof(TELEMETRY_MESSAGE_TYPES) == 4, "TELEMETRY_MESSAGE_TYPES size invalid.");
88
89 /* UID serial number (packed struct inhibits padding) */
90 typedef struct __attribute__((packed)) _ST_UID_TYPE
91 {
92 uint32_t wafer_coords;
93 char lot_num_1[3];
94 uint8_t wafer_num;
95 char lot_num_2[4];
96 } ST_UID_TYPE;
97 _Static_assert( sizeof(ST_UID_TYPE) == 12, "ST_UID_TYPE packing incorrect." );
98
99 typedef struct __attribute__((packed)) _LORA_INTERNAL_HEADER_TYPE
100 {
101 TELEMETRY_MESSAGE_TYPES mid; /* message identifier -- currently 32 bits but will reserve command/control bits later*/
102 uint32_t timestamp; /* systick in ms */
103 } LORA_INTERNAL_HEADER_TYPE;
104 _Static_assert( sizeof(LORA_INTERNAL_HEADER_TYPE) == LORA_INTERNAL_HEADER_SIZE, "LORA_INTERNAL_HEADER size invalid.");
105
106 typedef struct __attribute((packed)) _TELEMETRY_MSG_VEHICLE_ID_TYPE
107 {
108 ST_UID_TYPE uid; /* unique identifier per stm32 MCU */
109 uint8_t hw_opcode; /* hardware identifier as defined by connect command */
110 uint8_t fw_opcode; /* firmware identifier as defined by connect command */
111 VERSION_INFO_TYPE version; /* version string defined above */
112 char flight_id[16]; /* a 16 character c-string for the current flight (future: configurable) */
113 uint8_t explicit_padding[6]; /* pad the end of this struct so the union behaves as expected */
114 } TELEMETRY_MSG_VEHICLE_ID_TYPE;
115 _Static_assert( sizeof(TELEMETRY_MSG_VEHICLE_ID_TYPE) == LORA_PAYLOAD_SIZE, "TELEMETRY_MSG_VEHICLE_ID_TYPE size invalid.");
116
117 typedef struct __attribute__((packed)) _TELEMETRY_MSG_DASHBOARD_DUMP_TYPE
118 {
119 FLIGHT_COMP_STATE_TYPE fsm_state; /* current state of the flight computer */
120 DASHBOARD_DUMP_TYPE data; /* the data used by the dashboard for location/orientation */
121 uint8_t explicit_padding[3]; /* pad the end of this struct so the union behaves as expected */
122 } TELEMETRY_MSG_DASHBOARD_DUMP_TYPE;
123 _Static_assert( sizeof(TELEMETRY_MSG_DASHBOARD_DUMP_TYPE) == LORA_PAYLOAD_SIZE, "TELEMETRY_MSG_DASHBOARD_DUMP_TYPE size invalid.");
124
125 typedef struct __attribute__((packed)) _TELEMETRY_MSG_CALIBRATION_TYPE
126 {
127 IMU_OFFSET imu_offset;
128 BARO_PRESET baro_preset;
129 float qfe_elevation;
130 SERVO_PRESET servo_preset;
131 } TELEMETRY_MSG_CALIBRATION_TYPE;
132 _Static_assert( sizeof(TELEMETRY_MSG_CALIBRATION_TYPE) == LORA_PAYLOAD_SIZE, "TELEMETRY_MSG_CALIBRATION size invalid." );
133
134 /* struct is packed to inhibit padding */
135 typedef struct __attribute__((packed)) _TELEMETRY_MESSAGE
136 {
137 LORA_INTERNAL_HEADER_TYPE header; /* data common to every message */
138 union _payload
139 {
140 TELEMETRY_MSG_VEHICLE_ID_TYPE vehicle_id; /* provide information about the transmitting device */
141 TELEMETRY_MSG_DASHBOARD_DUMP_TYPE dashboard_dump; /* gives vehicle state info (location, orientation) */
142 TELEMETRY_MSG_CALIBRATION_TYPE calibration;
143 } payload;
144 } TELEMETRY_MESSAGE;
145 _Static_assert( sizeof(TELEMETRY_MESSAGE) == TELEMETRY_MESSAGE_SIZE, "LORA_PAYLOAD size invalid.");
146
147 /*------------------------------------------------------------------------------
148 Inlines
149 ------------------------------------------------------------------------------*/
150
151 /**
152 * @brief Get the UID from the HAL.
153 *
154 * @param uid_buffer A 12-byte buffer to store the UID in.
155 */
156 111 static inline void get_uid
157 (
158 ST_UID_TYPE* uid_buffer
159 )
160 {
161 111 uint32_t uid[3];
162 111 uid[0] = HAL_GetUIDw0();
163 111 uid[1] = HAL_GetUIDw1();
164 111 uid[2] = HAL_GetUIDw2();
165
166 111 memcpy( uid_buffer, uid, sizeof( ST_UID_TYPE ) );
167
168 111 } /* get_uid */
169
170
171 /*------------------------------------------------------------------------------
172 Function prototypes
173 ------------------------------------------------------------------------------*/
174
175 /**
176 * @brief Constructs the next telemetry message.
177 *
178 * @param payload Telemetry message buffer to fill.
179 */
180 void telemetry_get_next_message
181 (
182 TELEMETRY_MESSAGE* payload
183 );
184
185 /**
186 * @brief Builds a telemetry payload of the requested type.
187 *
188 * @param msg_buf Telemetry message buffer to fill.
189 * @param message_type Type of telemetry message to build.
190 */
191 void telemetry_build_payload
192 (
193 TELEMETRY_MESSAGE* msg_buf, /* o: buffer passed by caller */
194 TELEMETRY_MESSAGE_TYPES message_type /* i: what kind of message */
195 );
196
197 #ifdef __cplusplus
198 }
199 #endif
200
201 #endif /* __TELEM_H */
202
203
204 /*******************************************************************************
205 * END OF FILE *
206 */
207