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.
41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
#ifndef _MSGHANDLER_HPP_
|
|
#define _MSGHANDLER_HPP_
|
|
|
|
#include <queue>
|
|
#include <mutex>
|
|
#include <vector>
|
|
#include <map>
|
|
|
|
class MsgHandler {
|
|
public:
|
|
int fd;
|
|
std::string device;
|
|
std::vector<uint8_t> m_WeightData;
|
|
|
|
MsgHandler();
|
|
~MsgHandler() = default;
|
|
|
|
void HandleDdsMsg(const std::map<std::string, std::string>& msg);
|
|
template<typename T>
|
|
bool HandleDeviceMsg(T& msg);
|
|
bool SetDevice(const std::string& device);
|
|
|
|
virtual bool OpenPort(const std::string& port, const std::string& baudrate);
|
|
virtual int SendDeviceMsg(const std::vector<uint8_t>& data);
|
|
virtual int RecvDeviceMsg(std::vector<uint8_t>& data, int timeoutMs);
|
|
int SendMsg(const std::vector<uint8_t>& data);
|
|
int RecvMsg(std::vector<uint8_t>& data, int timeoutMs);
|
|
bool isOpen() const {
|
|
return fd != -1;
|
|
}
|
|
void ClosePort();
|
|
|
|
private:
|
|
bool get_frame(std::vector<uint8_t>& frame, uint8_t frame_size, uint8_t start, uint8_t end);
|
|
bool get_weight_1(std::string& weight, std::vector<uint8_t>& frame);
|
|
bool get_weight_1(float& weight, std::vector<uint8_t>& frame);
|
|
bool get_weight_2(std::string& weight, std::vector<uint8_t>& frame);
|
|
bool get_weight_2(float& weight, std::vector<uint8_t>& frame);
|
|
};
|
|
|
|
#endif |