diff --git a/das-dn/hostadsbf/hostadsbf.cpp b/das-dn/hostadsbf/hostadsbf.cpp index 18003cd0..838ccf03 100644 --- a/das-dn/hostadsbf/hostadsbf.cpp +++ b/das-dn/hostadsbf/hostadsbf.cpp @@ -967,6 +967,7 @@ BOOLEAN CHostADSBFProcess::OnTimer(void) last_sec = system32.timers; sec_changed = TRUE; } + FeedDog(); if (sec_changed) { if (m_turbine == NULL) @@ -1021,7 +1022,6 @@ BOOLEAN CHostADSBFProcess::OnTimer(void) } } readRealData(); - FeedDog(); } return TRUE; } @@ -1032,6 +1032,7 @@ BOOLEAN CHostADSBFProcess::readFileID() if (uid < 0 || uid >= UNIT_NUM) return TRUE; vLog(LOG_DEBUG, "%s here read file info\n", m_pidName.c_str()); +#if 0 AdsVariable wPathInfoInvalid {*m_turbine, ".gwPathInfoInvalid"}; //vLog(LOG_DEBUG, "Read back with first value %d\n", (WORD)wPathInfoInvalid); AdsVariable wCurrentFolderNo {*m_turbine, ".gwCurrentFolderNo"}; @@ -1046,7 +1047,77 @@ BOOLEAN CHostADSBFProcess::readFileID() //vLog(LOG_DEBUG, "Read back with first value %d\n", (DWORD)wFirstFolderNoRecoverable); AdsVariable wFirstFileNoRecoverable {*m_turbine, ".gwFirstFileNoRecoverable"}; //vLog(LOG_DEBUG, "Read back with first value %d\n", (DWORD)wFirstFileNoRecoverable); - +#else + WORD wPathInfoInvalid; + myAdsVariable myPathInfoInvalid {*m_turbine, ".gwPathInfoInvalid"}; + if (!myPathInfoInvalid.Read(2, &wPathInfoInvalid)) + { + delete m_turbine; + m_turbine = NULL; + return TRUE; + } + + DWORD wCurrentFolderNo; + myAdsVariable myCurrentFolderNo {*m_turbine, ".gwCurrentFolderNo"}; + if (!myCurrentFolderNo.Read(4, &wCurrentFolderNo)) + { + vLog(LOG_ERROR, "Read .gwCurrentFolderNo error.\n"); + delete m_turbine; + m_turbine = NULL; + return TRUE; + } + + DWORD wCurrentFileNo; + myAdsVariable myCurrentFileNo {*m_turbine, ".gwCurrentFileNo"}; + if (!myCurrentFileNo.Read(4, &wCurrentFileNo)) + { + vLog(LOG_ERROR, "Read .gwCurrentFileNo error.\n"); + delete m_turbine; + m_turbine = NULL; + return TRUE; + } + + DWORD wFirstFileNoInFolder; + myAdsVariable myFirstFileNoInFolder {*m_turbine, ".gwFirstFileNoInFolder"}; + if (!myFirstFileNoInFolder.Read(4, &wFirstFileNoInFolder)) + { + vLog(LOG_ERROR, "Read .gwFirstFileNoInFolder error.\n"); + delete m_turbine; + m_turbine = NULL; + return TRUE; + } + + DWORD wFileCountInFolder; + myAdsVariable myFileCountInFolder {*m_turbine, ".gwFileCountInFolder"}; + if (!myFileCountInFolder.Read(4, &wFileCountInFolder)) + { + vLog(LOG_ERROR, "Read .gwFileCountInFolder error.\n"); + delete m_turbine; + m_turbine = NULL; + return TRUE; + } + + DWORD wFirstFolderNoRecoverable; + myAdsVariable myFirstFolderNoRecoverable {*m_turbine, ".gwFirstFolderNoRecoverable"}; + if (!myFirstFolderNoRecoverable.Read(4, &wFirstFolderNoRecoverable)) + { + vLog(LOG_ERROR, "Read .gwFirstFolderNoRecoverable error.\n"); + delete m_turbine; + m_turbine = NULL; + return TRUE; + } + + DWORD wFirstFileNoRecoverable; + myAdsVariable myse {*m_turbine, ".gwFirstFileNoRecoverable"}; + if (!myFirstFolderNoRecoverable.Read(4, &wFirstFileNoRecoverable)) + { + vLog(LOG_ERROR, "Read .gwFirstFileNoRecoverable error.\n"); + delete m_turbine; + m_turbine = NULL; + return TRUE; + } +#endif + m_iv = (WORD)wPathInfoInvalid; if (m_iv) { vLog(LOG_DEBUG, "路径信息无效\n"); @@ -1099,11 +1170,14 @@ BOOLEAN CHostADSBFProcess::readRealData() BYTE params[MAX_UNIT_POINT_PARAM_SIZE]; BYTE* pParam = params; - AdsVariable> turbineData {*m_turbine, ADSIGRP_IOIMAGE_RWOB, m_adsOverviewDataMemAddr}; - pData = ((std::array)turbineData).data(); - if (!m_turbine->IsConnected()) +// AdsVariable> turbineData {*m_turbine, ADSIGRP_IOIMAGE_RWOB, m_adsOverviewDataMemAddr}; +// pData = ((std::array)turbineData).data(); + myAdsVariable turbineData {*m_turbine, ADSIGRP_IOIMAGE_RWOB, m_adsOverviewDataMemAddr}; + if (!turbineData.Read(1024, buffer)) { vLog(LOG_ERROR, "%s Read data error\n", m_pidName.c_str()); + delete m_turbine; + m_turbine = NULL; return TRUE; } diff --git a/das-dn/hostadsbf/hostadsbf.h b/das-dn/hostadsbf/hostadsbf.h index b3c033ed..2b4c5d09 100644 --- a/das-dn/hostadsbf/hostadsbf.h +++ b/das-dn/hostadsbf/hostadsbf.h @@ -9,7 +9,52 @@ #include "AdsVariable.h" #include "RouterAccess.h" using namespace Beckhoff::Ads; -//using namespace bhf::ads; + +#include "AdsDevice.h" + +namespace Beckhoff +{ +namespace Ads +{ +struct myAdsVariable { + myAdsVariable(const AdsDevice& route, const std::string& symbolName) + : m_Route(route), + m_IndexGroup(ADSIGRP_SYM_VALBYHND), + m_Handle(route.GetHandle(symbolName)) + {} + + myAdsVariable(const AdsDevice& route, const uint32_t group, const uint32_t offset) + : m_Route(route), + m_IndexGroup(group), + m_Handle(route.GetHandle(offset)) + {} + + BOOLEAN Read(const size_t size, void* data) const + { + if (!m_Route.IsConnected()) return FALSE; + uint32_t bytesRead = 0; + auto error = m_Route.ReadReqEx2(m_IndexGroup, + *m_Handle, + size, + data, + &bytesRead); + + if (error || (size != bytesRead)) { + vLog(LOG_ERROR, "AdsVariable read failed: %d,%s\n", error, strerror(errno)); + return FALSE; + } + + return TRUE; + } + +private: + const AdsDevice& m_Route; + const uint32_t m_IndexGroup; + const AdsHandle m_Handle; +}; +} +} + typedef std::unordered_map register2typemap; diff --git a/das/pom.xml b/das/pom.xml index df873674..aea4ba76 100644 --- a/das/pom.xml +++ b/das/pom.xml @@ -44,9 +44,17 @@ spring-boot-starter-tomcat org.springframework.boot + + org.springframework.boot + spring-boot-starter-logging + - + + + org.springframework.boot + spring-boot-starter-log4j2 + org.springframework.boot diff --git a/das/src/main/java/com/das/modules/data/service/TDEngineService.java b/das/src/main/java/com/das/modules/data/service/TDEngineService.java index b8c09675..b0d66f3a 100644 --- a/das/src/main/java/com/das/modules/data/service/TDEngineService.java +++ b/das/src/main/java/com/das/modules/data/service/TDEngineService.java @@ -58,8 +58,8 @@ public class TDEngineService { config.setUsername(username); config.setPassword(password); config.setConnectionTestQuery("select server_status()"); - config.setMinimumIdle(10); //minimum number of idle connection - config.setMaximumPoolSize(20); //maximum number of connection in the pool + config.setMinimumIdle(30); //minimum number of idle connection + config.setMaximumPoolSize(30); //maximum number of connection in the pool config.setMaxLifetime(0); // maximum life time for each connection // config.setIdleTimeout(0); // max idle time for recycle idle connection log.info("=======>TDEngineUrl:" + config.getJdbcUrl()); @@ -89,7 +89,7 @@ public class TDEngineService { } sb.append(") TAGS (`deviceid` BIGINT);"); try { - log.info(sb.toString()); + log.debug(sb.toString()); pstmt.executeUpdate(sb.toString()); } catch (Exception e) { log.error("创建超级表失败", e); @@ -111,7 +111,7 @@ public class TDEngineService { sb.append(dataType); sb.append(") TAGS (`deviceid` BIGINT);"); try { - log.info(sb.toString()); + log.debug(sb.toString()); pstmt.executeUpdate(sb.toString()); } catch (Exception e) { log.error("创建[计算量]超级表失败", e); @@ -426,7 +426,7 @@ public class TDEngineService { } try { pstmt.executeUpdate(sb.toString()); - log.info("告警信息入库:{}",sb.toString()); + log.debug("告警信息入库:{}",sb.toString()); } catch (SQLException ex) { log.error("save deviceEvent error", ex); } diff --git a/das/src/main/java/com/das/modules/equipment/service/impl/SysEquipmentServiceImpl.java b/das/src/main/java/com/das/modules/equipment/service/impl/SysEquipmentServiceImpl.java index fb35ffc9..3674db33 100644 --- a/das/src/main/java/com/das/modules/equipment/service/impl/SysEquipmentServiceImpl.java +++ b/das/src/main/java/com/das/modules/equipment/service/impl/SysEquipmentServiceImpl.java @@ -529,8 +529,10 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { minioViewsServcie.uploadTemFile(minioAutoProperties.getPublicBucket(), scale, scaleParent); SysEquipmentDocs sysEquipmentDocs = new SysEquipmentDocs(); sysEquipmentDocs.setUrl(parent); + sysEquipmentDocs.setName(file.getOriginalFilename()); SysEquipmentDocs sysEquipmentDocsScale = new SysEquipmentDocs(); sysEquipmentDocsScale.setUrl(scaleParent); + sysEquipmentDocsScale.setName(file.getOriginalFilename()); result.add(sysEquipmentDocs); result.add(sysEquipmentDocsScale); } catch (Exception e) { diff --git a/das/src/main/java/com/das/modules/node/service/impl/NodeMessageServiceImpl.java b/das/src/main/java/com/das/modules/node/service/impl/NodeMessageServiceImpl.java index f8c5e684..e9e14da1 100644 --- a/das/src/main/java/com/das/modules/node/service/impl/NodeMessageServiceImpl.java +++ b/das/src/main/java/com/das/modules/node/service/impl/NodeMessageServiceImpl.java @@ -94,7 +94,10 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node @PostConstruct public void init() { //初始化高性能队列 - int cpu = Runtime.getRuntime().availableProcessors(); + int cpu = Runtime.getRuntime().availableProcessors() / 2; + if (cpu < 2) { + cpu = 2; + } int bufferSize = 1024 * 4; disruptor = new Disruptor<>(TerminalMessage::new, bufferSize, DaemonThreadFactory.INSTANCE, ProducerType.MULTI, new BlockingWaitStrategy()); // @@ -355,7 +358,7 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node // 使用 TypeReference 来指定转换目标类型 List list = objectMapper.convertValue(dataEvent, new TypeReference>() { }); - log.info("消息data转化deviceVo,{}", list); + log.debug("消息data转化deviceVo,{}", list); for (DeviceEventVo item : list) { DeviceInfoCache deviceInfoCache = cacheService.getEquipmentCache().getDeviceInfoCacheById(Long.valueOf(item.getDeviceId())); Integer firstTriggeredCode = adminRedisTemplate.get(String.format("RT:%s:%s", item.getDeviceId(), "FirstTriggeredCode".toLowerCase())); @@ -394,8 +397,8 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node deviceEventInfo.setEventText(item.getAttrCode() + fieldName + descList.get(1)); } Integer level = dataService.eventLevelMap.get(model).get(item.getAttrCode()); - log.info("level:{}", level); - log.info("fieldname{}", fieldName); + log.debug("level:{}", level); + log.debug("fieldname{}", fieldName); deviceEventInfo.setEventLevel(level == null ? 0 : level); } } else { @@ -445,7 +448,7 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node } ConcurrentWebSocketSessionDecorator concurrentWebSocketSessionDecorator = new ConcurrentWebSocketSessionDecorator(session, 5 * 1000, 2 * 1024 * 1024); onlineWSSessions.put(nodeId, concurrentWebSocketSessionDecorator); - + log.info("节点:{}已连接, IP: {}", nodeId, remoteIp); //如果采集程序的版本是0,则直接下发当前配置。 if (version == 0) { sendTerminalConfig(nodeId); @@ -482,7 +485,7 @@ public class NodeMessageServiceImpl extends TextWebSocketHandler implements Node @Override protected void handlePongMessage(WebSocketSession session, PongMessage message) throws Exception { Long nodeId = (Long) session.getAttributes().get(NodeConstant.NODE_ID); - log.info("收到 Node:{} Pong Message", nodeId); + log.debug("收到 Node:{} Pong Message", nodeId); session.getAttributes().put(NodeConstant.LAST_PONG_TIME, System.currentTimeMillis()); } diff --git a/das/src/main/resources/application-dev.yml b/das/src/main/resources/application-dev.yml index 62cbd474..bb481740 100644 --- a/das/src/main/resources/application-dev.yml +++ b/das/src/main/resources/application-dev.yml @@ -96,11 +96,18 @@ calc: task-name: logging: + file: + name: /das/logs/das.log level: com: - das: DEBUG + das: INFO tdengine: password: taosdata url: jdbc:TAOS-RS://192.168.109.187:6041/das - username: root \ No newline at end of file + username: root +minio: + url: http://192.168.109.187:9000 + bucket: das + accessKey: das + secretKey: zaq12WSX \ No newline at end of file diff --git a/das/src/main/resources/application.yml b/das/src/main/resources/application.yml index 2d60c655..cdd4455a 100644 --- a/das/src/main/resources/application.yml +++ b/das/src/main/resources/application.yml @@ -96,6 +96,8 @@ das: key: b6967ee87b86d85a logging: + file: + name: /das/logs/das.log level: root: ERROR com: