添加广播方式升级
This commit is contained in:
75
interface/if_can.h
Normal file
75
interface/if_can.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#ifndef if_can_h__
|
||||
#define if_can_h__
|
||||
|
||||
#include <base/base.h>
|
||||
#include <QObject>
|
||||
#include <QCanBus>
|
||||
#include <QCanBusDevice>
|
||||
#include "stdint-gcc.h"
|
||||
#include "QList"
|
||||
#include "QTimer"
|
||||
#include "interface/interface.h"
|
||||
|
||||
// 定义can从机对象
|
||||
class can_slave : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
uint8_t addr;
|
||||
can_slave();
|
||||
can_slave(const can_slave &b);
|
||||
~can_slave();
|
||||
can_slave &operator=(const can_slave &b);
|
||||
void append(QByteArray data);
|
||||
QByteArray get_data();
|
||||
int get_pack_num();
|
||||
void clear();
|
||||
bool is_empty()
|
||||
{
|
||||
if (recv_data.size() == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
QByteArray recv_data;
|
||||
int recv_pack_num;
|
||||
};
|
||||
|
||||
// 定义can主机对象
|
||||
class can_host : public InterFace
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
can_host(int bitrate);
|
||||
~can_host();
|
||||
// 用户调用这个函数初始化
|
||||
void init();
|
||||
int write(myarray data){return 0;}
|
||||
int write(int dst,myarray data);
|
||||
|
||||
private:
|
||||
can_slave &get_slave_by_addr(uint8_t addr);
|
||||
void append(uint8_t addr, uint8_t fun_class, QByteArray data);
|
||||
public slots:
|
||||
// 用户把发送数据信号连接到这个槽
|
||||
void send_data_cb(uint8_t dst, int fun_class, QByteArray data);
|
||||
void send_data_mul_cb(QList<uint8_t> dst, int fun_class, QByteArray data);
|
||||
|
||||
private slots:
|
||||
void freams_sent_cb(qint64 count);
|
||||
void recv_data_cb();
|
||||
void on_error_cb(QCanBusDevice::CanBusError err);
|
||||
void init_cb();
|
||||
// void timerout_cb();
|
||||
private:
|
||||
int bitrate;
|
||||
QCanBusDevice *can_;
|
||||
QList<can_slave> slaves;
|
||||
QList<QCanBusFrame> send_packets;
|
||||
QList<QCanBusFrame> recv_packets;
|
||||
QTimer *timer_;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user