左晓为主开发手持机充值管理机
zuoxiao
2024-03-05 88c82455871cd03e0a0b6f32591f9bee74a2dc34
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
package com.dayu.recharge.card;
 
import com.dayu.recharge.dao.AppDatabase;
import com.dayu.recharge.tools.HexUtil;
import com.dayu.recharge.utils.MyCommon;
import com.tencent.bugly.crashreport.CrashReport;
 
import java.io.Serializable;
 
/**
 * Copyright (C), 2023,
 * Author: zuo
 * Date: 2023-11-08 13:26
 * Description: 配置水泵功率卡:
 * <p>
 * 为方便现场更换设备时重新注册的问题,配置设备信息卡,首先刷卡,把原设备的注册号和ID号读到卡内,
 * 同时卡状态则00修改为FF,再新设备上刷此卡时,注册号和ID号自动写到控制器内,可以直接刷卡使用
 */
public class ConfigurationPowerCard extends BaseCard implements Serializable {
 
 
    public String cardType = MyCommon.CONFIGURATION_POWER_CARD_TYPE;//卡类型
 
    public String getCardData() {
        return cardData;
    }
 
    public String power;//功率
 
    public String getPower() {
        return power;
    }
 
    public void setPower(String power) {
        this.power = power;
    }
 
 
    public static ConfigurationPowerCard toBean(byte[] data) {
        try {
            ConfigurationPowerCard powerCard = new ConfigurationPowerCard();
            int intPower = HexUtil.get16to10(HexUtil.byteToHex(data[5]));
            powerCard.setPower(String.valueOf(intPower));
            return powerCard;
        } catch (Exception e) {
            e.printStackTrace();
            CrashReport.postCatchedException(e);
            return null;
        }
    }
 
    public byte[] toByte(AppDatabase appDatabase) {
        setCardData(appDatabase,cardType);
        Zero zero = new Zero();
        return zero.toByte();
    }
 
    public class Zero  {
        public byte[] toByte() {
            byte[] data = new byte[16];
            data[0] = HexUtil.hexToByte(cardType);
            byte[] cardDatas = HexUtil.hexToByteArray(cardData);
                System.arraycopy(cardDatas, 0, data, 1, cardDatas.length);
            if (power != null) {
                float floatPower = Float.parseFloat(power);
                int intPower = (int) Math.ceil(floatPower); // 将浮点数向上取整并转换为整数
                String hexPower = HexUtil.get10to16(intPower);
                byte bytePower = HexUtil.hexToByte(hexPower);
                data[5] = bytePower;
            }
 
            data[15] = getByteSum(data);
            return data;
        }
 
    }
}