#ifndef __THER_COM_HPP__ #define __THER_COM_HPP__ #include "led.hpp" #include #include #include #include #include #include #include #include namespace ther { class Com { public: enum HostStatus : uint8_t { STANDBY, RUNNING, PAUSE, ERROR }; using RunningStateSignal = etl::signal; static auto Init() -> zpp::error { s_proto->SetRxCallbackTable(kRxCallbackTable); auto size = hwinfo_get_device_id(buff, sizeof(buff)); s_id_buff = etl::span(buff, size); return zpp::ok(); } static auto SendTemp(sensor_value val) -> void { const uint8_t temp_data[] = {(uint8_t)val.val1, (uint8_t)val.val2}; s_proto->Send(R_TEMP, temp_data); } static auto AddRunningState(RunningStateSignal::slot_type slot) -> bool { return s_running_state_sig.connect(slot); } private: enum Addr : uint8_t { R_TEMP = 0, R_GET_ID, W_RUNNING_STATE, }; inline static RunningStateSignal s_running_state_sig{}; static auto RunningState(uart_com::DataType data) -> void { if (data.size() != 1) { return; } s_running_state_sig(HostStatus(data[0])); } static auto GetId(uart_com::DataType data) -> void { printk("handle get id"); s_proto->Send(R_GET_ID, uart_com::DataType(s_id_buff)); }; constexpr static std::pair kRxCallbackTable[] = { {R_GET_ID, GetId}, {W_RUNNING_STATE, RunningState}, }; inline static auto s_proto = (uart_com::SimpleProtocal *)DEVICE_DT_GET( DT_COMPAT_GET_ANY_STATUS_OKAY(uart_com_simple_protocal)); inline static uint8_t buff[20]; inline static auto s_heating_state = false; inline static etl::span s_id_buff; }; } // namespace ther #endif