Commit e3cfe167 by “liusq”

修改mqtt断线

parent d18f6f37
...@@ -439,7 +439,7 @@ void CameraHandle::sdkDevSnapSyn(XSDK_HANDLE hDevice, int nChannel){ ...@@ -439,7 +439,7 @@ void CameraHandle::sdkDevSnapSyn(XSDK_HANDLE hDevice, int nChannel){
qDebug() << sSn<<":ping 的结果"<<is_ping; qDebug() << sSn<<":ping 的结果"<<is_ping;
if(is_ping){ if(is_ping){
resetGb28181(); deviceReboot();
}else { }else {
QString ip=QString::fromUtf8(loginParam->sDevId); QString ip=QString::fromUtf8(loginParam->sDevId);
MainWindow::sp_this->clearOfflineCameraHandle(ip,loginParam->nDevPort); MainWindow::sp_this->clearOfflineCameraHandle(ip,loginParam->nDevPort);
...@@ -1017,7 +1017,7 @@ void CameraHandle::printWifi(XSDK_HANDLE hDevice,XSDK_CFG::NetWork_Wifi &cfg){ ...@@ -1017,7 +1017,7 @@ void CameraHandle::printWifi(XSDK_HANDLE hDevice,XSDK_CFG::NetWork_Wifi &cfg){
需注意和定时任务对比GB28181配置冲突处理 需注意和定时任务对比GB28181配置冲突处理
需确认修改IP后抓图是否正常,如不正常需在命令开始前增加删除句柄,命令完成后增加句柄以保证抓图实时性 需确认修改IP后抓图是否正常,如不正常需在命令开始前增加删除句柄,命令完成后增加句柄以保证抓图实时性
*/ */
int CameraHandle::resetGb28181(){ int CameraHandle::resetGb28181(QString &uuiq){
NonConnectedCameraHandle *connectedCameraHandle =NonConnectedCameraHandle::getInstance(); NonConnectedCameraHandle *connectedCameraHandle =NonConnectedCameraHandle::getInstance();
int old=this->hDevice; int old=this->hDevice;
qInfo()<<QString("SN(%1): resetGb28181老句柄%2").arg(sSn).arg(old); qInfo()<<QString("SN(%1): resetGb28181老句柄%2").arg(sSn).arg(old);
...@@ -1050,12 +1050,9 @@ int CameraHandle::resetGb28181(){ ...@@ -1050,12 +1050,9 @@ int CameraHandle::resetGb28181(){
int newHandle=-1; int newHandle=-1;
if(!result ){ if(!result ){
qInfo()<<QString("SN(%1): WIFI修改的前的句柄%2").arg(sSn).arg(old); qInfo()<<QString("SN(%1): WIFI修改的前的句柄%2").arg(sSn).arg(old);
result=connectedCameraHandle->wifiChangeIp(reachableIp,old,sSn); result=connectedCameraHandle->wifiChangeIp(reachableIp,old,sSn);
is_wifi=true; is_wifi=true;
if(result){ if(result){
QThread::sleep(1);
//老句柄抓图不正常了 //老句柄抓图不正常了
int sdk_handle=this->sdkDevLoginSyn(reachableIp,loginParam->nDevPort,loginParam->sUserName,loginParam->sPassword,3000); int sdk_handle=this->sdkDevLoginSyn(reachableIp,loginParam->nDevPort,loginParam->sUserName,loginParam->sPassword,3000);
if(sdk_handle<0){ if(sdk_handle<0){
...@@ -1075,19 +1072,18 @@ int CameraHandle::resetGb28181(){ ...@@ -1075,19 +1072,18 @@ int CameraHandle::resetGb28181(){
} }
} }
// 阻塞等待5秒 // 阻塞等待5秒
QThread::sleep(5); //QThread::sleep(5);
QTimer::singleShot(5000, this, [this, &is_wifi,&result,&uuiq,&connectedCameraHandle, &newHandle, &device, &old]() { QString old_ip;
QString old_ip; int res=1;
MainWindow::sp_this->findSnMapIp(this->sSn,old_ip); MainWindow::sp_this->findSnMapIp(this->sSn,old_ip);
if(old_ip.length()>0){ if(old_ip.length()>0){
if(is_wifi){ if(is_wifi){
result=connectedCameraHandle->wifiChangeIp(old_ip,newHandle,sSn); result=connectedCameraHandle->wifiChangeIp(old_ip,newHandle,sSn);
QThread::sleep(1);
int sdk_handle=this->sdkDevLoginSyn(old_ip,loginParam->nDevPort,loginParam->sUserName,loginParam->sPassword,3000); int sdk_handle=this->sdkDevLoginSyn(old_ip,loginParam->nDevPort,loginParam->sUserName,loginParam->sPassword,3000);
if(sdk_handle<0){ if(sdk_handle<0){
qInfo()<<QString("SN(%1): WIFI新句柄生成失败").arg(sSn); qInfo()<<QString("SN(%1): WIFI新句柄生成失败").arg(sSn);
this->hDevice=newHandle; this->hDevice=newHandle;
return -1; res= -1;
}else { }else {
XSDK_DevLogout(newHandle); XSDK_DevLogout(newHandle);
qInfo()<<QString("SN(%1): WIFI新句柄生成成功").arg(sSn); qInfo()<<QString("SN(%1): WIFI新句柄生成成功").arg(sSn);
...@@ -1101,7 +1097,7 @@ int CameraHandle::resetGb28181(){ ...@@ -1101,7 +1097,7 @@ int CameraHandle::resetGb28181(){
if(sdk_handle<0){ if(sdk_handle<0){
qInfo()<<QString("SN(%1): 有线新句柄生成失败").arg(sSn); qInfo()<<QString("SN(%1): 有线新句柄生成失败").arg(sSn);
this->hDevice=old; this->hDevice=old;
return -1; res= -1;
}else { }else {
XSDK_DevLogout(old); XSDK_DevLogout(old);
qInfo()<<QString("SN(%1): 有线新句柄生成成功").arg(sSn); qInfo()<<QString("SN(%1): 有线新句柄生成成功").arg(sSn);
...@@ -1110,9 +1106,12 @@ int CameraHandle::resetGb28181(){ ...@@ -1110,9 +1106,12 @@ int CameraHandle::resetGb28181(){
} }
} }
} }
MainWindow::sp_this->mqttEmitAsynchronous(uuiq,res,device.sSn);
return res;
});
return 1;//this->updateSdkDevStatus(true); //this->updateSdkDevStatus(true);
return 1;
} }
int CameraHandle::forceWriteGb28181(){ int CameraHandle::forceWriteGb28181(){
......
...@@ -114,7 +114,7 @@ public: ...@@ -114,7 +114,7 @@ public:
//获取固件版本 //获取固件版本
void findFirmwareVersion(QString &firmwareVersion); void findFirmwareVersion(QString &firmwareVersion);
//复位GB28181 //复位GB28181
int resetGb28181(); int resetGb28181(QString &uuiq);
//强制gb28181配置后写入摄像头 //强制gb28181配置后写入摄像头
int forceWriteGb28181(); int forceWriteGb28181();
......
...@@ -58,6 +58,9 @@ void MqttSubscriber::init(vides_data::MqttConfig &config, QString &httpUrl, QStr ...@@ -58,6 +58,9 @@ void MqttSubscriber::init(vides_data::MqttConfig &config, QString &httpUrl, QStr
MqttSubscriber::MqttSubscriber(QObject* parent) MqttSubscriber::MqttSubscriber(QObject* parent)
: QObject(parent), retryTimer(new QTimer(this)), client(nullptr) { : 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); connect(this, &MqttSubscriber::connectionLostSignal, this, &MqttSubscriber::reconnectAndFetchConfig, Qt::QueuedConnection);
retryTimer->setInterval(10000); // 设置重试间隔为10秒 retryTimer->setInterval(10000); // 设置重试间隔为10秒
...@@ -104,6 +107,9 @@ void MqttSubscriber::start() { ...@@ -104,6 +107,9 @@ void MqttSubscriber::start() {
qInfo() << "启动连接失败,返回编码" << rc; qInfo() << "启动连接失败,返回编码" << rc;
} }
} }
void MqttSubscriber::emitAsynchronous(QString &uniq,int &res,QString &sn){
emit asynchronousMqtt(uniq,res,sn);
}
void MqttSubscriber::onConnect(MQTTAsync_successData* response) { void MqttSubscriber::onConnect(MQTTAsync_successData* response) {
...@@ -227,7 +233,7 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess ...@@ -227,7 +233,7 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess
} }
break; break;
} }
case 8: res = cameraHandle->resetGb28181(); break; case 8: res = cameraHandle->resetGb28181( response.uniq); break;
default: qInfo() << "Unknown message type"; break; default: qInfo() << "Unknown message type"; break;
} }
} }
...@@ -244,6 +250,10 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess ...@@ -244,6 +250,10 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess
} }
res=(connectedCameraHandle->distributionNetwork(ipAddress,response.sn,hDevice)?0x01 :-1); res=(connectedCameraHandle->distributionNetwork(ipAddress,response.sn,hDevice)?0x01 :-1);
} }
if (response.msg_type == 8) {
qInfo() << "mqtt 复位GB28181 异步走卡槽函数触发";
return -1;
}
vides_data::requestMqttData request; vides_data::requestMqttData request;
request.code = (res >= 0) ? 0 : 0x01; request.code = (res >= 0) ? 0 : 0x01;
...@@ -255,6 +265,13 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess ...@@ -255,6 +265,13 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess
MQTTAsync_free(topicName); MQTTAsync_free(topicName);
return 1; 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) { void MqttSubscriber::sendSubscriptionConfirmation(const vides_data::requestMqttData& response,QString &sn) {
QString responseTopic = "/thingshub/" +response.uniq+ "/device/post"; QString responseTopic = "/thingshub/" +response.uniq+ "/device/post";
......
...@@ -14,11 +14,16 @@ public: ...@@ -14,11 +14,16 @@ public:
void init(vides_data:: MqttConfig& config,QString &httpUrl,QString &serialNumber); void init(vides_data:: MqttConfig& config,QString &httpUrl,QString &serialNumber);
void start(); void start();
void emitAsynchronous(QString &uniq,int &res,QString &sn);
signals: signals:
void connectionLostSignal(); void connectionLostSignal();
void asynchronousMqtt(QString &uniq,int &res,QString &sn);
private slots: private slots:
void reconnectAndFetchConfig(); void reconnectAndFetchConfig();
void asynchronousPush(QString &uniq,int &res,QString &sn);
private: private:
MqttSubscriber(QObject* parent = nullptr); MqttSubscriber(QObject* parent = nullptr);
MqttSubscriber() = delete; MqttSubscriber() = delete;
...@@ -45,6 +50,7 @@ private: ...@@ -45,6 +50,7 @@ private:
void onPublishSuccess(MQTTAsync_successData* response); void onPublishSuccess(MQTTAsync_successData* response);
void onPublishFailure(MQTTAsync_failureData* response); void onPublishFailure(MQTTAsync_failureData* response);
void sendSubscriptionConfirmation(const vides_data::requestMqttData& response,QString &sn); void sendSubscriptionConfirmation(const vides_data::requestMqttData& response,QString &sn);
static MqttSubscriber* instance; static MqttSubscriber* instance;
}; };
......
...@@ -134,6 +134,11 @@ MainWindow::MainWindow():isResetting(false) ...@@ -134,6 +134,11 @@ MainWindow::MainWindow():isResetting(false)
runOrRebootMqtt(mqttConfig,httpurl,serialNumber); 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){ void MainWindow::runOrRebootMqtt(vides_data::MqttConfig &mqtt_config,QString &httpUrl,QString &serialNumber){
MqttSubscriber* subscriber = MqttSubscriber::getInstance(this); MqttSubscriber* subscriber = MqttSubscriber::getInstance(this);
subscriber->init(mqtt_config,httpUrl,serialNumber); subscriber->init(mqtt_config,httpUrl,serialNumber);
......
...@@ -50,6 +50,8 @@ public: ...@@ -50,6 +50,8 @@ public:
static MainWindow * sp_this; static MainWindow * sp_this;
void mqttEmitAsynchronous(QString &uniq,int &res,QString &sn);
CameraHandle* findHandle(QString sn); CameraHandle* findHandle(QString sn);
void modifySnMapIp(QString &sn,QString &ip); void modifySnMapIp(QString &sn,QString &ip);
......
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