Commit b04958e5 authored by 高东东's avatar 高东东

Merge branch 'gaodongdong' into develop

parents 224b64bc 4de510b1
...@@ -87,7 +87,10 @@ public class ClientHandler extends SimpleChannelInboundHandler<Apdu>{ ...@@ -87,7 +87,10 @@ public class ClientHandler extends SimpleChannelInboundHandler<Apdu>{
connetOk = false; connetOk = false;
} else if (apdu.getApciType() == Apdu.ApciType.TESTFR_ACT) { } else if (apdu.getApciType() == Apdu.ApciType.TESTFR_ACT) {
ctx.channel().writeAndFlush("680483000000", promise); ctx.channel().writeAndFlush("680483000000", promise);
if (startZZ) {
startZZ = false;
sendZzCommand();
}
Logger.getLogger(this.getClass()).debug("确认测试消息,U类型"); Logger.getLogger(this.getClass()).debug("确认测试消息,U类型");
} else if (apdu.getApciType() == Apdu.ApciType.STARTDT_CON) { } else if (apdu.getApciType() == Apdu.ApciType.STARTDT_CON) {
Logger.getLogger(this.getClass()).debug("启动确认帧回复,U类型"); Logger.getLogger(this.getClass()).debug("启动确认帧回复,U类型");
......
...@@ -70,6 +70,10 @@ public class IEC104NewHandler extends SimpleChannelInboundHandler<Apdu>{ ...@@ -70,6 +70,10 @@ public class IEC104NewHandler extends SimpleChannelInboundHandler<Apdu>{
close(); close();
} else if (apdu.getApciType() == Apdu.ApciType.TESTFR_ACT) { } else if (apdu.getApciType() == Apdu.ApciType.TESTFR_ACT) {
handleBlockingSendQueue.add("680483000000"); handleBlockingSendQueue.add("680483000000");
if (eecruiting_Communication == null) {
eecruiting_Communication = Executors.newSingleThreadScheduledExecutor();
eecruiting_Communication.scheduleAtFixedRate(Recruiting_runnable, Constant.Z_Z_INITIALDELAY, Constant.Z_Z_PREIOD, TimeUnit.SECONDS);
}
Logger.getLogger(this.getClass()).debug("确认测试消息,U类型"); Logger.getLogger(this.getClass()).debug("确认测试消息,U类型");
} else if (apdu.getApciType() == Apdu.ApciType.STARTDT_CON) { } else if (apdu.getApciType() == Apdu.ApciType.STARTDT_CON) {
Logger.getLogger(this.getClass()).debug("启动确认帧回复,U类型"); Logger.getLogger(this.getClass()).debug("启动确认帧回复,U类型");
......
...@@ -6,19 +6,11 @@ import java.util.concurrent.Executors; ...@@ -6,19 +6,11 @@ import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import com.yeejoin.amos.iec104.tcp.entity.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import com.yeejoin.amos.iec104.business.entity.mybatis.RecData; import com.yeejoin.amos.iec104.business.entity.mybatis.RecData;
import com.yeejoin.amos.iec104.tcp.entity.Apdu;
import com.yeejoin.amos.iec104.tcp.entity.Asdu;
import com.yeejoin.amos.iec104.tcp.entity.IeCP56Time2a;
import com.yeejoin.amos.iec104.tcp.entity.IeQuality;
import com.yeejoin.amos.iec104.tcp.entity.IeShortFloat;
import com.yeejoin.amos.iec104.tcp.entity.IeSinglePointWithQuality;
import com.yeejoin.amos.iec104.tcp.entity.InformationElement;
import com.yeejoin.amos.iec104.tcp.entity.InformationObject;
import com.yeejoin.amos.iec104.tcp.entity.ServerData;
public class ApduQueue { public class ApduQueue {
...@@ -27,15 +19,16 @@ public class ApduQueue { ...@@ -27,15 +19,16 @@ public class ApduQueue {
private volatile static ApduQueue instance = null; private volatile static ApduQueue instance = null;
private ApduQueue() {} private ApduQueue() {
}
public static ApduQueue getInstance(){ public static ApduQueue getInstance() {
//先检查实例是否存在,如果不存在才进入下面的同步块 //先检查实例是否存在,如果不存在才进入下面的同步块
if(instance == null){ if (instance == null) {
//同步块,线程安全的创建实例 //同步块,线程安全的创建实例
synchronized(ApduQueue.class){ synchronized (ApduQueue.class) {
//再次检查实例是否存在,如果不存在才真的创建实例 //再次检查实例是否存在,如果不存在才真的创建实例
if(instance == null){ if (instance == null) {
instance = new ApduQueue(); instance = new ApduQueue();
} }
} }
...@@ -58,7 +51,7 @@ public class ApduQueue { ...@@ -58,7 +51,7 @@ public class ApduQueue {
Runnable task_runnable = new Runnable() { Runnable task_runnable = new Runnable() {
public void run() { public void run() {
while(true) { while (true) {
try { try {
ServerData serverData = blockingQueue.take(); ServerData serverData = blockingQueue.take();
String serverId = serverData.getServerId(); String serverId = serverData.getServerId();
...@@ -97,6 +90,33 @@ public class ApduQueue { ...@@ -97,6 +90,33 @@ public class ApduQueue {
} }
break; break;
// 13 浮点型遥测 // 13 浮点型遥测
case 9:
InformationObject[] shortfloatInformationObjects = asdu.getInformationObjects();
numberOfSequenceElements = asdu.getSequenceLength();
for (int i = 0; i < numberOfSequenceElements; i++) {
InformationObject obj = shortfloatInformationObjects[i];
InformationElement[][] informationElement = obj.getInformationElements();
int informationObjectAddress = obj.getInformationObjectAddress();
RecData data = new RecData(serverId);
data.setCommonAddress(asdu.getCommonAddress());
data.setCreatedTime(new Date());
data.setDataType(2);
data.setInformationAddress(informationObjectAddress);
IeShort shortFloat = (IeShort) informationElement[0][0];
IeQuality ieQuality = (IeQuality) informationElement[0][1];
data.setValue(String.format("%.2f",shortFloat.getValue()));
data.setQuality(ieQuality.toJson().toString());
data.setIsBlocked(ieQuality.isBlocked() ? 0 : 1);
data.setIsSubstituted(ieQuality.isSubstituted() ? 0 : 1);
data.setIsNotTopical(ieQuality.isNotTopical() ? 0 : 1);
data.setIsInvalid(ieQuality.isInvalid() ? 0 : 1);
data.setIsOverflow(ieQuality.isOverflow() ? 0 : 1);
informationObjectAddress++;
RecDataQueue.getInstance().add(data);
// }
}
case 13: case 13:
InformationObject[] floatInformationObjects = asdu.getInformationObjects(); InformationObject[] floatInformationObjects = asdu.getInformationObjects();
numberOfSequenceElements = asdu.getSequenceLength(); numberOfSequenceElements = asdu.getSequenceLength();
...@@ -113,13 +133,13 @@ public class ApduQueue { ...@@ -113,13 +133,13 @@ public class ApduQueue {
data.setInformationAddress(informationObjectAddress); data.setInformationAddress(informationObjectAddress);
IeShortFloat shortFloat = (IeShortFloat) informationElement[0][0]; IeShortFloat shortFloat = (IeShortFloat) informationElement[0][0];
IeQuality ieQuality = (IeQuality) informationElement[0][1]; IeQuality ieQuality = (IeQuality) informationElement[0][1];
data.setValue(shortFloat.getValue() + ""); data.setValue(String.format("%.2f",shortFloat.getValue()));
data.setQuality(ieQuality.toJson().toString()); data.setQuality(ieQuality.toJson().toString());
data.setIsBlocked(ieQuality.isBlocked() ? 0 : 1); data.setIsBlocked(ieQuality.isBlocked() ? 0 : 1);
data.setIsSubstituted(ieQuality.isSubstituted() ? 0 : 1); data.setIsSubstituted(ieQuality.isSubstituted() ? 0 : 1);
data.setIsNotTopical(ieQuality.isNotTopical() ? 0 : 1); data.setIsNotTopical(ieQuality.isNotTopical() ? 0 : 1);
data.setIsInvalid(ieQuality.isInvalid() ? 0 : 1); data.setIsInvalid(ieQuality.isInvalid() ? 0 : 1);
data.setIsOverflow(ieQuality.isOverflow() ? 0: 1); data.setIsOverflow(ieQuality.isOverflow() ? 0 : 1);
informationObjectAddress++; informationObjectAddress++;
RecDataQueue.getInstance().add(data); RecDataQueue.getInstance().add(data);
...@@ -141,7 +161,7 @@ public class ApduQueue { ...@@ -141,7 +161,7 @@ public class ApduQueue {
data.setDataType(2); data.setDataType(2);
data.setInformationAddress(informationObjectAddress); data.setInformationAddress(informationObjectAddress);
IeShortFloat shortFloat = (IeShortFloat) informationElement[0][0]; IeShortFloat shortFloat = (IeShortFloat) informationElement[0][0];
data.setValue(shortFloat.getValue() + ""); data.setValue(String.format("%.2f",shortFloat.getValue()));
informationObjectAddress++; informationObjectAddress++;
RecDataQueue.getInstance().add(data); RecDataQueue.getInstance().add(data);
...@@ -174,7 +194,7 @@ public class ApduQueue { ...@@ -174,7 +194,7 @@ public class ApduQueue {
data.setIsSubstituted(singlePoint.isSubstituted() ? 0 : 1); data.setIsSubstituted(singlePoint.isSubstituted() ? 0 : 1);
data.setIsNotTopical(singlePoint.isNotTopical() ? 0 : 1); data.setIsNotTopical(singlePoint.isNotTopical() ? 0 : 1);
data.setIsInvalid(singlePoint.isInvalid() ? 0 : 1); data.setIsInvalid(singlePoint.isInvalid() ? 0 : 1);
Logger.getLogger(this.getClass()).debug("31类型 I帧: " +data.toString()); Logger.getLogger(this.getClass()).debug("31类型 I帧: " + data.toString());
RecDataQueue.getInstance().add(data); RecDataQueue.getInstance().add(data);
// } // }
} }
......
package com.yeejoin.amos.iec104.tcp.entity;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
public class IeShort extends InformationElement {
private final float value;
public IeShort(float value) {
this.value = value;
}
public IeShort(ByteBuf is) throws IOException {
value = Float.intBitsToFloat((is.readByte() & 0xff) | ((is.readByte() & 0xff) << 8));
}
@Override
public int encode(byte[] buffer, int i) {
int tempVal = Float.floatToIntBits(value);
buffer[i++] = (byte) tempVal;
buffer[i] = (byte) (tempVal >> 8);
return 2;
}
public float getValue() {
return value;
}
@Override
public String toString() {
return "短浮点数值: " + value;
}
}
...@@ -40,6 +40,16 @@ public class InformationObject { ...@@ -40,6 +40,16 @@ public class InformationObject {
} }
break; break;
// 9 测量值, 规一化值
case 9:
informationElements = new InformationElement[numberOfSequenceElements][2];
for (int i = 0; i < numberOfSequenceElements; i++) {
informationElements[i][0] = new IeShort(is);
informationElements[i][1] = new IeQuality(is);
log.debug("9 浮点型遥测1: " + i + "--->" + informationElements[i][0].toString());
log.debug("9 浮点型遥测2: " + i + "--->" + informationElements[i][1].toString());
}
break;
// 13 浮点型遥测 // 13 浮点型遥测
case 13: case 13:
informationElements = new InformationElement[numberOfSequenceElements][2]; informationElements = new InformationElement[numberOfSequenceElements][2];
...@@ -54,7 +64,7 @@ public class InformationObject { ...@@ -54,7 +64,7 @@ public class InformationObject {
case 21: case 21:
informationElements = new InformationElement[numberOfSequenceElements][1]; informationElements = new InformationElement[numberOfSequenceElements][1];
for (int i = 0; i < numberOfSequenceElements; i++) { for (int i = 0; i < numberOfSequenceElements; i++) {
informationElements[i][0] = new IeShortFloat(is); informationElements[i][0] = new IeShort(is);
log.debug("21 浮点型遥测, 不带品质描述词的规一化值: " + i + "--->" + informationElements[i][0].toString()); log.debug("21 浮点型遥测, 不带品质描述词的规一化值: " + i + "--->" + informationElements[i][0].toString());
} }
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment