qt/ledset/globalfunc.h
2023-06-06 12:13:33 +08:00

63 lines
1.5 KiB
C++

#ifndef GLOBALFUNC_H
#define GLOBALFUNC_H
#include <QtEndian>
#include "pcaprethread.h"
struct Head {
byte pre[2]{0x55, 0x55};
byte ver{1};
byte srv{0};
quint16_be len{0};
byte tgtAddr[4]{0xff, 0xff, 0xff, 0xff};
byte srcAddr[4]{0, 0, 0, 0};
byte ptr[4]{0, 0, 0, 0};
byte ans[2]{0, 0};
quint32_be chk{0};
byte bodyh[4]{0, 0, 0, 0};
quint16_be bodylen{0};
};
struct Msg1024 : Head {
byte body[1024-sizeof(Head)]{0};
};
static byte fi = 0;
inline byte ie(byte size = 1) {
fi = size;
return 0;
}
inline byte ipp(byte size = 1) {
auto rtn = fi;
fi += size;
return rtn;
}
struct HeadMap {
byte pre{ipp(2)};
byte ver{fi++};
byte srv{fi++};
byte len{ipp(2)};
byte tgtAddr{ipp(4)};
byte srcAddr{ipp(4)};
byte ptr{ipp(4)};
byte ans{ipp(2)};
byte chk{ipp(4)};
byte body{ipp(4)};
byte bodylen{ipp(2)};
byte end{fi};
};
extern HeadMap headMap;
extern pcap *pcapSend;
class PcapReThread;
extern PcapReThread *reThd;
QByteArray getNetDev(QWidget *parent, QByteArray, bool);
inline int sendMsg(const byte *msg, int size, int id, qint64 timeout, std::function<void(int code, const QByteArray)> callback, WaitingDlg *waitingDlg = 0) {
return reThd->sendMsgNet(msg, size, id, timeout, callback, waitingDlg);
}
inline int sendMsg(QByteArray &msg, int id, qint64 timeout, std::function<void(int code, const QByteArray)> callback, WaitingDlg *waitingDlg = 0) {
return sendMsg((byte*)msg.data(), msg.size(), id, timeout, callback, waitingDlg);
}
#endif // GLOBALFUNC_H