#ifndef _MSGHANDLER_HPP_ #define _MSGHANDLER_HPP_ #include #include #include #include #include "System.hpp" #define UP 1 #define DOWN 2 #define RED 1 #define GREEN 2 #define UNBLOCK 0 #define BLOCK 1 struct iomap_t { //name, (port, value) std::map> omap; std::map> imap; }; struct bar_state_t { uint8_t FrontBarState; uint8_t BackBarState; uint8_t FrontLEDState; uint8_t BackLEDState; uint8_t FrontResistanceSignal; uint8_t BackResistanceSignal; }; class MsgHandler { public: int fd; std::string device; uint8_t device_id; iomap_t iomap; bar_state_t new_bar_state; bar_state_t old_bar_state; MsgHandler(); ~MsgHandler() = default; void HandleDdsMsg(const std::map& msg); bool CtrlBar(const std::vector& port); bool CtrlLight(const std::map& port); int HandleDeviceMsg(); virtual bool OpenPort(const std::string& port, const std::string& baudrate); virtual int SendDeviceMsg(std::vector& data); virtual int RecvDeviceMsg(std::vector& data, int timeoutMs); int SendMsg(const void *buf, size_t len); int RecvMsg(void *buf, size_t len, int timeoutMs); bool isOpen() const { return fd != -1; } void ClosePort(); private: int ParseDeviceMsg(std::vector& data); }; #endif