174 lines
6.3 KiB
C++
174 lines
6.3 KiB
C++
#include "ConfigParam.h"
|
|
#include "ui_ConfigParam.h"
|
|
#include "msg.h"
|
|
#include <QMessageBox>
|
|
|
|
ConfigParam::ConfigParam(QWidget *parent)
|
|
: QWidget(parent)
|
|
, ui(new Ui::ConfigParam)
|
|
{
|
|
ui->setupUi(this);
|
|
}
|
|
|
|
ConfigParam::~ConfigParam()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
bool ConfigParam::checkNumber(char type, const QString& number){
|
|
if (number.isEmpty()) {
|
|
QMessageBox::information(this, "错误", QString("请输入%1电话号码").arg(QChar(type)));
|
|
return false;
|
|
}
|
|
// 检查号码是否只包含数字 0-9
|
|
QRegularExpression digitOnly("^[0-9]*$"); // 正则表达式:只允许数字
|
|
if (!digitOnly.match(number).hasMatch()) {
|
|
QMessageBox::information(this, "错误", QString("%1电话号码只能包含数字0-9").arg(QChar(type)));
|
|
return false;
|
|
}
|
|
//检查号码长度
|
|
if (number.size() > 20){
|
|
QMessageBox::information(this, "错误", QString("%1电话号码长度不能超过20").arg(QChar(type)));
|
|
return false;
|
|
}
|
|
// TODO: 检查电话号码格式是否满足要求
|
|
return true;
|
|
}
|
|
|
|
void ConfigParam::on_btnGetUDataChannelKeepTime_clicked()
|
|
{
|
|
emit sendUdpRequest(pack_config_cmd_UDataChannelKeepTimeGet());
|
|
}
|
|
|
|
|
|
void ConfigParam::on_btnSetUDataChannelKeepTime_clicked()
|
|
{
|
|
bool result;
|
|
QString keeptime = ui->uDataChannelKeepTime->text();
|
|
if (keeptime.isEmpty()) {
|
|
QMessageBox::information(this, "错误", "U数据通道保持时间不能为空");
|
|
return;
|
|
}
|
|
|
|
int keeptimeValue = keeptime.toInt(&result);
|
|
|
|
if(!result || (keeptimeValue < 0) || (keeptimeValue > 65535))
|
|
{
|
|
QMessageBox::information(this, "错误", "U数据通道保持时间参数错误,取值范围为0~65535");
|
|
return;
|
|
}
|
|
|
|
emit sendUdpRequest(pack_config_cmd_UDataChannelKeepTimeSet(keeptimeValue));
|
|
}
|
|
|
|
void ConfigParam::processConfigCmd(const QByteArray& cmd){
|
|
switch(uint8_t(cmd[COMMAND_TYPE_INDEX])){
|
|
case uint8_t(CommandType::kConfigCmdDefaultChannel):
|
|
if(cmd[SUB_COMMAND_TYPE_INDEX] == uint8_t(ConfigCommandType::kGetType))
|
|
{
|
|
int data_index = COMMAND_DATA_BEGIN_INDEX;
|
|
uint8_t channelType = cmd[data_index++];//信道类型
|
|
ui->defaultChannelType->setCurrentIndex(channelType + 1);
|
|
}
|
|
else if(cmd[SUB_COMMAND_TYPE_INDEX] == uint8_t(ConfigCommandType::kSetType))
|
|
{
|
|
if(cmd[COMMAND_DATA_BEGIN_INDEX] == uint8_t(VoiceAndShortMessageReponse::kSucess)){//设置成功
|
|
//QMessageBox::information(this, "提示", "默认信道设置成功");
|
|
}else if(cmd[COMMAND_DATA_BEGIN_INDEX] == uint8_t(VoiceAndShortMessageReponse::kFailure)){//设置失败
|
|
//QMessageBox::information(this, "提示", "默认信道设置失败");
|
|
}
|
|
emit sendUdpRequest(pack_config_cmd_DefaultChannelGet()); //查询一次
|
|
}
|
|
break;
|
|
case uint8_t(CommandType::kConfigCmdUDataChannelKeepTime):
|
|
if(cmd[SUB_COMMAND_TYPE_INDEX] == uint8_t(ConfigCommandType::kGetType))
|
|
{
|
|
int data_index = COMMAND_DATA_BEGIN_INDEX;
|
|
uint16_t keeptime = qFromBigEndian<quint16>(reinterpret_cast<const uchar*>(cmd.constData()+data_index));
|
|
ui->uDataChannelKeepTime->setText(QString("%1").arg(keeptime));
|
|
}
|
|
else if(cmd[SUB_COMMAND_TYPE_INDEX] == uint8_t(ConfigCommandType::kSetType))
|
|
{
|
|
if(cmd[COMMAND_DATA_BEGIN_INDEX] == uint8_t(VoiceAndShortMessageReponse::kSucess)){//设置成功
|
|
QMessageBox::information(this, "提示", "U数据通道保持时间设置成功");
|
|
}else if(cmd[COMMAND_DATA_BEGIN_INDEX] == uint8_t(VoiceAndShortMessageReponse::kFailure)){//设置失败
|
|
QMessageBox::information(this, "提示", "U数据通道保持时间设置失败");
|
|
}
|
|
}
|
|
break;
|
|
case uint8_t(CommandType::kConfigCmdDefaultNumber):
|
|
if(cmd[SUB_COMMAND_TYPE_INDEX] == uint8_t(ConfigCommandType::kGetType))
|
|
{
|
|
int data_index = COMMAND_DATA_BEGIN_INDEX;
|
|
// U号码,使用 QByteArray 处理
|
|
QByteArray u_data = QByteArray::fromRawData(cmd.constData() + data_index, 20);
|
|
u_data.replace('\0', ""); // 移除所有空字符
|
|
// 转换为 std::string
|
|
std::string u_number = u_data.toStdString();
|
|
data_index += 20;
|
|
// S号码,使用 QByteArray 处理
|
|
QByteArray s_data = QByteArray::fromRawData(cmd.constData() + data_index, 20);
|
|
s_data.replace('\0', ""); // 移除所有空字符
|
|
// 转换为 std::string
|
|
std::string s_number = s_data.toStdString();
|
|
data_index += 20;
|
|
ui->uDefaultNum->setText(QString::fromStdString(u_number));
|
|
ui->sDefaultNum->setText(QString::fromStdString(s_number));
|
|
}
|
|
else if(cmd[SUB_COMMAND_TYPE_INDEX] == uint8_t(ConfigCommandType::kSetType))
|
|
{
|
|
if(cmd[COMMAND_DATA_BEGIN_INDEX] == uint8_t(VoiceAndShortMessageReponse::kSucess)){//设置成功
|
|
QMessageBox::information(this, "提示", "默认电话号码设置成功");
|
|
}else if(cmd[COMMAND_DATA_BEGIN_INDEX] == uint8_t(VoiceAndShortMessageReponse::kFailure)){//设置失败
|
|
QMessageBox::information(this, "提示", "默认电话号码设置失败");
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
void ConfigParam::on_btnGetDefaultChannel_clicked()
|
|
{
|
|
emit sendUdpRequest(pack_config_cmd_DefaultChannelGet());
|
|
}
|
|
|
|
void ConfigParam::on_btnSetDefaultChannel_clicked()
|
|
{
|
|
uint8_t channelType = ui->defaultChannelType->currentIndex();
|
|
if(channelType == 0)
|
|
{
|
|
QMessageBox::information(this, "错误", "请选择默认话音通道");
|
|
return;
|
|
}
|
|
|
|
emit sendUdpRequest(pack_config_cmd_DefaultChannelSet((channelType - 1)));
|
|
|
|
}
|
|
|
|
|
|
void ConfigParam::on_btnGetDefaultNumber_clicked()
|
|
{
|
|
emit sendUdpRequest(pack_config_cmd_DefaultNumberGet());
|
|
}
|
|
|
|
|
|
void ConfigParam::on_btnSetDefaultNumber_clicked()
|
|
{
|
|
// 检查电话号码是否为空
|
|
QString u_number = ui->uDefaultNum->text();
|
|
if(!checkNumber('U', u_number)){
|
|
return;
|
|
}
|
|
|
|
QString s_number = ui->sDefaultNum->text();
|
|
if(!checkNumber('S', s_number)){
|
|
return;
|
|
}
|
|
|
|
emit sendUdpRequest(pack_config_cmd_DefaultNumberSet(u_number.toStdString(), s_number.toStdString()));
|
|
|
|
}
|
|
|
|
|