88 lines
3.5 KiB
C++
88 lines
3.5 KiB
C++
#include <ranczo-io/utils/mqtt_client.hpp>
|
|
|
|
#include <boost/asio/associated_executor.hpp>
|
|
#include <boost/asio/co_spawn.hpp>
|
|
#include <boost/asio/detached.hpp>
|
|
#include <boost/asio/io_context.hpp>
|
|
#include <boost/asio/strand.hpp>
|
|
#include <boost/asio/this_coro.hpp>
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
#include "heater_controller.hpp"
|
|
#include <ranczo-io/utils/mqtt_client.hpp>
|
|
#include <ranczo-io/utils/timer.hpp>
|
|
|
|
#include <vector>
|
|
#include <csignal>
|
|
|
|
namespace ranczo {
|
|
|
|
/// TODO
|
|
/// * Przypisanie przełącznika do maty grzewczej
|
|
/// * Zapis danych w DB
|
|
/// * Zapis ustawień
|
|
/// * Nasłuchiwanie na MQTT
|
|
|
|
} // namespace ranczo
|
|
|
|
// Modified completion token that will prevent co_await from throwing exceptions.
|
|
|
|
using namespace std::chrono_literals;
|
|
using namespace std::string_view_literals;
|
|
|
|
std::atomic<bool> running = true;
|
|
boost::asio::io_context* g_io = nullptr;
|
|
|
|
void signal_handler(int signum) {
|
|
spdlog::warn("Signal received: {}, stopping io_context...", signum);
|
|
running = false;
|
|
if (g_io) {
|
|
g_io->stop(); // <--- This stops io_context.run()
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
spdlog::set_level(spdlog::level::trace);
|
|
std::vector< std::shared_ptr< ranczo::IHeater > > _heaters;
|
|
|
|
boost::asio::io_context io_context;
|
|
g_io = &io_context;
|
|
|
|
// Register signal handler
|
|
spdlog::info("Registering signal handlers");
|
|
std::signal(SIGINT, signal_handler);
|
|
std::signal(SIGTERM, signal_handler);
|
|
|
|
boost::asio::any_io_executor io_executor = io_context.get_executor();
|
|
// PARTER
|
|
_heaters.emplace_back(std::make_shared< ranczo::ResistiveFloorHeater >(io_executor, "corridor"sv));
|
|
_heaters.emplace_back(std::make_shared< ranczo::ResistiveFloorHeater >(io_executor, "utilityRoom"sv));
|
|
_heaters.emplace_back(std::make_shared< ranczo::ResistiveFloorHeater >(io_executor, "wardrobe"sv));
|
|
_heaters.emplace_back(std::make_shared< ranczo::ResistiveFloorHeater >(io_executor, "bathroom_1"sv));
|
|
_heaters.emplace_back(std::make_shared< ranczo::ResistiveFloorHeater >(io_executor, "bathroom_2"sv));
|
|
_heaters.emplace_back(std::make_shared< ranczo::ResistiveFloorHeater >(io_executor, "beadroom_zone1"sv));
|
|
_heaters.emplace_back(std::make_shared< ranczo::ResistiveFloorHeater >(io_executor, "beadroom_zone2"sv));
|
|
_heaters.emplace_back(std::make_shared< ranczo::ResistiveFloorHeater >(io_executor, "livingroom_zone1"sv));
|
|
_heaters.emplace_back(std::make_shared< ranczo::ResistiveFloorHeater >(io_executor, "livingroom_zone2"sv));
|
|
_heaters.emplace_back(std::make_shared< ranczo::ResistiveFloorHeater >(io_executor, "livingroom_zone3"sv));
|
|
|
|
// PIĘTRO
|
|
_heaters.emplace_back(std::make_shared< ranczo::ResistiveFloorHeater >(io_executor, "askaRoom"sv));
|
|
_heaters.emplace_back(std::make_shared< ranczo::ResistiveFloorHeater >(io_executor, "maciejRoom"sv));
|
|
_heaters.emplace_back(std::make_shared< ranczo::ResistiveFloorHeater >(io_executor, "playroom"sv));
|
|
_heaters.emplace_back(std::make_shared< ranczo::ResistiveFloorHeater >(io_executor, "office"sv));
|
|
_heaters.emplace_back(std::make_shared< ranczo::ResistiveFloorHeater >(io_executor, "bathroom_1"sv));
|
|
_heaters.emplace_back(std::make_shared< ranczo::ResistiveFloorHeater >(io_executor, "corridor_up"sv));
|
|
|
|
for(auto & heater : _heaters) {
|
|
co_spawn(io_context, heater->start(), boost::asio::detached);
|
|
}
|
|
|
|
boost::asio::executor_work_guard< boost::asio::io_context::executor_type > work_guard = boost::asio::make_work_guard(io_context);
|
|
|
|
io_context.run();
|
|
|
|
return 0;
|
|
}
|