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.

48 lines
1.1 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef _MSGHANDLER_HPP_
#define _MSGHANDLER_HPP_
#include <queue>
#include <mutex>
#include <vector>
#include <map>
#include "WeighingDDSType.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;
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();
void HandleBarCommand(const WeighingSystem::BarCommandUpdate& cmd);
// 前拦车器两个 GPIO 显式 initexport + direction + 写 0
// 失败也不抛异常,保证调用点可以无脑连续调
void InitFrontBarGpioPair();
private:
};
#endif