#ifndef __THER_COM_HPP__ #define __THER_COM_HPP__ #include "led.hpp" #include #include #include #include #include #include namespace ther { class Com { public: static auto Init() -> zpp::error { s_proto->SetRxCallbackTable(kRxCallbackTable); return zpp::ok(); } static auto Send(sensor_value val) -> void { const uint8_t temp_data[] = {(uint8_t)val.val1, (uint8_t)val.val2}; s_proto->Send(TEMP, temp_data); } private: enum HostStatus : uint8_t { STANDBY, RUNNING, PAUSE, ERROR }; enum Addr : uint8_t { TEMP = 0, GET_ID, RUNNING_STATE }; using CbTableValueType = std::pair; struct Cb { static auto GetId(uart_com::DataType data) -> void { printk("handle get id"); uint8_t buff[20]; auto size = hwinfo_get_device_id(buff, sizeof(buff)); s_proto->Send(GET_ID, uart_com::DataType(buff, size)); } static auto RunningState(uart_com::DataType data) -> void { if (data.size() != 1) { return; } if (data[0] == RUNNING) { InfLed::On(); } else { InfLed::Off(); } s_led_strip_indicator->Status(data[0]); } }; constexpr static std::pair kRxCallbackTable[] = {{GET_ID, Cb::GetId}, {RUNNING_STATE, Cb::RunningState}}; inline static auto s_led_strip_indicator = ZPP_DRV_GET_P(ledstrip::Indicator, DT_NODELABEL(indicator)); inline static auto s_proto = (uart_com::SimpleProtocal *)(DEVICE_DT_GET(DT_NODELABEL(pm_protocal))); using InfLed = ther::Led; }; } // namespace ther #endif