diff --git a/das-dn/cmg/ry.cpp b/das-dn/cmg/ry.cpp index 1f8f41dd..3c677639 100644 --- a/das-dn/cmg/ry.cpp +++ b/das-dn/cmg/ry.cpp @@ -1320,6 +1320,7 @@ BOOLEAN CRYDevice::processRyADSParam(const Json::Value jsonRoot, int pid) snprintf(config_config.processes[pid].option.ryads.ftp.remotePath, sizeof(config_config.processes[pid].option.ryads.ftp.remotePath), "%s", "/data/rtdatalog"); } + //目标地址 if (jsonRoot["targetAddr"].isInt()) { config_config.processes[pid].option.ryads.net.target_addr = jsonRoot["targetAddr"].asInt(); } else if (jsonRoot["targetAddr"].isString()) { @@ -1329,6 +1330,13 @@ BOOLEAN CRYDevice::processRyADSParam(const Json::Value jsonRoot, int pid) vLog(LOG_ERROR, "inet_pton error(%d,%s).\n", errno, strerror(errno)); } } + //端口 + if (jsonRoot["targetPort"].isInt()) { + config_config.processes[pid].option.ryads.net.target_port = jsonRoot["targetPort"].asInt(); + } else if (jsonRoot["targetPort"].isString()) { + config_config.processes[pid].option.ryads.net.target_port = atoi(jsonRoot["targetPort"].asCString()); + } + //本机地址 if (jsonRoot["bindAddr"].isInt()) { config_config.processes[pid].option.ryads.net.bind_addr = jsonRoot["bindAddr"].asInt(); } else if (jsonRoot["bindAddr"].isString()) { @@ -1912,7 +1920,15 @@ BOOLEAN CRYDevice::processHostADSPointParam(const Json::Value jsonRoot, int uid, BYTE dataType = (BYTE)jsonRoot["dataType"].asInt(); config_config.units[uid].ycs[point].m_param[2] = dataType; } else { - config_config.units[uid].ycs[point].m_param[2] = 0; + config_config.units[uid].ycs[point].m_param[2] = 9; //8位数据,占一个寄存器 + } + { + BYTE data_type = config_config.units[uid].ycs[point].m_param[2]; + if ((data_type == 5) || (data_type == 0) || (data_type == 1)) + { //浮点数 + config_config.units[uid].ycs[point].factor = 1000; + config_config.units[uid].ycs[point].coef = 0.001; + } } break; case POINT_TYPE_YM: diff --git a/das-dn/hostadsbf/hostadsbf.cpp b/das-dn/hostadsbf/hostadsbf.cpp index e14fbf75..ac768e47 100644 --- a/das-dn/hostadsbf/hostadsbf.cpp +++ b/das-dn/hostadsbf/hostadsbf.cpp @@ -804,26 +804,48 @@ BOOLEAN CHostADSBFProcess::OnPreCreate(int id) m_remoteNetId = m_nOptions.remoteNetId; #endif char ipaddress[32]; + + //本机IP和netid memset(ipaddress, '\0', sizeof(ipaddress)); inet_ntop(AF_INET, &m_nOptions.net.bind_addr, ipaddress, 16); m_localIp = std::string(ipaddress); m_localNetId = m_localIp + std::string(".1.1"); + //目标IP和netid memset(ipaddress, '\0', sizeof(ipaddress)); inet_ntop(AF_INET, &m_nOptions.net.target_addr, ipaddress, 16); m_remoteIp = std::string(ipaddress); m_remoteNetId = m_remoteIp + std::string(".1.1"); + //目标端口 + m_remotePort = m_nOptions.net.target_port; m_bHaveFTP = m_nOptions.bHaveFTP; calc(); vLog(LOG_DEBUG, "local ip is: %s, netid is: %s, remote ip is: %s, and netid is: %s\n", m_localIp.c_str(), m_localNetId.c_str(), m_remoteIp.c_str(), m_remoteNetId.c_str()); SetLocalAmsNetId(AmsNetId(m_localNetId)); + //192.168.0.231 addroute --addr=192.168.0.1 --netid=192.168.0.1.1.1 --password=1 --username=guest --routename=Testroute //AddRemoteRoute(m_remoteIp, m_localNetId, m_localIp, std::string("isoftstone"), std::string("guest"), std::string("1")); - - m_turbine = new AdsDevice{m_remoteIp, AmsNetId(m_remoteNetId), AMSPORT_R0_PLC_RTS1}; - readDeviceState(*m_turbine); + //m_remotePort + //m_turbine = new AdsDevice{m_remoteIp, AmsNetId(m_remoteNetId), AMSPORT_R0_PLC_RTS1}; + m_turbine = new AdsDevice{m_remoteIp, AmsNetId(m_remoteNetId), m_remotePort}; + vLog(LOG_DEBUG, "here.\n"); + if (m_turbine->IsConnected()) + { + vLog(LOG_DEBUG, "here...\n"); + if (!readDeviceState(*m_turbine)) + { + vLog(LOG_DEBUG, "m_turbine is: %lu\n", m_turbine); + delete m_turbine; + m_turbine = NULL; + m_turbine = new AdsDevice{m_remoteIp, AmsNetId(m_remoteNetId), m_remotePort}; + + vLog(LOG_DEBUG, "m_turbine is: %lu\n", m_turbine); + } + } + + vLog(LOG_DEBUG, "here.....\n"); if (m_bHaveFTP) { snprintf(m_user, sizeof(m_user), "%s", m_nOptions.ftp.user); @@ -893,19 +915,22 @@ BOOLEAN CHostADSBFProcess::OnTimer(void) } if (sec_changed) { - if (m_bHaveFTP) - { //启动时读取一次,后面自己维护序号 - if ((m_currentDirNo == -1) && (m_currentFileNo == -1)) - { //当前文件和目录都为-1,程序第一次启动。需要获取ftp目录及文件ID - readFileID(); + if (m_turbine->IsConnected()) + { + if (m_bHaveFTP) + { //启动时读取一次,后面自己维护序号 + if ((m_currentDirNo == -1) && (m_currentFileNo == -1)) + { //当前文件和目录都为-1,程序第一次启动。需要获取ftp目录及文件ID + readFileID(); + } } + readRealData(); } - readRealData(); } return TRUE; } -void CHostADSBFProcess::readDeviceState(const AdsDevice& route) +BOOLEAN CHostADSBFProcess::readDeviceState(const AdsDevice& route) { const auto state = route.GetState(); vLog(LOG_DEBUG, "ADS state: %d devState: %d\n", (uint16_t)state.ads, (uint16_t)state.device); @@ -913,7 +938,11 @@ void CHostADSBFProcess::readDeviceState(const AdsDevice& route) { vLog(LOG_DEBUG, "try to add a route to remote device.\n"); AddRemoteRoute(m_remoteIp, m_localNetId, m_localIp, std::string("isoftstone"), std::string("guest"), std::string("1")); + + return FALSE; } + + return TRUE; } BOOLEAN CHostADSBFProcess::readFileID() diff --git a/das-dn/hostadsbf/hostadsbf.h b/das-dn/hostadsbf/hostadsbf.h index 301363dd..06079774 100644 --- a/das-dn/hostadsbf/hostadsbf.h +++ b/das-dn/hostadsbf/hostadsbf.h @@ -53,6 +53,7 @@ public: char m_password[64]; char m_remotePath[128]; char m_localPath[128]; + WORD m_remotePort; //文件信息 int m_iv; @@ -74,7 +75,7 @@ public: private: BOOLEAN calc(void); - void readDeviceState(const AdsDevice& route); + BOOLEAN readDeviceState(const AdsDevice& route); BOOLEAN readRealData(void); BOOLEAN readFileID(void); }; diff --git a/das-dn/third_party/AdsLib/AdsDevice.cpp b/das-dn/third_party/AdsLib/AdsDevice.cpp index 3268bbdb..89c59a89 100644 --- a/das-dn/third_party/AdsLib/AdsDevice.cpp +++ b/das-dn/third_party/AdsLib/AdsDevice.cpp @@ -24,6 +24,7 @@ static AmsNetId* Connect(AmsNetId ams, const char* ip) return new AmsNetId { 0, 0, 0, 0, 1, 1 }; } + return new AmsNetId { ams }; } diff --git a/das-dn/third_party/AdsLib/Standalone/AdsLib.cpp b/das-dn/third_party/AdsLib/Standalone/AdsLib.cpp index 390214ef..052a322a 100644 --- a/das-dn/third_party/AdsLib/Standalone/AdsLib.cpp +++ b/das-dn/third_party/AdsLib/Standalone/AdsLib.cpp @@ -43,6 +43,7 @@ long ConnectTarget(const AmsNetId ams, const char* ip) void DisconnectTarget(const AmsNetId ams) { + fprintf(stderr, "%s-------------------\n", __func__); GetLocalAmsRouter().DisconnectTarget(ams); }