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
|
* Date: 2024-02-29
|
* Time: 16:29
|
* 备注:区域表号卡
|
*/
|
public class RegionCard implements Serializable {
|
|
public String cardType = MyCommon.REGION;//卡命令
|
|
public short region;//区域地址(低前高后) 可以识别某县镇村
|
|
public short controllerCodel;// 控制器编号(低前高后) 本区域内控制器编号
|
|
|
|
public byte[] toByte() {
|
RegionCard.Zero zero = new RegionCard.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 = (short) HexUtil.get16to10LowHigh(HexUtil.bytesToHex(regionByte));
|
|
|
byte[] controllerCodelByte = new byte[2];
|
System.arraycopy(zero, 3, controllerCodelByte, 0, controllerCodelByte.length);
|
regionCard.controllerCodel = (short) HexUtil.get16to10LowHigh(HexUtil.bytesToHex(controllerCodelByte));
|
|
|
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(HexUtil.get10To16LowHigh(region));
|
if (regionBytes != null) {
|
System.arraycopy(regionBytes, 0, data, 1, regionBytes.length);
|
}
|
|
byte[] controllerCodelBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(controllerCodel));
|
if (controllerCodelBytes != null) {
|
System.arraycopy(controllerCodelBytes, 0, data, 3, controllerCodelBytes.length);
|
}
|
|
|
data[15] = getByteSum(data);
|
return data;
|
}
|
|
}
|
|
|
}
|