You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.5 KiB
58 lines
1.5 KiB
//
|
|
// Created by zwsd
|
|
//
|
|
|
|
#pragma once
|
|
#include <mutex>
|
|
|
|
#include "socket_can/socket_can.hpp"
|
|
//
|
|
#include "thirdlib/spdlogfactory/logger_factory.hpp"
|
|
|
|
namespace iflytop {
|
|
|
|
using namespace std;
|
|
using namespace core;
|
|
|
|
class ZCanReceiverHost {
|
|
ENABLE_LOGGER(ZCanReceiverHost);
|
|
|
|
public:
|
|
class CanPacketRxBuffer {
|
|
public:
|
|
uint16_t id;
|
|
shared_ptr<SocketCanFrame> m_canPacket[256]; // 用于接收can消息
|
|
uint8_t m_rxdata[255 * 8];
|
|
uint8_t m_canPacketNum = 0;
|
|
uint8_t m_rxdataLen = 0;
|
|
};
|
|
|
|
typedef function<void(uint8_t fromboardid, uint8_t *packet, size_t len)> onpacket_t;
|
|
|
|
public:
|
|
uint8_t m_hostId = 0;
|
|
CanPacketRxBuffer m_canPacketRxBuffer[255];
|
|
onpacket_t m_onpacket;
|
|
|
|
shared_ptr<SocketCan> m_socketCan;
|
|
|
|
string m_can_if_name;
|
|
int m_baudrate;
|
|
bool m_enablLoopback;
|
|
|
|
public:
|
|
ZCanReceiverHost();
|
|
void initialize(string can_if_name, int baudrate);
|
|
void sendPacket(uint8_t *packet, size_t len);
|
|
void registerListener(onpacket_t onpacket);
|
|
void restartCanInterface();
|
|
|
|
private:
|
|
bool sendPacketSub(int npacket, int packetIndex, uint8_t *packet, size_t len, int overtimems);
|
|
|
|
void processRx(shared_ptr<SocketCanFrame> frame);
|
|
void processOnePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len);
|
|
void sendcmd(uint16_t packetindex, uint16_t cmdid, uint8_t subcmdid, uint8_t *data, size_t len);
|
|
};
|
|
|
|
} // namespace iflytop
|