Add bootloader extension

This commit is contained in:
Thomas Stoddard
2026-10-21 19:22:50 -04:00
committed by Kyle Schwarz
parent 4db27aa187
commit 6ac041cadc
61 changed files with 13816 additions and 68 deletions
@@ -0,0 +1,56 @@
#ifndef __BOOTLOADER_REDPACKETIZER_H_
#define __BOOTLOADER_REDPACKETIZER_H_
#ifdef __cplusplus
#include "icsneo/core/ringbuffer.h"
#include <cstdint>
#include <vector>
namespace icsneo {
namespace Bootloader {
/**
* Splits bytes from a RED bootloader into frames:
* uint8_t Magic
* uint8_t Response
* uint16_t length (little-endian)
* uint8_t data[length]
*/
class REDPacketizer {
public:
static constexpr uint8_t Magic = 0xAA;
enum class Response : uint8_t {
Accepted = 0x77,
Rejected = 0x7F,
};
struct RxFrame {
uint16_t len = 0;
Response resp = Response::Rejected;
std::vector<uint8_t> data;
bool done = false;
};
/**
* Call with bytes received from the device.
* The returned boolean indicates if there is output waiting in output()
*/
bool input(icsneo::RingBuffer& bytes);
std::vector<RxFrame> output();
private:
enum ReadState { HEADER, CMD, LENGTH_LOWER, LENGTH_UPPER, DATA };
ReadState state = HEADER;
std::vector<RxFrame> working;
};
} // namespace Bootloader
} // namespace icsneo
#endif // __cplusplus
#endif // __BOOTLOADER_REDPACKETIZER_H_