From 22a6b851897ef5ef25f64b740159e7106cfd6433 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期二, 14 十一月 2023 17:21:17 +0800
Subject: [PATCH] 配置水泵功率卡 配置设备注册信息卡 测试卡 设置域名卡 删除全部用户卡 重新注册设备卡 等相关制作卡片代码

---
 app/src/main/java/com/dayu/recharge/card/DomainCard.java |   41 +++++++++++++++++++++++++++++++++--------
 1 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/app/src/main/java/com/dayu/recharge/card/DomainCard.java b/app/src/main/java/com/dayu/recharge/card/DomainCard.java
index 55d8718..bef709d 100644
--- a/app/src/main/java/com/dayu/recharge/card/DomainCard.java
+++ b/app/src/main/java/com/dayu/recharge/card/DomainCard.java
@@ -23,7 +23,24 @@
 
     //绔彛鍙蜂负5涓瓧鑺傦紝涓嶈冻5浣嶉珮浣嶈ˉ0銆傜鍙e彿涓庡煙鍚嶄箣闂寸敤鈥�,鈥濋殧寮�銆傜鍙e彿鏈�鍚庝互鈥�#鈥濈粨鏉�
     public String domainName;//鍩熷悕
-    public String port;//绔彛
+    public int port;//绔彛
+
+    public String getDomainName() {
+        return domainName;
+    }
+
+    public void setDomainName(String domainName) {
+        this.domainName = domainName;
+    }
+
+
+    public int getPort() {
+        return port;
+    }
+
+    public void setPort(int port) {
+        this.port = port;
+    }
 
     private byte[] asciiByte;//褰撳墠鍩熷悕鍜岀鍙e彿鏁扮粍
 
@@ -50,10 +67,18 @@
         public byte[] toByte() {
             byte[] data = new byte[16];
             data[0] = HexUtil.hexToByte(cardType);
-            byte[] domainNumbers = BcdUtil.strToBcd(domainNumber);
-            data[1] = domainNumbers[0];
+            if (domainNumber != null) {
+                byte[] domainNumbers = BcdUtil.strToBcd(domainNumber);
+                data[1] = domainNumbers[0];
+            }
+            domainLength = domainName.length();
             data[2] = HexUtil.hexToByte(HexUtil.get10to16(domainLength));
-            String ascii = IDN.toASCII(domainName + "," + port + "#");
+            String portStr = String.valueOf(port);
+            int lenght = portStr.length();
+            for (int i = 0; i < 5 - lenght; i++) {
+                portStr = "0" + portStr;
+            }
+            String ascii = IDN.toASCII(domainName + "," + portStr + "#");
             asciiByte = ascii.getBytes();
             if (asciiByte.length < 12) {
                 System.arraycopy(asciiByte, 0, data, 3, asciiByte.length);
@@ -75,9 +100,9 @@
             byte[] data = new byte[16];
             if (asciiByte.length > 12) {
                 if (asciiByte.length - 12 < 15) {
-                    System.arraycopy(asciiByte, 12, data, 3, asciiByte.length - 12);
+                    System.arraycopy(asciiByte, 12, data, 0, asciiByte.length - 12);
                 } else {
-                    System.arraycopy(asciiByte, 12, data, 3, 15);
+                    System.arraycopy(asciiByte, 12, data, 0, 15);
                 }
             }
             data[15] = getByteSum(data);
@@ -95,9 +120,9 @@
             byte[] data = new byte[16];
             if (asciiByte.length > (12 + 15)) {
                 if (asciiByte.length - (12 + 15) < 15) {
-                    System.arraycopy(asciiByte, 12, data, 3, asciiByte.length - (12 + 15));
+                    System.arraycopy(asciiByte, 12, data, 0, asciiByte.length - (12 + 15));
                 } else {
-                    System.arraycopy(asciiByte, 12, data, 3, 15);
+                    System.arraycopy(asciiByte, 12, data, 0, 15);
                 }
             }
             data[15] = getByteSum(data);

--
Gitblit v1.8.0