左晓为主开发手持机充值管理机
zuoxiao
2024-03-04 a9c1231be4e3c1c5bd5e9fc61489d55363090407
app/src/main/java/com/dayu/recharge/card/ElectricPriceCard.java
@@ -1,8 +1,10 @@
package com.dayu.recharge.card;
import com.dayu.recharge.tools.HexUtil;
import com.dayu.recharge.utils.MyCommon;
import java.io.Serializable;
import java.util.List;
/**
 * author: zuo
@@ -13,6 +15,64 @@
public class ElectricPriceCard implements Serializable {
    public String cardType = MyCommon.ELECTRIC_PRICE;
    public String cardData = "A0B1C289";//1-4下标固定值
    public Float electricPrice;// 电量单价(低)单位是元,3位小数点
    public byte[] toByte() {
        ElectricPriceCard.Zero zero = new ElectricPriceCard.Zero();
        return zero.toByte();
    }
    public static ElectricPriceCard getBean(List<byte[]> data){
        ElectricPriceCard regionCard=new ElectricPriceCard();
        byte[] zero=data.get(0);
        regionCard.cardType= HexUtil.byteToHex(zero[0]);
        byte[] cardDataByte = new byte[4];
        System.arraycopy(zero, 1, cardDataByte, 0, cardDataByte.length);
        regionCard.cardData = HexUtil.bytesToHex(cardDataByte);
        byte[] electricPriceByte = new byte[4];
        System.arraycopy(zero, 5, electricPriceByte, 0, electricPriceByte.length);
        regionCard.electricPrice = HexUtil.bytesToFloat(electricPriceByte);
        return regionCard;
    }
    /**
     * 第1扇区0块 存储的数据
     */
    public class Zero extends BaseCard {
        public byte[] toByte() {
            byte[] data = new byte[16];
            data[0] = HexUtil.hexToByte(cardType);
            byte[] regionBytes = HexUtil.hexToByteArray(cardData);
            if (regionBytes != null) {
                System.arraycopy(regionBytes, 0, data, 1, regionBytes.length);
            }
            byte[] controllerCodelBytes = HexUtil.folatToByte(electricPrice);
            if (controllerCodelBytes != null) {
                System.arraycopy(controllerCodelBytes, 0, data, 5, controllerCodelBytes.length);
            }
            data[15] = getByteSum(data);
            return data;
        }
    }
}