This commit is contained in:
zhouhuang 2024-12-04 16:02:58 +08:00
parent 977a0a6499
commit 299c58c769
5 changed files with 60 additions and 12 deletions

View File

@ -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:

View File

@ -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_remotePort
//m_turbine = new AdsDevice{m_remoteIp, AmsNetId(m_remoteNetId), AMSPORT_R0_PLC_RTS1};
m_turbine = new AdsDevice{m_remoteIp, AmsNetId(m_remoteNetId), AMSPORT_R0_PLC_RTS1};
readDeviceState(*m_turbine);
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()

View File

@ -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);
};

View File

@ -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 };
}

View File

@ -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);
}