左晓为主开发手持机充值管理机
zuoxiao
2024-07-29 fc1ec55e6ad56dc92737657750bcca7ed49f53eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.dayu.qiheonlinelibrary.card;
 
import com.dayu.baselibrary.tools.HexUtil;
import com.dayu.qiheonlinelibrary.utils.CardCommon;
 
 
import java.io.Serializable;
import java.util.List;
 
/**
 * author: zuo
 * Date: 2024-02-29
 * Time: 16:29
 * 备注:区域表号卡
 */
public class RegionCard extends BaseCard implements Serializable {
 
    public String cardType = CardCommon.REGION;//卡命令
 
    public int region;//区域地址(低前高后) 可以识别某县镇村
 
    public int controllerCodel;// 控制器编号(低前高后) 本区域内控制器编号
 
 
    public int getRegion() {
        return region;
    }
 
    public void setRegion(int region) {
        this.region = region;
    }
 
    public int getControllerCodel() {
        return controllerCodel;
    }
 
    public void setControllerCodel(int controllerCodel) {
        this.controllerCodel = controllerCodel;
    }
 
    public byte[] toByte() {
        Zero zero = new Zero();
        return zero.toByte();
    }
 
 
    public static RegionCard getBean(List<byte[]> data) {
        RegionCard regionCard = new RegionCard();
        byte[] zero = data.get(0);
        regionCard.cardType = HexUtil.byteToHex(zero[0]);
 
        byte[] regionByte = new byte[2];
        System.arraycopy(zero, 1, regionByte, 0, regionByte.length);
        regionCard.region = HexUtil.get16To10LowHightByBytes(regionByte);
 
 
        byte[] controllerCodelByte = new byte[2];
        System.arraycopy(zero, 3, controllerCodelByte, 0, controllerCodelByte.length);
        regionCard.controllerCodel = HexUtil.get16To10LowHightByBytes(controllerCodelByte);
 
 
        return regionCard;
    }
 
 
    /**
     * 第1扇区0块 存储的数据
     */
    public class Zero {
        public byte[] toByte() {
            byte[] data = new byte[16];
            data[0] = HexUtil.hexToByte(cardType);
            byte[] regionBytes = new byte[2];
            byte[] regionDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(region));
            System.arraycopy(regionDatas, 0, regionBytes, 0, regionDatas.length);
            if (regionBytes != null) {
                System.arraycopy(regionBytes, 0, data, 1, regionBytes.length);
            }
            byte[] controllerCodelBytes = new byte[2];
            byte[] controllerCodelDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(controllerCodel));
            System.arraycopy(controllerCodelDatas, 0, controllerCodelBytes, 0, controllerCodelDatas.length);
            if (controllerCodelBytes != null) {
                System.arraycopy(controllerCodelBytes, 0, data, 3, controllerCodelBytes.length);
            }
 
 
            data[15] = getByteSum(data);
            return data;
        }
 
    }
 
 
}