43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
|
#include "macconfig.h"
|
||
|
#include "ui_macconfig.h"
|
||
|
#include <QRegularExpression>
|
||
|
#include <QRegularExpressionValidator>
|
||
|
|
||
|
MacConfig::MacConfig(QWidget *parent) :
|
||
|
QWidget(parent),
|
||
|
ui(new Ui::MacConfig)
|
||
|
{
|
||
|
ui->setupUi(this);
|
||
|
QRegularExpression macRegex("^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$");
|
||
|
QRegularExpressionValidator *macValidator = new QRegularExpressionValidator(macRegex, this);
|
||
|
ui->lineEdit_mac->setValidator(macValidator);
|
||
|
}
|
||
|
|
||
|
MacConfig::~MacConfig()
|
||
|
{
|
||
|
delete ui;
|
||
|
}
|
||
|
|
||
|
void MacConfig::on_pushButton_confirm_clicked()
|
||
|
{
|
||
|
PackageHead header = { {0xAA, 0x55, 0xAA}, kConfigMac, sizeof(ConfigMacReq),0,{} };
|
||
|
ConfigMacReq config_mac;
|
||
|
memcpy(config_mac.mac,ui->lineEdit_mac->text().toStdString().c_str(),sizeof(config_mac.mac));
|
||
|
char send_buf[20] ={0};
|
||
|
memcpy(send_buf, (char*)&header, sizeof(PackageHead));
|
||
|
memcpy(send_buf + sizeof(PackageHead), (char*)&config_mac, sizeof(ConfigMacReq));
|
||
|
|
||
|
int length = sizeof(PackageHead) + sizeof(ConfigMacReq);
|
||
|
qint64 bytesWritten = m_tcpClient->sendData(send_buf, length);
|
||
|
m_tcpClient->waitForRead();
|
||
|
qDebug() << "bytesWritten: " << bytesWritten;
|
||
|
this->close();
|
||
|
}
|
||
|
|
||
|
|
||
|
void MacConfig::on_pushButton_cancel_clicked()
|
||
|
{
|
||
|
this->close();
|
||
|
}
|
||
|
|