|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.xydl.cac.iec;
|
|
|
|
|
|
|
|
|
|
import com.beanit.iec61850bean.*;
|
|
|
|
|
import com.xydl.cac.entity.IcdIed;
|
|
|
|
|
import com.xydl.cac.entity.constants.Constants;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
@ -17,19 +18,26 @@ import java.util.List;
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class IecClient implements ClientEventListener {
|
|
|
|
|
|
|
|
|
|
IcdIed ied;
|
|
|
|
|
int[] title;
|
|
|
|
|
ClientSap clientSap = new ClientSap();
|
|
|
|
|
ClientAssociation clientAssociation = null;
|
|
|
|
|
ServerModel serverModel;
|
|
|
|
|
|
|
|
|
|
public void connect(String host, int port, String apTitle, String xml) throws Exception {
|
|
|
|
|
public boolean keep = false;
|
|
|
|
|
public RealTimeDataService realTimeDataService;
|
|
|
|
|
int retry = 10;
|
|
|
|
|
|
|
|
|
|
public void connect(IcdIed _ied, String xml) throws Exception {
|
|
|
|
|
InputStream in = IOUtils.toInputStream(xml, StandardCharsets.UTF_8);
|
|
|
|
|
this.connect(host, port, apTitle, in);
|
|
|
|
|
this.connect(_ied, in);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void connect(String host, int port, String apTitle, InputStream in) throws Exception {
|
|
|
|
|
int[] title = new int[]{1, 3, 9999, 33};
|
|
|
|
|
if (StringUtils.isNotBlank(apTitle)) {
|
|
|
|
|
String[] strs = apTitle.replaceAll(" ", ",").split(",");
|
|
|
|
|
public void connect(IcdIed _ied, InputStream in) throws Exception {
|
|
|
|
|
ied = _ied;
|
|
|
|
|
title = new int[]{1, 3, 9999, 33};
|
|
|
|
|
if (StringUtils.isNotBlank(_ied.getApTitle())) {
|
|
|
|
|
String[] strs = _ied.getApTitle().replaceAll(" ", ",").split(",");
|
|
|
|
|
if (strs.length == 4) {
|
|
|
|
|
title[0] = Integer.parseInt(strs[0]);
|
|
|
|
|
title[1] = Integer.parseInt(strs[1]);
|
|
|
|
@ -47,9 +55,9 @@ public class IecClient implements ClientEventListener {
|
|
|
|
|
clientSap.setTSelRemote(new byte[]{0, 1});
|
|
|
|
|
clientSap.setTSelLocal(new byte[]{0, 0});
|
|
|
|
|
clientSap.setApTitleCalled(title);
|
|
|
|
|
|
|
|
|
|
clientAssociation = clientSap.associate(InetAddress.getByName(host), port, null, this);
|
|
|
|
|
serverModel = SclParser.parse(in).get(0);
|
|
|
|
|
|
|
|
|
|
clientAssociation = clientSap.associate(InetAddress.getByName(ied.getIp()), ied.getPort(), null, this);
|
|
|
|
|
clientAssociation.setServerModel(serverModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -60,6 +68,12 @@ public class IecClient implements ClientEventListener {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void reconnect() throws Exception {
|
|
|
|
|
clientAssociation = clientSap.associate(InetAddress.getByName(ied.getIp()), ied.getPort(), null, this);
|
|
|
|
|
clientAssociation.setServerModel(serverModel);
|
|
|
|
|
log.info("61850断线重连成功, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getValue(String paramindex, String fc) throws Exception {
|
|
|
|
|
FcModelNode node = (FcModelNode) serverModel.findModelNode(paramindex, Fc.valueOf(fc));
|
|
|
|
|
clientAssociation.getDataValues(node);
|
|
|
|
@ -124,13 +138,49 @@ public class IecClient implements ClientEventListener {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void associationClosed(IOException e) {
|
|
|
|
|
|
|
|
|
|
if (keep) {
|
|
|
|
|
this.disableReporting();
|
|
|
|
|
this.disconnect();
|
|
|
|
|
try {
|
|
|
|
|
if (retry <= 0) {
|
|
|
|
|
log.info("61850断线重连失败10次, 已断开不再重连. ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
|
|
|
|
|
if (realTimeDataService != null && ied != null) {
|
|
|
|
|
realTimeDataService.stopCollect(ied.getId());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (retry >= 5) {
|
|
|
|
|
Thread.sleep(10 * 1000);
|
|
|
|
|
retry--;
|
|
|
|
|
this.reconnect();
|
|
|
|
|
} else if (retry == 4) {
|
|
|
|
|
log.info("61850断线重连失败6次, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
|
|
|
|
|
Thread.sleep(60 * 1000);
|
|
|
|
|
this.reconnect();
|
|
|
|
|
} else if (retry == 3) {
|
|
|
|
|
Thread.sleep(3 * 60 * 1000);
|
|
|
|
|
this.reconnect();
|
|
|
|
|
} else if (retry == 2) {
|
|
|
|
|
Thread.sleep(5 * 60 * 1000);
|
|
|
|
|
this.reconnect();
|
|
|
|
|
} else if (retry == 1) {
|
|
|
|
|
Thread.sleep(10 * 60 * 1000);
|
|
|
|
|
this.reconnect();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
IecClient iecClient = new IecClient();
|
|
|
|
|
try {
|
|
|
|
|
iecClient.connect("192.168.1.17", 102, "1 3 9999 33", new FileInputStream("C:/资料/om.SCD"));
|
|
|
|
|
IcdIed ied = IcdIed.builder()
|
|
|
|
|
.ip("192.168.1.17")
|
|
|
|
|
.port(102)
|
|
|
|
|
.apTitle("1 3 9999 33")
|
|
|
|
|
.build();
|
|
|
|
|
iecClient.connect(ied, new FileInputStream("C:/资料/om.SCD"));
|
|
|
|
|
String str = iecClient.getValue("OMDLMONT/SPDC1.MaxDsch.mag.f", "MX");
|
|
|
|
|
System.out.println(str);
|
|
|
|
|
str = iecClient.getValue("OMDLMONT/SPDC1.MaxDsch.t", "MX");
|
|
|
|
|