Explorar o código

报文长度规则校验修改

xiuwei %!s(int64=4) %!d(string=hai) anos
pai
achega
0b6651aeb1
Modificáronse 17 ficheiros con 74 adicións e 30 borrados
  1. 1 1
      pom.xml
  2. 5 5
      protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/BooleanType.java
  3. 7 6
      protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/NoQualityNormalizedIntegerType.java
  4. 5 5
      protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/NormalizedIntegerType.java
  5. 5 5
      protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/ShortFloatType.java
  6. 5 5
      protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/ShortIntegerType.java
  7. 1 0
      protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/qualitydescription/IeAbstractQuality.java
  8. 2 0
      protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/qualitydescription/IeMeasuredQuality.java
  9. 2 0
      protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/typemodel/IeBoolean.java
  10. 4 2
      protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/typemodel/IeFourByteInteger.java
  11. 1 0
      protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/typemodel/IeProofreadTime.java
  12. 2 0
      protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/typemodel/IeShortFloat.java
  13. 2 0
      protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/typemodel/IeShortInteger.java
  14. 2 0
      protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/typemodel/InformationBodyAddress.java
  15. 1 1
      protocol-iec104/src/test/java/MasterTest.java
  16. 2 0
      protocol-iec104/src/test/java/SlaveTest.java
  17. 27 0
      protocol-iec104/src/test/java/TestTotalS.java

+ 1 - 1
pom.xml

@@ -6,7 +6,7 @@
 
     <groupId>wei.yigulu</groupId>
     <artifactId>protocol</artifactId>
-    <version>1.0</version>
+    <version>1.1</version>
     <packaging>pom</packaging>
     <modules>
         <module>protocol-core</module>

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

@@ -44,7 +44,7 @@ public class BooleanType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public BooleanType(List<InformationBodyAddress> addresses, List<IeBoolean> datas) throws Iec104Exception {
-		if ((this.datas.size() + this.addresses.size() * 4) > 240) {
+		if ((this.datas.size()*IeBoolean.OCCUPYBYTES + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) > 240) {
 			throw new Iec104Exception("长度超长,创建对象失败,请切割数据。");
 		}
 		this.addresses = addresses;
@@ -59,7 +59,7 @@ public class BooleanType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public void addData(boolean f) throws Iec104Exception {
-		validateLen(1);
+		validateLen(IeBoolean.OCCUPYBYTES);
 		this.datas.add(new IeBoolean(f));
 	}
 
@@ -72,7 +72,7 @@ public class BooleanType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public void addDataAndAdd(InformationBodyAddress address, boolean f) throws Iec104Exception {
-		this.addresses.add(address);
+		addAddress(address);
 		addData(f);
 	}
 
@@ -84,7 +84,7 @@ public class BooleanType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public void addAddress(InformationBodyAddress address) throws Iec104Exception {
-		validateLen(4);
+		validateLen(InformationBodyAddress.OCCUPYBYTES);
 		this.addresses.add(address);
 	}
 
@@ -95,7 +95,7 @@ public class BooleanType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	protected void validateLen(int increase) throws Iec104Exception {
-		if ((this.datas.size() * 1 + this.addresses.size() * 4 + increase) > 240) {
+		if ((this.datas.size() * IeBoolean.OCCUPYBYTES + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES + increase) > 240) {
 			throw new Iec104Exception("长度超长,不能再向此对象中添加元素");
 		}
 	}

+ 7 - 6
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/NoQualityNormalizedIntegerType.java

@@ -42,7 +42,7 @@ public class NoQualityNormalizedIntegerType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public NoQualityNormalizedIntegerType(List<InformationBodyAddress> addresses, List<Integer> datas) throws Iec104Exception {
-		if ((this.datas.size() * 3 + this.addresses.size() * 4) > 240) {
+		if ((this.datas.size() * IeShortInteger.OCCUPYBYTES + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) > 240) {
 			throw new Iec104Exception("长度超长,创建对象失败,请切割数据。");
 		}
 		this.addresses = addresses;
@@ -73,7 +73,8 @@ public class NoQualityNormalizedIntegerType extends AbstractDataFrameType {
 	 *
 	 * @param f f
 	 */
-	public void addData(int f) {
+	public void addData(int f) throws Iec104Exception {
+		validateLen(IeShortInteger.OCCUPYBYTES);
 		this.datas.add(f);
 	}
 
@@ -84,8 +85,8 @@ public class NoQualityNormalizedIntegerType extends AbstractDataFrameType {
 	 * @param address address
 	 * @param f       f
 	 */
-	public void addDataAndAdd(InformationBodyAddress address, int f) {
-		this.addresses.add(address);
+	public void addDataAndAdd(InformationBodyAddress address, int f) throws Iec104Exception {
+		addAddress(address);
 		addData(f);
 	}
 
@@ -97,7 +98,7 @@ public class NoQualityNormalizedIntegerType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public void addAddress(InformationBodyAddress address) throws Iec104Exception {
-		validateLen(4);
+		validateLen(InformationBodyAddress.OCCUPYBYTES);
 		this.addresses.add(address);
 	}
 
@@ -138,7 +139,7 @@ public class NoQualityNormalizedIntegerType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	protected void validateLen(int increase) throws Iec104Exception {
-		if ((this.datas.size() * 3 + this.addresses.size() * 4 + increase) > 240) {
+		if ((this.datas.size() * IeShortInteger.OCCUPYBYTES + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES+increase) > 240){
 			throw new Iec104Exception("长度超长,不能再向此对象中添加元素");
 		}
 	}

+ 5 - 5
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/NormalizedIntegerType.java

@@ -45,7 +45,7 @@ public class NormalizedIntegerType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public NormalizedIntegerType(List<InformationBodyAddress> addresses, Map<IeMeasuredQuality, Integer> datas) throws Iec104Exception {
-		if ((this.datas.size() * 3 + this.addresses.size() * 4) > 240) {
+		if ((this.datas.size() * (IeMeasuredQuality.OCCUPYBYTES+IeShortInteger.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) > 240) {
 			throw new Iec104Exception("长度超长,创建对象失败,请切割数据。");
 		}
 		this.addresses = addresses;
@@ -89,7 +89,7 @@ public class NormalizedIntegerType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public void addData(int f, IeMeasuredQuality quality) throws Iec104Exception {
-		validateLen(3);
+		validateLen(IeShortInteger.OCCUPYBYTES+IeMeasuredQuality.OCCUPYBYTES);
 		this.datas.put(quality, f);
 	}
 
@@ -115,7 +115,7 @@ public class NormalizedIntegerType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public void addDataAndAdd(InformationBodyAddress address, int f) throws Iec104Exception {
-		this.addresses.add(address);
+		addAddress(address);
 		addData(f);
 	}
 
@@ -127,7 +127,7 @@ public class NormalizedIntegerType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public void addAddress(InformationBodyAddress address) throws Iec104Exception {
-		validateLen(4);
+		validateLen(InformationBodyAddress.OCCUPYBYTES);
 		this.addresses.add(address);
 	}
 
@@ -170,7 +170,7 @@ public class NormalizedIntegerType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	protected void validateLen(int increase) throws Iec104Exception {
-		if ((this.datas.size() * 3 + this.addresses.size() * 4 + increase) > 240) {
+		if (((this.datas.size() * (IeMeasuredQuality.OCCUPYBYTES+IeShortInteger.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) + increase) > 240) {
 			throw new Iec104Exception("长度超长,不能再向此对象中添加元素");
 		}
 	}

+ 5 - 5
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/ShortFloatType.java

@@ -46,7 +46,7 @@ public class ShortFloatType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public ShortFloatType(List<InformationBodyAddress> addresses, Map<IeMeasuredQuality, Float> datas) throws Iec104Exception {
-		if ((this.datas.size() * 5 + this.addresses.size() * 4) > 240) {
+		if ((this.datas.size() * (IeShortFloat.OCCUPYBYTES+IeMeasuredQuality.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) > 240) {
 			throw new Iec104Exception("长度超长,创建对象失败,请切割数据。");
 		}
 		this.addresses = addresses;
@@ -72,7 +72,7 @@ public class ShortFloatType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public void addData(float f, IeMeasuredQuality quality) throws Iec104Exception {
-		validateLen(5);
+		validateLen(IeShortFloat.OCCUPYBYTES+IeMeasuredQuality.OCCUPYBYTES);
 		this.datas.put(quality, f);
 	}
 
@@ -98,7 +98,7 @@ public class ShortFloatType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public void addDataAndAdd(InformationBodyAddress address, float f) throws Iec104Exception {
-		this.addresses.add(address);
+		addAddress(address);
 		addData(f);
 	}
 
@@ -110,7 +110,7 @@ public class ShortFloatType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public void addAddress(InformationBodyAddress address) throws Iec104Exception {
-		validateLen(4);
+		validateLen(InformationBodyAddress.OCCUPYBYTES);
 		this.addresses.add(address);
 	}
 
@@ -154,7 +154,7 @@ public class ShortFloatType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	protected void validateLen(int increase) throws Iec104Exception {
-		if ((this.datas.size() * 5 + this.addresses.size() * 4 + increase) > 240) {
+		if ((this.datas.size() * (IeShortFloat.OCCUPYBYTES+IeMeasuredQuality.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES + increase) > 240) {
 			throw new Iec104Exception("长度超长,不能再向此对象中添加元素");
 		}
 	}

+ 5 - 5
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/ShortIntegerType.java

@@ -45,7 +45,7 @@ public class ShortIntegerType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public ShortIntegerType(List<InformationBodyAddress> addresses, Map<IeMeasuredQuality, Integer> datas) throws Iec104Exception {
-		if ((this.datas.size() * 3 + this.addresses.size() * 4) > 240) {
+		if ((this.datas.size() * (IeShortInteger.OCCUPYBYTES+IeMeasuredQuality.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) > 240) {
 			throw new Iec104Exception("长度超长,创建对象失败,请切割数据。");
 		}
 		this.addresses = addresses;
@@ -89,7 +89,7 @@ public class ShortIntegerType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public void addData(int f, IeMeasuredQuality quality) throws Iec104Exception {
-		validateLen(3);
+		validateLen(IeShortInteger.OCCUPYBYTES+IeMeasuredQuality.OCCUPYBYTES);
 		this.datas.put(quality, f);
 	}
 
@@ -115,7 +115,7 @@ public class ShortIntegerType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public void addDataAndAdd(InformationBodyAddress address, int f) throws Iec104Exception {
-		this.addresses.add(address);
+		addAddress(address);
 		addData(f);
 	}
 
@@ -127,7 +127,7 @@ public class ShortIntegerType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	public void addAddress(InformationBodyAddress address) throws Iec104Exception {
-		validateLen(4);
+		validateLen(InformationBodyAddress.OCCUPYBYTES);
 		this.addresses.add(address);
 	}
 
@@ -170,7 +170,7 @@ public class ShortIntegerType extends AbstractDataFrameType {
 	 * @throws Iec104Exception iec exception
 	 */
 	protected void validateLen(int increase) throws Iec104Exception {
-		if ((this.datas.size() * 3 + this.addresses.size() * 4 + increase) > 240) {
+		if ((this.datas.size() * (IeShortInteger.OCCUPYBYTES+IeMeasuredQuality.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES+ increase) > 240) {
 			throw new Iec104Exception("长度超长,不能再向此对象中添加元素");
 		}
 	}

+ 1 - 0
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/qualitydescription/IeAbstractQuality.java

@@ -17,6 +17,7 @@ import lombok.NoArgsConstructor;
 @NoArgsConstructor
 public class IeAbstractQuality {
 
+	public static final int  OCCUPYBYTES=1;
 
 	/**
 	 * 品质的值

+ 2 - 0
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/qualitydescription/IeMeasuredQuality.java

@@ -18,6 +18,8 @@ import lombok.NoArgsConstructor;
 @EqualsAndHashCode
 public class IeMeasuredQuality extends IeAbstractQuality {
 
+	public static final int  OCCUPYBYTES=1;
+
 	/**
 	 * 是否溢出 0 代表未溢出;1 代表溢出
 	 */

+ 2 - 0
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/typemodel/IeBoolean.java

@@ -19,6 +19,8 @@ import wei.yigulu.iec104.asdudataframe.qualitydescription.IeAbstractQuality;
 @Data
 public class IeBoolean extends IeAbstractQuality {
 
+	public static final int  OCCUPYBYTES=1;
+
 	/**
 	 * 信息状态,是否开闸 1:合;2:开
 	 */

+ 4 - 2
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/typemodel/IeFourBitInteger.java → protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/typemodel/IeFourByteInteger.java

@@ -16,7 +16,9 @@ import java.util.List;
 @Data
 @AllArgsConstructor
 @NoArgsConstructor
-public class IeFourBitInteger {
+public class IeFourByteInteger {
+
+	public static final int  OCCUPYBYTES=4;
 
 	private Integer value;
 
@@ -25,7 +27,7 @@ public class IeFourBitInteger {
 	 *
 	 * @param is is
 	 */
-	public IeFourBitInteger(ByteBuf is) {
+	public IeFourByteInteger(ByteBuf is) {
 		value = ((is.readByte() & 0xff) | ((is.readByte() & 0xff) << 8) | ((is.readByte() & 0xff) << 16) | ((is.readByte() & 0xff) << 24));
 	}
 

+ 1 - 0
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/typemodel/IeProofreadTime.java

@@ -20,6 +20,7 @@ import java.util.List;
 @AllArgsConstructor
 @Data
 public class IeProofreadTime {
+	public static final int  OCCUPYBYTES=8;
 
 	private DateTime time = new DateTime();
 

+ 2 - 0
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/typemodel/IeShortFloat.java

@@ -18,6 +18,8 @@ import java.util.List;
 @NoArgsConstructor
 public class IeShortFloat {
 
+	public static final int  OCCUPYBYTES=4;
+
 	private float value;
 
 	/**

+ 2 - 0
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/typemodel/IeShortInteger.java

@@ -18,6 +18,8 @@ import java.util.List;
 @NoArgsConstructor
 public class IeShortInteger {
 
+	public static final int  OCCUPYBYTES=2;
+
 	private Integer value;
 
 	/**

+ 2 - 0
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/typemodel/InformationBodyAddress.java

@@ -18,6 +18,8 @@ import java.util.List;
 @AllArgsConstructor
 public class InformationBodyAddress {
 
+	public static final int  OCCUPYBYTES=3;
+
 	/**
 	 * 信息体地址
 	 * 共三位16进制字节

+ 1 - 1
protocol-iec104/src/test/java/MasterTest.java

@@ -15,7 +15,7 @@ public class MasterTest {
 
 	public static void main(String[] args) throws Exception {
 
-		Iec104MasterBuilder masterBuilder = new Iec104MasterBuilder("127.0.0.1", 2409);
+		Iec104MasterBuilder masterBuilder = new Iec104MasterBuilder("127.0.0.1", 24004);
 		masterBuilder.createByUnBlock();
 
 	/*	//创建总召唤类型I帧

+ 2 - 0
protocol-iec104/src/test/java/SlaveTest.java

@@ -9,6 +9,8 @@ public class SlaveTest {
 	public static void main(String[] args) throws Exception {
 		Iec104SlaverBuilder slaverBuilder = new Iec104SlaverBuilder(2404);
 
+
+
 		/*slaverBuilder.getConnectFilterManager().appendFilter((c)->{
 			if(slaverBuilder.getChannels().size()>=1){
 				return -1;

+ 27 - 0
protocol-iec104/src/test/java/TestTotalS.java

@@ -0,0 +1,27 @@
+/**
+ * @author: xiuwei
+ * @version:
+ */
+
+import wei.yigulu.iec104.annotation.AsduType;
+import wei.yigulu.iec104.apdumodel.Apdu;
+import wei.yigulu.iec104.asdudataframe.TotalSummonType;
+import wei.yigulu.iec104.util.SendDataFrameHelper;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@AsduType
+public class TestTotalS extends TotalSummonType {
+
+	@Override
+	public byte[][] handleAndAnswer(Apdu apdu) throws Exception {
+		Map<Integer,Boolean> booleans=new HashMap<>();
+		for(int i =0 ;i<100;i++){
+			booleans.put(i,true);
+		}
+		SendDataFrameHelper.sendYxDataFrame(apdu.getChannel(),booleans,1,20,null);
+		return null;
+	}
+
+}