|
|
|
@ -1,11 +1,17 @@
|
|
|
|
|
package com.xydl.cac.iec104;
|
|
|
|
|
|
|
|
|
|
import com.xydl.cac.entity.Iec104Point;
|
|
|
|
|
import com.xydl.cac.model.StaticVariable;
|
|
|
|
|
import com.xydl.cac.util.DateUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.openmuc.j60870.*;
|
|
|
|
|
import org.openmuc.j60870.ie.*;
|
|
|
|
|
|
|
|
|
|
import java.io.EOFException;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class ServerConnectionEventListener implements ConnectionEventListener {
|
|
|
|
@ -20,7 +26,7 @@ public class ServerConnectionEventListener implements ConnectionEventListener {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void newASdu(Connection connection, ASdu aSdu) {
|
|
|
|
|
log.debug("Got new ASdu:" + aSdu.toString());
|
|
|
|
|
log.info("Got new ASdu, type=" + aSdu.getTypeIdentification());
|
|
|
|
|
InformationObject informationObject = null;
|
|
|
|
|
try {
|
|
|
|
|
switch (aSdu.getTypeIdentification()) {
|
|
|
|
@ -28,14 +34,9 @@ public class ServerConnectionEventListener implements ConnectionEventListener {
|
|
|
|
|
case C_IC_NA_1:
|
|
|
|
|
log.debug("Got interrogation command (100). Will send scaled measured values.");
|
|
|
|
|
connection.sendConfirmation(aSdu);
|
|
|
|
|
// example GI response values
|
|
|
|
|
connection.send(new ASdu(ASduType.M_ME_NB_1, true, CauseOfTransmission.INTERROGATED_BY_STATION,
|
|
|
|
|
false, false, 0, aSdu.getCommonAddress(),
|
|
|
|
|
new InformationObject(1, new InformationElement[][]{
|
|
|
|
|
{new IeScaledValue(-32768), new IeQuality(false, false, false, false, false)},
|
|
|
|
|
{new IeScaledValue(10), new IeQuality(false, false, false, false, false)},
|
|
|
|
|
{new IeScaledValue(-5),
|
|
|
|
|
new IeQuality(false, false, false, false, false)}})));
|
|
|
|
|
|
|
|
|
|
this.sendAll104(connection);
|
|
|
|
|
|
|
|
|
|
connection.sendActivationTermination(aSdu);
|
|
|
|
|
break;
|
|
|
|
|
case C_SC_NA_1:
|
|
|
|
@ -76,12 +77,40 @@ public class ServerConnectionEventListener implements ConnectionEventListener {
|
|
|
|
|
} catch (EOFException e) {
|
|
|
|
|
log.debug("Will quit listening for commands on connection (" + connectionId,
|
|
|
|
|
") because socket was closed.");
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.debug("Will quit listening for commands on connection (" + connectionId, ") because of error: ",
|
|
|
|
|
e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendAll104(Connection conn) throws Exception {
|
|
|
|
|
List<Iec104Point> list = StaticVariable.point104_Cache;
|
|
|
|
|
for (Iec104Point item : list) {
|
|
|
|
|
this.sendOne104(conn, item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void sendOne104(Connection conn, Iec104Point item) throws Exception {
|
|
|
|
|
HashMap<String, String> map = StaticVariable.sensorLastDataMap.get(item.getEqmid());
|
|
|
|
|
String value = map.get(item.getField());
|
|
|
|
|
String time = map.get("acquisitionTime");
|
|
|
|
|
if (value != null && time != null) {
|
|
|
|
|
Date date = DateUtil.parse(time);
|
|
|
|
|
Float f = Float.valueOf(value);
|
|
|
|
|
InformationObject infoObj = new InformationObject(item.getSadr(), new InformationElement[][]{
|
|
|
|
|
{new IeShortFloat(f),
|
|
|
|
|
new IeQuality(false, false, false, false, false),
|
|
|
|
|
new IeTime56(date.getTime())}
|
|
|
|
|
});
|
|
|
|
|
ASdu obj = new ASdu(ASduType.M_ME_TF_1, true, CauseOfTransmission.INTERROGATED_BY_STATION,
|
|
|
|
|
false, false, 0, 1, infoObj);
|
|
|
|
|
conn.send(obj);
|
|
|
|
|
log.info("104服务端发送: sadr=" + item.getSadr() + ", value=" + value + ", time=" + time);
|
|
|
|
|
} else {
|
|
|
|
|
log.info("数据不全,104服务端不发送: sadr=" + item.getSadr() + ", value=" + value + ", time=" + time);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void connectionClosed(Connection connection, IOException e) {
|
|
|
|
|
|
|
|
|
|