2023-12-02 11:27:25 +08:00
|
|
|
|
|
|
|
#ifndef prot_cmdline_h__
|
|
|
|
#define prot_cmdline_h__
|
|
|
|
|
|
|
|
#include "QObject"
|
|
|
|
#include "base/base.h"
|
|
|
|
#include "QList"
|
|
|
|
#include "interface/codec.h"
|
|
|
|
#include "interface/interface.h"
|
|
|
|
#include "base/mycfg.h"
|
|
|
|
#include "QThread"
|
|
|
|
#include <QNetworkInterface>
|
|
|
|
#include <QUdpSocket>
|
2023-12-21 18:51:58 +08:00
|
|
|
#include "QTimer"
|
2023-12-02 11:27:25 +08:00
|
|
|
|
|
|
|
// using namespace std;
|
|
|
|
// using namespace std::placeholders;
|
|
|
|
|
|
|
|
// typedef std::function<void(myarray data)> prot_cmdline_cb;
|
|
|
|
typedef void (*prot_cmdline_cb)(QList<myarray> data);
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const char *cmd;
|
|
|
|
const char *help;
|
|
|
|
prot_cmdline_cb fun;
|
|
|
|
} cmdline_def;
|
|
|
|
|
|
|
|
#define cmdline_export(name_, fun_, help_) \
|
|
|
|
const static char __cmdline_##name_##_name[] __attribute__((section(".rodata.cmdlstr"))) = #name_; \
|
|
|
|
const static char __cmdline_##name_##_help[] __attribute__((section(".rodata.cmdlstr"))) = #help_; \
|
|
|
|
__attribute__((used)) static cmdline_def _cmdline_##name_ __attribute__((section("cmdldef"))) = { \
|
|
|
|
.cmd = __cmdline_##name_##_name, \
|
|
|
|
.help = __cmdline_##name_##_help, \
|
|
|
|
.fun = fun_, \
|
|
|
|
}
|
|
|
|
|
|
|
|
class command : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
command()
|
|
|
|
{
|
|
|
|
socket_ = nullptr;
|
2023-12-21 18:51:58 +08:00
|
|
|
timer_=nullptr;
|
|
|
|
networt_state=0;
|
2023-12-02 11:27:25 +08:00
|
|
|
}
|
|
|
|
virtual ~command()
|
|
|
|
{
|
|
|
|
if (socket_ != nullptr)
|
|
|
|
delete socket_;
|
|
|
|
}
|
|
|
|
void send(QByteArray data);
|
|
|
|
void init_cb();
|
2023-12-21 18:51:58 +08:00
|
|
|
void timer_cb();
|
2023-12-02 11:27:25 +08:00
|
|
|
void ready_read_cb();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QUdpSocket *socket_;
|
|
|
|
QByteArray recv_data;
|
|
|
|
QHostAddress host_addr;
|
|
|
|
quint16 port;
|
2023-12-21 18:51:58 +08:00
|
|
|
QTimer *timer_;
|
|
|
|
int networt_state;
|
2023-12-02 11:27:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
command *command_start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|