This commit is contained in:
高云鹏 2024-12-31 14:12:23 +08:00
commit 81d46ccda5
6 changed files with 63 additions and 40 deletions

View File

@ -2817,11 +2817,11 @@ void CRYDevice::heart_beat(int status)
if (status == 1) {
Json::Value jsonLink;
Json::Value jsonDevice;
Json::Value jsonValue;
for (int i = 0; i < PROCESSES_NUM; i++) {
if ((config.processes[i].state & 0x01) == TRUE) {
char linkId[32];
if (config.processes[i].irn == 0) continue;
Json::Value jsonValue;
#ifdef NOPOLL_64BIT_PLATFORM
snprintf(linkId, sizeof(linkId), "%ld", config.processes[i].irn);
#else
@ -2830,7 +2830,7 @@ void CRYDevice::heart_beat(int status)
jsonValue["linkId"] = linkId;
jsonValue["online"] = (config.processes[i].real_softdog >= PROCESS_WATCHDOG_TIME) ? false : true;
jsonValue["real"] = (config.processes[i].real_softdog >= PROCESS_WATCHDOG_TIME) ? false : true;
if (config.processes[i].state & 0x20) {
if ((config.processes[i].state & 0x20) == 0x20) {
jsonValue["ftp"] = (config.processes[i].real_softdog >= PROCESS_WATCHDOG_TIME) ? false : true;
}
jsonLink.append(jsonValue);
@ -2845,6 +2845,7 @@ void CRYDevice::heart_beat(int status)
if ((config.units[i].state & 0x01) == TRUE) {
char deviceId[32];
if (config.units[i].irn == 0) continue;
Json::Value jsonValue;
#ifdef NOPOLL_64BIT_PLATFORM
snprintf(deviceId, sizeof(deviceId), "%ld", config.units[i].irn);
#else

View File

@ -523,7 +523,7 @@ static void* ryftp_process(void* param)
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);
config.units[uid].value &= ~0x02;
ftpget_retry_count = 0;
if (chunk.size <= (int)(sizeof(struRYDeviceData) << 5)) {
if (chunk.size <= (int)(sizeof(struRYDeviceData) * 248)) {
vLog(LOG_DEBUG, "%s PLC文件生成未完成\n", processName);
continue;
}
@ -531,7 +531,8 @@ static void* ryftp_process(void* param)
struRYDeviceData *data = (struRYDeviceData *)chunk.response;
int uid = mbt->GetCurUnitID();
mbt->UnitFeedFTPDog(uid);
for (int i = 0; i < 250; i++, data++) { //每个文件有250个数据块
int data_count = (chunk.size / sizeof(struRYDeviceData));
for (int i = 0; i < data_count; i++, data++) { //每个文件有250个数据块
QLONG unix_time = filetime_to_unix(data->localtime);
DWORD localtime = ((unix_time / 1000) - 28800L);
@ -539,14 +540,17 @@ static void* ryftp_process(void* param)
unix_time = localtime; unix_time *= 1000;
unix_time += millisec;
#if 0
unionCP56Time st;
st = Time_ttounionCP56Time(localtime);
vLog(LOG_DEBUG, "data<%d> time is: %04d/%02d/%02d %02d:%02d:%02d.%03d\n", \
i, \
st.year + 2000, st.month, st.dayofmonth, \
st.hour, st.minute, st.millisecond/1000, st.millisecond%1000);
if (unix_time < 1735488000000 || unix_time >= 1735660800000)
{
unionCP56Time st;
st = Time_ttounionCP56Time(localtime);
vLog(LOG_DEBUG, "unix_time is: %ld, localtime is: %d, and data<%d> time is: %04d/%02d/%02d %02d:%02d:%02d.%03d\n", \
unix_time, localtime,
i, \
st.year + 2000, st.month, st.dayofmonth, \
st.hour, st.minute, st.millisecond/1000, millisec);
}
#endif
//vLog(LOG_DEBUG, "data.iPitchAngle1 is: %d, data.iPitchAngle2 is: %d, and data.iPitchAngle3 is: %d\n", data->iPitchAngle1, data->iPitchAngle2, data->iPitchAngle3);
//如何将结构化数据传入,且快速获取
Json::Value highspeedvalues;
for (datatypemap::iterator it = highspeedmap.begin(); it != highspeedmap.end(); it++) {
@ -556,7 +560,6 @@ static void* ryftp_process(void* param)
int point = it->second;
if (GetYCValue(point, fields, (const char *)data, dvalue)) {
if (adsGetUnitYCIsFloat(uid, point)) {
//fprintf(stderr, "%s, ", config.units[uid].ycs[order].name);
highspeedvalues[(const char *)config.units[uid].ycs[order].name] = adsGetUnitYCRealFromValue(uid, point, dvalue);
} else {
highspeedvalues[(const char *)config.units[uid].ycs[order].name] = dvalue;
@ -579,9 +582,7 @@ static void* ryftp_process(void* param)
int order = it->first;
int point = it->second;
if (GetYCValue(point, fields, (const char *)data, dvalue)) {
//fprintf(stderr, "get<%d> value is: %d.\n", point, dvalue);
if (adsGetUnitYCIsFloat(uid, point)) {
//fprintf(stderr, "%s, ", config.units[uid].ycs[order].name);
lowspeedvalues[(const char *)config.units[uid].ycs[order].name] = adsGetUnitYCRealFromValue(uid, point, dvalue);
} else {
lowspeedvalues[(const char *)config.units[uid].ycs[order].name] = dvalue;
@ -595,7 +596,6 @@ static void* ryftp_process(void* param)
int order = it->first;
int point = it->second.point;
int pos = it->second.pos;
//vLog(LOG_DEBUG, "start to get point is: %d, pos is: %d\n", point, pos);
if (GetYXValue(point, fields, (const char *)data, pos, bvalue)) {
lowspeedvalues[(const char *)config.units[uid].yxs[order].name] = (int)bvalue;
} else {

View File

@ -528,7 +528,7 @@ static void* ryftp_process(void* param)
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);
config.units[uid].value &= ~0x02;
ftpget_retry_count = 0;
if (chunk.size <= (int)(sizeof(struRYDeviceData) << 5)) {
if (chunk.size <= (int)(sizeof(struRYDeviceData) * 248)) {
vLog(LOG_DEBUG, "%s PLC文件生成未完成\n", processName);
continue;
}
@ -536,7 +536,8 @@ static void* ryftp_process(void* param)
struRYDeviceData *data = (struRYDeviceData *)chunk.response;
int uid = mbt->GetCurUnitID();
mbt->UnitFeedFTPDog(uid);
for (int i = 0; i < 250; i++, data++) { //每个文件有250个数据块
int data_count = (chunk.size / sizeof(struRYDeviceData));
for (int i = 0; i < data_count; i++, data++) { //每个文件有250个数据块
QLONG unix_time = filetime_to_unix(data->localtime);
DWORD localtime = ((unix_time / 1000) - 28800L);

View File

@ -49,14 +49,14 @@ public class HeartbeatCommand implements BaseCommand{
JsonNode realNode = linkNode.get("real");
if (realNode != null){
boolean real = realNode.asBoolean();
String key = String.format("link:%s:modbus", linkId);
ops.set(key, real, HEARTBEAT_TTL, TimeUnit.SECONDS);
String key = String.format("link:%s:real", linkId);
ops.set(key, real?1:0, HEARTBEAT_TTL, TimeUnit.SECONDS);
}
JsonNode ftpNode = linkNode.get("ftp");
if (ftpNode != null){
boolean ftp = ftpNode.asBoolean();
String key = String.format("link:%s:ftp", linkId);
ops.set(key, ftp, HEARTBEAT_TTL, TimeUnit.SECONDS);
ops.set(key, ftp?1:0, HEARTBEAT_TTL, TimeUnit.SECONDS);
}
String key = String.format("link:%s:online", linkId);
// 更新链路在线状态到Redis

View File

@ -38,9 +38,23 @@ public class SysCommunicationLinkVo {
private String nodeName;
/**
* 状态 0 - 正常 1 - 通讯中断
* 链路状态 0 - 离线 1 - 正常
*/
private Integer onlineStatus;
/**
* ftp状态 0 - 异常 1 - 正常
*/
private Integer ftpStatus;
/**
* 实时数据状态 0 - 异常 1 - 正常
*/
private Integer realStatus;
/**
* 实时数据状态
*/
private Integer status;
/**
* 所属系统节点id

View File

@ -39,6 +39,7 @@ import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@ -81,7 +82,7 @@ public class SysNodeServiceImpl implements SysNodeService {
SysIotModelServiceMapper iotModelServiceMapper;
@Autowired
AdminRedisTemplate adminRedisTemplate;
RedisTemplate<String,Object> redisTemplate;
@Override
public List<SysNodeVo> querySysNodeList() {
@ -144,6 +145,7 @@ public class SysNodeServiceImpl implements SysNodeService {
*/
@Override
public PageDataInfo<SysCommunicationLinkVo> querySysCommunicationLinkList(SysCommunicationLinkDto sysCommunicationLinkDto) {
ValueOperations<String,Object> ops = redisTemplate.opsForValue();
// 初始化分页查询对象
PageQuery pageQuery = new PageQuery();
pageQuery.setPageNum(sysCommunicationLinkDto.getPageNum());
@ -158,32 +160,37 @@ public class SysNodeServiceImpl implements SysNodeService {
// 根据条件判断是否需要查询在线状态
if (sysCommunicationLinkDto.getWithStatus() != null && sysCommunicationLinkDto.getWithStatus() == 1) {
// 初始化用于存储在线状态键的列表
List<String> keys = new ArrayList<>(records.size());
List<String> onlines = new ArrayList<>(records.size());
List<String> ftps = new ArrayList<>(records.size());
List<String> reals = new ArrayList<>(records.size());
// 遍历查询结果构造每个通信链路的在线状态键
for (int i = 0; i < records.size(); i++) {
SysCommunicationLinkVo sysCommunicationLinkVo = records.get(i);
String onlineKey = String.format("link:%d:online", sysCommunicationLinkVo.getId());
keys.add(onlineKey);
onlines.add(String.format("link:%d:online", sysCommunicationLinkVo.getId()));
ftps.add(String.format("link:%d:ftp", sysCommunicationLinkVo.getId()));
reals.add(String.format("link:%d:real", sysCommunicationLinkVo.getId()));
}
// 批量获取在线状态值
List<Object> values = adminRedisTemplate.mGet(keys);
List<Object> onlinesStatus = ops.multiGet(onlines);
List<Object> ftpsStatus = ops.multiGet(ftps);
List<Object> realsStatus = ops.multiGet(reals);
// 遍历在线状态值更新通信链路的在线状态
for (int i = 0; i < values.size(); i++) {
Object val = values.get(i);
if (val == null) {
records.get(i).setStatus(1);
for (int i = 0; i < records.size(); i++) {
SysCommunicationLinkVo sysCommunicationLinkVo = records.get(i);
Integer ostatus = (Integer) onlinesStatus.get(i);
Integer fstatus = (Integer) ftpsStatus.get(i);
Integer rstatus = (Integer) realsStatus.get(i);
if (ostatus == null) {
ostatus = 0;
}
else{
Integer status = NumberUtil.parseInt(val.toString(), null);
if (status == null || status == 0) {
records.get(i).setStatus(1);
}
else{
records.get(i).setStatus(0);
}
sysCommunicationLinkVo.setOnlineStatus(ostatus);
if (fstatus != null){
sysCommunicationLinkVo.setFtpStatus(fstatus);
}
if (rstatus != null ){
sysCommunicationLinkVo.setRealStatus(rstatus);
}
}
}