You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB
C++

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