2025-12-14 12:43:31 +01:00
|
|
|
#pragma once
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
|
|
// This class takes max-16-character packet and parses commands from it
|
|
|
|
|
// Singleton-class
|
|
|
|
|
class CommandParser
|
|
|
|
|
{
|
|
|
|
|
public:
|
2025-12-14 18:57:28 +01:00
|
|
|
// Each command is 5 bytes long (assuming no padding)
|
|
|
|
|
struct Command {
|
|
|
|
|
enum class TYPE : uint8_t {
|
|
|
|
|
MOVE_ABSOLUTE = 0x00,
|
|
|
|
|
MOVE_RELATIVE = 0x01,
|
|
|
|
|
RESET_POSITIONS = 0x02,
|
|
|
|
|
} instruction;
|
|
|
|
|
int16_t args[2];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static CommandParser& getInstance() noexcept;
|
2025-12-14 12:43:31 +01:00
|
|
|
|
2025-12-14 18:57:28 +01:00
|
|
|
// Expecting command to be a packet of max size UartHandler::PACKET_SIZE
|
|
|
|
|
Command parsePacket(const uint8_t* packet) noexcept;
|
2025-12-14 12:43:31 +01:00
|
|
|
|
|
|
|
|
private:
|
2025-12-14 18:57:28 +01:00
|
|
|
CommandParser() noexcept {};
|
2025-12-14 12:43:31 +01:00
|
|
|
CommandParser(const CommandParser&) = delete;
|
|
|
|
|
CommandParser(CommandParser&&) = delete;
|
|
|
|
|
~CommandParser();
|
|
|
|
|
};
|