Midnight Sun Firmware
Loading...
Searching...
No Matches
fota_packet.h
1#pragma once
2
3/************************************************************************************************
4 * @file fota_packet.h
5 *
6 * @brief Packet implementation for firmware over the air (FOTA) updates
7 *
8 * @date 2025-03-16
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stdint.h>
14
15/* Inter-component Headers */
16
17/* Intra-component Headers */
18#include "fota_error.h"
19
46#define FOTA_PACKET_PAYLOAD_SIZE 256U
48#define FOTA_PACKET_SOF 0xAAU
50#define FOTA_PACKET_EOF 0xBBU
52#define FOTA_PACKET_MINIMUM_SIZE 14U
53
57typedef enum {
64
68typedef struct {
69 uint32_t crc32;
70 uint32_t datagram_id;
72 uint16_t payload_length;
73 uint8_t sequence_num;
74 uint8_t sof;
75 uint8_t eof;
77 uint8_t payload[FOTA_PACKET_PAYLOAD_SIZE];
79
88FotaError fota_packet_init(FotaPacket *packet, FotaPacketType type, uint8_t sequence, uint16_t length);
89
96
105FotaError fota_packet_serialize(FotaPacket *packet, uint8_t *buffer, uint32_t buf_size, uint32_t *bytes_written);
106
114FotaError fota_packet_deserialize(FotaPacket *packet, uint8_t *buffer, uint32_t buf_size);
115
FotaError fota_packet_serialize(FotaPacket *packet, uint8_t *buffer, uint32_t buf_size, uint32_t *bytes_written)
Serialize packet into a buffer for transmission.
Definition: fota_packet.c:48
FotaPacketType
FOTA Packet Type.
Definition: fota_packet.h:57
#define FOTA_PACKET_PAYLOAD_SIZE
FOTA packet payload size.
Definition: fota_packet.h:46
FotaError fota_packet_init(FotaPacket *packet, FotaPacketType type, uint8_t sequence, uint16_t length)
Initialize a packet structure.
Definition: fota_packet.c:20
FotaError fota_packet_set_crc(FotaPacket *packet)
Calculate and set the CRC for a packet.
Definition: fota_packet.c:37
FotaError fota_packet_deserialize(FotaPacket *packet, uint8_t *buffer, uint32_t buf_size)
Deserialize packet from received data.
Definition: fota_packet.c:86
FotaError
FOTA Error code definitions.
Definition: fota_error.h:27
@ FOTA_PACKET_TYPE_ERROR
Definition: fota_packet.h:62
@ FOTA_PACKET_TYPE_ACK
Definition: fota_packet.h:60
@ FOTA_PACKET_TYPE_HEADER
Definition: fota_packet.h:59
@ FOTA_PACKET_TYPE_DATA
Definition: fota_packet.h:58
@ FOTA_PACKET_TYPE_NACK
Definition: fota_packet.h:61
FOTA Packet structure.
Definition: fota_packet.h:68
uint32_t datagram_id
Definition: fota_packet.h:70
uint8_t _reserved_padding
Definition: fota_packet.h:76
uint8_t eof
Definition: fota_packet.h:75
uint16_t payload_length
Definition: fota_packet.h:72
uint32_t crc32
Definition: fota_packet.h:69
uint8_t sequence_num
Definition: fota_packet.h:73
FotaPacketType packet_type
Definition: fota_packet.h:71
uint8_t sof
Definition: fota_packet.h:74