From 80eceabf9a67107e475367a84cc8246d2aa63a1c Mon Sep 17 00:00:00 2001 From: zhouhuang Date: Wed, 11 Dec 2024 13:33:15 +0800 Subject: [PATCH] update --- das-dn/cmg/ry.cpp | 25 +++---------------- das-dn/comm/public.cpp | 22 +++------------- das-dn/hostadsbf/hostadsbf.cpp | 10 +++++--- das-dn/hostmodbustcpbf/host_modbus_tcp_bf.cpp | 5 ++-- das-dn/rtustatusproc/rtustatus.cpp | 6 ++--- das-dn/third_party/AdsLib/Sockets.cpp | 4 +-- das-dn/third_party/AdsLib/Sockets.h | 2 +- 7 files changed, 23 insertions(+), 51 deletions(-) diff --git a/das-dn/cmg/ry.cpp b/das-dn/cmg/ry.cpp index ea52deac..4e471b60 100644 --- a/das-dn/cmg/ry.cpp +++ b/das-dn/cmg/ry.cpp @@ -2849,13 +2849,6 @@ bool CRYDevice::publishinitDeviceData(int uid) { if (uid < 0 || uid >= UNIT_NUM) return false; - if ((config.units[uid].state & 0x80) != 0x80) { - return false; - } - if ((config.units[uid].state & 0x40) == 0x40) { //该设备已经发送过初始化 - return false; - } - Json::Value root; Json::Value values; @@ -2882,7 +2875,6 @@ bool CRYDevice::publishinitDeviceData(int uid) root["deviceId"] = static_units[uid].deviceId; root["values"] = values; - config.units[uid].state |= 0x40; return publish_sensor_data("", "initDeviceData", root); } return false; @@ -2919,7 +2911,6 @@ bool CRYDevice::publishAnalogData(int uid) datatime *= 1000; root["dataTime"] = datatime; root["deviceId"] = static_units[uid].deviceId; -// root["isStore"] = config.units[uid].state & 0x20 ? false : true; if (values.size()) { root["values"] = values; @@ -3020,14 +3011,6 @@ bool CRYDevice::publishdeviceEventData(void) return FALSE; } -void CRYDevice::releaseAllUnits(void) -{ - for (int i = 0; i < UNIT_NUM; i++) { - if ((config.units[i].state & 0x01) != 0x01) continue; - config.units[i].state &= 0xBF; //0x40取反 - } -} - int CRYDevice::sendMsg(std::string sMessage) { if (NULL != m_ws && m_ws->getReadyState() == easywsclient::WebSocket::OPEN) @@ -3117,7 +3100,6 @@ BOOLEAN CRYDevice::ry_init(const char *host, const int port, const char *nodeId, snprintf(url, sizeof(url), "/node/%s/%s", m_nodeId, m_version); snprintf(cPort, sizeof(cPort), "%d", m_port); vLog(LOG_DEBUG, "%d here to connect:%s:%s.\n", __LINE__, m_host, cPort); - releaseAllUnits(); conn = nopoll_conn_new(ctx, m_host, cPort, NULL, url, NULL, NULL); g_conn = conn; } @@ -3222,7 +3204,6 @@ bool CRYDevice::ry_run(void) snprintf(url, sizeof(url), "/node/%s/%s", m_nodeId, m_version); snprintf(cPort, sizeof(cPort), "%d", m_port); vLog(LOG_DEBUG, "%d here to connect:%s:%s.\n", __LINE__, m_host, cPort); - releaseAllUnits(); conn = nopoll_conn_new(ctx, m_host, cPort, NULL, url, NULL, NULL); g_conn = conn; last_connect_sec = system32.timers; @@ -3240,7 +3221,7 @@ bool CRYDevice::ry_run(void) } } publishdeviceEventData(); - int i = 0; +// int i = 0; #if 1 for (int i = 0; i < UNIT_NUM; i++) { @@ -3249,8 +3230,8 @@ bool CRYDevice::ry_run(void) m_nCurUnit++; if (m_nCurUnit >= UNIT_NUM) m_nCurUnit = 0; #endif - if ((config.units[i].state & 0x01) != TRUE) break; - if (config.units[i].type != MASTER_UNIT) break; + if ((config.units[i].state & 0x01) != TRUE) continue; + if (config.units[i].type != MASTER_UNIT) continue; MakeYKFrame(i); MakeYTFrame(i); if (sec_changed) { diff --git a/das-dn/comm/public.cpp b/das-dn/comm/public.cpp index c5322338..166e494b 100644 --- a/das-dn/comm/public.cpp +++ b/das-dn/comm/public.cpp @@ -2315,25 +2315,11 @@ void* idle_process(void* param) config.units[i].softdog++; if (config.units[i].softdog > UNIT_WATCHDOG_TIME) { config.units[i].softdog = UNIT_WATCHDOG_TIME; - config.units[i].value = SPI_ON; + //config.units[i].value = SPI_ON; + config.units[i].value |= SPI_ON; } else { - config.units[i].value = SPI_OFF; - if ((config.units[i].state & 0x80) != 0x80) { - int j = 0; - for (j = 0; j < config.units[i].yxcount; j++) { - if ((config.units[i].yxs[j].qds & 0x80) == 0x80) break; - } - if (j < config.units[i].yxcount) { - continue; - } - for (j = 0; j < config.units[i].yccount; j++) { - if ((config.units[i].ycs[j].qds & 0x80) == 0x80) break; - } - if (j < config.units[i].yccount) { - continue; - } - config.units[i].state |= 0x80; - } + //config.units[i].value = SPI_OFF; + config.units[i].value &= ~SPI_ON; } } } diff --git a/das-dn/hostadsbf/hostadsbf.cpp b/das-dn/hostadsbf/hostadsbf.cpp index 6dbec090..1a0de13e 100644 --- a/das-dn/hostadsbf/hostadsbf.cpp +++ b/das-dn/hostadsbf/hostadsbf.cpp @@ -408,10 +408,9 @@ static void* ryftp_process(void* param) m_datalen2mbaddr_map.insert(datalen2mbaddrmap::value_type(m_datalen_mbaddr[i].address, i + 1)); } - int len = 0; //struRYDeviceData t_data; FIELDDES fields[1024]; - len = calcFields(fields); + calcFields(fields); //判断是否链接单元 int uid = mbt->GetUnitID(0); //默认只接一个设备 @@ -486,6 +485,7 @@ static void* ryftp_process(void* param) if (result == CURLE_OK) { //成功,处理文件 vLog(LOG_DEBUG, "%s get %s to local memory, with name: %s, and password: %s okay, and file length is: %d.\n", processName, remote, user, password, chunk.size); + config.units[uid].value &= ~0x02; ftpget_retry_count = 0; if (chunk.size <= (int)(sizeof(struRYDeviceData) << 5)) { vLog(LOG_DEBUG, "%s PLC文件生成未完成!\n", processName); @@ -602,6 +602,7 @@ static void* ryftp_process(void* param) mbt->m_iv = 0; mbt->m_currentDirNo = -1; mbt->m_currentFileNo = -1; + config.units[uid].value |= 0x02; // } //此处空闲读取未读的文件 if (mbt->m_bHaveUnReadFile) { @@ -934,11 +935,12 @@ BOOLEAN CHostADSBFProcess::OnTimer(void) if (m_bRouteAdded == FALSE) { long ret = AddRemoteRoute(m_remoteIp, m_localNetId, m_localIp, std::string("isoftstone"), std::string("admin"), std::string("admin")); - vLog(LOG_DEBUG, "%s add route return value is: %d\n", m_pidName.c_str(), ret); + 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) @@ -960,6 +962,7 @@ BOOLEAN CHostADSBFProcess::OnTimer(void) } } 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) { @@ -1066,6 +1069,7 @@ BOOLEAN CHostADSBFProcess::readRealData() DWORD nValue = 0; int point; + UnitFeedDog(uid); for (int i = 0; i < MAX_BLOCKF_SIZE;) { //vLog(LOG_DEBUG, "registerAddr is: %d\n", registerAddr); diff --git a/das-dn/hostmodbustcpbf/host_modbus_tcp_bf.cpp b/das-dn/hostmodbustcpbf/host_modbus_tcp_bf.cpp index a0454f3c..ae35dfe2 100644 --- a/das-dn/hostmodbustcpbf/host_modbus_tcp_bf.cpp +++ b/das-dn/hostmodbustcpbf/host_modbus_tcp_bf.cpp @@ -447,11 +447,10 @@ static void* ryftp_process(void* param) m_datalen2mbaddr_map.insert(datalen2mbaddrmap::value_type(m_datalen_mbaddr[i].address, i + 1)); } - int len = 0; //struRYDeviceData t_data; FIELDDES fields[1024]; - len = calcFields(fields); + calcFields(fields); //判断是否链接单元 int uid = mbt->GetUnitID(0); //默认只接一个设备 @@ -525,6 +524,7 @@ static void* ryftp_process(void* param) if (result == CURLE_OK) { //成功,处理文件 vLog(LOG_DEBUG, "%s get %s to local memory, with name: %s, and password: %s okay, and file length is: %d.\n", processName, remote, user, password, chunk.size); + config.units[uid].value &= ~0x02; ftpget_retry_count = 0; if (chunk.size <= (int)(sizeof(struRYDeviceData) << 5)) { vLog(LOG_DEBUG, "%s PLC文件生成未完成!\n", processName); @@ -641,6 +641,7 @@ static void* ryftp_process(void* param) mbt->m_iv = 0; mbt->m_currentDirNo = -1; mbt->m_currentFileNo = -1; + config.units[uid].value |= 0x02; // } //此处空闲读取未读的文件 if (mbt->m_bHaveUnReadFile) { diff --git a/das-dn/rtustatusproc/rtustatus.cpp b/das-dn/rtustatusproc/rtustatus.cpp index 99a4b976..fc3ca81b 100644 --- a/das-dn/rtustatusproc/rtustatus.cpp +++ b/das-dn/rtustatusproc/rtustatus.cpp @@ -52,11 +52,11 @@ BOOLEAN CRTUStatusProcess::OnTimer(void) for (i = 0; i < UNIT_NUM; i++) { //单元状态在idle_process中计算,此处刷新单元状态 - if (GetUnitYX(uid, i + PROCESSES_NUM) != config.units[i].value) + if (GetUnitYX(uid, i + PROCESSES_NUM) != (config.units[i].value & 0x01)) { - SetUnitSOE(uid, i + PROCESSES_NUM, config.units[i].value, system32.now); + SetUnitSOE(uid, i + PROCESSES_NUM, (config.units[i].value & 0x01), system32.now); } - SetUnitYX(uid, i + PROCESSES_NUM, config.units[i].value); //单元通讯中断,设置单元数据无效 + SetUnitYX(uid, i + PROCESSES_NUM, (config.units[i].value & 0x01)); //单元通讯中断,设置单元数据无效 } } UnitFeedDog(uid); diff --git a/das-dn/third_party/AdsLib/Sockets.cpp b/das-dn/third_party/AdsLib/Sockets.cpp index 5f3dd79b..3488877b 100644 --- a/das-dn/third_party/AdsLib/Sockets.cpp +++ b/das-dn/third_party/AdsLib/Sockets.cpp @@ -111,8 +111,8 @@ bool IpV4::operator==(const IpV4& ref) const return value == ref.value; } -Socket::Socket(const struct addrinfo* const host, const int type) - : m_WSAInitialized(!InitSocketLibrary()), +Socket::Socket(const struct addrinfo* const host, const int type) : + m_WSAInitialized(!InitSocketLibrary()), m_DestAddr(SOCK_DGRAM == type ? reinterpret_cast(&m_SockAddress) : nullptr), m_DestAddrLen(0), m_LastError(0), diff --git a/das-dn/third_party/AdsLib/Sockets.h b/das-dn/third_party/AdsLib/Sockets.h index 54224905..027fc99c 100644 --- a/das-dn/third_party/AdsLib/Sockets.h +++ b/das-dn/third_party/AdsLib/Sockets.h @@ -50,7 +50,7 @@ struct Socket { bool IsConnectedTo(const struct addrinfo* targetAddresses) const; protected: - bool m_Connected; + bool m_Connected; int m_WSAInitialized; int m_LastError; SOCKET m_Socket;