From a836f03a5d1fbfa81e147d09ffdfa87ba3975c13 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期二, 18 三月 2025 16:45:02 +0800
Subject: [PATCH] 1

---
 server/jtt808_parent/jtt808-protocol/src/main/java/org/yzh/protocol/commons/transform/attribute/Battery.java |  119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 119 insertions(+), 0 deletions(-)

diff --git a/server/jtt808_parent/jtt808-protocol/src/main/java/org/yzh/protocol/commons/transform/attribute/Battery.java b/server/jtt808_parent/jtt808-protocol/src/main/java/org/yzh/protocol/commons/transform/attribute/Battery.java
new file mode 100644
index 0000000..26885aa
--- /dev/null
+++ b/server/jtt808_parent/jtt808-protocol/src/main/java/org/yzh/protocol/commons/transform/attribute/Battery.java
@@ -0,0 +1,119 @@
+package org.yzh.protocol.commons.transform.attribute;
+
+import io.github.yezhihao.protostar.Schema;
+import io.github.yezhihao.protostar.util.ByteBufUtils;
+import io.netty.buffer.ByteBuf;
+import org.yzh.commons.util.Byte2NumberUtils;
+
+import java.util.Arrays;
+
+/**
+ * 鑳庡帇 0x05
+ * length 30
+ */
+
+public class Battery {
+
+    public static final Integer key = 0Xe3;
+
+    public static final Schema<Battery> SCHEMA = new TirePressureSchema();
+
+    private byte[] value;
+    private Integer capacity;//鐢垫睜鐢甸噺
+    private Float voltage;//鐢垫睜鐢靛帇
+    private Float chargeVoltage;//鍏呯數鐢靛帇
+
+    public Integer getCapacity() {
+        return capacity;
+    }
+
+    public void setCapacity(Integer capacity) {
+        this.capacity = capacity;
+    }
+
+    public Float getVoltage() {
+        return voltage;
+    }
+
+    public void setVoltage(Float voltage) {
+        this.voltage = voltage;
+    }
+
+    public Float getChargeVoltage() {
+        return chargeVoltage;
+    }
+
+    public void setChargeVoltage(Float chargeVoltage) {
+        this.chargeVoltage = chargeVoltage;
+    }
+
+    public Battery() {
+    }
+
+    /**
+     * byte[] data={0x01,0x02,0x03,0x04,0x05,0x06}
+     * 鐢垫睜鐢甸噺鏄� 0x0102锛�
+     * 鐢垫睜鐢靛帇鏄�0x0304锛�
+     * 鍏呯數鐢靛帇鏄� 0x0506,
+     * 鐢靛帇鍗曚綅鏄�0.001v锛�
+     * 涓婁紶 1000琛ㄧず 1v銆�
+     * @param value
+     */
+    public Battery(byte[] value) {
+        this.value = value;
+        if(value!=null && value.length>2){
+            this.setCapacity(Byte2NumberUtils.bytesToInteger(new byte[]{value[0],value[1]}));
+        }
+        if(value!=null && value.length>4){
+            try {
+                this.setVoltage((float) (Byte2NumberUtils.bytesToInteger(new byte[]{value[2],value[3]}) * 0.01));
+            }catch (Exception e){
+
+            }
+        }
+        if(value!=null && value.length>6){
+            try {
+                this.setChargeVoltage((float) (Byte2NumberUtils.bytesToInteger(new byte[]{value[4],value[4]}) * 0.01));
+            }catch (Exception e){
+
+            }
+        }
+    }
+
+    public byte[] getValue() {
+        return value;
+    }
+
+    public void setValue(byte[] value) {
+        this.value = value;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder(32);
+        sb.append("Battery{value=").append(Arrays.toString(value));
+        sb.append('}');
+        return sb.toString();
+    }
+
+    private static class TirePressureSchema implements Schema<Battery> {
+
+        private TirePressureSchema() {
+        }
+
+        @Override
+        public Battery readFrom(ByteBuf input) {
+            int len = input.readableBytes();
+            if (len > 30)
+                len = 30;
+            byte[] value = new byte[len];
+            input.readBytes(value);
+            return new Battery(value);
+        }
+
+        @Override
+        public void writeTo(ByteBuf output, Battery message) {
+            ByteBufUtils.writeFixedLength(output, 30, message.value);
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3