Mod Library
Sun Devil Rocketry's hardware agnostic utility library
Loading...
Searching...
No Matches
telemetry.h
Go to the documentation of this file.
1
20
21/* Define to prevent recursive inclusion -------------------------------------*/
22#ifndef __TELEM_H
23#define __TELEM_H
24
25#ifdef __cplusplus
26extern "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
59typedef 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
63typedef struct {
64 float imu_offset[ 6 ];
65} IMU_OFFSET;
66
67typedef struct {
68 float baro_preset[ 2 ];
69} BARO_PRESET;
70
71typedef struct {
72 uint8_t servo_preset[ 4 ];
73} SERVO_PRESET;
74#endif /* F1_TESTBED */
75#endif
76
77typedef uint32_t VERSION_INFO_TYPE; /* hw version : fw version : fw patch : fw prerelease */
78 /* msb lsb */
79
80typedef 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) */
90typedef 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
99typedef 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
106typedef 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
117typedef 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
125typedef 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 */
135typedef 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
156static inline void get_uid
157 (
158 ST_UID_TYPE* uid_buffer
159 )
160{
161uint32_t uid[3];
162uid[0] = HAL_GetUIDw0();
163uid[1] = HAL_GetUIDw1();
164uid[2] = HAL_GetUIDw2();
165
166memcpy( uid_buffer, uid, sizeof( ST_UID_TYPE ) );
167
168} /* get_uid */
169
170
171/*------------------------------------------------------------------------------
172 Function prototypes
173------------------------------------------------------------------------------*/
174
181 (
182 TELEMETRY_MESSAGE* payload
183 );
184
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 */
: Contains general command functions common to all embedded controllers
: Contains error handling functions for SDR code.
: Contains functions to interface between SDEC terminal commands and SDR sensor APIs
void telemetry_build_payload(TELEMETRY_MESSAGE *msg_buf, TELEMETRY_MESSAGE_TYPES message_type)
Builds the requested telemetry payload and fills its message header.
Definition telemetry.c:110
void telemetry_get_next_message(TELEMETRY_MESSAGE *payload)
Selects and constructs the next scheduled telemetry message.
Definition telemetry.c:77