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.

66 lines
1.5 KiB
C++

#ifndef _MSGHANDLER_HPP_
#define _MSGHANDLER_HPP_
#include <queue>
#include <mutex>
#include <vector>
#include <map>
#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<std::string, std::pair<uint8_t, uint8_t>> omap;
std::map<std::string, std::pair<uint8_t, uint8_t>> 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<std::string, std::string>& msg);
bool CtrlBar(const std::vector<std::string>& port);
bool CtrlLight(const std::map<std::string, uint8_t>& port);
int HandleDeviceMsg();
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);
};
#endif