UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
packet.h
1 
11 #ifndef __PACKET_FORMAT_H__
12 #define __PACKET_FORMAT_H__
13 
14 // Compile-time assertions in < C11, Source: https://stackoverflow.com/a/3385694
15 #define STATIC_ASSERT(COND,MSG) typedef char static_assertion_##MSG[(!!(COND))*2-1]
16 #define COMPILE_TIME_ASSERT3(X,L) STATIC_ASSERT(X,static_assertion_at_line_##L)
17 #define COMPILE_TIME_ASSERT2(X,L) COMPILE_TIME_ASSERT3(X,L)
18 #define COMPILE_TIME_ASSERT(X) COMPILE_TIME_ASSERT2(X,__LINE__)
19 
20 #include "../firmware.h"
21 
22 #define PACKET_PREAMBLE_WORD 0x55555555
23 #define PACKET_PREAMBLE_LENGTH 4
24 
25 #define PACKET_SYNC_WORD 0x42A6F8B3
26 #define PACKET_SYNC_LENGTH 4
27 
28 #define PACKET_SPACECRAFT_ID 0x4242
29 #define PACKET_CODED_DATA_LENGTH 1024
30 
31 typedef struct packet_telemetry_1024 {
32  uint16_t spacecraft;
33  uint16_t type;
34  uint8_t data[106]; /* 848 bits */
35  uint8_t hash[16];
36  uint16_t crc;
38 
39 COMPILE_TIME_ASSERT(sizeof(packet_telemetry_1024)==128);
40 
42  uint8_t data[110];
43  uint8_t hash[16];
44  uint16_t _crc;
46 
47 COMPILE_TIME_ASSERT(sizeof(packet_telemetry_1024_hash)==128);
48 
49 typedef struct packet_telemetry_1024_crc {
50  uint8_t data[126];
51  uint16_t crc;
53 
54 COMPILE_TIME_ASSERT(sizeof(packet_telemetry_1024_crc)==128);
55 
56 // Telecommand with 256 bit (: 128b hash: 10 bytes data, 64b hash: 18 bytes data
57 
58 
59 typedef struct packet_telecommand_512 {
60  uint16_t spacecraft;
61  uint16_t type;
62  uint8_t data[42]; /* 336 bits */
63  uint8_t hash[16];
64  uint16_t crc;
66 
67 COMPILE_TIME_ASSERT(sizeof(packet_telecommand_512)==64);
68 
70  uint8_t data[46];
71  uint8_t hash[16];
72  uint16_t _crc;
74 
75 COMPILE_TIME_ASSERT(sizeof(packet_telecommand_512_hash)==64);
76 
78  uint8_t data[62];
79  uint16_t crc;
81 
82 COMPILE_TIME_ASSERT(sizeof(packet_telecommand_512_crc)==64);
83 
84 typedef enum {
85  PACKET_TYPE_NULL = 0
86 } packet_type;
87 
88 void Packet_telecommand_512_encode(packet_telecommand_512 *input_packet, uint8_t *output_buffer, const uint16_t origin, const uint8_t *key, uint32_t key_length);
89 
90 bool Packet_telecommand_512_decode(uint8_t *input_buffer, packet_telecommand_512 *output_packet, const uint16_t destination, const uint8_t *key, uint32_t key_length);
91 
108 void Packet_telemetry_1024_encode(packet_telemetry_1024 *input_packet, uint8_t *output_buffer, const uint16_t origin, const uint8_t *key, uint32_t key_length);
109 
110 bool Packet_telemetry_1024_decode(uint8_t *input_buffer, packet_telemetry_1024 *output_packet, const uint16_t destination, const uint8_t *key, uint32_t key_length);
111 
112 void Packet_sign_shake128(const uint8_t *input, uint32_t input_length, const uint8_t *key, uint32_t key_length, uint8_t *output);
113 
114 #endif /* __PACKET_FORMAT_H__ */
void Packet_telemetry_1024_encode(packet_telemetry_1024 *input_packet, uint8_t *output_buffer, const uint16_t origin, const uint8_t *key, uint32_t key_length)
Definition: packet.c:104