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/comm/process.cpp b/das-dn/comm/process.cpp index de8b7ad8..cf304b37 100644 --- a/das-dn/comm/process.cpp +++ b/das-dn/comm/process.cpp @@ -108,11 +108,7 @@ const BYTE crc16tableLo[] = { CProcess::CProcess() { int i; -#ifdef WIN32 - memset(&m_pid, NULL, sizeof(m_pid)); -#else m_pid = 0; -#endif m_nProcess = -1; m_nCurUnit = 0; m_bUnitLoop = FALSE; diff --git a/das-dn/comm/ycbw.cpp b/das-dn/comm/ycbw.cpp index f6ea5364..a5bbbc5f 100644 --- a/das-dn/comm/ycbw.cpp +++ b/das-dn/comm/ycbw.cpp @@ -52,8 +52,6 @@ void CYCBW::PushYCBW(unionCP56Time& st, int order, LONG value, BYTE qds, int uid #endif m_save++; m_save = m_save % DATABASE_YCBW_NUM; - - vLog(LOG_DEBUG, "push a ycbw value.\n"); } void CYCBW::DumpYCBW(void) diff --git a/das-dn/hostadsbf/hostadsbf.cpp b/das-dn/hostadsbf/hostadsbf.cpp index 42a125e2..32a62cd7 100644 --- a/das-dn/hostadsbf/hostadsbf.cpp +++ b/das-dn/hostadsbf/hostadsbf.cpp @@ -5,7 +5,7 @@ #include #define MAX_BLOCKF_SIZE 512 -#define DATA_BLOCK_BOUNDARY 1000 +#define DATA_BLOCK_BOUNDARY 400 #define REGISTER_DATA_TYPE_YC 1 #define REGISTER_DATA_TYPE_YM 2 @@ -15,8 +15,8 @@ #define ADSP_READ_ID 100 //读取文件及文件夹ID #define ADSP_READ_ID_FUNCCODE 0x03 //读取文件及文件夹ID功能码。 -#define ADSP_READ_ID_REGISTER_ADDRESS 150 //读取文件及文件夹ID寄存器地址。 -#define ADSP_READ_ID_REGISTER_LENGTH 9 //读取文件及文件夹ID寄存器长度。 +#define ADSP_READ_ID_REGISTER_ADDRESS 300 //读取文件及文件夹ID寄存器地址。 +#define ADSP_READ_ID_REGISTER_LENGTH 32 //读取文件及文件夹ID寄存器长度。 static datalen2mbaddrmap m_datalen2mbaddr_map; @@ -348,7 +348,7 @@ static bool publishhistoryLowSpeedData(const noPollConn* conn, const int uid, co static int ftpget(const char* remote, const char* local, const char* user, const char* pwd, const long timeout = 3, struct memory* chunk = NULL) { - //vLog(LOG_DEBUG, "start to get %s to local %s, with name: %s, and password: %s.\n", remote, local, user, pwd); + vLog(LOG_DEBUG, "start to get %s to local %s, with name: %s, and password: %s.\n", remote, local, user, pwd); curl_global_init(CURL_GLOBAL_ALL); CURL* curl = curl_easy_init(); @@ -388,6 +388,8 @@ static void* ryftp_process(void* param) char remotePath[128] = "Hard Disk2/data/rtdatalog"; char pathName[128] = "./"; + char processName[128]; + snprintf(processName, sizeof(processName), "%s", mbt->GetCurProcessName()); //配置远方路径 char* escaped_string = escape_char_in_string(mbt->m_remotePath, ' '); if (escaped_string == NULL) @@ -494,7 +496,7 @@ static void* ryftp_process(void* param) int result = ftpget(remote, name, user, password, 3, &chunk); if (result == CURLE_OK) { //成功,处理文件 - vLog(LOG_DEBUG, "get %s to local memory, with name: %s, and password: %s okay, and file length is: %d.\n", remote, user, password, chunk.size); + 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); ftpget_retry_count = 0; if (chunk.size <= (int)(sizeof(struRYDeviceData) << 5)) { vLog(LOG_DEBUG, "PLC文件生成未完成!\n"); @@ -597,7 +599,7 @@ static void* ryftp_process(void* param) mbt->m_lastReadDirNo++; } if (mbt->m_curStartDirNo <= mbt->m_lastReadDirNo && mbt->m_curStartFileNo <= mbt->m_lastReadFileNo) { - vLog(LOG_DEBUG, "a已读取完成所有未读的文件。\n"); + vLog(LOG_DEBUG, "%s a已读取完成所有未读的文件。\n", processName); mbt->m_bHaveUnReadFile = FALSE; } } @@ -617,7 +619,7 @@ static void* ryftp_process(void* param) bReadCurrentFile = FALSE; } } else if (result == CURLE_REMOTE_ACCESS_DENIED) { - vLog(LOG_DEBUG, "b已读取完成所有未读的文件。\n"); + vLog(LOG_DEBUG, "%s b已读取完成所有未读的文件。\n", processName); mbt->m_bHaveUnReadFile = FALSE; bReadCurrentFile = TRUE; } @@ -635,10 +637,10 @@ CHostADSBFProcess::CHostADSBFProcess() m_adsDatas[1].inuse = FALSE; m_adsDatas[2].inuse = FALSE; m_adsDatas[3].inuse = FALSE; - m_adsDatas[0].adsDataMemAddr = 99999; - m_adsDatas[1].adsDataMemAddr = 99999; - m_adsDatas[2].adsDataMemAddr = 99999; - m_adsDatas[3].adsDataMemAddr = 99999; + m_adsDatas[0].adsDataMemAddr = 65535; + m_adsDatas[1].adsDataMemAddr = 65535; + m_adsDatas[2].adsDataMemAddr = 65535; + m_adsDatas[3].adsDataMemAddr = 65535; m_localIp = "192.168.0.1"; //本机IP地址 m_localNetId = "192.168.0.1.1.1"; //本机IP地址 @@ -686,10 +688,10 @@ BOOLEAN CHostADSBFProcess::calc(void) m_adsDatas[1].inuse = FALSE; m_adsDatas[2].inuse = FALSE; m_adsDatas[3].inuse = FALSE; - m_adsDatas[0].adsDataMemAddr = 99999; - m_adsDatas[1].adsDataMemAddr = 99999; - m_adsDatas[2].adsDataMemAddr = 99999; - m_adsDatas[3].adsDataMemAddr = 99999; + m_adsDatas[0].adsDataMemAddr = 65535; + m_adsDatas[1].adsDataMemAddr = 65535; + m_adsDatas[2].adsDataMemAddr = 65535; + m_adsDatas[3].adsDataMemAddr = 65535; //需要给单元添加一个是否有ftp数据的标识 if (m_bHaveFTP) config.units[uid].state |= 0x20; //存在ftp标识 @@ -710,6 +712,7 @@ BOOLEAN CHostADSBFProcess::calc(void) pData = GetUnitYCParamByPoint(uid, n); if (pData[4] == 1) continue; registerAddr = MAKEWORD(pData[0], pData[1]); + vLog(LOG_DEBUG, "registerAddr is: %d\n", registerAddr); if (registerAddr < DATA_BLOCK_BOUNDARY) { if (!m_adsDatas[0].inuse) m_adsDatas[0].inuse = TRUE; @@ -802,24 +805,41 @@ 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}; + //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}; + if (m_turbine->IsConnected()) + { + if (!readDeviceState(*m_turbine)) + { +// delete m_turbine; +// m_turbine = NULL; +// m_turbine = new AdsDevice{m_remoteIp, AmsNetId(m_remoteNetId), m_remotePort}; + } + } if (m_bHaveFTP) { @@ -890,18 +910,36 @@ 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; } +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); + if ((uint16_t)state.ads >= ADSSTATE::ADSSTATE_MAXSTATES && (uint16_t)state.device >= ADSSTATE::ADSSTATE_MAXSTATES) + { + 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() { int uid = GetCurUnitID(); @@ -911,11 +949,46 @@ BOOLEAN CHostADSBFProcess::readFileID() BYTE buffer[1024]; BYTE *pData = buffer; - BYTE params[MAX_UNIT_POINT_PARAM_SIZE]; - BYTE* pParam = params; - pData = ((std::array)turbineData).data(); - WORD registerAddr = ADSP_READ_ID_REGISTER_ADDRESS; + WORD wPathInfoInvalid = (WORD)((pData[1] << 8) | pData[0]); pData += 2; + DWORD wCurrentFolderNo = (DWORD)(pData[3] << 24 | pData[2] << 16 | pData[1] << 8 | pData[0]); pData += 4; + DWORD wCurrentFileNo = (DWORD)(pData[3] << 24 | pData[2] << 16 | pData[1] << 8 | pData[0]); pData += 4; + DWORD wFirstFileNoInFolder = (DWORD)(pData[3] << 24 | pData[2] << 16 | pData[1] << 8 | pData[0]); pData += 4; + DWORD wFileCountInFolder = (DWORD)(pData[3] << 24 | pData[2] << 16 | pData[1] << 8 | pData[0]); pData += 4; + DWORD wFirstFolderNoRecoverable = (DWORD)(pData[3] << 24 | pData[2] << 16 | pData[1] << 8 | pData[0]); pData += 4; + DWORD wFirstFileNoRecoverable = (DWORD)(pData[3] << 24 | pData[2] << 16 | pData[1] << 8 | pData[0]); pData += 4; + + m_iv = wPathInfoInvalid; + if (m_iv) { + vLog(LOG_DEBUG, "路径信息无效\n"); + return FALSE; + } + //当前文件夹路径名 + m_currentDirNo = wCurrentFolderNo; + //当前文件夹下最后新文件 + m_currentFileNo = wCurrentFileNo; + //当前目录文件开始编号 + m_currentDirStartFileNo = wFirstFileNoInFolder; + + + m_curStartDirNo = m_currentDirNo; //当前开始目录 + m_curStartFileNo = m_currentFileNo; //当前开始文件 + //判断是否有要读取的文件 + if (m_curStartDirNo <= m_lastReadDirNo && m_curStartFileNo <= m_lastReadFileNo) + { + vLog(LOG_DEBUG, "不存在未读的文件。\n"); + m_bHaveUnReadFile = FALSE; + } + else + { + m_bHaveUnReadFile = TRUE; + int dir_count = m_curStartDirNo - m_lastReadDirNo + 1; + int file_count = m_curStartFileNo - m_lastReadFileNo; + vLog(LOG_DEBUG, "%s 总共有%d个目录的%d个文件未读取。\n", GetCurProcessName(), dir_count, file_count); + } + + vLog(LOG_DEBUG, "%s 最新文件夹编号: %ld, 最新文件名编号: %ld: 最新文件夹中第一个文件的编号: %ld\n", GetCurProcessName(), m_currentDirNo, m_currentFileNo, m_currentDirStartFileNo); + return TRUE; } diff --git a/das-dn/hostadsbf/hostadsbf.h b/das-dn/hostadsbf/hostadsbf.h index 634261f0..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,6 +75,7 @@ public: private: BOOLEAN calc(void); + BOOLEAN readDeviceState(const AdsDevice& route); BOOLEAN readRealData(void); BOOLEAN readFileID(void); }; diff --git a/das-dn/hostmodbustcpbf/host_modbus_tcp_bf.cpp b/das-dn/hostmodbustcpbf/host_modbus_tcp_bf.cpp index 1e1a3465..de3e92cf 100644 --- a/das-dn/hostmodbustcpbf/host_modbus_tcp_bf.cpp +++ b/das-dn/hostmodbustcpbf/host_modbus_tcp_bf.cpp @@ -1739,11 +1739,11 @@ BOOLEAN CHostModbusTcpBFProcess::OnReceiveIDData(CHostModbusTcpBFProcessItem *pI pBuf = pData; /* - 1)、路径信息是否有效 byte; + 1)、路径信息是否有效 byte; 2)、当前文件夹路径名的后缀 dint,按照顺序增加1(转字符串时在前补0); 3)、当前文件夹下最后新文件的编号 dint; 4)、当前文件夹下第一个文件的编号 dint; - 5)、当前文件夹下文件个数 dint; + 5)、当前文件夹下文件个数 dint; */ //路径有效性判断 int iv = ((pBuf[0] << 8) | pBuf[1]); pBuf += 2; diff --git a/das-dn/inc/process.h b/das-dn/inc/process.h index d737abab..d65fc99e 100644 --- a/das-dn/inc/process.h +++ b/das-dn/inc/process.h @@ -52,6 +52,7 @@ public: if (m_nProcess < 0 || m_nProcess >= PROCESSES_NUM) return NULL; return config.processes[m_nProcess].name; } + inline int GetCurID(void) const { return m_nProcess; diff --git a/das-dn/inc/ryFileDef.h b/das-dn/inc/ryFileDef.h index 43f413ee..7940948d 100644 --- a/das-dn/inc/ryFileDef.h +++ b/das-dn/inc/ryFileDef.h @@ -2,6 +2,7 @@ #define _RYFILE_DEFINE_H_ #include "zjdtypes.h" +#include #include #include diff --git a/das-dn/third_party/AdsLib/AdsDevice.cpp b/das-dn/third_party/AdsLib/AdsDevice.cpp index 3d8baaac..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 }; } @@ -143,8 +144,8 @@ long AdsDevice::GetLocalPort() const AdsDeviceState AdsDevice::GetState() const { - uint16_t state[2]; - if(m_Connected == true){ + uint16_t state[2] = {ADSSTATE_MAXSTATES, ADSSTATE_MAXSTATES}; + if (m_Connected == true) { auto error = AdsSyncReadStateReqEx(GetLocalPort(), &m_Addr, &state[0], &state[1]); if (error) { LOG_ERROR("AdsDevice can not read device state."); diff --git a/das-dn/third_party/AdsLib/Sockets.cpp b/das-dn/third_party/AdsLib/Sockets.cpp index 093ae267..2e272f39 100644 --- a/das-dn/third_party/AdsLib/Sockets.cpp +++ b/das-dn/third_party/AdsLib/Sockets.cpp @@ -126,7 +126,7 @@ Socket::Socket(const struct addrinfo* const host, const int type) if (SOCK_STREAM == type) { if (::connect(m_Socket, rp->ai_addr, rp->ai_addrlen)) { - LOG_WARN("Socket connect["<(rp->ai_addr)->sin_addr)) << "] timeout"); + LOG_WARN("Socket connect[" << std::string(inet_ntoa(reinterpret_cast(rp->ai_addr)->sin_addr)) << "] timeout"); closesocket(m_Socket); m_Socket = INVALID_SOCKET; continue; 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); } diff --git a/document/风电场数据采集系统使用手册.docx b/document/风电场数据采集系统使用手册.docx index f413e8b4..1b93911a 100644 Binary files a/document/风电场数据采集系统使用手册.docx and b/document/风电场数据采集系统使用手册.docx differ