|
|
|
@ -29,9 +29,12 @@ public class IecClient implements ClientEventListener {
|
|
|
|
|
ServerModel serverModel;
|
|
|
|
|
|
|
|
|
|
public boolean keep = false;
|
|
|
|
|
public boolean connected = false;
|
|
|
|
|
private RealTimeDataService realTimeDataService;
|
|
|
|
|
private WebSocketServer webSocketServer;
|
|
|
|
|
public int retry = 10;
|
|
|
|
|
public int retry = 0;
|
|
|
|
|
public int seconds = 0;
|
|
|
|
|
private boolean inRetry = false;
|
|
|
|
|
public Date lastReportTime;
|
|
|
|
|
|
|
|
|
|
public IecClient() {
|
|
|
|
@ -42,16 +45,20 @@ public class IecClient implements ClientEventListener {
|
|
|
|
|
webSocketServer = _webSocketServer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void connect(IcdIed _ied, String xml) throws Exception {
|
|
|
|
|
public void init(IcdIed _ied, String xml) throws Exception {
|
|
|
|
|
InputStream in = IOUtils.toInputStream(xml, StandardCharsets.UTF_8);
|
|
|
|
|
this.connect(_ied, in);
|
|
|
|
|
this.init(_ied, in);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void connect(IcdIed _ied, InputStream in) throws Exception {
|
|
|
|
|
public void init(IcdIed _ied, InputStream in) throws Exception {
|
|
|
|
|
ied = _ied;
|
|
|
|
|
serverModel = SclParser.parse(in).get(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void connect() throws Exception {
|
|
|
|
|
title = new int[]{1, 3, 9999, 33};
|
|
|
|
|
if (StringUtils.isNotBlank(_ied.getApTitle())) {
|
|
|
|
|
String[] strs = _ied.getApTitle().replaceAll(" ", ",").split(",");
|
|
|
|
|
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]);
|
|
|
|
@ -69,14 +76,15 @@ public class IecClient implements ClientEventListener {
|
|
|
|
|
clientSap.setTSelRemote(new byte[]{0, 1});
|
|
|
|
|
clientSap.setTSelLocal(new byte[]{0, 0});
|
|
|
|
|
clientSap.setApTitleCalled(title);
|
|
|
|
|
serverModel = SclParser.parse(in).get(0);
|
|
|
|
|
|
|
|
|
|
clientAssociation = clientSap.associate(InetAddress.getByName(ied.getIp()), ied.getPort(), null, this);
|
|
|
|
|
clientAssociation.setServerModel(serverModel);
|
|
|
|
|
connected = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void disconnect() {
|
|
|
|
|
try {
|
|
|
|
|
connected = false;
|
|
|
|
|
clientAssociation.disconnect();
|
|
|
|
|
clientAssociation = null;
|
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
@ -87,11 +95,13 @@ public class IecClient implements ClientEventListener {
|
|
|
|
|
if (StaticVariable.shutdown == 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
retry++;
|
|
|
|
|
seconds = 0;
|
|
|
|
|
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());
|
|
|
|
|
retry = 10;
|
|
|
|
|
keep = true;
|
|
|
|
|
connected = true;
|
|
|
|
|
retry = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getValue(String paramindex, String fc) throws Exception {
|
|
|
|
@ -126,7 +136,6 @@ public class IecClient implements ClientEventListener {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.info("61850订阅成功, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
|
|
|
|
|
keep = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void disableReporting() {
|
|
|
|
@ -151,7 +160,6 @@ public class IecClient implements ClientEventListener {
|
|
|
|
|
} else {
|
|
|
|
|
log.info("61850停止订阅, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
|
|
|
|
|
}
|
|
|
|
|
keep = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<FileInformation> listFile(String path) throws Exception {
|
|
|
|
@ -177,36 +185,31 @@ public class IecClient implements ClientEventListener {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void associationClosed(IOException e) {
|
|
|
|
|
if (keep) {
|
|
|
|
|
if (keep && !inRetry) {
|
|
|
|
|
inRetry = true;
|
|
|
|
|
retry = 0;
|
|
|
|
|
seconds = 0;
|
|
|
|
|
this.disableReporting();
|
|
|
|
|
this.disconnect();
|
|
|
|
|
while (retry > 0 && StaticVariable.shutdown == 0) {
|
|
|
|
|
retry--;
|
|
|
|
|
while (!connected && StaticVariable.shutdown == 0) {
|
|
|
|
|
try {
|
|
|
|
|
if (retry >= 5) {
|
|
|
|
|
StaticVariable.wait(10);
|
|
|
|
|
this.reconnect();
|
|
|
|
|
} else if (retry == 4) {
|
|
|
|
|
log.warn("61850订阅断线重连已失败5次, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
|
|
|
|
|
StaticVariable.wait(60);
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
seconds++;
|
|
|
|
|
if (retry < 10 && seconds > 60) {
|
|
|
|
|
this.reconnect();
|
|
|
|
|
} else if (retry >= 1) {
|
|
|
|
|
StaticVariable.wait(60);
|
|
|
|
|
} else if (seconds > 60 * 60) {
|
|
|
|
|
this.reconnect();
|
|
|
|
|
} else {
|
|
|
|
|
String err = "61850订阅断线重连已失败多次不再重连. ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort();
|
|
|
|
|
log.warn(err);
|
|
|
|
|
if (realTimeDataService != null && ied != null) {
|
|
|
|
|
realTimeDataService.stopCollect(ied.getId());
|
|
|
|
|
}
|
|
|
|
|
if (webSocketServer != null) {
|
|
|
|
|
webSocketServer.sendMessage(err, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
|
String err = "61850订阅断线重连失败" + retry + "次, ied="
|
|
|
|
|
+ ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort();
|
|
|
|
|
log.warn(err);
|
|
|
|
|
if (webSocketServer != null && retry >= 10) {
|
|
|
|
|
webSocketServer.sendMessage(err, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
inRetry = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -218,7 +221,8 @@ public class IecClient implements ClientEventListener {
|
|
|
|
|
.port(102)
|
|
|
|
|
.apTitle("1 3 9999 33")
|
|
|
|
|
.build();
|
|
|
|
|
iecClient.connect(ied, new FileInputStream("C:/资料/om.SCD"));
|
|
|
|
|
iecClient.init(ied, new FileInputStream("C:/资料/om.SCD"));
|
|
|
|
|
iecClient.connect();
|
|
|
|
|
String str = iecClient.getValue("OMDLMONT/SPDC1.MaxDsch.mag.f", "MX");
|
|
|
|
|
System.out.println(str);
|
|
|
|
|
str = iecClient.getValue("OMDLMONT/SPDC1.MaxDsch.t", "MX");
|
|
|
|
|