feat: 增加IecClient

iec104
huangfeng 9 months ago
parent 830ef69c1d
commit 7e52af155b

@ -0,0 +1,87 @@
package com.xydl.cac.iec;
import com.beanit.iec61850bean.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;
@Slf4j
public class IecClient implements ClientEventListener {
ClientSap clientSap = new ClientSap();
ClientAssociation clientAssociation = null;
ServerModel serverModel;
public void connect(String host, int port, String apTitle, String xml) throws Exception {
InputStream in = IOUtils.toInputStream(xml, StandardCharsets.UTF_8);
this.connect(host, port, apTitle, 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(",");
if (strs.length > 3) {
title[0] = Integer.parseInt(strs[0]);
title[1] = Integer.parseInt(strs[1]);
title[2] = Integer.parseInt(strs[2]);
title[3] = Integer.parseInt(strs[3]);
}
}
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.setServerModel(serverModel);
}
public void disconnect() {
try {
clientAssociation.disconnect();
} catch (Exception ignore) {
}
}
public String getValue(String paramindex, String fc) throws Exception {
FcModelNode node = (FcModelNode) serverModel.findModelNode(paramindex, Fc.valueOf(fc));
clientAssociation.getDataValues(node);
if (node instanceof BasicDataAttribute) {
String value = ((BasicDataAttribute) node).getValueString();
return value;
}
return null;
}
@Override
public void newReport(Report report) {
}
@Override
public void associationClosed(IOException e) {
}
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"));
String str = iecClient.getValue("OMDLMONT/SPDC1.MaxDsch.mag.f", "MX");
System.out.println(str);
str = iecClient.getValue("OMDLMONT/SPDC1.MaxDsch.t", "MX");
System.out.println(str);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
iecClient.disconnect();
}
}
}
Loading…
Cancel
Save