update ads connect time

This commit is contained in:
zhouhuang 2024-12-11 20:25:29 +08:00
parent c4705541ea
commit 05b3f71b4e
2 changed files with 33 additions and 44 deletions

View File

@ -853,6 +853,7 @@ BOOLEAN CHostADSBFProcess::OnPreCreate(int id)
m_turbine = NULL; m_turbine = NULL;
m_bRouteAdded = FALSE; m_bRouteAdded = FALSE;
m_apdu_t0_begin = 10;
SetLocalAmsNetId(AmsNetId(m_localNetId)); SetLocalAmsNetId(AmsNetId(m_localNetId));
#if 0 #if 0
m_threadRun = TRUE; m_threadRun = TRUE;
@ -927,24 +928,16 @@ BOOLEAN CHostADSBFProcess::OnTimer(void)
} }
if (sec_changed) if (sec_changed)
{ {
if (m_turbine == NULL) { if (m_turbine == NULL)
#if 0
m_turbine = new AdsDevice{m_remoteIp, AmsNetId(m_remoteNetId), m_remotePort};
const auto state = m_turbine->GetState();
if ((uint16_t)state.ads >= ADSSTATE::ADSSTATE_MAXSTATES || (uint16_t)state.device >= ADSSTATE::ADSSTATE_MAXSTATES)
{ {
vLog(LOG_DEBUG, "read device state error.\n"); if ((m_apdu_t0_begin + 20) < system32.timers)
long ret = AddRemoteRoute(m_remoteIp, m_localNetId, m_localIp, std::string("isoftstone"), std::string("admin"), std::string("admin")); {
vLog(LOG_DEBUG, "bbb %s add route return value is: %d\n", m_pidName.c_str(), ret); m_apdu_t0_begin = system32.timers;
delete m_turbine;
m_turbine = NULL;
}
#else
//先添加一条路由 //先添加一条路由
if (m_bRouteAdded == FALSE) if (m_bRouteAdded == FALSE)
{ {
long ret = AddRemoteRoute(m_remoteIp, AmsNetId(m_localNetId), m_localIp, std::string("isoftstone"), std::string("admin"), std::string("admin")); long ret = AddRemoteRoute(m_remoteIp, AmsNetId(m_localNetId), m_localIp, std::string("isoftstone"), std::string("admin"), std::string("admin"));
vLog(LOG_DEBUG, "%s add route(%s to %s) return value is: %d\n", m_localIp.c_str(), m_remoteIp.c_str(), m_pidName.c_str(), ret); vLog(LOG_DEBUG, "%s add route(%s to %s) return value is: %d\n", m_pidName.c_str(), m_localIp.c_str(), m_remoteIp.c_str(), ret);
if (ret != 0) return TRUE; if (ret != 0) return TRUE;
} }
m_bRouteAdded = TRUE; m_bRouteAdded = TRUE;
@ -958,11 +951,11 @@ BOOLEAN CHostADSBFProcess::OnTimer(void)
delete m_turbine; delete m_turbine;
m_turbine = NULL; m_turbine = NULL;
} }
#endif }
return TRUE; return TRUE;
} }
if (!m_turbine->IsConnected()) return TRUE; if (!m_turbine->IsConnected()) return TRUE;
//try { m_apdu_t0_begin = system32.timers;
if (m_bHaveFTP) if (m_bHaveFTP)
{ //启动时读取一次,后面自己维护序号 { //启动时读取一次,后面自己维护序号
if ((m_currentDirNo == -1) && (m_currentFileNo == -1)) if ((m_currentDirNo == -1) && (m_currentFileNo == -1))
@ -972,11 +965,6 @@ BOOLEAN CHostADSBFProcess::OnTimer(void)
} }
readRealData(); readRealData();
FeedDog(); FeedDog();
// } catch (const AdsException& ex) {
// vLog(LOG_ERROR, "%s AdsException message: %s, remote is: %s:%d\n", m_pidName.c_str(), ex.what(), m_remoteIp.c_str(), m_remotePort);
// } catch (const std::runtime_error& ex) {
// vLog(LOG_ERROR, "%s %s\n", m_pidName.c_str(), ex.what());
// }
} }
return TRUE; return TRUE;
} }

View File

@ -46,6 +46,7 @@ private:
AdsDevice *m_turbine; AdsDevice *m_turbine;
BOOLEAN m_bRouteAdded; //路由是否添加成功 BOOLEAN m_bRouteAdded; //路由是否添加成功
DWORD m_apdu_t0_begin;
int m_total_length; int m_total_length;
DWORD last_sec; DWORD last_sec;