Midnight Sun Firmware
Loading...
Searching...
No Matches
i2c_datagram.h
1#pragma once
2
3/************************************************************************************************
4 * @file i2c_datagram.h
5 *
6 * @brief Header file defining the I2CDatagram 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 I2C {
37 public:
38 static constexpr size_t I2C_MAX_BUFFER_SIZE = 256;
43 enum class Port {
47 };
48
52 struct Payload {
54 size_t bufferLength;
56 };
57
62 explicit I2C(Payload &data);
63
67 I2C() = default;
68
74 std::string serialize(const CommandCode &commandCode) const;
75
80 void deserialize(std::string &i2cDatagramPayload);
81
86 void setI2CPort(const Port &i2cPort);
87
93 void setBuffer(const uint8_t *data, size_t length);
94
98 void clearBuffer();
99
104 Port getI2CPort() const;
105
110 size_t getBufferLength() const;
111
116 const uint8_t *getBuffer() const;
117
118 private:
120};
121
122} // namespace Datagram
123
Definition: i2c_datagram.h:36
const uint8_t * getBuffer() const
Gets the I2C buffer.
Definition: i2c_datagram.cc:69
void clearBuffer()
Clear the I2C data buffer.
Definition: i2c_datagram.cc:57
Payload m_i2cDatagram
Definition: i2c_datagram.h:119
static constexpr size_t I2C_MAX_BUFFER_SIZE
Definition: i2c_datagram.h:38
void deserialize(std::string &i2cDatagramPayload)
Deserializes I2C data from payload string.
Definition: i2c_datagram.cc:35
I2C()=default
Default constructor for I2C object.
void setBuffer(const uint8_t *data, size_t length)
Sets data in the I2C buffer.
Definition: i2c_datagram.cc:52
Port
I2C Port definition.
Definition: i2c_datagram.h:43
std::string serialize(const CommandCode &commandCode) const
Serializes I2C data with command code for transmission.
Definition: i2c_datagram.cc:27
void setI2CPort(const Port &i2cPort)
Sets the target I2C port.
Definition: i2c_datagram.cc:48
size_t getBufferLength() const
Gets the I2C buffer length.
Definition: i2c_datagram.cc:65
Port getI2CPort() const
Gets the target I2C port.
Definition: i2c_datagram.cc:61
CommandCode
Command Code Class.
Definition: command_code.h:28
I2C Datagram payload storage.
Definition: i2c_datagram.h:52
uint8_t buffer[I2C_MAX_BUFFER_SIZE]
Definition: i2c_datagram.h:55
size_t bufferLength
Definition: i2c_datagram.h:54
Port i2cPort
Definition: i2c_datagram.h:53