完成通讯
This commit is contained in:
+185
@@ -0,0 +1,185 @@
|
||||
#ifndef DLINK_H
|
||||
#define DLINK_H
|
||||
|
||||
#include <QObject>
|
||||
#include "QtSerialPort"
|
||||
#include <QHostAddress>
|
||||
#include <QUdpSocket>
|
||||
#include "QDebug"
|
||||
#include <QNetworkProxy>
|
||||
#include "QEvent"
|
||||
#include "QNetworkInterface"
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
#ifdef QtDlink
|
||||
#include <dlinkglobal.h>
|
||||
class DLINKSHARED_EXPORT DLink : public QObject {
|
||||
#else
|
||||
class DLink : public QObject
|
||||
{
|
||||
#endif
|
||||
Q_OBJECT
|
||||
//Q_DECLARE_PRIVATE(DLink)
|
||||
|
||||
enum devtype{
|
||||
ganeral = 0,
|
||||
datalink,
|
||||
remote,
|
||||
rtk,
|
||||
video,
|
||||
exportinfo
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
|
||||
uint64_t total = 0;
|
||||
uint64_t count = 0;//总字节数
|
||||
uint64_t lastcount = 0;//上一次字节数
|
||||
uint64_t rate = 0;//每秒字节数
|
||||
uint64_t frame = 0;//包
|
||||
uint64_t lastframe = 0;//上一次包
|
||||
qreal frequency = 0;//包频率
|
||||
}_node_status;
|
||||
|
||||
|
||||
struct clientNode{
|
||||
QUdpSocket * sock;
|
||||
QHostAddress addr;
|
||||
quint16 port;
|
||||
devtype type;
|
||||
|
||||
_node_status in;
|
||||
_node_status out;
|
||||
|
||||
uint32_t tansmit_mode;
|
||||
|
||||
bool operator==(const clientNode& other)
|
||||
{
|
||||
if (this->sock == other.sock)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
struct serialNode{
|
||||
QSerialPort * port;
|
||||
QString name;
|
||||
qint32 baud;
|
||||
QSerialPort::Parity parity;
|
||||
devtype type;
|
||||
|
||||
_node_status in;
|
||||
_node_status out;
|
||||
|
||||
bool operator==(const serialNode& other)
|
||||
{
|
||||
if (this->name == other.name)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
explicit DLink(QObject *parent = nullptr);
|
||||
~DLink();
|
||||
|
||||
//设置串口,本软件没用到
|
||||
Q_INVOKABLE bool PortSetup(const QString &name, qint32 baudrate = 115200, QSerialPort::Parity parity = QSerialPort::NoParity);
|
||||
|
||||
Q_INVOKABLE bool PortState(const QString &name);
|
||||
|
||||
Q_INVOKABLE bool PortStop(const QString &name);
|
||||
|
||||
//设置UDP,本软件没用到
|
||||
Q_INVOKABLE bool setupClient(const QHostAddress &local_addr,int local_port,const QHostAddress &remote_addr,int remote_port);
|
||||
|
||||
//设置组播接收
|
||||
Q_INVOKABLE bool setup_multicast_recieve(const QHostAddress &ip, const quint16 &port, QHostAddress newip = QHostAddress("0,0,0,0"), quint16 newport = 0);
|
||||
|
||||
//设置组播发送
|
||||
Q_INVOKABLE bool setup_multicast_transmit(const QHostAddress &ip, const quint16 &port, QHostAddress newip = QHostAddress("0,0,0,0"), quint16 newport = 0);
|
||||
|
||||
//设置组播关闭
|
||||
Q_INVOKABLE bool setup_multicast_close(const QHostAddress &ip,const quint16 &port);
|
||||
|
||||
bool isExportInfo = true;
|
||||
|
||||
signals:
|
||||
void showMessage(const QString &message,int TimeOut = 0);
|
||||
|
||||
void recieveMessage(quint32 src,QByteArray data);
|
||||
|
||||
|
||||
void status(QHostAddress ip, quint16 port, qreal in_all, qreal in_rate, qreal in_frq,qreal out_all, qreal out_rate, qreal out_frq);
|
||||
|
||||
void recieve(QHostAddress ip,quint16 port,QByteArray data);
|
||||
|
||||
void recieve(QString name,QByteArray data);
|
||||
|
||||
|
||||
|
||||
public slots:
|
||||
|
||||
void readPendingDatagramsSerialPort(void);
|
||||
|
||||
void readPendingDatagramsClient(void);
|
||||
|
||||
int SendMessageTo(quint8 ch, quint8 *msg, quint16 len);
|
||||
|
||||
void transmit(QHostAddress ip,quint16 port,QByteArray data);
|
||||
|
||||
void transmit(QString name,QByteArray data);//QOverload<QString,QByteArray>::of(&DLink::recieve) 信号重载的调用方式
|
||||
|
||||
private slots:
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
enum SourceType{
|
||||
|
||||
c_sock = 0,
|
||||
s_port = 1,
|
||||
p_port = 2,
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
QMap<uint32_t,unsigned> cnts_in;
|
||||
QMap<uint32_t,unsigned> cnts_out;
|
||||
|
||||
QList<clientNode> sockets;
|
||||
QList<serialNode> serials;
|
||||
|
||||
QMap<quint8,QIODevice *> Device;
|
||||
|
||||
|
||||
quint32 outCount = 0;
|
||||
quint32 inCount = 0;
|
||||
quint32 errCount = 0;
|
||||
quint32 frameCount = 0;
|
||||
|
||||
double out_bits = 0;
|
||||
double in_bits = 0;
|
||||
double rssi_bits = 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
||||
|
||||
#endif // DLINK_H
|
||||
Reference in New Issue
Block a user