#ifndef _MSGHANDLER_HPP_ #define _MSGHANDLER_HPP_ #include #include #include #include #include "System.hpp" struct iomap_t { //name, (port, value) std::map> omap; std::map> imap; }; class MsgHandler { public: int fd; std::string device; uint8_t device_id; iomap_t iomap; MsgHandler(); ~MsgHandler() = default; void HandleDdsMsg(const std::map& msg); int HandleDeviceMsg(InternalSystem::IoCtrlRsp& rsp); 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, InternalSystem::IoCtrlRsp& rsp); }; #endif