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.
118 lines
3.6 KiB
118 lines
3.6 KiB
#pragma once
|
|
#include <fstream>
|
|
#include <functional>
|
|
#include <iostream>
|
|
#include <list>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <set>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
//
|
|
#include "app_protocols/zscanprotocol/zscanprotocol.hpp"
|
|
#include "protocol/waveshare_can/waveshare_can.hpp"
|
|
#include "zqui/zqui/zqui.hpp"
|
|
|
|
namespace iflytop {
|
|
using namespace std;
|
|
namespace zscanprotocol {
|
|
|
|
typedef function<void(packet_type_t type, uint8_t from, uint8_t to, uint8_t *hex, uint32_t hexlen)> on_raw_data_t;
|
|
|
|
typedef function<string(int ecode)> ecode2str_t;
|
|
|
|
class RxReceiptContext {
|
|
public:
|
|
bool waittingForReceipt;
|
|
bool receiptIsReady;
|
|
uint8_t waittingIndex;
|
|
uint8_t receipt[1024];
|
|
size_t receiptLen;
|
|
};
|
|
|
|
class Receipt {
|
|
public:
|
|
uint8_t receipt[1024];
|
|
size_t receiptLen;
|
|
|
|
zcanbus_packet_t *getPacket() { return (zcanbus_packet_t *)receipt; }
|
|
int32_t getContent(int index) { return getPacket()->params[index]; }
|
|
uint8_t *getByte() { return (uint8_t *)getPacket()->params; }
|
|
};
|
|
|
|
class CanPacketRxBuffer {
|
|
public:
|
|
int32_t id = 0;
|
|
uint8_t from = 0;
|
|
uint8_t to = 0;
|
|
|
|
uint8_t rxdata[2048] = {0};
|
|
int rxdataSize = 0;
|
|
|
|
int rxPacketNum = 0;
|
|
};
|
|
|
|
class ZSCanProtocolCom {
|
|
WaveshareCan *m_channel = nullptr;
|
|
|
|
uint8_t m_rxcache[1024] = {0};
|
|
int32_t m_rxlen = 0;
|
|
bool m_rxcache_is_full = false;
|
|
|
|
mutex lock_;
|
|
|
|
unique_ptr<thread> m_thread;
|
|
|
|
RxReceiptContext m_rxReceiptContext;
|
|
mutex m_rxReceiptContext_lock;
|
|
|
|
/*******************************************************************************
|
|
* TX CONTEXT *
|
|
*******************************************************************************/
|
|
mutex m_tx_lock;
|
|
uint8_t m_txbuf[1024] = {0};
|
|
int32_t m_rxsize = 0;
|
|
uint8_t m_txindex = 0;
|
|
|
|
CanPacketRxBuffer m_rxbuf[255];
|
|
|
|
on_raw_data_t on_rx_raw;
|
|
|
|
uint8_t m_receipt_cache[1024];
|
|
zcanbus_packet_t *m_receipt_frame = (zcanbus_packet_t *)m_receipt_cache;
|
|
size_t m_receipt_len = 0;
|
|
|
|
public:
|
|
ZSCanProtocolCom() {}
|
|
|
|
public:
|
|
void initialize(QTSerialChannel *ch);
|
|
void regOnRawData(on_raw_data_t cb) { on_rx_raw = cb; }
|
|
void updateChannelConfig();
|
|
|
|
shared_ptr<Receipt> callcmd(int32_t to, int32_t cmdid, uint8_t *param, int32_t paramLen, int32_t overtime = 100);
|
|
shared_ptr<Receipt> callcmd0(int32_t to, int32_t cmdid, int32_t overtime = 100);
|
|
shared_ptr<Receipt> callcmd1(int32_t to, int32_t cmdid, int32_t param0, int32_t overtime = 100);
|
|
shared_ptr<Receipt> callcmd2(int32_t to, int32_t cmdid, int32_t param0, int32_t param1, int32_t overtime = 100);
|
|
shared_ptr<Receipt> callcmd3(int32_t to, int32_t cmdid, int32_t param0, int32_t param1, int32_t param2, int32_t overtime = 100);
|
|
shared_ptr<Receipt> callcmd4(int32_t to, int32_t cmdid, int32_t param0, int32_t param1, int32_t param2, int32_t param3, int32_t overtime = 100);
|
|
shared_ptr<Receipt> callcmd5(int32_t to, int32_t cmdid, int32_t param0, int32_t param1, int32_t param2, int32_t param3, int32_t param4, int32_t overtime = 100);
|
|
|
|
void sendraw(int32_t from, int32_t to, uint8_t *data, size_t len);
|
|
|
|
private:
|
|
void sendframe(int32_t from, int32_t to, uint8_t *frame, size_t len);
|
|
void sendsubframe(int32_t from, int32_t to, int npacket, int packetIndex, uint8_t *packet, size_t len);
|
|
void processRxPacket(int32_t from, int32_t to, uint8_t *data, size_t len);
|
|
|
|
private:
|
|
CanPacketRxBuffer *findRxBuff(int deviceId);
|
|
string ecode2str(int ecode);
|
|
};
|
|
} // namespace zscanprotocol
|
|
|
|
} // namespace iflytop
|