|
|
|
@ -2,7 +2,7 @@ package com.xydl.cac.iec104;
|
|
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.openmuc.j60870.*;
|
|
|
|
|
import org.openmuc.j60870.ie.IeQualifierOfInterrogation;
|
|
|
|
|
import org.openmuc.j60870.ie.*;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.InetAddress;
|
|
|
|
@ -11,7 +11,7 @@ import java.net.InetAddress;
|
|
|
|
|
public class Iec104Client implements ConnectionEventListener {
|
|
|
|
|
public String ip;
|
|
|
|
|
public Integer port;
|
|
|
|
|
Connection connection;
|
|
|
|
|
Connection connection = null;
|
|
|
|
|
|
|
|
|
|
public void connect(String _ip, Integer _port) throws Exception {
|
|
|
|
|
ip = _ip;
|
|
|
|
@ -23,11 +23,17 @@ public class Iec104Client implements ConnectionEventListener {
|
|
|
|
|
.setPort(port)
|
|
|
|
|
.setConnectionEventListener(this);
|
|
|
|
|
connection = clientConnectionBuilder.build();
|
|
|
|
|
connection.startDataTransfer();
|
|
|
|
|
log.info("IEC104客户端已连接上" + ip + ":" + port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void disconnect() {
|
|
|
|
|
if (connection != null) {
|
|
|
|
|
try {
|
|
|
|
|
connection.stopDataTransfer();
|
|
|
|
|
connection.close();
|
|
|
|
|
connection = null;
|
|
|
|
|
log.info("IEC104客户端已断开" + ip + ":" + port);
|
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -39,6 +45,15 @@ public class Iec104Client implements ConnectionEventListener {
|
|
|
|
|
@Override
|
|
|
|
|
public void newASdu(Connection connection, ASdu aSdu) {
|
|
|
|
|
log.debug("Got new ASdu:" + aSdu.toString());
|
|
|
|
|
InformationObject[] objs = aSdu.getInformationObjects();
|
|
|
|
|
if (objs != null && objs.length > 0) {
|
|
|
|
|
log.debug("InformationObject size=" + objs.length);
|
|
|
|
|
for (InformationObject obj : objs) {
|
|
|
|
|
log.debug("ObjectAddress=" + obj.getInformationObjectAddress());
|
|
|
|
|
InformationElement[][] elements = obj.getInformationElements();
|
|
|
|
|
log.debug("elements=" + elements);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -50,4 +65,17 @@ public class Iec104Client implements ConnectionEventListener {
|
|
|
|
|
public void dataTransferStateChanged(Connection connection, boolean b) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
Iec104Client client = new Iec104Client();
|
|
|
|
|
try {
|
|
|
|
|
client.connect("127.0.0.1", 2404);
|
|
|
|
|
client.interrogation();
|
|
|
|
|
while (true) {
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|