浏览代码

修改104 遥信长度校验

xiuwei 4 年之前
父节点
当前提交
664303d461

+ 8 - 0
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/BooleanType.java

@@ -12,6 +12,7 @@ import wei.yigulu.iec104.asdudataframe.typemodel.IeBoolean;
 import wei.yigulu.iec104.asdudataframe.typemodel.InformationBodyAddress;
 import wei.yigulu.iec104.asdudataframe.typemodel.InformationBodyAddress;
 import wei.yigulu.iec104.exception.Iec104Exception;
 import wei.yigulu.iec104.exception.Iec104Exception;
 import wei.yigulu.iec104.nettyconfig.TechnicalTerm;
 import wei.yigulu.iec104.nettyconfig.TechnicalTerm;
+import wei.yigulu.iec104.util.SendDataFrameHelper;
 
 
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
@@ -32,6 +33,7 @@ public class BooleanType extends AbstractDataFrameType {
 	 */
 	 */
 	public static final int TYPEID = TechnicalTerm.SINGEL_POINT_TYPE;
 	public static final int TYPEID = TechnicalTerm.SINGEL_POINT_TYPE;
 
 
+
 	private List<InformationBodyAddress> addresses = new ArrayList<>();
 	private List<InformationBodyAddress> addresses = new ArrayList<>();
 
 
 	private List<IeBoolean> datas = new ArrayList<>();
 	private List<IeBoolean> datas = new ArrayList<>();
@@ -44,6 +46,9 @@ public class BooleanType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 * @throws Iec104Exception iec exception
 	 */
 	 */
 	public BooleanType(List<InformationBodyAddress> addresses, List<IeBoolean> datas) throws Iec104Exception {
 	public BooleanType(List<InformationBodyAddress> addresses, List<IeBoolean> datas) throws Iec104Exception {
+		if(datas.size()> SendDataFrameHelper.MAXCONTINUITYYXNUM){
+			throw new Iec104Exception("数据个数过多,创建对象失败,请切割数据。");
+		}
 		if ((this.datas.size()*IeBoolean.OCCUPYBYTES + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) > 240) {
 		if ((this.datas.size()*IeBoolean.OCCUPYBYTES + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) > 240) {
 			throw new Iec104Exception("长度超长,创建对象失败,请切割数据。");
 			throw new Iec104Exception("长度超长,创建对象失败,请切割数据。");
 		}
 		}
@@ -95,6 +100,9 @@ public class BooleanType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 * @throws Iec104Exception iec exception
 	 */
 	 */
 	protected void validateLen(int increase) throws Iec104Exception {
 	protected void validateLen(int increase) throws Iec104Exception {
+		if(datas.size()> SendDataFrameHelper.MAXCONTINUITYYXNUM){
+			throw new Iec104Exception("数据个数过多,不能再向此对象中添加元素");
+		}
 		if ((this.datas.size() * IeBoolean.OCCUPYBYTES + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES + increase) > 240) {
 		if ((this.datas.size() * IeBoolean.OCCUPYBYTES + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES + increase) > 240) {
 			throw new Iec104Exception("长度超长,不能再向此对象中添加元素");
 			throw new Iec104Exception("长度超长,不能再向此对象中添加元素");
 		}
 		}

+ 28 - 7
protocol-iec104/src/main/java/wei/yigulu/iec104/util/SendDataFrameHelper.java

@@ -21,6 +21,27 @@ import java.util.*;
 public class SendDataFrameHelper {
 public class SendDataFrameHelper {
 
 
 	/**
 	/**
+	 * 单帧最长连续遥信个数
+	 */
+	public static final int MAXCONTINUITYYXNUM=127;
+
+	/**
+	 * 单帧最长单点遥信个数
+	 */
+	public static final int MAXDISCONTINUITYYXNUM=49;
+
+	/**
+	 * 单帧最长连续遥测个数
+	 */
+	public static final int MAXCONTINUITYYCNUM=45;
+
+	/**
+	 * 单帧最长单点遥测个数
+	 */
+	public static final int MAXDISCONTINUITYYCNUM=25;
+
+
+	/**
 	 * 发送遥信数据帧
 	 * 发送遥信数据帧
 	 *
 	 *
 	 * @param channel 通达对象
 	 * @param channel 通达对象
@@ -41,7 +62,7 @@ public class SendDataFrameHelper {
 			max = Collections.max(keys);
 			max = Collections.max(keys);
 			min = Collections.min(keys);
 			min = Collections.min(keys);
 			if ((max - min) == (keys.size() - 1)) {
 			if ((max - min) == (keys.size() - 1)) {
-				for (List<Integer> li : splitAndSort(keys, 400)) {
+				for (List<Integer> li : splitAndSort(keys, MAXCONTINUITYYXNUM)) {
 					booleanType = new BooleanType();
 					booleanType = new BooleanType();
 					booleanType.addAddress(new InformationBodyAddress(li.get(0)));
 					booleanType.addAddress(new InformationBodyAddress(li.get(0)));
 					for (Integer i : li) {
 					for (Integer i : li) {
@@ -56,7 +77,7 @@ public class SendDataFrameHelper {
 					Thread.sleep(20);
 					Thread.sleep(20);
 				}
 				}
 			} else {
 			} else {
-				for (Map<Integer, Boolean> m : split(dates, 100)) {
+				for (Map<Integer, Boolean> m : split(dates, MAXDISCONTINUITYYXNUM)) {
 					booleanType = new BooleanType();
 					booleanType = new BooleanType();
 					for (Map.Entry<Integer, Boolean> em : m.entrySet()) {
 					for (Map.Entry<Integer, Boolean> em : m.entrySet()) {
 						booleanType.addDataAndAdd(new InformationBodyAddress(em.getKey()), em.getValue());
 						booleanType.addDataAndAdd(new InformationBodyAddress(em.getKey()), em.getValue());
@@ -88,7 +109,7 @@ public class SendDataFrameHelper {
 		Apdu apdu;
 		Apdu apdu;
 		Asdu asdu;
 		Asdu asdu;
 		if (dates.size() > 0) {
 		if (dates.size() > 0) {
-			for (Map<Integer, Boolean> m : split(dates, 100)) {
+			for (Map<Integer, Boolean> m : split(dates, MAXDISCONTINUITYYXNUM)) {
 				booleanType = new BooleanType();
 				booleanType = new BooleanType();
 				for (Map.Entry<Integer, Boolean> em : m.entrySet()) {
 				for (Map.Entry<Integer, Boolean> em : m.entrySet()) {
 					booleanType.addDataAndAdd(new InformationBodyAddress(em.getKey()), em.getValue());
 					booleanType.addDataAndAdd(new InformationBodyAddress(em.getKey()), em.getValue());
@@ -125,7 +146,7 @@ public class SendDataFrameHelper {
 			max = Collections.max(keys);
 			max = Collections.max(keys);
 			min = Collections.min(keys);
 			min = Collections.min(keys);
 			if ((max - min) == (keys.size() - 1)) {
 			if ((max - min) == (keys.size() - 1)) {
-				for (List<Integer> li : splitAndSort(keys, 45)) {
+				for (List<Integer> li : splitAndSort(keys, MAXCONTINUITYYCNUM)) {
 					shortFloatType = new ShortFloatType();
 					shortFloatType = new ShortFloatType();
 					shortFloatType.addAddress(new InformationBodyAddress(li.get(0)));
 					shortFloatType.addAddress(new InformationBodyAddress(li.get(0)));
 					for (Integer i : li) {
 					for (Integer i : li) {
@@ -140,7 +161,7 @@ public class SendDataFrameHelper {
 					Thread.sleep(20);
 					Thread.sleep(20);
 				}
 				}
 			} else {
 			} else {
-				for (Map<Integer, Number> m : split(dates, 25)) {
+				for (Map<Integer, Number> m : split(dates, MAXDISCONTINUITYYCNUM)) {
 					shortFloatType = new ShortFloatType();
 					shortFloatType = new ShortFloatType();
 					for (Map.Entry<Integer, Number> em : m.entrySet()) {
 					for (Map.Entry<Integer, Number> em : m.entrySet()) {
 						shortFloatType.addDataAndAdd(new InformationBodyAddress(em.getKey()), em.getValue().floatValue());
 						shortFloatType.addDataAndAdd(new InformationBodyAddress(em.getKey()), em.getValue().floatValue());
@@ -172,7 +193,7 @@ public class SendDataFrameHelper {
 		Asdu asdu;
 		Asdu asdu;
 		ShortFloatType shortFloatType;
 		ShortFloatType shortFloatType;
 		if (dates.size() > 0) {
 		if (dates.size() > 0) {
-			for (Map<Integer, Number> m : split(dates, 25)) {
+			for (Map<Integer, Number> m : split(dates, MAXDISCONTINUITYYCNUM)) {
 				shortFloatType = new ShortFloatType();
 				shortFloatType = new ShortFloatType();
 				for (Map.Entry<Integer, Number> em : m.entrySet()) {
 				for (Map.Entry<Integer, Number> em : m.entrySet()) {
 					shortFloatType.addDataAndAdd(new InformationBodyAddress(em.getKey()), em.getValue().floatValue());
 					shortFloatType.addDataAndAdd(new InformationBodyAddress(em.getKey()), em.getValue().floatValue());
@@ -239,7 +260,7 @@ public class SendDataFrameHelper {
 
 
 	/**
 	/**
 	 * 进行拆分并排序 主要是排序map 中的keyset 对keyset的int型进行排序
 	 * 进行拆分并排序 主要是排序map 中的keyset 对keyset的int型进行排序
-	 *
+	 * 	 *
 	 * @param set    要排序的set
 	 * @param set    要排序的set
 	 * @param maxLen 设定的最长长度
 	 * @param maxLen 设定的最长长度
 	 * @return 拆分后的集合 的集合
 	 * @return 拆分后的集合 的集合