Midnight Sun Firmware
Loading...
Searching...
No Matches
spi_datagram.h
1#pragma once
2
3/************************************************************************************************
4 * @file spi_datagram.h
5 *
6 * @brief Header file defining the SPIDatagram class
7 *
8 * @date 2025-01-04
9 * @author Aryan Kashem
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <cstdint>
14#include <string>
15
16/* Inter-component Headers */
17
18/* Intra-component Headers */
19#include "command_code.h"
20
27namespace Datagram {
28
36class SPI {
37 public:
38 static constexpr size_t SPI_MAX_BUFFER_SIZE = 256;
43 enum class Port {
47 };
48
52 struct Payload {
54 size_t bufferLength;
56 };
57
62 explicit SPI(Payload &data);
63
67 SPI() = default;
68
74 std::string serialize(const CommandCode &commandCode) const;
75
80 void deserialize(std::string &spiDatagramPayload);
81
86 void setSPIPort(const Port &spiPort);
87
93 void setBuffer(const uint8_t *data, size_t length);
94
98 void clearBuffer();
99
104 Port getSPIPort() const;
105
110 size_t getBufferLength() const;
111
116 const uint8_t *getBuffer() const;
117
118 private:
120};
121
122} // namespace Datagram
123
Definition: spi_datagram.h:36
const uint8_t * getBuffer() const
Gets the SPI buffer.
Definition: spi_datagram.cc:69
void clearBuffer()
Clear the SPI data buffer.
Definition: spi_datagram.cc:57
static constexpr size_t SPI_MAX_BUFFER_SIZE
Definition: spi_datagram.h:38
void setBuffer(const uint8_t *data, size_t length)
Sets data in the SPI buffer.
Definition: spi_datagram.cc:52
Port getSPIPort() const
Gets the target SPI port.
Definition: spi_datagram.cc:61
SPI()=default
Default constructor for SPI object.
void deserialize(std::string &spiDatagramPayload)
Deserializes SPI data from payload string.
Definition: spi_datagram.cc:35
Port
SPI Port definition.
Definition: spi_datagram.h:43
std::string serialize(const CommandCode &commandCode) const
Serializes SPI data with command code for transmission.
Definition: spi_datagram.cc:27
Payload m_spiDatagram
Definition: spi_datagram.h:119
void setSPIPort(const Port &spiPort)
Sets the target SPI port.
Definition: spi_datagram.cc:48
size_t getBufferLength() const
Gets the SPI buffer length.
Definition: spi_datagram.cc:65
CommandCode
Command Code Class.
Definition: command_code.h:28
SPI Datagram payload storage.
Definition: spi_datagram.h:52
uint8_t buffer[SPI_MAX_BUFFER_SIZE]
Definition: spi_datagram.h:55
Port spiPort
Definition: spi_datagram.h:53
size_t bufferLength
Definition: spi_datagram.h:54