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
45#define FOTA_PACKET_SOF 0xAAU
46#define FOTA_PACKET_EOF 0xBBU
47#define FOTA_PACKET_PAYLOAD_SIZE 128U
48#define FOTA_PACKET_HEADER_SIZE (1U + 1U + 4U + 1U + 2U)
49#define FOTA_PACKET_SERIALIZED_SIZE (FOTA_PACKET_HEADER_SIZE + FOTA_PACKET_PAYLOAD_SIZE + 4U + 1U)
50#define FOTA_PACKET_MINIMUM_SIZE FOTA_PACKET_SERIALIZED_SIZE
51
55typedef enum {
62
69typedef struct {
70 uint8_t sof;
72 uint32_t datagram_id;
73 uint8_t sequence_num;
74 uint16_t payload_length;
75 uint8_t payload[FOTA_PACKET_PAYLOAD_SIZE];
76 uint32_t crc32;
77 uint8_t eof;
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 FOTA packet into buffer.
Definition: fota_packet.c:56
FotaPacketType
FOTA Packet Type.
Definition: fota_packet.h:55
FotaError fota_packet_init(FotaPacket *packet, FotaPacketType type, uint8_t sequence, uint16_t length)
Initialize a FOTA packet.
Definition: fota_packet.c:20
FotaError fota_packet_set_crc(FotaPacket *packet)
Compute and set CRC32 of payload.
Definition: fota_packet.c:37
FotaError fota_packet_deserialize(FotaPacket *packet, uint8_t *buffer, uint32_t buf_size)
Deserialize buffer into FOTA packet.
Definition: fota_packet.c:99
FotaError
FOTA Error code definitions.
Definition: fota_error.h:27
@ FOTA_PACKET_TYPE_ERROR
Definition: fota_packet.h:60
@ FOTA_PACKET_TYPE_ACK
Definition: fota_packet.h:58
@ FOTA_PACKET_TYPE_HEADER
Definition: fota_packet.h:57
@ FOTA_PACKET_TYPE_DATA
Definition: fota_packet.h:56
@ FOTA_PACKET_TYPE_NACK
Definition: fota_packet.h:59
FOTA Packet structure.
Definition: fota_packet.h:69
uint32_t datagram_id
Definition: fota_packet.h:72
uint8_t eof
Definition: fota_packet.h:77
uint16_t payload_length
Definition: fota_packet.h:74
uint32_t crc32
Definition: fota_packet.h:76
uint8_t sequence_num
Definition: fota_packet.h:73
FotaPacketType packet_type
Definition: fota_packet.h:71
uint8_t sof
Definition: fota_packet.h:70