mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 09:37:21 +02:00
60 lines
2.5 KiB
C++
60 lines
2.5 KiB
C++
//
|
|
// Created by Johnathon Slightham on 2025-07-05.
|
|
//
|
|
|
|
#ifndef LOOPMANAGER_H
|
|
#define LOOPMANAGER_H
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
#include <cstdint>
|
|
|
|
#include "MessagingInterface.h"
|
|
#include "control/ActuatorFactory.h"
|
|
#include "control/SensorFactory.h"
|
|
#include "control/IActuator.h"
|
|
|
|
class LoopManager {
|
|
public:
|
|
LoopManager() : m_config_manager(ConfigManager::get_instance()),
|
|
m_messaging_interface(std::make_unique<MessagingInterface>()),
|
|
m_actuator(ActuatorFactory::create_actuator(m_config_manager.get_module_type())),
|
|
m_sensor(SensorFactory::create_sensor(m_config_manager.get_module_type())) {
|
|
xTaskCreate(reinterpret_cast<TaskFunction_t>(LoopManager::metadata_tx_loop),
|
|
"metadata_tx", 3096, this, 3, nullptr);
|
|
xTaskCreate(reinterpret_cast<TaskFunction_t>(LoopManager::sensor_loop),
|
|
"sensor_tx", 3096, this, 3, nullptr);
|
|
|
|
// todo: temporary demo register_function call.
|
|
const auto function_tag = 100;
|
|
m_messaging_interface->register_function(function_tag, [](const uint8_t *parameters, size_t parameter_size, Writer& writer) {
|
|
ESP_LOGI("TMP", "%s", (char*)parameters);
|
|
std::string msg = "Hello from board!";
|
|
std::vector<uint8_t> return_value(msg.begin(), msg.end());
|
|
writer.write(return_value);
|
|
});
|
|
const auto bandwidth_test_fn_tag = 101;
|
|
m_messaging_interface->register_function(bandwidth_test_fn_tag, [](const uint8_t *parameters, size_t parameter_size, Writer& writer) {
|
|
std::string msg = "";
|
|
std::vector<uint8_t> return_value(msg.begin(), msg.end());
|
|
writer.write(return_value);
|
|
});
|
|
}
|
|
|
|
MessagingInterface &get_messaging_interface();
|
|
[[noreturn]] void control_loop() const; // gets control commands
|
|
[[noreturn]] static void sensor_loop(char * args); // sends sensor data commands continually
|
|
[[noreturn]] static void metadata_tx_loop(char * args); // sends metadata continually (low duty cycle)
|
|
[[noreturn]] static void metadata_rx_loop(char * args); // gets other commands from PC (ie. f/w updates, nvs updates)
|
|
|
|
private:
|
|
ConfigManager& m_config_manager;
|
|
std::unique_ptr<MessagingInterface> m_messaging_interface;
|
|
std::unique_ptr<IActuator> m_actuator;
|
|
std::unique_ptr<ISensor> m_sensor;
|
|
|
|
void send_sensor_reading(bool durable) const;
|
|
};
|
|
|
|
#endif //LOOPMANAGER_H
|