update ads

This commit is contained in:
zhouhuang 2024-12-30 17:20:28 +08:00
parent 1dd47ef259
commit 3990dd9e01
13 changed files with 172 additions and 1162 deletions

View File

@ -224,11 +224,11 @@ int main(int argc, char** argv)
int i, uid; int i, uid;
for (i = 0; i < PROCESSES_NUM; i++) for (i = 0; i < PROCESSES_NUM; i++)
{ {
if (config.processes[i].state == FALSE) break; if ((config.processes[i].state & 0x01) == FALSE) break;
} }
for (uid = 0; uid < UNIT_NUM; uid++) for (uid = 0; uid < UNIT_NUM; uid++)
{ {
if (config.units[uid].state == FALSE) break; if ((config.units[uid].state & 0x01) == FALSE) break;
} }
snprintf(config.processes[i].name, sizeof(config.processes[i].name), "%s", "本地调试"); snprintf(config.processes[i].name, sizeof(config.processes[i].name), "%s", "本地调试");

View File

@ -78,13 +78,15 @@ bool CRYDevice::configInitializeMemory(void)
config_config.hardware.ports[i].timeout = 1000; //1s config_config.hardware.ports[i].timeout = 1000; //1s
} }
for (i = 0; i < PROCESSES_NUM; i++) { for (i = 0; i < PROCESSES_NUM; i++) {
config_config.processes[i].softdog = 0; config_config.processes[i].real_softdog = 0;
config_config.processes[i].ftp_softdog = 0;
for (j = 0; j < PROCESS_UNIT_NUM; j++) { for (j = 0; j < PROCESS_UNIT_NUM; j++) {
config_config.processes[i].units[j] = -1; config_config.processes[i].units[j] = -1;
} }
} }
for (i = 0; i < UNIT_NUM; i++) { for (i = 0; i < UNIT_NUM; i++) {
config_config.units[i].softdog = 0; config_config.units[i].real_softdog = 0;
config_config.units[i].ftp_softdog = 0;
} }
return true; return true;
@ -2303,7 +2305,7 @@ bool CRYDevice::dealConfigFile(const Json::Value jsonRoot)
config_config.units[uid].irn = strtoll(id.c_str(), NULL, 10); config_config.units[uid].irn = strtoll(id.c_str(), NULL, 10);
config_config.units[uid].value = SPI_ON; config_config.units[uid].value = SPI_ON;
config_config.units[uid].softdog = UNIT_WATCHDOG_TIME; config_config.units[uid].real_softdog = UNIT_WATCHDOG_TIME;
config_config.units[uid].state = TRUE; config_config.units[uid].state = TRUE;
config_config.units[uid].type = MASTER_UNIT; config_config.units[uid].type = MASTER_UNIT;
config_config.units[uid].yxcount = yxs.size(); config_config.units[uid].yxcount = yxs.size();
@ -2558,7 +2560,7 @@ bool CRYDevice::dealConfigFile(const Json::Value jsonRoot)
break; break;
} }
config_config.units[sub_uid].value = SPI_ON; config_config.units[sub_uid].value = SPI_ON;
config_config.units[sub_uid].softdog = UNIT_WATCHDOG_TIME; config_config.units[sub_uid].real_softdog = UNIT_WATCHDOG_TIME;
config_config.units[sub_uid].state = TRUE; config_config.units[sub_uid].state = TRUE;
config_config.units[sub_uid].type = SLAVER_UNIT; config_config.units[sub_uid].type = SLAVER_UNIT;
config_config.units[sub_uid].yxcount = attrs.yxs.size(); config_config.units[sub_uid].yxcount = attrs.yxs.size();
@ -2826,8 +2828,11 @@ void CRYDevice::heart_beat(int status)
snprintf(linkId, sizeof(linkId), "%lld", config.processes[i].irn); snprintf(linkId, sizeof(linkId), "%lld", config.processes[i].irn);
#endif #endif
jsonValue["linkId"] = linkId; jsonValue["linkId"] = linkId;
jsonValue["online"] = (config.processes[i].softdog >= PROCESS_WATCHDOG_TIME) ? false : true; jsonValue["online"] = (config.processes[i].real_softdog >= PROCESS_WATCHDOG_TIME) ? false : true;
//vLog(LOG_DEBUG, "link %s, %d\n", linkId, (config.processes[i].softdog >= PROCESS_WATCHDOG_TIME) ? 0 : 1); jsonValue["real"] = (config.processes[i].real_softdog >= PROCESS_WATCHDOG_TIME) ? false : true;
if (config.processes[i].state & 0x20) {
jsonValue["ftp"] = (config.processes[i].real_softdog >= PROCESS_WATCHDOG_TIME) ? false : true;
}
jsonLink.append(jsonValue); jsonLink.append(jsonValue);
} }
} }
@ -2846,13 +2851,11 @@ void CRYDevice::heart_beat(int status)
snprintf(deviceId, sizeof(deviceId), "%lld", config.units[i].irn); snprintf(deviceId, sizeof(deviceId), "%lld", config.units[i].irn);
#endif #endif
jsonValue["deviceId"] = deviceId; jsonValue["deviceId"] = deviceId;
jsonValue["online"] = (config.units[i].softdog >= PROCESS_WATCHDOG_TIME) ? false : true; jsonValue["online"] = (config.units[i].real_softdog >= UNIT_WATCHDOG_TIME) ? false : true;
//vLog(LOG_DEBUG, "unit %s, %d\n", deviceId, (config.units[i].softdog >= PROCESS_WATCHDOG_TIME) ? 0 : 1);
jsonDevice.append(jsonValue); jsonDevice.append(jsonValue);
} }
} }
if (jsonLink.size() > 0) { if (jsonLink.size() > 0) {
//vLog(LOG_DEBUG, "device is: %d\n", jsonDevice.size());
payload["devices"] = jsonDevice; payload["devices"] = jsonDevice;
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,7 @@
#define ADSP_READ_ID_REGISTER_ADDRESS 300 //读取文件及文件夹ID寄存器地址。 #define ADSP_READ_ID_REGISTER_ADDRESS 300 //读取文件及文件夹ID寄存器地址。
#define ADSP_READ_ID_REGISTER_LENGTH 32 //读取文件及文件夹ID寄存器长度。 #define ADSP_READ_ID_REGISTER_LENGTH 32 //读取文件及文件夹ID寄存器长度。
#define vLog(...)
static datalen2mbaddrmap m_datalen2mbaddr_map; static datalen2mbaddrmap m_datalen2mbaddr_map;
static struDataLengthADSAddr m_datalen_adsaddr[] = { static struDataLengthADSAddr m_datalen_adsaddr[] = {
{ 2, 421, 0.1 }, { 2, 421, 0.1 },
@ -493,6 +493,8 @@ static void* ryftp_process(void* param)
while (TRUE) { while (TRUE) {
sleep(1); //每秒执行一次 sleep(1); //每秒执行一次
if (!mbt->m_bFtpRun) break; if (!mbt->m_bFtpRun) break;
mbt->FeedFTPDog();
//ftp获取文件 //ftp获取文件
if (mbt->m_iv == 1) { if (mbt->m_iv == 1) {
//文件目录无效 //文件目录无效
@ -527,8 +529,8 @@ static void* ryftp_process(void* param)
} }
struRYDeviceData *data = (struRYDeviceData *)chunk.response; struRYDeviceData *data = (struRYDeviceData *)chunk.response;
int uid = mbt->GetCurUnitID(); int uid = mbt->GetCurUnitID();
mbt->UnitFeedFTPDog(uid);
for (int i = 0; i < 250; i++, data++) { //每个文件有250个数据块 for (int i = 0; i < 250; i++, data++) { //每个文件有250个数据块
QLONG unix_time = filetime_to_unix(data->localtime); QLONG unix_time = filetime_to_unix(data->localtime);
DWORD localtime = ((unix_time / 1000) - 28800L); DWORD localtime = ((unix_time / 1000) - 28800L);
@ -711,12 +713,6 @@ CHostADSBFProcess::~CHostADSBFProcess()
pthread_join(m_cpid, NULL); pthread_join(m_cpid, NULL);
vLog(LOG_DEBUG, "child protocol thread [%s] is destroyed.\n", (name[0] != '\0') ? name : "unknow"); vLog(LOG_DEBUG, "child protocol thread [%s] is destroyed.\n", (name[0] != '\0') ? name : "unknow");
} }
#if 0
if (m_threadRun) {
m_threadRun = FALSE;
m_startup.join();
}
#endif
} }
BOOLEAN CHostADSBFProcess::calc(void) BOOLEAN CHostADSBFProcess::calc(void)
@ -734,8 +730,6 @@ BOOLEAN CHostADSBFProcess::calc(void)
m_adsDatas[1].adsDataMemAddr = 65535; m_adsDatas[1].adsDataMemAddr = 65535;
m_adsDatas[2].adsDataMemAddr = 65535; m_adsDatas[2].adsDataMemAddr = 65535;
m_adsDatas[3].adsDataMemAddr = 65535; m_adsDatas[3].adsDataMemAddr = 65535;
//需要给单元添加一个是否有ftp数据的标识
if (m_bHaveFTP) config.units[uid].state |= 0x20; //存在ftp标识
int yccount, ymcount, yxcount; int yccount, ymcount, yxcount;
yccount = GetUnitYCCount(uid); yccount = GetUnitYCCount(uid);
@ -830,33 +824,6 @@ BOOLEAN CHostADSBFProcess::calc(void)
return TRUE; return TRUE;
} }
void CHostADSBFProcess::tryStartup()
{
m_turbine = NULL;
pthread_setname_np(pthread_self(), m_pidName.c_str());
while (m_threadRun) {
if (m_turbine == NULL) {
SetLocalAmsNetId(AmsNetId(m_localNetId));
m_turbine = new AdsDevice{m_remoteIp, AmsNetId(m_remoteNetId), m_remotePort};
const auto state = m_turbine->GetState();
vLog(LOG_DEBUG, "%s ADS state: %d devState: %d\n", m_pidName.c_str(), (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, "read device state error.\n");
long ret = AddRemoteRoute(m_remoteIp, m_localNetId, m_localIp, std::string("isoftstone"), std::string("admin"), std::string("admin"));
vLog(LOG_DEBUG, "bbb %s add route return value is: %d\n", m_pidName.c_str(), ret);
delete m_turbine;
m_turbine = NULL;
}
} else {
if (m_turbine->IsConnected()) continue;
delete m_turbine;
m_turbine = NULL;
}
sleep(5);
}
}
BOOLEAN CHostADSBFProcess::OnPreCreate(int id) BOOLEAN CHostADSBFProcess::OnPreCreate(int id)
{ {
if (!CProcess::OnPreCreate(id)) return FALSE; if (!CProcess::OnPreCreate(id)) return FALSE;
@ -887,6 +854,14 @@ BOOLEAN CHostADSBFProcess::OnPreCreate(int id)
m_adsPassword = std::string(m_nOptions.password); m_adsPassword = std::string(m_nOptions.password);
m_bHaveFTP = m_nOptions.bHaveFTP; m_bHaveFTP = m_nOptions.bHaveFTP;
//需要给单元添加一个是否有ftp数据的标识
int uid = GetCurUnitID();
if (uid < 0 || uid >= UNIT_NUM) return FALSE;
if (m_bHaveFTP) {
config.units[uid].state |= 0x20; //存在ftp标识
config.processes[id].state |= 0x20;
}
calc(); calc();
//vLog(LOG_DEBUG, "%s local ip is: %s, netid is: %s, remote ip is: %s, and netid is: %s\n", m_pidName.c_str(), m_localIp.c_str(), m_localNetId.c_str(), m_remoteIp.c_str(), m_remoteNetId.c_str()); //vLog(LOG_DEBUG, "%s local ip is: %s, netid is: %s, remote ip is: %s, and netid is: %s\n", m_pidName.c_str(), m_localIp.c_str(), m_localNetId.c_str(), m_remoteIp.c_str(), m_remoteNetId.c_str());
@ -896,10 +871,7 @@ BOOLEAN CHostADSBFProcess::OnPreCreate(int id)
m_connect_count = 0; m_connect_count = 0;
m_apdu_t0_begin = 10; m_apdu_t0_begin = 10;
SetLocalAmsNetId(AmsNetId(m_localNetId)); SetLocalAmsNetId(AmsNetId(m_localNetId));
#if 0
m_threadRun = TRUE;
m_startup = std::thread(&CHostADSBFProcess::tryStartup, this);
#endif
if (m_bHaveFTP) if (m_bHaveFTP)
{ {
snprintf(m_user, sizeof(m_user), "%s", m_nOptions.ftp.user); snprintf(m_user, sizeof(m_user), "%s", m_nOptions.ftp.user);
@ -967,24 +939,32 @@ BOOLEAN CHostADSBFProcess::OnTimer(void)
last_sec = system32.timers; last_sec = system32.timers;
sec_changed = TRUE; sec_changed = TRUE;
} }
FeedDog(); FeedDog();
if (sec_changed) if (sec_changed)
{ {
//if (GetCurID() == 52) fprintf(stderr, "here second changed m_turbine is: %lu\n", m_turbine);
if (m_turbine == NULL) if (m_turbine == NULL)
{ {
if ((m_apdu_t0_begin + 20) < system32.timers) if ((m_apdu_t0_begin + 20) < system32.timers)
{ {
//if (GetCurID() == 52) fprintf(stderr, "here apdu t0 timeout, start to connect\n");
m_apdu_t0_begin = system32.timers; m_apdu_t0_begin = system32.timers;
//先添加一条路由 //先添加一条路由
if (m_bRouteAdded == FALSE) if (m_bRouteAdded == FALSE)
{ {
//if (GetCurID() == 52) fprintf(stderr, "here route not add, start to add a route: %s to %s\n", m_localIp.c_str(), m_remoteIp.c_str());
long ret = AddRemoteRoute(m_remoteIp, AmsNetId(m_localNetId), m_localIp, std::string("isoftstone"), m_adsUser, m_adsPassword); long ret = AddRemoteRoute(m_remoteIp, AmsNetId(m_localNetId), m_localIp, std::string("isoftstone"), m_adsUser, m_adsPassword);
//if (GetCurID() == 52) fprintf(stderr, "here add route return value is: %d\n", ret);
vLog(LOG_DEBUG, "%s add route(%s to %s) with remote user name: %s, and remote password: %s, return value is: %d\n", m_pidName.c_str(), m_localIp.c_str(), m_remoteIp.c_str(), m_adsUser.c_str(), m_adsPassword.c_str(), ret); vLog(LOG_DEBUG, "%s add route(%s to %s) with remote user name: %s, and remote password: %s, return value is: %d\n", m_pidName.c_str(), m_localIp.c_str(), m_remoteIp.c_str(), m_adsUser.c_str(), m_adsPassword.c_str(), ret);
if (ret != 0) return TRUE; if (ret != 0) return TRUE;
} }
//添加成功 //添加成功
//if (GetCurID() == 52) fprintf(stderr, "here start to connect(%s:%d)\n", m_remoteIp.c_str(), m_remotePort);
vLog(LOG_DEBUG, "%s start to connect(%s:%d)\n", m_pidName.c_str(), m_remoteIp.c_str(), m_remotePort); 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}; m_turbine = new AdsDevice{m_remoteIp, AmsNetId(m_remoteNetId), m_remotePort};
//if (GetCurID() == 52) fprintf(stderr, "here start to get device state\n");
const auto state = m_turbine->GetState(); const auto state = m_turbine->GetState();
if ((uint16_t)state.ads >= ADSSTATE::ADSSTATE_MAXSTATES || (uint16_t)state.device >= ADSSTATE::ADSSTATE_MAXSTATES) if ((uint16_t)state.ads >= ADSSTATE::ADSSTATE_MAXSTATES || (uint16_t)state.device >= ADSSTATE::ADSSTATE_MAXSTATES)
{ {
@ -1003,7 +983,7 @@ BOOLEAN CHostADSBFProcess::OnTimer(void)
{ {
vLog(LOG_DEBUG, "%s device not connected.\n", m_pidName.c_str()); vLog(LOG_DEBUG, "%s device not connected.\n", m_pidName.c_str());
m_connect_count++; m_connect_count++;
if (m_connect_count >= 10) //if (m_connect_count >= 10)
{ {
m_connect_count = 10; m_connect_count = 10;
m_bRouteAdded = FALSE; m_bRouteAdded = FALSE;
@ -1051,6 +1031,7 @@ BOOLEAN CHostADSBFProcess::readFileID()
myAdsVariable myPathInfoInvalid {*m_turbine, ".gwPathInfoInvalid"}; myAdsVariable myPathInfoInvalid {*m_turbine, ".gwPathInfoInvalid"};
if (!myPathInfoInvalid.Read(2, &wPathInfoInvalid)) if (!myPathInfoInvalid.Read(2, &wPathInfoInvalid))
{ {
m_bRouteAdded = FALSE;
delete m_turbine; delete m_turbine;
m_turbine = NULL; m_turbine = NULL;
return TRUE; return TRUE;
@ -1061,6 +1042,7 @@ BOOLEAN CHostADSBFProcess::readFileID()
if (!myCurrentFolderNo.Read(4, &wCurrentFolderNo)) if (!myCurrentFolderNo.Read(4, &wCurrentFolderNo))
{ {
vLog(LOG_ERROR, "Read .gwCurrentFolderNo error.\n"); vLog(LOG_ERROR, "Read .gwCurrentFolderNo error.\n");
m_bRouteAdded = FALSE;
delete m_turbine; delete m_turbine;
m_turbine = NULL; m_turbine = NULL;
return TRUE; return TRUE;
@ -1071,6 +1053,7 @@ BOOLEAN CHostADSBFProcess::readFileID()
if (!myCurrentFileNo.Read(4, &wCurrentFileNo)) if (!myCurrentFileNo.Read(4, &wCurrentFileNo))
{ {
vLog(LOG_ERROR, "Read .gwCurrentFileNo error.\n"); vLog(LOG_ERROR, "Read .gwCurrentFileNo error.\n");
m_bRouteAdded = FALSE;
delete m_turbine; delete m_turbine;
m_turbine = NULL; m_turbine = NULL;
return TRUE; return TRUE;
@ -1081,6 +1064,7 @@ BOOLEAN CHostADSBFProcess::readFileID()
if (!myFirstFileNoInFolder.Read(4, &wFirstFileNoInFolder)) if (!myFirstFileNoInFolder.Read(4, &wFirstFileNoInFolder))
{ {
vLog(LOG_ERROR, "Read .gwFirstFileNoInFolder error.\n"); vLog(LOG_ERROR, "Read .gwFirstFileNoInFolder error.\n");
m_bRouteAdded = FALSE;
delete m_turbine; delete m_turbine;
m_turbine = NULL; m_turbine = NULL;
return TRUE; return TRUE;
@ -1091,6 +1075,7 @@ BOOLEAN CHostADSBFProcess::readFileID()
if (!myFileCountInFolder.Read(4, &wFileCountInFolder)) if (!myFileCountInFolder.Read(4, &wFileCountInFolder))
{ {
vLog(LOG_ERROR, "Read .gwFileCountInFolder error.\n"); vLog(LOG_ERROR, "Read .gwFileCountInFolder error.\n");
m_bRouteAdded = FALSE;
delete m_turbine; delete m_turbine;
m_turbine = NULL; m_turbine = NULL;
return TRUE; return TRUE;
@ -1101,6 +1086,7 @@ BOOLEAN CHostADSBFProcess::readFileID()
if (!myFirstFolderNoRecoverable.Read(4, &wFirstFolderNoRecoverable)) if (!myFirstFolderNoRecoverable.Read(4, &wFirstFolderNoRecoverable))
{ {
vLog(LOG_ERROR, "Read .gwFirstFolderNoRecoverable error.\n"); vLog(LOG_ERROR, "Read .gwFirstFolderNoRecoverable error.\n");
m_bRouteAdded = FALSE;
delete m_turbine; delete m_turbine;
m_turbine = NULL; m_turbine = NULL;
return TRUE; return TRUE;
@ -1111,6 +1097,7 @@ BOOLEAN CHostADSBFProcess::readFileID()
if (!myFirstFolderNoRecoverable.Read(4, &wFirstFileNoRecoverable)) if (!myFirstFolderNoRecoverable.Read(4, &wFirstFileNoRecoverable))
{ {
vLog(LOG_ERROR, "Read .gwFirstFileNoRecoverable error.\n"); vLog(LOG_ERROR, "Read .gwFirstFileNoRecoverable error.\n");
m_bRouteAdded = FALSE;
delete m_turbine; delete m_turbine;
m_turbine = NULL; m_turbine = NULL;
return TRUE; return TRUE;
@ -1174,6 +1161,7 @@ BOOLEAN CHostADSBFProcess::readRealData()
if (!turbineData.Read(1024, buffer)) if (!turbineData.Read(1024, buffer))
{ {
vLog(LOG_ERROR, "%s Read data error\n", m_pidName.c_str()); vLog(LOG_ERROR, "%s Read data error\n", m_pidName.c_str());
m_bRouteAdded = FALSE;
delete m_turbine; delete m_turbine;
m_turbine = NULL; m_turbine = NULL;
return TRUE; return TRUE;

View File

@ -99,9 +99,6 @@ private:
int m_total_length; int m_total_length;
DWORD last_sec; DWORD last_sec;
BOOLEAN m_threadRun;
std::thread m_startup;
void tryStartup();
struADSData m_adsDatas[4]; struADSData m_adsDatas[4];
public: public:

View File

@ -498,6 +498,8 @@ static void* ryftp_process(void* param)
while (TRUE) { while (TRUE) {
sleep(1); //每秒执行一次 sleep(1); //每秒执行一次
if (!mbt->m_bFtpRun) break; if (!mbt->m_bFtpRun) break;
mbt->FeedFTPDog();
//ftp获取文件 //ftp获取文件
if (mbt->m_iv == 1) { if (mbt->m_iv == 1) {
//文件目录无效 //文件目录无效
@ -532,8 +534,8 @@ static void* ryftp_process(void* param)
} }
struRYDeviceData *data = (struRYDeviceData *)chunk.response; struRYDeviceData *data = (struRYDeviceData *)chunk.response;
int uid = mbt->GetCurUnitID(); int uid = mbt->GetCurUnitID();
mbt->UnitFeedFTPDog(uid);
for (int i = 0; i < 250; i++, data++) { //每个文件有250个数据块 for (int i = 0; i < 250; i++, data++) { //每个文件有250个数据块
QLONG unix_time = filetime_to_unix(data->localtime); QLONG unix_time = filetime_to_unix(data->localtime);
DWORD localtime = ((unix_time / 1000) - 28800L); DWORD localtime = ((unix_time / 1000) - 28800L);
@ -867,12 +869,13 @@ void CHostModbusTcpBFProcess::calc2(void)
uid = pItem->GetUnitID(); uid = pItem->GetUnitID();
if (uid < 0 || uid >= UNIT_NUM) continue; if (uid < 0 || uid >= UNIT_NUM) continue;
//需要给单元添加一个是否有ftp数据的标识
if (m_bHaveFTP) config.units[uid].state |= 0x20; //存在ftp标识
if (GetUnitAddr(uid, &addr, 1)) if (GetUnitAddr(uid, &addr, 1))
{ //获取单元地址成功,则该段原地址采用配置地址,否则该单元为无效地址。 { //获取单元地址成功,则该段原地址采用配置地址,否则该单元为无效地址。
pItem->m_addr = addr; pItem->m_addr = addr;
} }
//需要给单元添加一个是否有ftp数据的标识
if (m_bHaveFTP) config.units[uid].state |= 0x20; //存在ftp标识
struModbusExtFrame ycframes[MODBUS_RTU_AUTOMATIC_FRAME]; struModbusExtFrame ycframes[MODBUS_RTU_AUTOMATIC_FRAME];
struModbusExtFrame ymframes[MODBUS_RTU_AUTOMATIC_FRAME]; struModbusExtFrame ymframes[MODBUS_RTU_AUTOMATIC_FRAME];
@ -1130,6 +1133,11 @@ BOOLEAN CHostModbusTcpBFProcess::OnPreCreate(int id)
m_bHaveFTP = m_nOptions.bHaveFTP; m_bHaveFTP = m_nOptions.bHaveFTP;
m_nTimeout = 200; m_nTimeout = 200;
//需要给单元添加一个是否有ftp数据的标识
if (m_bHaveFTP)
{
config.processes[id].state |= 0x20;
}
calc2(); calc2();
if (m_bHaveFTP) if (m_bHaveFTP)

View File

@ -44,7 +44,15 @@ public:
inline void FeedDog(void) inline void FeedDog(void)
{ {
if (m_nProcess < 0 || m_nProcess >= PROCESSES_NUM) return; if (m_nProcess < 0 || m_nProcess >= PROCESSES_NUM) return;
config.processes[m_nProcess].softdog = 0; //config.processes[m_nProcess].softdog = 0;
config.processes[m_nProcess].real_softdog = 0;
}
inline void FeedFTPDog(void)
{
if (m_nProcess < 0 || m_nProcess >= PROCESSES_NUM) return;
//config.processes[m_nProcess].softdog = 0;
config.processes[m_nProcess].ftp_softdog = 0;
} }
inline char* GetCurProcessName(void) const inline char* GetCurProcessName(void) const
@ -134,7 +142,12 @@ public:
inline void UnitFeedDog(int uid) inline void UnitFeedDog(int uid)
{ {
if (uid < 0 || uid >= UNIT_NUM) return; if (uid < 0 || uid >= UNIT_NUM) return;
config.units[uid].softdog = 0; config.units[uid].real_softdog = 0;
}
inline void UnitFeedFTPDog(int uid)
{
if (uid < 0 || uid >= UNIT_NUM) return;
config.units[uid].ftp_softdog = 0;
} }
inline int GetUnitYXCount(int uid) const inline int GetUnitYXCount(int uid) const

View File

@ -94,8 +94,8 @@ typedef int SOCKET;
#define DATABASE_YT_LOG_NUM 1024 #define DATABASE_YT_LOG_NUM 1024
#define DATABASE_CTRL_LOG_NUM 1024 #define DATABASE_CTRL_LOG_NUM 1024
#define DATABASE_LIMIT_NUM 1024 #define DATABASE_LIMIT_NUM 1024
#define PROCESS_WATCHDOG_TIME 90 #define PROCESS_WATCHDOG_TIME 60
#define UNIT_WATCHDOG_TIME 180 #define UNIT_WATCHDOG_TIME 120
#define PROCESS_MODE_MASTER 0 #define PROCESS_MODE_MASTER 0
#define PROCESS_MODE_SLAVE 1 #define PROCESS_MODE_SLAVE 1
@ -752,7 +752,9 @@ typedef struct
BYTE mode; //slave mode or master mode or duplex mode BYTE mode; //slave mode or master mode or duplex mode
short time_gap; //send out time from this proc 18.2c/s short time_gap; //send out time from this proc 18.2c/s
short poll_gap; //send out command 18.2c/s short poll_gap; //send out command 18.2c/s
short softdog; //software watchdog counter //short softdog; //software watchdog counter
BYTE real_softdog;
BYTE ftp_softdog;
short units[PROCESS_UNIT_NUM]; short units[PROCESS_UNIT_NUM];
unionProcOption option; unionProcOption option;
QLONG irn; QLONG irn;
@ -868,7 +870,9 @@ typedef struct
short ymcount; short ymcount;
short ykcount; short ykcount;
short ytcount; short ytcount;
short softdog; //short softdog;
BYTE real_softdog;
BYTE ftp_softdog;
LONG yxbwload; LONG yxbwload;
LONG soeload; LONG soeload;
LONG ycbwload; LONG ycbwload;

View File

@ -37,10 +37,10 @@ BOOLEAN CRTUStatusProcess::OnTimer(void)
//更新协议运行状态 //更新协议运行状态
for (i = 1; i < PROCESSES_NUM; i++) for (i = 1; i < PROCESSES_NUM; i++)
{ {
config.processes[i].softdog++; config.processes[i].real_softdog++;
if (config.processes[i].softdog > PROCESS_WATCHDOG_TIME) if (config.processes[i].real_softdog > PROCESS_WATCHDOG_TIME)
{ {
config.processes[i].softdog = PROCESS_WATCHDOG_TIME; config.processes[i].real_softdog = PROCESS_WATCHDOG_TIME;
SetUnitYX(uid, i, SPI_ON); // 协议中断 SetUnitYX(uid, i, SPI_ON); // 协议中断
} }
else else

View File

@ -125,12 +125,56 @@ Socket::Socket(const struct addrinfo* const host, const int type) :
continue; continue;
} }
if (SOCK_STREAM == type) { if (SOCK_STREAM == type) {
if (::connect(m_Socket, rp->ai_addr, rp->ai_addrlen)) { fprintf(stderr, "start to connect.\n");
LOG_WARN("Socket connect["<<std::string(inet_ntoa(reinterpret_cast<sockaddr_in*>(rp->ai_addr)->sin_addr)) << "] timeout"); #if 0
net_socket_nonblock(m_Socket, true); //设置为非阻塞模式
int errormsg = -1;
int len;
len = sizeof(int);
timeval tm;
fd_set set;
#endif
if (::connect(m_Socket, rp->ai_addr, rp->ai_addrlen) == SOCKET_ERROR) {
LOG_WARN("Socket connect["<<std::string(inet_ntoa(reinterpret_cast<sockaddr_in*>(rp->ai_addr)->sin_addr)) << "," << reinterpret_cast<sockaddr_in*>(rp->ai_addr)->sin_port << "] timeout");
#if 1
closesocket(m_Socket); closesocket(m_Socket);
m_Socket = INVALID_SOCKET; m_Socket = INVALID_SOCKET;
continue; continue;
#else
if (errno != EINPROGRESS && errno != EWOULDBLOCK)
{
net_socket_nonblock(m_Socket, false); //设置为阻塞模式
closesocket(m_Socket);
m_Socket = INVALID_SOCKET;
continue;
}
else
{
tm.tv_sec = 5;
tm.tv_usec = 0;
FD_ZERO(&set);
FD_SET(m_Socket, &set);
if (select(m_Socket + 1, NULL, &set, NULL, &tm) > 0)
{
getsockopt(m_Socket, SOL_SOCKET, SO_ERROR, &errormsg, (socklen_t *)&len);
if (errormsg == 0)
{
net_socket_nonblock(m_Socket, false); //设置为阻塞模式
m_Connected = true;
m_HostAddr = *(reinterpret_cast<sockaddr_in*>(rp->ai_addr));
memcpy(&m_SockAddress, rp->ai_addr, std::min<size_t>(sizeof(m_SockAddress), rp->ai_addrlen));
return;
}
}
net_socket_nonblock(m_Socket, false); //设置为阻塞模式
closesocket(m_Socket);
m_Socket = INVALID_SOCKET;
continue;
}
#endif
} else { } else {
LOG_WARN("Socket connect["<<std::string(inet_ntoa(reinterpret_cast<sockaddr_in*>(rp->ai_addr)->sin_addr)) << "] timeout");
net_socket_nonblock(m_Socket, false); //设置为阻塞模式
m_Connected = true; m_Connected = true;
m_HostAddr = *(reinterpret_cast<sockaddr_in*>(rp->ai_addr)); m_HostAddr = *(reinterpret_cast<sockaddr_in*>(rp->ai_addr));
} }
@ -223,7 +267,7 @@ size_t Socket::read(uint8_t* buffer, size_t maxBytes, timeval* timeout)
LOG_ERROR("Socket read frame failed with error: " << std::dec << std::strerror(m_LastError)); LOG_ERROR("Socket read frame failed with error: " << std::dec << std::strerror(m_LastError));
} }
Shutdown(); // Shutdown();
return 0; return 0;
} }
@ -261,7 +305,7 @@ bool Socket::Select(timeval* timeout)
m_LastError = WSAGetLastError(); m_LastError = WSAGetLastError();
if (m_LastError == WSAENOTSOCK) { if (m_LastError == WSAENOTSOCK) {
//throw std::runtime_error("connection closed"); //throw std::runtime_error("connection closed");
Shutdown(); // Shutdown();
return false; return false;
} }
@ -272,7 +316,7 @@ bool Socket::Select(timeval* timeout)
} }
if (m_Socket < 0 || m_Socket >= FD_SETSIZE) { if (m_Socket < 0 || m_Socket >= FD_SETSIZE) {
LOG_ERROR("received a non valid socket (" << m_Socket << "), unable to add to the set"); LOG_ERROR("received a non valid socket (" << m_Socket << "), unable to add to the set 2");
return false; return false;
} }
if (!FD_ISSET(m_Socket, &readSockets)) if (!FD_ISSET(m_Socket, &readSockets))
@ -302,7 +346,7 @@ size_t Socket::write(const Frame& frame)
if(0 == len){ if(0 == len){
LOG_INFO("write error, Socket: " << m_Socket << " connection closed by remote with error: " << std::dec << std::strerror(m_LastError)); LOG_INFO("write error, Socket: " << m_Socket << " connection closed by remote with error: " << std::dec << std::strerror(m_LastError));
Shutdown(); //Shutdown();
return 0; return 0;
} }
@ -326,8 +370,10 @@ uint32_t TcpSocket::GetLocalSockAddr() const
struct sockaddr_storage source; struct sockaddr_storage source;
socklen_t len = sizeof(source); socklen_t len = sizeof(source);
if(m_Socket == INVALID_SOCKET) if(m_Socket == INVALID_SOCKET) {
LOG_WARN("SocketTcp is invalid."); LOG_WARN("SocketTcp is invalid.");
return 0;
}
if (getsockname(m_Socket, reinterpret_cast<sockaddr*>(&source), &len)) { if (getsockname(m_Socket, reinterpret_cast<sockaddr*>(&source), &len)) {
LOG_ERROR("TcpSocket read local tcp/ip address failed."); LOG_ERROR("TcpSocket read local tcp/ip address failed.");

View File

@ -9,6 +9,8 @@
#include "wrap_socket.h" #include "wrap_socket.h"
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <sys/uio.h>
#include <sys/ioctl.h>
namespace Beckhoff namespace Beckhoff
{ {
@ -49,6 +51,14 @@ struct Socket {
*/ */
bool IsConnectedTo(const struct addrinfo* targetAddresses) const; bool IsConnectedTo(const struct addrinfo* targetAddresses) const;
bool net_socket_nonblock(SOCKET sock, bool blocking)
{
uint32_t ul = 1;
if (blocking) ul = 1;
else ul = 0;
return ioctl(sock, FIONBIO, &ul);
}
protected: protected:
bool m_Connected; bool m_Connected;
int m_WSAInitialized; int m_WSAInitialized;

View File

@ -71,7 +71,7 @@ AmsConnection::AmsConnection(Router& __router, const struct addrinfo* const dest
refCount(0), refCount(0),
invokeId(0) invokeId(0)
{ {
if(socket.IsConnected()) // if(socket.IsConnected())
{ {
localIp = socket.GetLocalSockAddr(); localIp = socket.GetLocalSockAddr();
remoteIp = socket.GetHostSockAddr(); remoteIp = socket.GetHostSockAddr();
@ -79,25 +79,21 @@ AmsConnection::AmsConnection(Router& __router, const struct addrinfo* const dest
struct in_addr ss{htonl(remoteIp)}; struct in_addr ss{htonl(remoteIp)};
LOG_INFO("Socket connect["<<std::string(inet_ntoa(ss))<<"] is done."); LOG_INFO("Socket connect["<<std::string(inet_ntoa(ss))<<"] is done.");
} }
#if 0
else else
{ {
socket.Shutdown(); socket.Shutdown();
} }
#endif
} }
AmsConnection::~AmsConnection() AmsConnection::~AmsConnection()
{ {
if (socket.IsConnected()) // if (socket.IsConnected())
{ {
socket.Shutdown(); socket.Shutdown();
receiver.join(); receiver.join();
} }
#if 0
if (socket.IsValid())
{
socket.Shutdown();
}
#endif
} }
SharedDispatcher AmsConnection::CreateNotifyMapping(uint32_t hNotify, std::shared_ptr<Notification> notification) SharedDispatcher AmsConnection::CreateNotifyMapping(uint32_t hNotify, std::shared_ptr<Notification> notification)

View File

@ -709,13 +709,13 @@ BOOLEAN CZJD3100Process::OnSyntanProcessInfo(char *pData, int ord)
snprintf(buffer, sizeof(buffer), ",%s", "unknow protocol"); snprintf(buffer, sizeof(buffer), ",%s", "unknow protocol");
pItem->WriteData((BYTE *)buffer, strlen(buffer), ord); pItem->WriteData((BYTE *)buffer, strlen(buffer), ord);
} }
snprintf(buffer, sizeof(buffer), ", softdog is: %d, link units: ", config.processes[pid].softdog); snprintf(buffer, sizeof(buffer), ", softdog is: %d, link units: ", config.processes[pid].real_softdog);
pItem->WriteData((BYTE *)buffer, strlen(buffer), ord); pItem->WriteData((BYTE *)buffer, strlen(buffer), ord);
for (int i = 0; i < PROCESS_UNIT_NUM; i++) for (int i = 0; i < PROCESS_UNIT_NUM; i++)
{ {
if (config.processes[pid].units[i] < 0) continue; if (config.processes[pid].units[i] < 0) continue;
if (i == 0) snprintf(buffer, sizeof(buffer), "%d-%d", config.processes[pid].units[i], config.units[config.processes[pid].units[i]].softdog); if (i == 0) snprintf(buffer, sizeof(buffer), "%d-%d", config.processes[pid].units[i], config.units[config.processes[pid].units[i]].real_softdog);
else snprintf(buffer, sizeof(buffer), ", %d-%d", config.processes[pid].units[i], config.units[config.processes[pid].units[i]].softdog); else snprintf(buffer, sizeof(buffer), ", %d-%d", config.processes[pid].units[i], config.units[config.processes[pid].units[i]].real_softdog);
pItem->WriteData((BYTE *)buffer, strlen(buffer), ord); pItem->WriteData((BYTE *)buffer, strlen(buffer), ord);
} }
pItem->WriteData((BYTE *)"\r\n", strlen("\r\n"), ord); pItem->WriteData((BYTE *)"\r\n", strlen("\r\n"), ord);
@ -1865,7 +1865,7 @@ BOOLEAN CZJD3100Process::OnSyntaxExtInfoStatus(char *pData, int ord)
for (int i = 0; i < PROCESSES_NUM; i++) for (int i = 0; i < PROCESSES_NUM; i++)
{ {
buffer[i].irn = GetProcessIRNByPid(i); buffer[i].irn = GetProcessIRNByPid(i);
buffer[i].value = ((config.processes[i].softdog >= PROCESS_WATCHDOG_TIME) ? false : true) | (config.processes[i].state ? 0x00 : 0x80); buffer[i].value = ((config.processes[i].real_softdog >= PROCESS_WATCHDOG_TIME) ? false : true) | (config.processes[i].state ? 0x00 : 0x80);
} }
pItem->WriteData((BYTE*)buffer, sizeof(buffer), ord); pItem->WriteData((BYTE*)buffer, sizeof(buffer), ord);
return TRUE; return TRUE;