打开61850服务

This commit is contained in:
weitang 2025-05-21 09:21:48 +08:00
parent 5aa90c2fcc
commit 51bcf3edc0
8 changed files with 160 additions and 140 deletions

View File

@ -61,30 +61,30 @@ public class IEC104ClientRunner implements ApplicationRunner {
GatewayDevice::getIpAddr, GatewayDevice::getIecAddr);
queryWrapper.orderByAsc(GatewayDevice::getDeviceCode);
List<GatewayDevice> list = gatewayDeviceMapper.selectList(queryWrapper);
// if (list.size() > 0) {
// for (GatewayDevice gatewayDevice : list) {
// Iec104Config iec104Config = new Iec104Config();
// iec104Config.setFrameAmountMax((short) 10);
// short terminnalAddress = gatewayDevice.getIecAddr().shortValue();
// //通讯网关机地址
// iec104Config.setTerminnalAddress(terminnalAddress);
// iec104Config.setSlaveCode(gatewayDevice.getDeviceCode());
// iec104Config.setSlaveIP(gatewayDevice.getIpAddr());
// OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
// threadPool.execute(() -> {
// Iec104Master iec104server = Iec104MasterFactory.createTcpClientMaster(iec104Config.getSlaveIP(),
// 2404);
// try {
// iec104server.setDataHandler(new MasterSysDataHandler()).setConfig(iec104Config).run();
//
// } catch (Exception e) {
// log.error(String.format("%s-对应的终端连接失败!", iec104Config.getSlaveIP()));
// }
// });
// threadPool.shutdown();
// }
//
// }
if (list.size() > 0) {
for (GatewayDevice gatewayDevice : list) {
Iec104Config iec104Config = new Iec104Config();
iec104Config.setFrameAmountMax((short) 10);
short terminnalAddress = gatewayDevice.getIecAddr().shortValue();
//通讯网关机地址
iec104Config.setTerminnalAddress(terminnalAddress);
iec104Config.setSlaveCode(gatewayDevice.getDeviceCode());
iec104Config.setSlaveIP(gatewayDevice.getIpAddr());
OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
threadPool.execute(() -> {
Iec104Master iec104server = Iec104MasterFactory.createTcpClientMaster(iec104Config.getSlaveIP(),
2404);
try {
iec104server.setDataHandler(new MasterSysDataHandler()).setConfig(iec104Config).run();
} catch (Exception e) {
log.error(String.format("%s-对应的终端连接失败!", iec104Config.getSlaveIP()));
}
});
threadPool.shutdown();
}
}
}
}

View File

@ -60,26 +60,26 @@ public class ControlManageUtil {
* 启动S发送S确认帧 的任务
*/
public void startSendFrameTask() {
// OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
// threadPool.execute(() -> {
// while (true) {
// try {
// synchronized (sendSframeLock) {
// if (frameAmount >= frameAmountMax) {
// // 查过最大帧 的数量就要发送一个确认帧出去
// byte[] control = Iec104Util.getScontrol(accept);
// MessageDetail ruleDetail104 = new MessageDetail(control);
// ctx.channel().writeAndFlush(Encoder104.encoder(ruleDetail104));
// frameAmount = 0;
// }
// sendSframeLock.wait();
// }
// } catch (Exception e) {
// LOGGER.error("Exception caught", e);
// }
// }
// });
// threadPool.shutdown();
OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
threadPool.execute(() -> {
while (true) {
try {
synchronized (sendSframeLock) {
if (frameAmount >= frameAmountMax) {
// 查过最大帧 的数量就要发送一个确认帧出去
byte[] control = Iec104Util.getScontrol(accept);
MessageDetail ruleDetail104 = new MessageDetail(control);
ctx.channel().writeAndFlush(Encoder104.encoder(ruleDetail104));
frameAmount = 0;
}
sendSframeLock.wait();
}
} catch (Exception e) {
LOGGER.error("Exception caught", e);
}
}
});
threadPool.shutdown();
}

View File

@ -72,22 +72,22 @@ public class ScheduledTaskPool {
* @Description: 发送测试帧
*/
private void sendTestFrame() {
// OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
// threadPool.execute(() -> {
// try {
// BootNettyClientChannel channel = BootNettyClientChannelCache.get(ctx.channel().id().asShortText());
// if(ObjUtil.isNotEmpty(channel )){
// String slaveIp = channel .getCode();
// LOGGER.info(String.format("向从站[%s]发送测试链路指令!",slaveIp ));
// ctx.channel().writeAndFlush(BasicInstruction104.TESTFR);
// //对时指令
// ctx.channel().writeAndFlush(BasicInstruction104.getTimeScale104());
// }
// } catch (Exception e) {
// LOGGER.error("Exception caught", e);
// }
// });
// threadPool.shutdown();
OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
threadPool.execute(() -> {
try {
BootNettyClientChannel channel = BootNettyClientChannelCache.get(ctx.channel().id().asShortText());
if(ObjUtil.isNotEmpty(channel )){
String slaveIp = channel .getCode();
LOGGER.info(String.format("向从站[%s]发送测试链路指令!",slaveIp ));
ctx.channel().writeAndFlush(BasicInstruction104.TESTFR);
//对时指令
ctx.channel().writeAndFlush(BasicInstruction104.getTimeScale104());
}
} catch (Exception e) {
LOGGER.error("Exception caught", e);
}
});
threadPool.shutdown();
}
@ -101,21 +101,21 @@ public class ScheduledTaskPool {
}
private void sendGeneralCall() {
// OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
// threadPool.execute(() -> {
// try {
// BootNettyClientChannel channel = BootNettyClientChannelCache.get(ctx.channel().id().asShortText());
// if (ObjUtil.isNotEmpty(channel)) {
// String slaveIp = channel.getCode();
// MessageDetail messageDetail = BasicInstruction104.getGeneralCallRuleDetail104();
// LOGGER.info(String.format("向从站[%s]发送总召唤指令[%s]", slaveIp, messageDetail.getHexString()));
// ctx.channel().writeAndFlush(messageDetail);
// }
// } catch (Exception e) {
// LOGGER.error("Exception caught", e);
// }
// });
// threadPool.shutdown();
OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
threadPool.execute(() -> {
try {
BootNettyClientChannel channel = BootNettyClientChannelCache.get(ctx.channel().id().asShortText());
if (ObjUtil.isNotEmpty(channel)) {
String slaveIp = channel.getCode();
MessageDetail messageDetail = BasicInstruction104.getGeneralCallRuleDetail104();
LOGGER.info(String.format("向从站[%s]发送总召唤指令[%s]", slaveIp, messageDetail.getHexString()));
ctx.channel().writeAndFlush(messageDetail);
}
} catch (Exception e) {
LOGGER.error("Exception caught", e);
}
});
threadPool.shutdown();
}
public void stopSendCommandTask() {

View File

@ -49,17 +49,17 @@ public class Iec104ClientHandler extends SimpleChannelInboundHandler<MessageDeta
BootNettyClientChannelCache.remove(ctx.channel().id().asShortText());
BootNettyClientChannelCache.save(ctx.channel().id().asShortText(),Channel);
// if (dataHandler != null) {
// OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
// threadPool.execute(() -> {
// try {
// dataHandler.handlerAdded(new ChannelHandlerImpl(ctx));
// } catch (Exception e) {
// LOGGER.error("Exception caught", e);
// }
// });
// threadPool.shutdown();
// }
if (dataHandler != null) {
OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
threadPool.execute(() -> {
try {
dataHandler.handlerAdded(new ChannelHandlerImpl(ctx));
} catch (Exception e) {
LOGGER.error("Exception caught", e);
}
});
threadPool.shutdown();
}
}
@Override
@ -76,18 +76,18 @@ public class Iec104ClientHandler extends SimpleChannelInboundHandler<MessageDeta
@Override
public void channelRead0(ChannelHandlerContext ctx, MessageDetail ruleDetail104) throws IOException {
// if (dataHandler != null) {
// OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
// threadPool.execute(() -> {
// try {
// dataHandler.channelRead(new ChannelHandlerImpl(ctx), ruleDetail104);
// } catch (Exception e) {
// // TODO Auto-generated catch block
// LOGGER.error("Exception caught", e);
// }
// });
// threadPool.shutdown();
// }
if (dataHandler != null) {
OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
threadPool.execute(() -> {
try {
dataHandler.channelRead(new ChannelHandlerImpl(ctx), ruleDetail104);
} catch (Exception e) {
// TODO Auto-generated catch block
LOGGER.error("Exception caught", e);
}
});
threadPool.shutdown();
}
}

View File

@ -40,17 +40,17 @@ public class Iec104TcpSlaveHandler extends SimpleChannelInboundHandler<MessageDe
* 启动
*/
Iec104ThreadLocal.getControlPool().startSendFrameTask();
// if (dataHandler != null) {
// OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
// threadPool.execute(() -> {
// try {
// dataHandler.handlerAdded(new ChannelHandlerImpl(ctx));
// } catch (Exception e) {
// LOGGER.error("Exception caught", e);
// }
// });
// threadPool.shutdown();
// }
if (dataHandler != null) {
OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
threadPool.execute(() -> {
try {
dataHandler.handlerAdded(new ChannelHandlerImpl(ctx));
} catch (Exception e) {
LOGGER.error("Exception caught", e);
}
});
threadPool.shutdown();
}
}
/**
@ -65,18 +65,18 @@ public class Iec104TcpSlaveHandler extends SimpleChannelInboundHandler<MessageDe
*/
@Override
protected void channelRead0(ChannelHandlerContext ctx, MessageDetail ruleDetail104) throws Exception {
// if (dataHandler != null) {
//
// OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
// threadPool.execute(() -> {
// try {
// dataHandler.channelRead(new ChannelHandlerImpl(ctx), ruleDetail104);
// } catch (Exception e) {
// LOGGER.error("Exception caught", e);
// }
// });
// threadPool.shutdown();
// }
if (dataHandler != null) {
OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
threadPool.execute(() -> {
try {
dataHandler.channelRead(new ChannelHandlerImpl(ctx), ruleDetail104);
} catch (Exception e) {
LOGGER.error("Exception caught", e);
}
});
threadPool.shutdown();
}
}
/**

View File

@ -45,10 +45,10 @@ public class IEC61850ClientRunner implements ApplicationRunner {
queryWrapper.orderByAsc(GatewayDevice::getDeviceCode);
List<GatewayDevice> list = gatewayDeviceMapper.selectList(queryWrapper);
if (!list.isEmpty()) {
// for (GatewayDevice systemDevice : list) {
// OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
// threadPool.execute(() -> iec61850Service.connect(systemDevice));
// }
for (GatewayDevice systemDevice : list) {
OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
threadPool.execute(() -> iec61850Service.connect(systemDevice));
}
}
}

View File

@ -1,17 +1,18 @@
package com.yfd.platform.modules.algorithm.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.net.NetUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfd.platform.modules.algorithm.domain.AlgorithmClass;
import com.yfd.platform.modules.algorithm.domain.AlgorithmClassComponent;
import com.yfd.platform.modules.algorithm.domain.AlgorithmDevice;
import com.yfd.platform.modules.algorithm.domain.AlgorithmParams;
import com.yfd.platform.modules.algorithm.domain.*;
import com.yfd.platform.modules.algorithm.mapper.AlgorithmClassMapper;
import com.yfd.platform.modules.algorithm.mapper.AlgorithmDeviceMapper;
import com.yfd.platform.modules.algorithm.mapper.AlgorithmLogsMapper;
import com.yfd.platform.modules.algorithm.mapper.AlgorithmParamsMapper;
import com.yfd.platform.modules.algorithm.service.IAlgorithmParamsService;
import com.yfd.platform.modules.basedata.domain.SubstationComponent;
import com.yfd.platform.modules.basedata.mapper.SubstationComponentMapper;
import com.yfd.platform.utils.HttpRESTfulUtils;
import com.yfd.platform.utils.StringUtils;
import org.springframework.stereotype.Service;
@ -20,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -43,6 +45,13 @@ public class AlgorithmParamsServiceImpl extends ServiceImpl<AlgorithmParamsMappe
@Resource
private AlgorithmDeviceMapper algorithmDeviceMapper;
@Resource
private SubstationComponentMapper substationComponentMapper;
@Resource
private AlgorithmLogsMapper algorithmLogsMapper;
@Resource
private HttpRESTfulUtils httpRESTfulUtils;
@ -136,6 +145,17 @@ public class AlgorithmParamsServiceImpl extends ServiceImpl<AlgorithmParamsMappe
param.put("param", senData);
JSONObject jsonObject = httpRESTfulUtils.sendHttpUrlPost("json", serviceAddress, "", param, null);
String desc = algorithmDeviceMapper.getReturnDesc(componentId);
SubstationComponent substationComponent = substationComponentMapper.selectById(componentId);
if (substationComponent != null) {
AlgorithmLogs algorithmLogs = BeanUtil.copyProperties(substationComponent, AlgorithmLogs.class);
algorithmLogs.setAlgorithmId(id);
algorithmLogs.setParamsValue(senData.toString());
if (jsonObject.containsKey("result")) {
algorithmLogs.setAnalysisResult(jsonObject.getString("result"));
}
algorithmLogs.setAnalysisTime(LocalDateTime.now());
algorithmLogsMapper.insert(algorithmLogs);
}
jsonObject.put("mapList", mapList);
jsonObject.put("desc", desc);
return jsonObject;

View File

@ -167,17 +167,17 @@ public class GatewayDeviceServiceImpl extends ServiceImpl<GatewayDeviceMapper, G
log.error("Exception caught", e);
}
}
// Runnable runnable = () -> {
// Iec104Master iec104server = Iec104MasterFactory.createTcpClientMaster(iec104Config.getSlaveIP(), 2404);
// try {
// iec104server.setDataHandler(new MasterSysDataHandler()).setConfig(iec104Config).run();
// } catch (Exception e) {
// EventLoopGroupManager.shutdownEventLoopGroup(ip);
// log.error(String.format("%s-对应的终端连接失败!", iec104Config.getSlaveIP()));
// }
// };
// OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
// threadPool.execute(runnable);
Runnable runnable = () -> {
Iec104Master iec104server = Iec104MasterFactory.createTcpClientMaster(iec104Config.getSlaveIP(), 2404);
try {
iec104server.setDataHandler(new MasterSysDataHandler()).setConfig(iec104Config).run();
} catch (Exception e) {
EventLoopGroupManager.shutdownEventLoopGroup(ip);
log.error(String.format("%s-对应的终端连接失败!", iec104Config.getSlaveIP()));
}
};
OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance();
threadPool.execute(runnable);
}
return true;