Browse Source

修改以前写的解析方法

(cherry picked from commit 6816deab655f0d1a2c510637e756132af0a2c65e)
xiuwei 3 years ago
parent
commit
e6b5660856

+ 3 - 9
protocol-iec104/src/main/java/wei/yigulu/iec104/apdumodel/Cot.java

@@ -28,15 +28,9 @@ public class Cot {
 	 */
 	public Cot readByte(Byte value) {
 		original = value;
-		String cotFormat = value > 0 ? String.format("%08d", Integer.parseInt(Integer.toBinaryString(original))) : "00000011";
-		//可变结构限定词,转为二进制后获取第8位
-		if (Integer.parseInt(cotFormat.substring(0, 1)) == 1) {
-			test = true;
-		}
-		if (Integer.parseInt(cotFormat.substring(1, 2)) == 1) {
-			negativeConfirm = true;
-		}
-		not = Integer.parseInt(cotFormat.substring(2, 8), 2);
+		test=value>>7==1;
+		negativeConfirm=(value&0x40)>>7==1;
+		not=value&0x3f;
 		return this;
 	}
 

+ 2 - 3
protocol-iec104/src/main/java/wei/yigulu/iec104/apdumodel/Vsq.java

@@ -32,10 +32,9 @@ public class Vsq {
 	 */
 	public Vsq readByte(Byte value) {
 		original = value;
-		String vsqFormat = String.format("%08d", Integer.parseInt(Integer.toBinaryString(this.original & 0xff)));
 		//可变结构限定词,转为二进制后获取第8位
-		sq = Integer.parseInt(vsqFormat.substring(0, 1));
-		num = Integer.parseInt(vsqFormat.substring(1, 8), 2);
+		sq = value>>7;
+		num = value&0x7f;
 		return this;
 	}
 

+ 8 - 10
protocol-iec104/src/main/java/wei/yigulu/iec104/asdudataframe/typemodel/IeProofreadTime.java

@@ -63,16 +63,14 @@ public class IeProofreadTime {
 		int minute = time.getMinuteOfHour();
 		int second = time.getSecondOfMinute();
 		int milliSecond = time.getMillisOfSecond();
-		String nums = Integer.toBinaryString(second * 1000 + milliSecond);
-		String secondStr = nums.substring(nums.length() - 8);
-		String milliSecondStr = nums.substring(0, nums.length() - 8);
-		buffer.add((byte) (Integer.parseInt(Integer.toHexString(Integer.parseInt(milliSecondStr, 2)), 16)));
-		buffer.add((byte) (Integer.parseInt(Integer.toHexString(Integer.parseInt(secondStr, 2)), 16)));
-		buffer.add((byte) (Integer.parseInt(Integer.toHexString(minute), 16)));
-		buffer.add((byte) (Integer.parseInt(Integer.toHexString(hour), 16)));
-		buffer.add((byte) (Integer.parseInt(Integer.toHexString(day), 16)));
-		buffer.add((byte) (Integer.parseInt(Integer.toHexString(month), 16)));
-		buffer.add((byte) (Integer.parseInt(Integer.toHexString(year - 2000), 16)));
+		int nums = second * 1000 + milliSecond;
+		buffer.add((byte) (nums&0xff));
+		buffer.add((byte) (nums&0xff00>>8));
+		buffer.add((byte) (minute&0xff));
+		buffer.add((byte) (hour&0xff));
+		buffer.add((byte) (day&0xff));
+		buffer.add((byte) (month&0xff));
+		buffer.add((byte) ((year - 2000)&0xff));
 	}
 
 	@Override