diff --git a/das-dn/hostadsbf/hostadsbf.cpp b/das-dn/hostadsbf/hostadsbf.cpp index 2d62d090..ea54c3e8 100644 --- a/das-dn/hostadsbf/hostadsbf.cpp +++ b/das-dn/hostadsbf/hostadsbf.cpp @@ -853,6 +853,7 @@ BOOLEAN CHostADSBFProcess::OnPreCreate(int id) m_turbine = NULL; m_bRouteAdded = FALSE; + m_apdu_t0_begin = 10; SetLocalAmsNetId(AmsNetId(m_localNetId)); #if 0 m_threadRun = TRUE; @@ -927,56 +928,43 @@ BOOLEAN CHostADSBFProcess::OnTimer(void) } if (sec_changed) { - 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) + if (m_turbine == NULL) + { + if ((m_apdu_t0_begin + 20) < system32.timers) { - vLog(LOG_DEBUG, "read device state error.\n"); - 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); - delete m_turbine; - m_turbine = NULL; + m_apdu_t0_begin = system32.timers; + //先添加一条路由 + if (m_bRouteAdded == FALSE) + { + 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_pidName.c_str(), m_localIp.c_str(), m_remoteIp.c_str(), ret); + if (ret != 0) return TRUE; + } + m_bRouteAdded = TRUE; + //添加成功 + vLog(LOG_DEBUG, "%s start to connect(%s:%d)\n", m_pidName.c_str(), m_remoteIp.c_str(), m_remotePort); + 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, "%s read device state error.\n", m_pidName.c_str()); + delete m_turbine; + m_turbine = NULL; + } } -#else - //先添加一条路由 - if (m_bRouteAdded == FALSE) - { - 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); - if (ret != 0) return TRUE; - } - m_bRouteAdded = TRUE; - //添加成功 - vLog(LOG_DEBUG, "%s start to connect(%s:%d)\n", m_pidName.c_str(), m_remoteIp.c_str(), m_remotePort); - 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, "%s read device state error.\n", m_pidName.c_str()); - delete m_turbine; - m_turbine = NULL; - } -#endif return TRUE; } if (!m_turbine->IsConnected()) return TRUE; - //try { - if (m_bHaveFTP) - { //启动时读取一次,后面自己维护序号 - if ((m_currentDirNo == -1) && (m_currentFileNo == -1)) - { //当前文件和目录都为-1,程序第一次启动。需要获取ftp目录及文件ID - readFileID(); - } + m_apdu_t0_begin = system32.timers; + if (m_bHaveFTP) + { //启动时读取一次,后面自己维护序号 + if ((m_currentDirNo == -1) && (m_currentFileNo == -1)) + { //当前文件和目录都为-1,程序第一次启动。需要获取ftp目录及文件ID + readFileID(); } - readRealData(); - 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()); -// } + } + readRealData(); + FeedDog(); } return TRUE; } diff --git a/das-dn/hostadsbf/hostadsbf.h b/das-dn/hostadsbf/hostadsbf.h index 8fd129ee..891537f4 100644 --- a/das-dn/hostadsbf/hostadsbf.h +++ b/das-dn/hostadsbf/hostadsbf.h @@ -46,6 +46,7 @@ private: AdsDevice *m_turbine; BOOLEAN m_bRouteAdded; //路由是否添加成功 + DWORD m_apdu_t0_begin; int m_total_length; DWORD last_sec;