Commit 07a92e1b by 郭峰

Merge branch 'feature-1007488' into 'release'

修改mqtt断线08

See merge request !70
parents b3a7628b c8177478
......@@ -1072,50 +1072,41 @@ int CameraHandle::resetGb28181(QString &uuiq){
}
}
// 阻塞等待5秒
//QThread::sleep(5);
QTimer* timer = new QTimer(this);
timer->moveToThread(this->thread());
QThread::sleep(5);
// 连接 QTimer 的超时信号到匿名槽函数
QObject::connect(timer, &QTimer::timeout, [this, &is_wifi, &result, &uuiq, &connectedCameraHandle, &newHandle, &device, &old, timer]() {
QString old_ip;
int res = 1;
MainWindow::sp_this->findSnMapIp(this->sSn, old_ip);
if (old_ip.length() > 0) {
if (is_wifi) {
result = connectedCameraHandle->wifiChangeIp(old_ip, newHandle, sSn);
QString old_ip;
int res = 1;
MainWindow::sp_this->findSnMapIp(this->sSn, old_ip);
if (old_ip.length() > 0) {
if (is_wifi) {
result = connectedCameraHandle->wifiChangeIp(old_ip, newHandle, sSn);
int sdk_handle = this->sdkDevLoginSyn(old_ip, loginParam->nDevPort, loginParam->sUserName, loginParam->sPassword, 3000);
if (sdk_handle < 0) {
qInfo() << QString("SN(%1): WIFI新句柄生成失败").arg(sSn);
this->hDevice = newHandle;
res = -1;
} else {
XSDK_DevLogout(newHandle);
qInfo() << QString("SN(%1): WIFI新句柄生成成功").arg(sSn);
}
} else {
device.reachableIp = old_ip;
device.sSn = sSn;
bool result = connectedCameraHandle->changeCameraIp(device);
if (result) {
int sdk_handle = this->sdkDevLoginSyn(old_ip, loginParam->nDevPort, loginParam->sUserName, loginParam->sPassword, 3000);
if (sdk_handle < 0) {
qInfo() << QString("SN(%1): WIFI新句柄生成失败").arg(sSn);
this->hDevice = newHandle;
qInfo() << QString("SN(%1): 有线新句柄生成失败").arg(sSn);
this->hDevice = old;
res = -1;
} else {
XSDK_DevLogout(newHandle);
qInfo() << QString("SN(%1): WIFI新句柄生成成功").arg(sSn);
}
} else {
device.reachableIp = old_ip;
device.sSn = sSn;
bool result = connectedCameraHandle->changeCameraIp(device);
if (result) {
int sdk_handle = this->sdkDevLoginSyn(old_ip, loginParam->nDevPort, loginParam->sUserName, loginParam->sPassword, 3000);
if (sdk_handle < 0) {
qInfo() << QString("SN(%1): 有线新句柄生成失败").arg(sSn);
this->hDevice = old;
res = -1;
} else {
XSDK_DevLogout(old);
qInfo() << QString("SN(%1): 有线新句柄生成成功").arg(sSn);
}
XSDK_DevLogout(old);
qInfo() << QString("SN(%1): 有线新句柄生成成功").arg(sSn);
}
}
}
MainWindow::sp_this->mqttEmitAsynchronous(uuiq, res, device.sSn);
timer->deleteLater(); // 确保在任务完成后删除 QTimer
});
}
// 设置 QTimer 的超时时间为 5 秒
timer->setSingleShot(true);
timer->start(5000);
//this->updateSdkDevStatus(true);
return 1;
}
......
......@@ -58,8 +58,6 @@ void MqttSubscriber::init(vides_data::MqttConfig &config, QString &httpUrl, QStr
MqttSubscriber::MqttSubscriber(QObject* parent)
: QObject(parent), retryTimer(new QTimer(this)), client(nullptr) {
connect(this, &MqttSubscriber::asynchronousMqtt, this, &MqttSubscriber::asynchronousPush, Qt::QueuedConnection);
// 连接信号和槽
connect(this, &MqttSubscriber::connectionLostSignal, this, &MqttSubscriber::reconnectAndFetchConfig, Qt::QueuedConnection);
......@@ -107,9 +105,6 @@ void MqttSubscriber::start() {
qInfo() << "启动连接失败,返回编码" << rc;
}
}
void MqttSubscriber::emitAsynchronous(QString &uniq,int &res,QString &sn){
emit asynchronousMqtt(uniq,res,sn);
}
void MqttSubscriber::onConnect(MQTTAsync_successData* response) {
......@@ -250,11 +245,6 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess
}
res=(connectedCameraHandle->distributionNetwork(ipAddress,response.sn,hDevice)?0x01 :-1);
}
if (response.msg_type == 8) {
qInfo() << "mqtt 复位GB28181 异步走卡槽函数触发";
return -1;
}
vides_data::requestMqttData request;
request.code = (res >= 0) ? 0 : 0x01;
request.msg = (res >= 0) ?"成功":"失败";
......@@ -265,14 +255,6 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess
MQTTAsync_free(topicName);
return 1;
}
void MqttSubscriber::asynchronousPush(QString &uniq,int &res,QString &sn){
vides_data::requestMqttData request;
request.code = (res >= 0) ? 0 : 0x01;
request.msg = (res >= 0) ?"成功":"失败";
request.uniq= uniq;
sendSubscriptionConfirmation(request,sn);
}
void MqttSubscriber::sendSubscriptionConfirmation(const vides_data::requestMqttData& response,QString &sn) {
QString responseTopic = "/thingshub/" +response.uniq+ "/device/post";
QByteArray bResponseTopic = responseTopic.toUtf8();
......
......@@ -14,15 +14,12 @@ public:
void init(vides_data:: MqttConfig& config,QString &httpUrl,QString &serialNumber);
void start();
void emitAsynchronous(QString &uniq,int &res,QString &sn);
signals:
void connectionLostSignal();
void asynchronousMqtt(QString &uniq,int &res,QString &sn);
private slots:
void reconnectAndFetchConfig();
void asynchronousPush(QString &uniq,int &res,QString &sn);
private:
MqttSubscriber(QObject* parent = nullptr);
......
......@@ -133,12 +133,6 @@ MainWindow::MainWindow():isResetting(false)
this->mqttConfig= config.mqttConfig;
runOrRebootMqtt(mqttConfig,httpurl,serialNumber);
}
void MainWindow::mqttEmitAsynchronous(QString &uuiq,int &res,QString &sn){
MqttSubscriber* subscriber = MqttSubscriber::getInstance(this);
subscriber->emitAsynchronous(uuiq,res,sn);
}
void MainWindow::runOrRebootMqtt(vides_data::MqttConfig &mqtt_config,QString &httpUrl,QString &serialNumber){
MqttSubscriber* subscriber = MqttSubscriber::getInstance(this);
subscriber->init(mqtt_config,httpUrl,serialNumber);
......
......@@ -49,8 +49,6 @@ public:
void divParameterUpdate(vides_data::responseConfig &cloudConfig,QString &httpUrl,QString &serialNumber );
static MainWindow * sp_this;
void mqttEmitAsynchronous(QString &uniq,int &res,QString &sn);
CameraHandle* findHandle(QString sn);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment