keep = nullptr;
keepNetState = NET_DISCONNECT;
-
keepTimer = new QTimer(this);
- connect(keepTimer, &QTimer::timeout, this, &MyNetManager::keepTimerOverProcess);
- keepTimer->stop();
+
+ connect(m_pManager, &QNetworkAccessManager::finished,this,
+ &MyNetManager::onKeepConnectFinished);
+
}
MyNetManager::~MyNetManager()
{
request.setUrl(qurl);
QNetworkReply* reply = m_pManager->get(request);
connect(reply,SIGNAL(readyRead()),this,SLOT(onKeepRelyfinished()));
+ connect(reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
+ [=](QNetworkReply::NetworkError e){
+ qDebug() << QString("onKeepConnectErr: %1\n").arg(e);
+ KeepDisconnect();
+ });
+
+
+
keep = reply;
- qDebug() << "keep:" << keep << endl;
+ qDebug() << "keep:" << keep;
//启动倒计数15秒
- keepTimer->start(15000);
+ disconnect(keepTimer,0,0,0);
+ connect(keepTimer, &QTimer::timeout, this, &MyNetManager::onKeepConnectTimeOut);
+ keepTimer->start(connect_over_time_seconds);
+
keepNetState = NET_CONNECTING;
qDebug() << "KeepConnect start...\n";
{
qDebug() << QString("KeepDisconnect\n");
+ //m_pManager->clearConnectionCache();
+ m_pManager->clearAccessCache();
+
keepNetState = NET_DISCONNECT;
keepTimer->stop();
+ disconnect(keepTimer,0,0,0);
if(keep == nullptr){
return true;
}
- qDebug() << QString("disconnect\n");
- disconnect(keep);
+
+ //qDebug() << QString("disconnect\n");
+ disconnect(keep,0,0,0);
+ /*
if(keep->isRunning()){
qDebug()<< "keepRelayErrProcess keep->isRunning() true" << endl;
}else{
keep->close();
qDebug() << QString("keep->abort()\n");
keep->abort();
+ */
qDebug() << QString("keep->deleteLater()\n");
keep->deleteLater();
- keep = nullptr;
+ //keep = nullptr;
+
return true;
}
void MyNetManager::onCapPicRelyfinished()
{
+ qDebug("onCapPicRelyfinished\n");
QDateTime dateTime;
dateTime = QDateTime::currentDateTime();
QString currentdatetime = dateTime.toString("yyyy_MM_dd hh_mm_ss");
return false;
}
+ reply->deleteLater();
return true;
}
void MyNetManager::keepRelayOkProcess(QNetworkReply *reply)
{
- qDebug() << "replay :" << reply << endl;
+ qDebug() << "reply :" << reply << endl;
if(keepNetState == NET_CONNECTING){
+ keepNetState = NET_CONNECTED;
qDebug() << "keepRelayOkProcess State == NET_CONNECTING\n" << endl;
qDebug()<<"operation:"<<reply->operation();
qDebug()<<"status code:"<<reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qDebug()<<"reply:"<<reply<< endl;
- //QByteArray bytes = reply->readAll();
- //qDebug() << bytes;
-
- keepNetState = NET_CONNECTED;
+ connect_over_time_seconds = 15000;
+ disconnect(keepTimer,0,0,0);
+ connect(keepTimer, &QTimer::timeout, this, &MyNetManager::onKeepTimerOverProcess);
keepTimer->start(11000);
qDebug() << "KeepConnect ok\n";
}else if(keepNetState == NET_CONNECTED){
- qDebug() << "keepRelayOkProcess State == NET_CONNECTED\n" << endl;
+ qDebug() << "keepRelayOkProcess State == NET_CONNECTED\n";
qDebug()<<"reply:"<<reply<< endl;
keepTimer->start(11000);
QByteArray bytes = reply->readAll();
if (qstr_byte.contains("Temperature Measurement Alarm"))
{
emit sigTempAlarm(1);
- qDebug() << "Temperature Measurement Alarm1\n" << endl;
+ qDebug() << "Temperature Measurement Alarm1\n";
}else{
qDebug() << "recv heart beat!\n";
}
{
Q_UNUSED(reply);
qDebug() << QString("keepRelayErrProcess\n");
- KeepDisconnect();
+ //当前处于连接状态,出错,需要告警
+ if(keepNetState == NET_CONNECTED){
+ emit sigKeepBrokeAlarm();
+ }
+
+ KeepDisconnect();
}
-void MyNetManager::keepTimerOverProcess()
+void MyNetManager::onKeepTimerOverProcess()
{
- qDebug() << "keepTimerOverProcess" << endl;
-
+ qDebug() << "onKeepTimerOverProcess\n";
//连接失败, 或者连接超时未接收到任何数据,告警
emit sigKeepBrokeAlarm();
KeepDisconnect();
}
+
+static uint32_t time_add(uint32_t t)
+{
+ float val = t * 1.5;
+ return (uint32_t)val;
+}
+
+void MyNetManager::onKeepConnectTimeOut()
+{
+ qDebug() << "onKeepConnectTimeOut\n";
+ connect_over_time_seconds = time_add(connect_over_time_seconds) ;
+ KeepDisconnect();
+}
+
+void MyNetManager::onKeepConnectFinished(QNetworkReply *reply)
+{
+ qDebug() << ">>onKeepConnectFinished:" << reply << endl;
+}
+