25#ifndef __PACKET_UTILS_H__
26#define __PACKET_UTILS_H__
33#include "esp_random.h"
65#define PACKET_BYTES (111)
68#define PAYLOAD_BYTES (48)
74#define PKT_NO_LOCATION (-1)
86typedef enum : uint8_t {
98typedef enum : uint8_t {
110typedef enum : uint8_t {
123typedef enum : uint8_t {
136typedef enum : uint8_t {
148typedef enum : uint8_t {
159typedef enum : uint8_t {
177typedef enum : uint8_t {
188typedef enum : uint8_t {
380 int8_t* restrict relative_loc
520 const uint8_t* restrict payload,
uint8_t u8
Raw byte value for DCT packing.
Definition packet_utils.h:234
tc_ctrl_type_t ctrl
Type interpreted as a TC control type.
Definition packet_utils.h:250
tm_category_t tm
Category interpreted as a TM category.
Definition packet_utils.h:231
tc_req_type_t req
Type interpreted as a TC request type.
Definition packet_utils.h:249
tm_bdata_type_t bdata
Type interpreted as a TM big data type.
Definition packet_utils.h:247
tm_event_type_t event
Type interpreted as a TM event type.
Definition packet_utils.h:248
uint16_t total
Total number of chunks minus 1.
Definition packet_utils.h:266
tm_sdata_type_t sdata
Type interpreted as a TM small data type.
Definition packet_utils.h:246
uint8_t u8
Raw byte value for DCT packing.
Definition packet_utils.h:251
category_t category
Message category (bits 5–4 of DCT).
Definition packet_utils.h:263
type_t type
Message type (bits 3–0 of DCT).
Definition packet_utils.h:264
uint16_t index
Chunk sequence number (0-based).
Definition packet_utils.h:265
tc_category_t tc
Category interpreted as a TC category.
Definition packet_utils.h:232
test_category_t test
Category interpreted as a Test type.
Definition packet_utils.h:233
domain_t domain
Message domain (bits 7–6 of DCT).
Definition packet_utils.h:262
tm_category_t
Categories within the Telemetry domain.
Definition packet_utils.h:98
struct packet packet_t
Opaque packet handle.
Definition packet_utils.h:201
void dec_pool_destroy(pkt_dec_pool_t *restrict pool)
Free a decoder pool allocated by dec_pool_create().
Definition packet_utils.c:587
pkt_err_t header_old_sensor_config(header_t *restrict header, uint16_t old_id)
Configure a header for a retransmitted (old) sensor measurement packet.
Definition packet_utils.c:710
pkt_err_t
Return codes for packet utility functions.
Definition packet_utils.h:273
pkt_err_t pkt_set_header(packet_t *restrict pkt, const header_t *restrict header)
Pack header fields into a raw packet.
Definition packet_utils.c:737
tm_sdata_type_t
Types within the Telemetry / Small data category.
Definition packet_utils.h:110
pkt_err_t header_sensor_config(header_t *restrict header)
Configure a header for a current sensor measurement packet.
Definition packet_utils.c:699
tc_category_t
Categories within the Telecommand domain.
Definition packet_utils.h:148
pkt_err_t pkt_get_id(const packet_t *restrict pkt, uint16_t *id)
Read the packet identifier.
Definition packet_utils.c:691
domain_t
Top-level message domain.
Definition packet_utils.h:86
pkt_err_t pkt_log(const packet_t *restrict pkt)
Log a human-readable dump of a packet to the PAL logger.
Definition packet_utils.c:795
void pkt_destroy(packet_t *restrict pkt)
Free a packet allocated by pkt_create().
Definition packet_utils.c:546
pkt_enc_pool_t * enc_pool_create(void)
Allocate and initialize an encoder pool.
Definition packet_utils.c:555
pkt_err_t pkt_get_payload(const packet_t *restrict pkt, uint8_t *payload, size_t len)
Copy the payload field out of a packet.
Definition packet_utils.c:756
struct pkt_enc_pool pkt_enc_pool_t
Opaque encoder pool handle.
Definition packet_utils.h:210
packet_t * pkt_create(void)
Allocate and initialize a packet, with each byte set to 0.
Definition packet_utils.c:537
pkt_err_t dec_pool_get_pkt_from_relative_loc(const pkt_dec_pool_t *restrict pool, int8_t relative_loc, packet_t *restrict pkt)
Reconstruct a recovered packet from the decoder pool.
Definition packet_utils.c:664
pkt_err_t pkt_test_random_set_sync8(packet_t *restrict pkt, bool *failed)
Randomly corrupt the SYNC8 field for testing purposes.
Definition packet_utils.c:845
pkt_dec_pool_t * dec_pool_create(void)
Allocate and initialize a decoder pool.
Definition packet_utils.c:576
struct pkt_dec_pool pkt_dec_pool_t
Opaque decoder pool handle.
Definition packet_utils.h:220
pkt_err_t pkt_test_random_set_crc16(packet_t *restrict pkt)
Randomly corrupt the CRC16 field for testing purposes.
Definition packet_utils.c:859
tc_req_type_t
Types within the Telecommand / Request category.
Definition packet_utils.h:159
test_category_t
Types within the Test domain.
Definition packet_utils.h:188
tc_ctrl_type_t
Types within the Telecommand / Control category.
Definition packet_utils.h:177
tm_bdata_type_t
Types within the Telemetry / Big data category.
Definition packet_utils.h:123
tm_event_type_t
Types within the Telemetry / Event category.
Definition packet_utils.h:136
pkt_err_t pkt_decode(const packet_t *restrict pkt, pkt_dec_pool_t *restrict pool, int8_t *restrict relative_loc)
Validate and decode a received packet.
Definition packet_utils.c:625
void enc_pool_destroy(pkt_enc_pool_t *restrict pool)
Free an encoder pool allocated by enc_pool_create().
Definition packet_utils.c:566
pkt_err_t pkt_encode(packet_t *restrict pkt, pkt_enc_pool_t *restrict pool)
Finalize and encode a packet for transmission.
Definition packet_utils.c:597
pkt_err_t pkt_get_header(const packet_t *restrict pkt, header_t *header)
Unpack the header fields from a raw packet.
Definition packet_utils.c:721
pkt_err_t pkt_set_payload(packet_t *restrict pkt, const uint8_t *restrict payload, size_t len)
Copy data into the payload field of a packet.
Definition packet_utils.c:771
bool pkt_is_chunked(const packet_t *restrict pkt)
Check whether a packet carries chunked data.
Definition packet_utils.c:790
@ TM_EVENT
Events (logs, errors, crashes).
Definition packet_utils.h:101
@ TM_BDATA
Big data (images, video streams).
Definition packet_utils.h:100
@ TM_SDATA
Small data (sensor measurements, system status).
Definition packet_utils.h:99
@ PKT_OK
Operation completed successfully.
Definition packet_utils.h:274
@ PKT_ERR_SYNC
SYNC8 word mismatch: packet boundary error.
Definition packet_utils.h:277
@ PKT_ERR_INVALID_ARG
One or more arguments are invalid or NULL.
Definition packet_utils.h:276
@ PKT_FAIL
Generic failure.
Definition packet_utils.h:275
@ PKT_ERR_CRC
CRC16 mismatch: packet is corrupted.
Definition packet_utils.h:278
@ TM_SDATA_STATUS
System status payload.
Definition packet_utils.h:112
@ TM_SDATA_SENSORS
Sensor measurements payload.
Definition packet_utils.h:111
@ TC_CTRL
Control commands (e.g. reboot).
Definition packet_utils.h:149
@ TC_REQ
Data or status requests.
Definition packet_utils.h:150
@ DOMAIN_TM
Telemetry domain (CubeSat to Ground).
Definition packet_utils.h:87
@ DOMAIN_TC
Telecommand domain (Ground to CubeSat).
Definition packet_utils.h:88
@ DOMAIN_TEST
Test domain (Ground to CubeSat, for tests only).
Definition packet_utils.h:89
@ TC_REQ_IMAGE
Request image transmission.
Definition packet_utils.h:162
@ TC_REQ_SENSORS
Request current sensor measurements.
Definition packet_utils.h:160
@ TC_REQ_LOG
Request log retrieval.
Definition packet_utils.h:164
@ TC_REQ_ERROR
Request error list.
Definition packet_utils.h:165
@ TC_REQ_CRASH
Request last crash information.
Definition packet_utils.h:166
@ TC_REQ_STATUS
Request current system status.
Definition packet_utils.h:161
@ TC_REQ_VIDEO
Request video transmission.
Definition packet_utils.h:163
@ TEST_WIMG
Write an image to OBC memory.
Definition packet_utils.h:189
@ TEST_FRM
Remove a file from OBC file system.
Definition packet_utils.h:190
@ TEST_MSG
Send a text message.
Definition packet_utils.h:191
@ TC_CTRL_REBOOT
Force a system reboot.
Definition packet_utils.h:178
@ TM_BDATA_IMAGE
Image data (JPEG).
Definition packet_utils.h:124
@ TM_BDATA_VIDEO
Video stream (H.264).
Definition packet_utils.h:125
@ TM_EVENT_CRASH
Critical failure / crash report.
Definition packet_utils.h:139
@ TM_EVENT_ERROR
Non-critical error.
Definition packet_utils.h:138
@ TM_EVENT_LOG
Normal event log.
Definition packet_utils.h:137
Type-safe union for the category field of a packet header.
Definition packet_utils.h:230
Type-safe union for the type field of a packet header.
Definition packet_utils.h:245
Definition packet_utils.c:83
Definition packet_utils.c:129
Definition packet_utils.c:107
Platform-agnostic logging macros.