62 lines
2.1 KiB
C++
62 lines
2.1 KiB
C++
#include "redis_config.h"
|
|
#include "ui_redis_config.h"
|
|
#include <QRegExpValidator>
|
|
#include <QMessageBox>
|
|
RedisConfig::RedisConfig(QWidget *parent) :
|
|
QWidget(parent),
|
|
ui(new Ui::RedisConfig)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
QString exp = "\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.)"
|
|
"{3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b";
|
|
QRegExp rege(exp);
|
|
QValidator *Validator = new QRegExpValidator(rege);
|
|
ui->lineEdit_ip->setValidator(Validator);
|
|
m_tcpClient = MyTcpClient::instance();
|
|
connect(m_tcpClient, SIGNAL(dataReceived(const QByteArray &)), this, SLOT(readData(const QByteArray &)));
|
|
}
|
|
|
|
RedisConfig::~RedisConfig()
|
|
{
|
|
delete ui;
|
|
}
|
|
void RedisConfig::readData(const QByteArray &data) {
|
|
qDebug() << "Received from server:" << data;
|
|
uint8_t cmd = data[3];
|
|
if (cmd == kConfigRedisServer) {
|
|
RedisCfgRsp redis_config_rsp;
|
|
memcpy(&redis_config_rsp, data.data(), sizeof(RedisCfgRsp));
|
|
qDebug() << "mqtt_config_rsp code" << redis_config_rsp.code ;
|
|
if(redis_config_rsp.code == 0){
|
|
QMessageBox::information(this, QStringLiteral("提示"), "配置成功!");
|
|
}else{
|
|
QMessageBox::warning(this, QStringLiteral("提示"), "配置失败!");
|
|
}
|
|
}
|
|
}
|
|
void RedisConfig::on_pushButton_confirm_clicked()
|
|
{
|
|
RedisCfgReq redis_config = { {0xAA, 0x55, 0xAA}, kConfigRedisServer, 1,1,{},0,{},{} };
|
|
memcpy(redis_config.ip,ui->lineEdit_ip->text().toStdString().c_str(),sizeof(redis_config.ip));
|
|
redis_config.port = ui->lineEdit_port->text().toInt();
|
|
memcpy(redis_config.redis_key,ui->lineEdit_redis_key->text().toStdString().c_str(),sizeof(redis_config.redis_key));
|
|
memcpy(redis_config.vib_code,ui->lineEdit_code->text().toStdString().c_str(),sizeof(redis_config.vib_code));
|
|
|
|
char send_buf[100] ={0};
|
|
memcpy(send_buf, (char*)&redis_config, sizeof(RedisCfgReq));
|
|
|
|
int length = sizeof(RedisCfgReq);
|
|
qint64 bytesWritten = m_tcpClient->sendData(send_buf, length);
|
|
m_tcpClient->waitForRead();
|
|
qDebug() << "bytesWritten: " << bytesWritten;
|
|
|
|
}
|
|
|
|
|
|
void RedisConfig::on_pushButton_cancel_clicked()
|
|
{
|
|
|
|
}
|
|
|