Midnight Sun Firmware
Loading...
Searching...
No Matches
gpio_manager.h
1#pragma once
2
3/************************************************************************************************
4 * @file gpio_manager.h
5 *
6 * @brief Header file defining the Server GpioManager class
7 *
8 * @date 2025-01-04
9 * @author Aryan Kashem
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stdint.h>
14#include <string.h>
15
16#include <unordered_map>
17
18/* Inter-component Headers */
19#include "gpio_datagram.h"
20
21/* Intra-component Headers */
22
36class GpioManager {
37 private:
39 using PinInfo = std::unordered_map<std::string, std::string>;
40
41 std::unordered_map<std::string, PinInfo> m_gpioInfo;
49 std::string stringifyPinMode(Datagram::Gpio::Mode mode);
50
57
62 void loadGpioInfo(std::string &projectName);
63
68 void saveGpioInfo(std::string &projectName);
69
70 public:
75 GpioManager() = default;
76
84 void updateGpioPinState(std::string &projectName, std::string &payload);
85
93 void updateGpioAllStates(std::string &projectName, std::string &payload);
94
102 void updateGpioPinMode(std::string &projectName, std::string &payload);
103
111 void updateGpioAllModes(std::string &projectName, std::string &payload);
112
120 void updateGpioPinAltFunction(std::string &projectName, std::string &payload);
121
129 void updateGpioAllAltFunctions(std::string &projectName, std::string &payload);
130
140 std::string createGpioCommand(CommandCode commandCode, std::string &gpioPortPin, std::string data);
141};
142
Definition: gpio_datagram.h:36
Mode
Gpio Mode definition.
Definition: gpio_datagram.h:60
AltFunction
Gpio Alt function definition.
Definition: gpio_datagram.h:75
Class that manages receiving and transmitting Gpio commands and JSON logging.
Definition: gpio_manager.h:36
std::unordered_map< std::string, PinInfo > m_gpioInfo
Definition: gpio_manager.h:41
std::string stringifyPinMode(Datagram::Gpio::Mode mode)
Matches a string based on the received Gpio mode.
Definition: gpio_manager.cc:30
void updateGpioPinAltFunction(std::string &projectName, std::string &payload)
Update a Gpio Pin alternate function for a provided project given the data payload.
Definition: gpio_manager.cc:216
std::unordered_map< std::string, std::string > PinInfo
Hash-map to store Pin specific data such as state, mode, or alternate function.
Definition: gpio_manager.h:39
void loadGpioInfo(std::string &projectName)
Loads the Hash-map cache with a projects Gpio data.
Definition: gpio_manager.cc:124
void updateGpioPinState(std::string &projectName, std::string &payload)
Update a Gpio Pin state for a provided project given the data payload.
Definition: gpio_manager.cc:135
void updateGpioAllModes(std::string &projectName, std::string &payload)
Update all Gpio Pin modes for a provided project given the data payload.
Definition: gpio_manager.cc:194
void saveGpioInfo(std::string &projectName)
Saves the Hash-map cache to a projects Gpio data.
Definition: gpio_manager.cc:128
Datagram::Gpio m_gpioDatagram
Definition: gpio_manager.h:38
void updateGpioAllStates(std::string &projectName, std::string &payload)
Update all Gpio Pin states for a provided project given the data payload.
Definition: gpio_manager.cc:155
void updateGpioPinMode(std::string &projectName, std::string &payload)
Update a Gpio Pin mode for a provided project given the data payload.
Definition: gpio_manager.cc:179
GpioManager()=default
Constructs a GpioManager object.
void updateGpioAllAltFunctions(std::string &projectName, std::string &payload)
Update all Gpio Pin alternate functions for a provided project given the data payload.
Definition: gpio_manager.cc:231
std::string stringifyPinAltFunction(Datagram::Gpio::AltFunction altFunction)
Matches a string based on the received Gpio mode.
Definition: gpio_manager.cc:75
std::string createGpioCommand(CommandCode commandCode, std::string &gpioPortPin, std::string data)
Create a Gpio command given a CommandCode and if required, a specific Port/Pin map and data.
Definition: gpio_manager.cc:253
CommandCode
Command Code Class.
Definition: command_code.h:28