feat: 增加IEC61850服务端
parent
ace787d472
commit
c52bb82375
@ -0,0 +1,36 @@
|
||||
package com.xydl.cac.controller;
|
||||
|
||||
import com.xydl.cac.iec.IecServerService;
|
||||
import com.xydl.cac.model.Response;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController
|
||||
@Api(tags = {"Iec服务端接口"})
|
||||
@RequestMapping("iecserver")
|
||||
@Slf4j
|
||||
public class IecServerController extends BasicController {
|
||||
|
||||
@Resource
|
||||
IecServerService iecServerService;
|
||||
|
||||
@GetMapping("start")
|
||||
@ApiOperation("启动IEC服务端")
|
||||
public Response<String> start() throws Exception {
|
||||
iecServerService.startServer();
|
||||
return Response.success("OK");
|
||||
}
|
||||
|
||||
@GetMapping("stop")
|
||||
@ApiOperation("停止IEC服务端")
|
||||
public Response<String> stop() throws Exception {
|
||||
iecServerService.stop();
|
||||
return Response.success("OK");
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.xydl.cac.iec;
|
||||
|
||||
import com.beanit.iec61850bean.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public class IecServer extends Thread implements ServerEventListener {
|
||||
ServerSap serverSap = null;
|
||||
ServerModel serversServerModel = null;
|
||||
|
||||
public void startServer(String xml, int port) throws Exception {
|
||||
InputStream in = IOUtils.toInputStream(xml, StandardCharsets.UTF_8);
|
||||
serverSap = new ServerSap(port, 0, null, SclParser.parse(in).get(0), null);
|
||||
|
||||
serverSap.setPort(port);
|
||||
serverSap.startListening(this);
|
||||
serversServerModel = serverSap.getModelCopy();
|
||||
this.start();
|
||||
log.info("已启动IEC服务端.");
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (serverSap != null) {
|
||||
serverSap.stop();
|
||||
log.info("已停止IEC服务端.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ServiceError> write(List<BasicDataAttribute> bdas) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serverStoppedListening(ServerSap serverSAP) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.xydl.cac.iec;
|
||||
|
||||
import com.xydl.cac.entity.IcdFile;
|
||||
import com.xydl.cac.repository.IcdFileRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class IecServerService {
|
||||
@Resource
|
||||
IcdFileRepository fileRepository;
|
||||
|
||||
IecServer iecServer = new IecServer();
|
||||
boolean started = false;
|
||||
|
||||
public void startServer() {
|
||||
if (!started) {
|
||||
List<IcdFile> icdFileList = fileRepository.findAll();
|
||||
if (!CollectionUtils.isEmpty(icdFileList)) {
|
||||
IcdFile icdFile = icdFileList.get(0);
|
||||
try {
|
||||
iecServer.startServer(icdFile.getXml(), 102);
|
||||
started = true;
|
||||
} catch (Exception e) {
|
||||
log.error("启动IEC服务端异常.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void stop() {
|
||||
if (iecServer != null) {
|
||||
iecServer.close();
|
||||
started = false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue