فهرست منبع

添加累计值报文解析

xiuwei 2 سال پیش
والد
کامیت
07842dd8f5

+ 147 - 0
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/CumulativeIntegerType.java

@@ -0,0 +1,147 @@
+package wei.yigulu.iec104.asdudataframe;
+
+
+import io.netty.buffer.ByteBuf;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import wei.yigulu.iec104.apdumodel.Apdu;
+import wei.yigulu.iec104.apdumodel.Asdu;
+import wei.yigulu.iec104.apdumodel.Vsq;
+import wei.yigulu.iec104.asdudataframe.qualitydescription.IeCounterReadingQuality;
+import wei.yigulu.iec104.asdudataframe.qualitydescription.IeMeasuredQuality;
+import wei.yigulu.iec104.asdudataframe.typemodel.IeFourByteInteger;
+import wei.yigulu.iec104.asdudataframe.typemodel.IeShortFloat;
+import wei.yigulu.iec104.asdudataframe.typemodel.InformationBodyAddress;
+import wei.yigulu.iec104.exception.Iec104Exception;
+import wei.yigulu.iec104.nettyconfig.TechnicalTerm;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 电能累计值报文
+ *
+ * @author 修唯xiuwei
+ * @version 3.0
+ */
+@NoArgsConstructor
+@Data
+public class CumulativeIntegerType extends AbstractDataFrameType {
+
+	/**
+	 * TYPEID
+	 */
+	public static final int TYPEID = TechnicalTerm.CUMULATIVE_ELECTRIC_ENERGY_MEASUREMENT;
+
+	private List<InformationBodyAddress> addresses = new ArrayList<>();
+
+	private Map<IeCounterReadingQuality, IeFourByteInteger> datas = new LinkedHashMap<>();
+
+
+
+
+
+	@Override
+	public void encode(List<Byte> buffer) {
+		if (addresses.size() == 1) {
+			addresses.get(0).encode(buffer);
+			for (Map.Entry<IeCounterReadingQuality, IeFourByteInteger> i : datas.entrySet()) {
+				i.getValue().encode(buffer);
+				buffer.add((byte) i.getKey().encode());
+			}
+		} else {
+			int s = 0;
+			for (Map.Entry<IeCounterReadingQuality, IeFourByteInteger> i : datas.entrySet()) {
+				addresses.get(s++).encode(buffer);
+				i.getValue().encode(buffer);
+				buffer.add((byte) i.getKey().encode());
+			}
+		}
+
+	}
+
+	@Override
+	public Asdu generateBack() {
+		Asdu asdu = new Asdu();
+		asdu.setTypeId(TYPEID);
+		asdu.setDataFrame(this);
+		asdu.getVsq().setSq(this.addresses.size() == 1 ? 1 : 0);
+		asdu.getVsq().setNum(this.datas.size());
+		asdu.setOriginatorAddress(0);
+		asdu.setCommonAddress(1);
+		return asdu;
+	}
+
+
+	/**
+	 * Validate len *
+	 *
+	 * @param increase increase
+	 * @throws Iec104Exception iec exception
+	 */
+	protected void validateLen(int increase) throws Iec104Exception {
+		if ((this.datas.size() * (IeShortFloat.OCCUPYBYTES+IeMeasuredQuality.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES + increase) > 240) {
+			throw new Iec104Exception("长度超长,不能再向此对象中添加元素");
+		}
+	}
+
+	@Override
+	public void loadByteBuf(ByteBuf is, Vsq vsq) {
+		IeFourByteInteger value;
+		try {
+			if (vsq.getSq() == 0) {
+				for (int i = 0; i < vsq.getNum(); i++) {
+					addresses.add(new InformationBodyAddress(is));
+					value=new IeFourByteInteger(is);
+					datas.put(new IeCounterReadingQuality(is), value);
+
+				}
+			} else {
+				addresses.add(new InformationBodyAddress(is));
+				for (int i = 0; i < vsq.getNum(); i++) {
+					value=new IeFourByteInteger(is);
+					datas.put(new IeCounterReadingQuality(is), value);
+				}
+			}
+		}catch (Iec104Exception e){
+			if(e.getCode()==3301){
+				return;
+			}
+		}
+	}
+
+	@Override
+	public byte[][] handleAndAnswer(Apdu apdu) throws Exception {
+		return null;
+	}
+
+	@Override
+	public String toString() {
+		StringBuilder s = new StringBuilder("电度累计值");
+		if (addresses.size() == 1) {
+			s.append( "连续寻址\n");
+			s.append(addresses.get(0).toString() + "\n");
+			int i=0;
+			for (Map.Entry<IeCounterReadingQuality, IeFourByteInteger> e : datas.entrySet()) {
+				s.append("点位:"+(addresses.get(0).getAddress()+(i++))+",");
+				s.append( "值为 :" + e.getValue() + ";" + e.getKey().toString() + "\n");
+			}
+		} else {
+			s.append("单一寻址\n");
+			int f = 0;
+			for (Map.Entry<IeCounterReadingQuality, IeFourByteInteger> i : datas.entrySet()) {
+				s.append( addresses.get(f++).toString());
+				s.append( i.getValue().toString());
+				s.append( i.getKey().toString() + "\n");
+			}
+		}
+		return s.toString();
+	}
+
+
+
+
+
+}

+ 105 - 0
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/qualitydescription/IeCounterReadingQuality.java

@@ -0,0 +1,105 @@
+package wei.yigulu.iec104.asdudataframe.qualitydescription;
+
+import io.netty.buffer.ByteBuf;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import wei.yigulu.iec104.exception.Iec104Exception;
+
+
+/**
+ * 计数器读数品质描述 的抽象类
+ *
+ * @author 修唯xiuwei
+ * @version 3.0
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class IeCounterReadingQuality {
+
+
+    @Override
+    public boolean equals(Object o) {
+        return false;
+    }
+
+    public static final int OCCUPYBYTES = 1;
+
+    /**
+     * 品质的值
+     */
+    protected int value;
+
+    /**
+     * 顺序号
+     */
+    protected int sequence;
+
+    /**
+     * 溢出标识  0-未溢出;1溢出
+     */
+    protected boolean overflow;
+
+    /**
+     * 调整标志 0未被调整;1被调整
+     */
+    protected boolean adjust;
+
+    /**
+     * 有效标志 0有效;1无效
+     */
+    protected boolean invalid;
+
+
+    /**
+     * Ie abstract quality
+     *
+     * @param is is
+     */
+    public IeCounterReadingQuality(ByteBuf is) throws Iec104Exception {
+        if (is.readableBytes() < OCCUPYBYTES) {
+            throw new Iec104Exception(3301, "可用字节不足,不能进行读取");
+        }
+        this.value = (is.readByte() & 0xff);
+        this.sequence = value & 0x1f;
+        this.overflow = (value & 0x20) == 0x20;
+        this.adjust = (value & 0x40) == 0x40;
+        this.invalid = (value & 0x80) == 0x80;
+    }
+
+
+    /**
+     * 描述品质位 为1位
+     *
+     * @return int
+     */
+    public int encode() {
+        int v = 0x00;
+        v |= sequence;
+        if (overflow) {
+            v |= 0x20;
+        }
+        if (adjust) {
+            v |= 0x40;
+        }
+        if (invalid) {
+            v |= 0x80;
+        }
+        return v;
+    }
+
+    /**
+     * 是否是良好值
+     *
+     * @return boolean
+     */
+    public boolean isGoodValue() {
+        return !this.isOverflow() && !isInvalid() && !isAdjust();
+    }
+
+    @Override
+    public String toString() {
+        return "溢出: " + isOverflow() + ", 无效: " + isInvalid() + ", 被调整: " + isAdjust();
+    }
+}

+ 9 - 3
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/typemodel/IeFourByteInteger.java

@@ -21,7 +21,7 @@ public class IeFourByteInteger {
 
 	public static final int  OCCUPYBYTES=4;
 
-	private Integer value;
+	private Long value;
 
 	/**
 	 * Ie four bit integer
@@ -32,7 +32,7 @@ public class IeFourByteInteger {
 		if(is.readableBytes()<OCCUPYBYTES){
 			throw new Iec104Exception(3301,"可用字节不足,不能进行读取");
 		}
-		value = ((is.readByte() & 0xff) | ((is.readByte() & 0xff) << 8) | ((is.readByte() & 0xff) << 16) | ((is.readByte() & 0xff) << 24));
+		value =(((long)is.readByte() & 0xff)|((long)(is.readByte() & 0xff) << 8) | ((long)(is.readByte() & 0xff) << 16) |  ((long)(is.readByte() & 0xff) << 24) );
 	}
 
 	/**
@@ -41,11 +41,17 @@ public class IeFourByteInteger {
 	 * @param buffer buffer
 	 */
 	public void encode(List<Byte> buffer) {
-		int tempVal = value & 0xff;
+		long tempVal = value & 0xffff;
 		buffer.add((byte) tempVal);
 		buffer.add((byte) (tempVal >> 8));
 		buffer.add((byte) (tempVal >> 16));
 		buffer.add((byte) (tempVal >> 24));
 	}
 
+	@Override
+	public String toString() {
+			return "长整型数值: " + value;
+
+	}
+
 }

+ 7 - 0
protocol-iec104/src/main/java/wei/yigulu/iec104/nettyconfig/TechnicalTerm.java

@@ -107,6 +107,13 @@ public class TechnicalTerm {
 	 * 测量值,短浮点数
 	 */
 	public static final Integer SHORT_FLOAT_TYPE = 13;
+
+
+
+	/**
+	 * 电能累计值
+	 */
+	public static final Integer CUMULATIVE_ELECTRIC_ENERGY_MEASUREMENT = 15;
 	/**
 	 * 测量值,标度化值 带时标
 	 */