Bladeren bron

打印连续寻址时 打印点位

xiuwei 3 jaren geleden
bovenliggende
commit
80a33eba58

+ 154 - 152
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/NoQualityNormalizedIntegerType.java

@@ -25,156 +25,158 @@ import java.util.List;
 @NoArgsConstructor
 public class NoQualityNormalizedIntegerType extends AbstractDataFrameType {
 
-	/**
-	 * TYPEID
-	 */
-	public static final int TYPEID = TechnicalTerm.NOQUALITY_NORMALIZED_INTEGER_TYPE;
-
-	private List<InformationBodyAddress> addresses = new ArrayList<>();
-
-	private List<Integer> datas = new ArrayList<>();
-
-	/**
-	 * No quality normalized integer type
-	 *
-	 * @param addresses addresses
-	 * @param datas     datas
-	 * @throws Iec104Exception iec exception
-	 */
-	public NoQualityNormalizedIntegerType(List<InformationBodyAddress> addresses, List<Integer> datas) throws Iec104Exception {
-		if ((this.datas.size() * IeShortInteger.OCCUPYBYTES + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) > 240) {
-			throw new Iec104Exception("长度超长,创建对象失败,请切割数据。");
-		}
-		this.addresses = addresses;
-		this.datas = datas;
-	}
-
-
-	@Override
-	public void loadByteBuf(ByteBuf is, Vsq vsq) {
-		Integer f;
-		try {
-			if (vsq.getSq() == 0) {
-				for (int i = 0; i < vsq.getNum(); i++) {
-					addresses.add(new InformationBodyAddress(is));
-					f = new IeShortInteger(is).getValue();
-					datas.add(f);
-				}
-			} else {
-				addresses.add(new InformationBodyAddress(is));
-				for (int i = 0; i < vsq.getNum(); i++) {
-					f = new IeShortInteger(is).getValue();
-					datas.add(f);
-				}
-			}
-		} catch (Iec104Exception e) {
-			if (e.getCode() == 3301) {
-				return;
-			}
-		}
-	}
-
-	/**
-	 * 向datas中添加数据,默认的质量描述
-	 *
-	 * @param f f
-	 */
-	public void addData(int f) throws Iec104Exception {
-		validateLen(IeShortInteger.OCCUPYBYTES);
-		this.datas.add(f);
-	}
-
-
-	/**
-	 * 向datas中添加数据和数据地址
-	 *
-	 * @param address address
-	 * @param f       f
-	 */
-	public void addDataAndAdd(InformationBodyAddress address, int f) throws Iec104Exception {
-		addAddress(address);
-		addData(f);
-	}
-
-
-	/**
-	 * 向datas中添加数据和数据地址
-	 *
-	 * @param address address
-	 * @throws Iec104Exception iec exception
-	 */
-	public void addAddress(InformationBodyAddress address) throws Iec104Exception {
-		validateLen(InformationBodyAddress.OCCUPYBYTES);
-		this.addresses.add(address);
-	}
-
-
-	@Override
-	public void encode(List<Byte> buffer) {
-		if (addresses.size() == 1) {
-			addresses.get(0).encode(buffer);
-			for (Integer i : datas) {
-				new IeShortInteger(i).encode(buffer);
-			}
-		} else {
-			int s = 0;
-			for (Integer i : datas) {
-				addresses.get(s++).encode(buffer);
-				new IeShortInteger(i).encode(buffer);
-			}
-		}
-	}
-
-	@Override
-	public Asdu generateBack() {
-		Asdu asdu = new Asdu();
-		asdu.setTypeId(11);
-		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() * IeShortInteger.OCCUPYBYTES + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES + increase) > 240) {
-			throw new Iec104Exception("长度超长,不能再向此对象中添加元素");
-		}
-	}
-
-	@Override
-	public byte[][] handleAndAnswer(Apdu apdu) throws Exception {
-
-
-		return null;
-	}
-
-
-	@Override
-	public String toString() {
-		String s = "无质量归一化值";
-		if (addresses.size() == 1) {
-			s += "连续寻址\n";
-			s += addresses.get(0).toString() + "\n";
-			for (Integer e : datas) {
-				s += "值为 :" + e + "\n";
-			}
-		} else {
-			s += "单一寻址\n";
-			int f = 0;
-			for (Integer i : datas) {
-				s += addresses.get(f++).toString();
-				s += i.toString() + "\n";
-			}
-		}
-		return s;
-	}
+    /**
+     * TYPEID
+     */
+    public static final int TYPEID = TechnicalTerm.NOQUALITY_NORMALIZED_INTEGER_TYPE;
+
+    private List<InformationBodyAddress> addresses = new ArrayList<>();
+
+    private List<Integer> datas = new ArrayList<>();
+
+    /**
+     * No quality normalized integer type
+     *
+     * @param addresses addresses
+     * @param datas     datas
+     * @throws Iec104Exception iec exception
+     */
+    public NoQualityNormalizedIntegerType(List<InformationBodyAddress> addresses, List<Integer> datas) throws Iec104Exception {
+        if ((this.datas.size() * IeShortInteger.OCCUPYBYTES + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) > 240) {
+            throw new Iec104Exception("长度超长,创建对象失败,请切割数据。");
+        }
+        this.addresses = addresses;
+        this.datas = datas;
+    }
+
+
+    @Override
+    public void loadByteBuf(ByteBuf is, Vsq vsq) {
+        Integer f;
+        try {
+            if (vsq.getSq() == 0) {
+                for (int i = 0; i < vsq.getNum(); i++) {
+                    addresses.add(new InformationBodyAddress(is));
+                    f = new IeShortInteger(is).getValue();
+                    datas.add(f);
+                }
+            } else {
+                addresses.add(new InformationBodyAddress(is));
+                for (int i = 0; i < vsq.getNum(); i++) {
+                    f = new IeShortInteger(is).getValue();
+                    datas.add(f);
+                }
+            }
+        } catch (Iec104Exception e) {
+            if (e.getCode() == 3301) {
+                return;
+            }
+        }
+    }
+
+    /**
+     * 向datas中添加数据,默认的质量描述
+     *
+     * @param f f
+     */
+    public void addData(int f) throws Iec104Exception {
+        validateLen(IeShortInteger.OCCUPYBYTES);
+        this.datas.add(f);
+    }
+
+
+    /**
+     * 向datas中添加数据和数据地址
+     *
+     * @param address address
+     * @param f       f
+     */
+    public void addDataAndAdd(InformationBodyAddress address, int f) throws Iec104Exception {
+        addAddress(address);
+        addData(f);
+    }
+
+
+    /**
+     * 向datas中添加数据和数据地址
+     *
+     * @param address address
+     * @throws Iec104Exception iec exception
+     */
+    public void addAddress(InformationBodyAddress address) throws Iec104Exception {
+        validateLen(InformationBodyAddress.OCCUPYBYTES);
+        this.addresses.add(address);
+    }
+
+
+    @Override
+    public void encode(List<Byte> buffer) {
+        if (addresses.size() == 1) {
+            addresses.get(0).encode(buffer);
+            for (Integer i : datas) {
+                new IeShortInteger(i).encode(buffer);
+            }
+        } else {
+            int s = 0;
+            for (Integer i : datas) {
+                addresses.get(s++).encode(buffer);
+                new IeShortInteger(i).encode(buffer);
+            }
+        }
+    }
+
+    @Override
+    public Asdu generateBack() {
+        Asdu asdu = new Asdu();
+        asdu.setTypeId(11);
+        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() * IeShortInteger.OCCUPYBYTES + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES + increase) > 240) {
+            throw new Iec104Exception("长度超长,不能再向此对象中添加元素");
+        }
+    }
+
+    @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 (Integer e : datas) {
+                s.append("点位:" + addresses.get(0) + (i++) + ",");
+                s.append("值为 :" + e + "\n");
+            }
+        } else {
+            s.append("单一寻址\n");
+            int f = 0;
+            for (Integer i : datas) {
+                s.append(addresses.get(f++).toString());
+                s.append(i.toString() + "\n");
+            }
+        }
+        return s.toString();
+    }
 }

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

@@ -28,183 +28,185 @@ import java.util.Map;
 @Data
 public class NormalizedIntegerType extends AbstractDataFrameType {
 
-	/**
-	 * TYPEID
-	 */
-	public static final int TYPEID = TechnicalTerm.NORMALIZED_INTEGER_TYPE;
-
-	private List<InformationBodyAddress> addresses = new ArrayList<>();
-
-	private Map<IeMeasuredQuality, Integer> datas = new LinkedHashMap<>();
-
-	/**
-	 * Normalized integer type
-	 *
-	 * @param addresses addresses
-	 * @param datas     datas
-	 * @throws Iec104Exception iec exception
-	 */
-	public NormalizedIntegerType(List<InformationBodyAddress> addresses, Map<IeMeasuredQuality, Integer> datas) throws Iec104Exception {
-		if ((this.datas.size() * (IeMeasuredQuality.OCCUPYBYTES + IeShortInteger.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) > 240) {
-			throw new Iec104Exception("长度超长,创建对象失败,请切割数据。");
-		}
-		this.addresses = addresses;
-		this.datas = datas;
-	}
-
-
-	@Override
-	public void loadByteBuf(ByteBuf is, Vsq vsq) {
-		Integer f;
-		try {
-			if (vsq.getSq() == 0) {
-				for (int i = 0; i < vsq.getNum(); i++) {
-					addresses.add(new InformationBodyAddress(is));
-					f = new IeShortInteger(is).getValue();
-					datas.put(new IeMeasuredQuality(is), f);
-				}
-			} else {
-				addresses.add(new InformationBodyAddress(is));
-				for (int i = 0; i < vsq.getNum(); i++) {
-					f = new IeShortInteger(is).getValue();
-					datas.put(new IeMeasuredQuality(is), f);
-				}
-			}
-		} catch (Iec104Exception e) {
-			if (e.getCode() == 3301) {
-				return;
-			}
-		}
-	}
-
-	/**
-	 * 向datas中添加数据,默认的质量描述
-	 *
-	 * @param f f
-	 * @throws Iec104Exception iec exception
-	 */
-	public void addData(int f) throws Iec104Exception {
-		addData(f, new IeMeasuredQuality());
-	}
-
-	/**
-	 * 向datas中添加数据
-	 *
-	 * @param f       f
-	 * @param quality quality
-	 * @throws Iec104Exception iec exception
-	 */
-	public void addData(int f, IeMeasuredQuality quality) throws Iec104Exception {
-		validateLen(IeShortInteger.OCCUPYBYTES + IeMeasuredQuality.OCCUPYBYTES);
-		this.datas.put(quality, f);
-	}
-
-
-	/**
-	 * 向datas中添加数据和数据地址
-	 *
-	 * @param address address
-	 * @param f       f
-	 * @param quality quality
-	 * @throws Iec104Exception iec exception
-	 */
-	public void addDataAndAdd(InformationBodyAddress address, int f, IeMeasuredQuality quality) throws Iec104Exception {
-		addAddress(address);
-		addData(f, quality);
-	}
-
-	/**
-	 * 向datas中添加数据和数据地址
-	 *
-	 * @param address address
-	 * @param f       f
-	 * @throws Iec104Exception iec exception
-	 */
-	public void addDataAndAdd(InformationBodyAddress address, int f) throws Iec104Exception {
-		addAddress(address);
-		addData(f);
-	}
-
-
-	/**
-	 * 向datas中添加数据和数据地址
-	 *
-	 * @param address address
-	 * @throws Iec104Exception iec exception
-	 */
-	public void addAddress(InformationBodyAddress address) throws Iec104Exception {
-		validateLen(InformationBodyAddress.OCCUPYBYTES);
-		this.addresses.add(address);
-	}
-
-
-	@Override
-	public void encode(List<Byte> buffer) {
-		if (addresses.size() == 1) {
-			addresses.get(0).encode(buffer);
-			for (Map.Entry<IeMeasuredQuality, Integer> i : datas.entrySet()) {
-				new IeShortInteger(i.getValue()).encode(buffer);
-				buffer.add((byte) i.getKey().encode());
-			}
-		} else {
-			int s = 0;
-			for (Map.Entry<IeMeasuredQuality, Integer> i : datas.entrySet()) {
-				addresses.get(s++).encode(buffer);
-				new IeShortInteger(i.getValue()).encode(buffer);
-				buffer.add((byte) i.getKey().encode());
-			}
-		}
-	}
-
-	@Override
-	public Asdu generateBack() {
-		Asdu asdu = new Asdu();
-		asdu.setTypeId(11);
-		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() * (IeMeasuredQuality.OCCUPYBYTES + IeShortInteger.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) + increase) > 240) {
-			throw new Iec104Exception("长度超长,不能再向此对象中添加元素");
-		}
-	}
-
-	@Override
-	public byte[][] handleAndAnswer(Apdu apdu) throws Exception {
-		return null;
-	}
-
-
-	@Override
-	public String toString() {
-		String s = "归一化值";
-		if (addresses.size() == 1) {
-			s += "连续寻址\n";
-			s += addresses.get(0).toString() + "\n";
-			for (Map.Entry<IeMeasuredQuality, Integer> e : datas.entrySet()) {
-				s += "值为 :" + e.getValue() + ";" + e.getKey().toString() + "\n";
-			}
-		} else {
-			s += "单一寻址\n";
-			int f = 0;
-			for (Map.Entry<IeMeasuredQuality, Integer> i : datas.entrySet()) {
-				s += addresses.get(f++).toString();
-				s += i.getValue().toString();
-				s += i.getKey().toString() + "\n";
-			}
-		}
-		return s;
-	}
+    /**
+     * TYPEID
+     */
+    public static final int TYPEID = TechnicalTerm.NORMALIZED_INTEGER_TYPE;
+
+    private List<InformationBodyAddress> addresses = new ArrayList<>();
+
+    private Map<IeMeasuredQuality, Integer> datas = new LinkedHashMap<>();
+
+    /**
+     * Normalized integer type
+     *
+     * @param addresses addresses
+     * @param datas     datas
+     * @throws Iec104Exception iec exception
+     */
+    public NormalizedIntegerType(List<InformationBodyAddress> addresses, Map<IeMeasuredQuality, Integer> datas) throws Iec104Exception {
+        if ((this.datas.size() * (IeMeasuredQuality.OCCUPYBYTES + IeShortInteger.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) > 240) {
+            throw new Iec104Exception("长度超长,创建对象失败,请切割数据。");
+        }
+        this.addresses = addresses;
+        this.datas = datas;
+    }
+
+
+    @Override
+    public void loadByteBuf(ByteBuf is, Vsq vsq) {
+        Integer f;
+        try {
+            if (vsq.getSq() == 0) {
+                for (int i = 0; i < vsq.getNum(); i++) {
+                    addresses.add(new InformationBodyAddress(is));
+                    f = new IeShortInteger(is).getValue();
+                    datas.put(new IeMeasuredQuality(is), f);
+                }
+            } else {
+                addresses.add(new InformationBodyAddress(is));
+                for (int i = 0; i < vsq.getNum(); i++) {
+                    f = new IeShortInteger(is).getValue();
+                    datas.put(new IeMeasuredQuality(is), f);
+                }
+            }
+        } catch (Iec104Exception e) {
+            if (e.getCode() == 3301) {
+                return;
+            }
+        }
+    }
+
+    /**
+     * 向datas中添加数据,默认的质量描述
+     *
+     * @param f f
+     * @throws Iec104Exception iec exception
+     */
+    public void addData(int f) throws Iec104Exception {
+        addData(f, new IeMeasuredQuality());
+    }
+
+    /**
+     * 向datas中添加数据
+     *
+     * @param f       f
+     * @param quality quality
+     * @throws Iec104Exception iec exception
+     */
+    public void addData(int f, IeMeasuredQuality quality) throws Iec104Exception {
+        validateLen(IeShortInteger.OCCUPYBYTES + IeMeasuredQuality.OCCUPYBYTES);
+        this.datas.put(quality, f);
+    }
+
+
+    /**
+     * 向datas中添加数据和数据地址
+     *
+     * @param address address
+     * @param f       f
+     * @param quality quality
+     * @throws Iec104Exception iec exception
+     */
+    public void addDataAndAdd(InformationBodyAddress address, int f, IeMeasuredQuality quality) throws Iec104Exception {
+        addAddress(address);
+        addData(f, quality);
+    }
+
+    /**
+     * 向datas中添加数据和数据地址
+     *
+     * @param address address
+     * @param f       f
+     * @throws Iec104Exception iec exception
+     */
+    public void addDataAndAdd(InformationBodyAddress address, int f) throws Iec104Exception {
+        addAddress(address);
+        addData(f);
+    }
+
+
+    /**
+     * 向datas中添加数据和数据地址
+     *
+     * @param address address
+     * @throws Iec104Exception iec exception
+     */
+    public void addAddress(InformationBodyAddress address) throws Iec104Exception {
+        validateLen(InformationBodyAddress.OCCUPYBYTES);
+        this.addresses.add(address);
+    }
+
+
+    @Override
+    public void encode(List<Byte> buffer) {
+        if (addresses.size() == 1) {
+            addresses.get(0).encode(buffer);
+            for (Map.Entry<IeMeasuredQuality, Integer> i : datas.entrySet()) {
+                new IeShortInteger(i.getValue()).encode(buffer);
+                buffer.add((byte) i.getKey().encode());
+            }
+        } else {
+            int s = 0;
+            for (Map.Entry<IeMeasuredQuality, Integer> i : datas.entrySet()) {
+                addresses.get(s++).encode(buffer);
+                new IeShortInteger(i.getValue()).encode(buffer);
+                buffer.add((byte) i.getKey().encode());
+            }
+        }
+    }
+
+    @Override
+    public Asdu generateBack() {
+        Asdu asdu = new Asdu();
+        asdu.setTypeId(11);
+        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() * (IeMeasuredQuality.OCCUPYBYTES + IeShortInteger.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) + increase) > 240) {
+            throw new Iec104Exception("长度超长,不能再向此对象中添加元素");
+        }
+    }
+
+    @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<IeMeasuredQuality, Integer> e : datas.entrySet()) {
+                s.append("点位:" + addresses.get(0) + (i++) + ",");
+                s.append("值为 :" + e.getValue() + ";" + e.getKey().toString() + "\n");
+            }
+        } else {
+            s.append("单一寻址\n");
+            int f = 0;
+            for (Map.Entry<IeMeasuredQuality, Integer> i : datas.entrySet()) {
+                s.append(addresses.get(f++).toString());
+                s.append(i.getValue().toString());
+                s.append(i.getKey().toString() + "\n");
+            }
+        }
+        return s.toString();
+    }
 }

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

@@ -28,185 +28,188 @@ import java.util.Map;
 @Data
 public class ShortFloatType extends AbstractDataFrameType {
 
-	/**
-	 * TYPEID
-	 */
-	public static final int TYPEID = TechnicalTerm.SHORT_FLOAT_TYPE;
-
-	private List<InformationBodyAddress> addresses = new ArrayList<>();
-
-	private Map<IeMeasuredQuality, Float> datas = new LinkedHashMap<>();
-
-
-	/**
-	 * Short float type
-	 *
-	 * @param addresses addresses
-	 * @param datas     datas
-	 * @throws Iec104Exception iec exception
-	 */
-	public ShortFloatType(List<InformationBodyAddress> addresses, Map<IeMeasuredQuality, Float> datas) throws Iec104Exception {
-		if ((this.datas.size() * (IeShortFloat.OCCUPYBYTES + IeMeasuredQuality.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) > 240) {
-			throw new Iec104Exception("长度超长,创建对象失败,请切割数据。");
-		}
-		this.addresses = addresses;
-		this.datas = datas;
-	}
-
-
-	/**
-	 * 向datas中添加数据,默认的质量描述
-	 *
-	 * @param f f
-	 * @throws Iec104Exception iec exception
-	 */
-	public void addData(float f) throws Iec104Exception {
-		addData(f, new IeMeasuredQuality());
-	}
-
-	/**
-	 * 向datas中添加数据
-	 *
-	 * @param f       f
-	 * @param quality quality
-	 * @throws Iec104Exception iec exception
-	 */
-	public void addData(float f, IeMeasuredQuality quality) throws Iec104Exception {
-		validateLen(IeShortFloat.OCCUPYBYTES + IeMeasuredQuality.OCCUPYBYTES);
-		this.datas.put(quality, f);
-	}
-
-
-	/**
-	 * 向datas中添加数据和数据地址
-	 *
-	 * @param address address
-	 * @param f       f
-	 * @param quality quality
-	 * @throws Iec104Exception iec exception
-	 */
-	public void addDataAndAdd(InformationBodyAddress address, float f, IeMeasuredQuality quality) throws Iec104Exception {
-		addAddress(address);
-		addData(f, quality);
-	}
-
-	/**
-	 * 向datas中添加数据和数据地址
-	 *
-	 * @param address address
-	 * @param f       f
-	 * @throws Iec104Exception iec exception
-	 */
-	public void addDataAndAdd(InformationBodyAddress address, float f) throws Iec104Exception {
-		addAddress(address);
-		addData(f);
-	}
-
-
-	/**
-	 * 向datas中添加数据和数据地址
-	 *
-	 * @param address address
-	 * @throws Iec104Exception iec exception
-	 */
-	public void addAddress(InformationBodyAddress address) throws Iec104Exception {
-		validateLen(InformationBodyAddress.OCCUPYBYTES);
-		this.addresses.add(address);
-	}
-
-
-	@Override
-	public void encode(List<Byte> buffer) {
-		if (addresses.size() == 1) {
-			addresses.get(0).encode(buffer);
-			for (Map.Entry<IeMeasuredQuality, Float> i : datas.entrySet()) {
-				new IeShortFloat(i.getValue()).encode(buffer);
-				buffer.add((byte) i.getKey().encode());
-			}
-		} else {
-			int s = 0;
-			for (Map.Entry<IeMeasuredQuality, Float> i : datas.entrySet()) {
-				addresses.get(s++).encode(buffer);
-				new IeShortFloat(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) {
-		float f;
-		try {
-			if (vsq.getSq() == 0) {
-				for (int i = 0; i < vsq.getNum(); i++) {
-					addresses.add(new InformationBodyAddress(is));
-					f = new IeShortFloat(is).getValue();
-					datas.put(new IeMeasuredQuality(is), f);
-				}
-			} else {
-				addresses.add(new InformationBodyAddress(is));
-				for (int i = 0; i < vsq.getNum(); i++) {
-					f = new IeShortFloat(is).getValue();
-					datas.put(new IeMeasuredQuality(is), f);
-				}
-			}
-		} catch (Iec104Exception e) {
-			if (e.getCode() == 3301) {
-				return;
-			}
-		}
-	}
-
-	@Override
-	public byte[][] handleAndAnswer(Apdu apdu) throws Exception {
-		return null;
-	}
-
-	@Override
-	public String toString() {
-		String s = "短浮点";
-		if (addresses.size() == 1) {
-			s += "连续寻址\n";
-			s += addresses.get(0).toString() + "\n";
-			for (Map.Entry<IeMeasuredQuality, Float> e : datas.entrySet()) {
-				s += "值为 :" + e.getValue() + ";" + e.getKey().toString() + "\n";
-			}
-		} else {
-			s += "单一寻址\n";
-			int f = 0;
-			for (Map.Entry<IeMeasuredQuality, Float> i : datas.entrySet()) {
-				s += addresses.get(f++).toString();
-				s += i.getValue().toString();
-				s += i.getKey().toString() + "\n";
-			}
-		}
-		return s;
-	}
+    /**
+     * TYPEID
+     */
+    public static final int TYPEID = TechnicalTerm.SHORT_FLOAT_TYPE;
+
+    private List<InformationBodyAddress> addresses = new ArrayList<>();
+
+    private Map<IeMeasuredQuality, Float> datas = new LinkedHashMap<>();
+
+
+    /**
+     * Short float type
+     *
+     * @param addresses addresses
+     * @param datas     datas
+     * @throws Iec104Exception iec exception
+     */
+    public ShortFloatType(List<InformationBodyAddress> addresses, Map<IeMeasuredQuality, Float> datas) throws Iec104Exception {
+        if ((this.datas.size() * (IeShortFloat.OCCUPYBYTES + IeMeasuredQuality.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) > 240) {
+            throw new Iec104Exception("长度超长,创建对象失败,请切割数据。");
+        }
+        this.addresses = addresses;
+        this.datas = datas;
+    }
+
+
+    /**
+     * 向datas中添加数据,默认的质量描述
+     *
+     * @param f f
+     * @throws Iec104Exception iec exception
+     */
+    public void addData(float f) throws Iec104Exception {
+        addData(f, new IeMeasuredQuality());
+    }
+
+    /**
+     * 向datas中添加数据
+     *
+     * @param f       f
+     * @param quality quality
+     * @throws Iec104Exception iec exception
+     */
+    public void addData(float f, IeMeasuredQuality quality) throws Iec104Exception {
+        validateLen(IeShortFloat.OCCUPYBYTES + IeMeasuredQuality.OCCUPYBYTES);
+        this.datas.put(quality, f);
+    }
+
+
+    /**
+     * 向datas中添加数据和数据地址
+     *
+     * @param address address
+     * @param f       f
+     * @param quality quality
+     * @throws Iec104Exception iec exception
+     */
+    public void addDataAndAdd(InformationBodyAddress address, float f, IeMeasuredQuality quality) throws Iec104Exception {
+        addAddress(address);
+        addData(f, quality);
+    }
+
+    /**
+     * 向datas中添加数据和数据地址
+     *
+     * @param address address
+     * @param f       f
+     * @throws Iec104Exception iec exception
+     */
+    public void addDataAndAdd(InformationBodyAddress address, float f) throws Iec104Exception {
+        addAddress(address);
+        addData(f);
+    }
+
+
+    /**
+     * 向datas中添加数据和数据地址
+     *
+     * @param address address
+     * @throws Iec104Exception iec exception
+     */
+    public void addAddress(InformationBodyAddress address) throws Iec104Exception {
+        validateLen(InformationBodyAddress.OCCUPYBYTES);
+        this.addresses.add(address);
+    }
+
+
+    @Override
+    public void encode(List<Byte> buffer) {
+        if (addresses.size() == 1) {
+            addresses.get(0).encode(buffer);
+            for (Map.Entry<IeMeasuredQuality, Float> i : datas.entrySet()) {
+                new IeShortFloat(i.getValue()).encode(buffer);
+                buffer.add((byte) i.getKey().encode());
+            }
+        } else {
+            int s = 0;
+            for (Map.Entry<IeMeasuredQuality, Float> i : datas.entrySet()) {
+                addresses.get(s++).encode(buffer);
+                new IeShortFloat(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) {
+        float f;
+        try {
+            if (vsq.getSq() == 0) {
+                for (int i = 0; i < vsq.getNum(); i++) {
+                    addresses.add(new InformationBodyAddress(is));
+                    f = new IeShortFloat(is).getValue();
+                    datas.put(new IeMeasuredQuality(is), f);
+                }
+            } else {
+                addresses.add(new InformationBodyAddress(is));
+                for (int i = 0; i < vsq.getNum(); i++) {
+                    f = new IeShortFloat(is).getValue();
+                    datas.put(new IeMeasuredQuality(is), f);
+                }
+            }
+        } 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<IeMeasuredQuality, Float> e : datas.entrySet()) {
+                s.append("点位:" + addresses.get(0) + (i++) + ",");
+                s.append("值为 :" + e.getValue() + ";" + e.getKey().toString() + "\n");
+            }
+        } else {
+            s.append("单一寻址\n");
+            int f = 0;
+            for (Map.Entry<IeMeasuredQuality, Float> i : datas.entrySet()) {
+                s.append(addresses.get(f++).toString());
+                s.append(i.getValue().toString());
+                s.append(i.getKey().toString() + "\n");
+            }
+        }
+        return s.toString();
+    }
+
 
 }

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

@@ -28,183 +28,185 @@ import java.util.Map;
 @Data
 public class ShortIntegerType extends AbstractDataFrameType {
 
-	/**
-	 * TYPEID
-	 */
-	public static final int TYPEID = TechnicalTerm.SCALING_INTEGER_TYPE;
-
-	private List<InformationBodyAddress> addresses = new ArrayList<>();
-
-	private Map<IeMeasuredQuality, Integer> datas = new LinkedHashMap<>();
-
-	/**
-	 * Short integer type
-	 *
-	 * @param addresses addresses
-	 * @param datas     datas
-	 * @throws Iec104Exception iec exception
-	 */
-	public ShortIntegerType(List<InformationBodyAddress> addresses, Map<IeMeasuredQuality, Integer> datas) throws Iec104Exception {
-		if ((this.datas.size() * (IeShortInteger.OCCUPYBYTES + IeMeasuredQuality.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) > 240) {
-			throw new Iec104Exception("长度超长,创建对象失败,请切割数据。");
-		}
-		this.addresses = addresses;
-		this.datas = datas;
-	}
-
-
-	@Override
-	public void loadByteBuf(ByteBuf is, Vsq vsq) {
-		Integer f;
-		try {
-			if (vsq.getSq() == 0) {
-				for (int i = 0; i < vsq.getNum(); i++) {
-					addresses.add(new InformationBodyAddress(is));
-					f = new IeShortInteger(is).getValue();
-					datas.put(new IeMeasuredQuality(is), f);
-				}
-			} else {
-				addresses.add(new InformationBodyAddress(is));
-				for (int i = 0; i < vsq.getNum(); i++) {
-					f = new IeShortInteger(is).getValue();
-					datas.put(new IeMeasuredQuality(is), f);
-				}
-			}
-		} catch (Iec104Exception e) {
-			if (e.getCode() == 3301) {
-				return;
-			}
-		}
-	}
-
-	/**
-	 * 向datas中添加数据,默认的质量描述
-	 *
-	 * @param f f
-	 * @throws Iec104Exception iec exception
-	 */
-	public void addData(int f) throws Iec104Exception {
-		addData(f, new IeMeasuredQuality());
-	}
-
-	/**
-	 * 向datas中添加数据
-	 *
-	 * @param f       f
-	 * @param quality quality
-	 * @throws Iec104Exception iec exception
-	 */
-	public void addData(int f, IeMeasuredQuality quality) throws Iec104Exception {
-		validateLen(IeShortInteger.OCCUPYBYTES + IeMeasuredQuality.OCCUPYBYTES);
-		this.datas.put(quality, f);
-	}
-
-
-	/**
-	 * 向datas中添加数据和数据地址
-	 *
-	 * @param address address
-	 * @param f       f
-	 * @param quality quality
-	 * @throws Iec104Exception iec exception
-	 */
-	public void addDataAndAdd(InformationBodyAddress address, int f, IeMeasuredQuality quality) throws Iec104Exception {
-		addAddress(address);
-		addData(f, quality);
-	}
-
-	/**
-	 * 向datas中添加数据和数据地址
-	 *
-	 * @param address address
-	 * @param f       f
-	 * @throws Iec104Exception iec exception
-	 */
-	public void addDataAndAdd(InformationBodyAddress address, int f) throws Iec104Exception {
-		addAddress(address);
-		addData(f);
-	}
-
-
-	/**
-	 * 向datas中添加数据和数据地址
-	 *
-	 * @param address address
-	 * @throws Iec104Exception iec exception
-	 */
-	public void addAddress(InformationBodyAddress address) throws Iec104Exception {
-		validateLen(InformationBodyAddress.OCCUPYBYTES);
-		this.addresses.add(address);
-	}
-
-
-	@Override
-	public void encode(List<Byte> buffer) {
-		if (addresses.size() == 1) {
-			addresses.get(0).encode(buffer);
-			for (Map.Entry<IeMeasuredQuality, Integer> i : datas.entrySet()) {
-				new IeShortInteger(i.getValue()).encode(buffer);
-				buffer.add((byte) i.getKey().encode());
-			}
-		} else {
-			int s = 0;
-			for (Map.Entry<IeMeasuredQuality, Integer> i : datas.entrySet()) {
-				addresses.get(s++).encode(buffer);
-				new IeShortInteger(i.getValue()).encode(buffer);
-				buffer.add((byte) i.getKey().encode());
-			}
-		}
-	}
-
-	@Override
-	public Asdu generateBack() {
-		Asdu asdu = new Asdu();
-		asdu.setTypeId(11);
-		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() * (IeShortInteger.OCCUPYBYTES + IeMeasuredQuality.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES + increase) > 240) {
-			throw new Iec104Exception("长度超长,不能再向此对象中添加元素");
-		}
-	}
-
-	@Override
-	public byte[][] handleAndAnswer(Apdu apdu) throws Exception {
-		return null;
-	}
-
-
-	@Override
-	public String toString() {
-		String s = "短整型";
-		if (addresses.size() == 1) {
-			s += "连续寻址\n";
-			s += addresses.get(0).toString() + "\n";
-			for (Map.Entry<IeMeasuredQuality, Integer> e : datas.entrySet()) {
-				s += "值为 :" + e.getValue() + ";" + e.getKey().toString() + "\n";
-			}
-		} else {
-			s += "单一寻址\n";
-			int f = 0;
-			for (Map.Entry<IeMeasuredQuality, Integer> i : datas.entrySet()) {
-				s += addresses.get(f++).toString();
-				s += i.getValue().toString();
-				s += i.getKey().toString() + "\n";
-			}
-		}
-		return s;
-	}
+    /**
+     * TYPEID
+     */
+    public static final int TYPEID = TechnicalTerm.SCALING_INTEGER_TYPE;
+
+    private List<InformationBodyAddress> addresses = new ArrayList<>();
+
+    private Map<IeMeasuredQuality, Integer> datas = new LinkedHashMap<>();
+
+    /**
+     * Short integer type
+     *
+     * @param addresses addresses
+     * @param datas     datas
+     * @throws Iec104Exception iec exception
+     */
+    public ShortIntegerType(List<InformationBodyAddress> addresses, Map<IeMeasuredQuality, Integer> datas) throws Iec104Exception {
+        if ((this.datas.size() * (IeShortInteger.OCCUPYBYTES + IeMeasuredQuality.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES) > 240) {
+            throw new Iec104Exception("长度超长,创建对象失败,请切割数据。");
+        }
+        this.addresses = addresses;
+        this.datas = datas;
+    }
+
+
+    @Override
+    public void loadByteBuf(ByteBuf is, Vsq vsq) {
+        Integer f;
+        try {
+            if (vsq.getSq() == 0) {
+                for (int i = 0; i < vsq.getNum(); i++) {
+                    addresses.add(new InformationBodyAddress(is));
+                    f = new IeShortInteger(is).getValue();
+                    datas.put(new IeMeasuredQuality(is), f);
+                }
+            } else {
+                addresses.add(new InformationBodyAddress(is));
+                for (int i = 0; i < vsq.getNum(); i++) {
+                    f = new IeShortInteger(is).getValue();
+                    datas.put(new IeMeasuredQuality(is), f);
+                }
+            }
+        } catch (Iec104Exception e) {
+            if (e.getCode() == 3301) {
+                return;
+            }
+        }
+    }
+
+    /**
+     * 向datas中添加数据,默认的质量描述
+     *
+     * @param f f
+     * @throws Iec104Exception iec exception
+     */
+    public void addData(int f) throws Iec104Exception {
+        addData(f, new IeMeasuredQuality());
+    }
+
+    /**
+     * 向datas中添加数据
+     *
+     * @param f       f
+     * @param quality quality
+     * @throws Iec104Exception iec exception
+     */
+    public void addData(int f, IeMeasuredQuality quality) throws Iec104Exception {
+        validateLen(IeShortInteger.OCCUPYBYTES + IeMeasuredQuality.OCCUPYBYTES);
+        this.datas.put(quality, f);
+    }
+
+
+    /**
+     * 向datas中添加数据和数据地址
+     *
+     * @param address address
+     * @param f       f
+     * @param quality quality
+     * @throws Iec104Exception iec exception
+     */
+    public void addDataAndAdd(InformationBodyAddress address, int f, IeMeasuredQuality quality) throws Iec104Exception {
+        addAddress(address);
+        addData(f, quality);
+    }
+
+    /**
+     * 向datas中添加数据和数据地址
+     *
+     * @param address address
+     * @param f       f
+     * @throws Iec104Exception iec exception
+     */
+    public void addDataAndAdd(InformationBodyAddress address, int f) throws Iec104Exception {
+        addAddress(address);
+        addData(f);
+    }
+
+
+    /**
+     * 向datas中添加数据和数据地址
+     *
+     * @param address address
+     * @throws Iec104Exception iec exception
+     */
+    public void addAddress(InformationBodyAddress address) throws Iec104Exception {
+        validateLen(InformationBodyAddress.OCCUPYBYTES);
+        this.addresses.add(address);
+    }
+
+
+    @Override
+    public void encode(List<Byte> buffer) {
+        if (addresses.size() == 1) {
+            addresses.get(0).encode(buffer);
+            for (Map.Entry<IeMeasuredQuality, Integer> i : datas.entrySet()) {
+                new IeShortInteger(i.getValue()).encode(buffer);
+                buffer.add((byte) i.getKey().encode());
+            }
+        } else {
+            int s = 0;
+            for (Map.Entry<IeMeasuredQuality, Integer> i : datas.entrySet()) {
+                addresses.get(s++).encode(buffer);
+                new IeShortInteger(i.getValue()).encode(buffer);
+                buffer.add((byte) i.getKey().encode());
+            }
+        }
+    }
+
+    @Override
+    public Asdu generateBack() {
+        Asdu asdu = new Asdu();
+        asdu.setTypeId(11);
+        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() * (IeShortInteger.OCCUPYBYTES + IeMeasuredQuality.OCCUPYBYTES) + this.addresses.size() * InformationBodyAddress.OCCUPYBYTES + increase) > 240) {
+            throw new Iec104Exception("长度超长,不能再向此对象中添加元素");
+        }
+    }
+
+    @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<IeMeasuredQuality, Integer> e : datas.entrySet()) {
+                s.append("点位:" + addresses.get(0) + (i++) + ",");
+                s.append("值为 :" + e.getValue() + ";" + e.getKey().toString() + "\n");
+            }
+        } else {
+            s.append("单一寻址\n");
+            int f = 0;
+            for (Map.Entry<IeMeasuredQuality, Integer> i : datas.entrySet()) {
+                s.append(addresses.get(f++).toString());
+                s.append(i.getValue().toString());
+                s.append(i.getKey().toString() + "\n");
+            }
+        }
+        return s.toString();
+    }
 }