| | |
| | | package com.dayu.qihealonelibrary.card; |
| | | |
| | | import com.dayu.baselibrary.tools.HexUtil; |
| | | import com.dayu.qihealonelibrary.utils.MyCommon; |
| | | import com.dayu.qihealonelibrary.utils.CardCommon; |
| | | import com.tencent.bugly.crashreport.CrashReport; |
| | | |
| | | import java.io.Serializable; |
| | |
| | | * Description: 齐河项目用户卡结构 |
| | | */ |
| | | public class UserCard implements Serializable { |
| | | public String cardType = MyCommon.USER_CARD_TYPE_1;//写卡标志 A1刷卡开泵前 A8刷卡开泵后 A2叠加充值 |
| | | public String cardType = CardCommon.USER_CARD_TYPE_1;//写卡标志 A1刷卡开泵前 A8刷卡开泵后 A2叠加充值 |
| | | |
| | | public short arerNumber;//区域号(底位在前高位在后) |
| | | public int arerNumber;//区域号(底位在前高位在后) |
| | | |
| | | public short deviceNumberl;//设备编号(底位在前高位在后) |
| | | public byte rechargeTimes;//充值次数 |
| | | public int deviceNumberl;//设备编号(底位在前高位在后) |
| | | public short rechargeTimes;//充值次数 |
| | | |
| | | public int totalWater;//用户总用水量 底位在前,高位在后2位小数点 含两个小数点的整数 |
| | | |
| | | public int totalElectric;//总用电量位 底位在前,高位在后 1位小数点 含1位小数点的整数 |
| | | |
| | | public int balance;//剩余金额 底位在前 2位小数点,单位元 |
| | | public int balance;//剩余金额 底位在前 2位小数点,单位分 |
| | | |
| | | public int surplusWater;//剩余水量 底位在前 2位小数点 单位立方米 |
| | | public int surplusWater;//剩余水量 底位在前 2位小数点 单位立方米 (跟价格一样先乘以100) |
| | | |
| | | public Calendar rechargeDate;// 购水时间 BCD |
| | | |
| | |
| | | |
| | | byte[] arerNumberByte = new byte[2]; |
| | | System.arraycopy(zero, 1, arerNumberByte, 0, arerNumberByte.length); |
| | | userCard.arerNumber = (short) HexUtil.get16to10LowHigh(HexUtil.bytesToHex(arerNumberByte)); |
| | | userCard.arerNumber = HexUtil.get16To10LowHightByBytes(arerNumberByte); |
| | | |
| | | byte[] deviceNumberlByte = new byte[2]; |
| | | System.arraycopy(zero, 3, deviceNumberlByte, 0, deviceNumberlByte.length); |
| | | userCard.deviceNumberl = (short) HexUtil.get16to10LowHigh(HexUtil.bytesToHex(deviceNumberlByte)); |
| | | userCard.deviceNumberl = HexUtil.get16To10LowHightByBytes(deviceNumberlByte); |
| | | |
| | | userCard.rechargeTimes = HexUtil.hexToByte(HexUtil.byteToHex(zero[5])); |
| | | |
| | | byte[] totalWaterByte = new byte[4]; |
| | | System.arraycopy(zero, 3, totalWaterByte, 0, totalWaterByte.length); |
| | | userCard.totalWater = HexUtil.get16to10LowHigh(HexUtil.bytesToHex(totalWaterByte)); |
| | | System.arraycopy(zero, 6, totalWaterByte, 0, totalWaterByte.length); |
| | | userCard.totalWater = HexUtil.get16To10LowHightByBytes(totalWaterByte); |
| | | |
| | | byte[] totalElectricByte = new byte[4]; |
| | | System.arraycopy(zero, 3, totalElectricByte, 0, totalElectricByte.length); |
| | | userCard.totalElectric = HexUtil.get16to10LowHigh(HexUtil.bytesToHex(totalElectricByte)); |
| | | System.arraycopy(zero, 10, totalElectricByte, 0, totalElectricByte.length); |
| | | userCard.totalElectric = HexUtil.get16To10LowHightByBytes(totalElectricByte); |
| | | |
| | | //第1块解析 |
| | | byte[] one = data.get(1); |
| | | |
| | | byte[] balanceByte = new byte[4]; |
| | | System.arraycopy(one, 0, balanceByte, 0, balanceByte.length); |
| | | userCard.balance = HexUtil.get16to10LowHigh(HexUtil.bytesToHex(balanceByte)); |
| | | userCard.balance =HexUtil.get16To10LowHightByBytes(balanceByte); |
| | | |
| | | byte[] surplusWaterByte = new byte[4]; |
| | | System.arraycopy(one, 4, surplusWaterByte, 0, surplusWaterByte.length); |
| | | userCard.surplusWater = HexUtil.get16to10LowHigh(HexUtil.bytesToHex(surplusWaterByte)); |
| | | userCard.surplusWater = HexUtil.get16To10LowHightByBytes(surplusWaterByte); |
| | | |
| | | byte[] rechargeDateByte = new byte[3]; |
| | | System.arraycopy(one, 12, rechargeDateByte, 0, rechargeDateByte.length); |
| | |
| | | try { |
| | | byte[] data = new byte[16]; |
| | | data[0] = HexUtil.hexToByte(cardType); |
| | | byte[] arerNumberBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(arerNumber)); |
| | | //区域号 |
| | | byte[] arerNumberBytes = new byte[2]; |
| | | byte[] arerNumberDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(arerNumber)); |
| | | System.arraycopy(arerNumberDatas, 0, arerNumberBytes, 0, arerNumberDatas.length); |
| | | if (arerNumberBytes != null) { |
| | | System.arraycopy(arerNumberBytes, 0, data, 1, arerNumberBytes.length); |
| | | } |
| | | byte[] deviceNumberlBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(deviceNumberl)); |
| | | //设备编号 |
| | | byte[] deviceNumberlBytes = new byte[2]; |
| | | byte[] deviceNumberlDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(deviceNumberl)); |
| | | System.arraycopy(deviceNumberlDatas, 0, deviceNumberlBytes, 0, deviceNumberlDatas.length); |
| | | if (deviceNumberlBytes != null) { |
| | | System.arraycopy(deviceNumberlBytes, 0, data, 3, deviceNumberlBytes.length); |
| | | } |
| | | //充值次数 |
| | | byte rechargeTimesByte = HexUtil.hexToByte(HexUtil.get10to16(rechargeTimes)); |
| | | data[5] = rechargeTimesByte; |
| | | byte[] totalWaterBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(totalWater)); |
| | | |
| | | //用户总用水量 |
| | | byte[] totalWaterBytes = new byte[4]; |
| | | byte[] totalWaterDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(totalWater)); |
| | | System.arraycopy(totalWaterDatas, 0, totalWaterBytes, 0, totalWaterDatas.length); |
| | | if (totalWaterBytes != null) { |
| | | System.arraycopy(totalWaterBytes, 0, data, 6, totalWaterBytes.length); |
| | | } |
| | | byte[] totalElectricBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(totalElectric)); |
| | | //总用电量位 |
| | | byte[] totalElectricBytes = new byte[4]; |
| | | byte[] totalElectricDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(totalElectric)); |
| | | System.arraycopy(totalElectricDatas, 0, totalElectricBytes, 0, totalElectricDatas.length); |
| | | if (totalElectricBytes != null) { |
| | | System.arraycopy(totalElectricBytes, 0, data, 10, totalElectricBytes.length); |
| | | } |
| | |
| | | |
| | | |
| | | try { |
| | | byte[] balanceBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(balance)); |
| | | byte[] balanceBytes = new byte[4]; |
| | | byte[] balanceDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(balance)); |
| | | System.arraycopy(balanceDatas, 0, balanceBytes, 0, balanceDatas.length); |
| | | if (balanceBytes != null) { |
| | | System.arraycopy(balanceBytes, 0, data, 0, balanceBytes.length); |
| | | } |
| | | |
| | | byte[] surplusWaterBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(surplusWater)); |
| | | byte[] surplusWaterBytes = new byte[4]; |
| | | byte[] surplusWaterDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(surplusWater)); |
| | | System.arraycopy(surplusWaterDatas, 0, surplusWaterBytes, 0, surplusWaterDatas.length); |
| | | if (surplusWaterBytes != null) { |
| | | System.arraycopy(surplusWaterBytes, 0, data, 0, surplusWaterBytes.length); |
| | | System.arraycopy(surplusWaterBytes, 0, data, 4, surplusWaterBytes.length); |
| | | } |
| | | |
| | | |
| | | if (rechargeDate != null) { |
| | | // 获取年、月、日、时、分、秒 |
| | | int year = (rechargeDate.get(Calendar.YEAR)) % 1000; |
| | | int month = rechargeDate.get(Calendar.MONTH) + 1; // 月份从0开始,所以需要加1 |
| | | int day = rechargeDate.get(Calendar.DAY_OF_MONTH); |
| | | byte bcdYear = (byte) ((year / 10) << 4 | ((year % 10) / 100)); |
| | | byte bcdMonth = (byte) ((month / 10) << 4 | (month % 10)); |
| | | byte bcdDay = (byte) ((day / 10) << 4 | (day % 10)); |
| | | byte bcdYear = HexUtil.getIntToBCD(year)[0]; |
| | | byte bcdMonth = HexUtil.getIntToBCD(month)[0]; |
| | | byte bcdDay = HexUtil.getIntToBCD(day)[0]; |
| | | data[12] = bcdYear; |
| | | data[13] = bcdMonth; |
| | | data[14] = bcdDay; |
| | |
| | | byte[] data = new byte[16]; |
| | | |
| | | try { |
| | | byte[] balanceBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(balance)); |
| | | byte[] balanceBytes = new byte[4]; |
| | | byte[] balanceDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(balance)); |
| | | System.arraycopy(balanceDatas, 0, balanceBytes, 0, balanceDatas.length); |
| | | if (balanceBytes != null) { |
| | | System.arraycopy(balanceBytes, 0, data, 0, balanceBytes.length); |
| | | } |
| | | |
| | | byte[] surplusWaterBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(surplusWater)); |
| | | byte[] surplusWaterBytes = new byte[4]; |
| | | byte[] surplusWaterDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(surplusWater)); |
| | | System.arraycopy(surplusWaterDatas, 0, surplusWaterBytes, 0, surplusWaterDatas.length); |
| | | if (surplusWaterBytes != null) { |
| | | System.arraycopy(surplusWaterBytes, 0, data, 0, surplusWaterBytes.length); |
| | | System.arraycopy(surplusWaterBytes, 0, data, 4, surplusWaterBytes.length); |
| | | } |
| | | |
| | | if (rechargeDate != null) { |
| | |
| | | int year = (rechargeDate.get(Calendar.YEAR)) % 1000; |
| | | int month = rechargeDate.get(Calendar.MONTH) + 1; // 月份从0开始,所以需要加1 |
| | | int day = rechargeDate.get(Calendar.DAY_OF_MONTH); |
| | | byte bcdYear = (byte) ((year / 10) << 4 | ((year % 10) / 100)); |
| | | byte bcdMonth = (byte) ((month / 10) << 4 | (month % 10)); |
| | | byte bcdDay = (byte) ((day / 10) << 4 | (day % 10)); |
| | | byte bcdYear = HexUtil.getIntToBCD(year)[0]; |
| | | byte bcdMonth = HexUtil.getIntToBCD(month)[0]; |
| | | byte bcdDay = HexUtil.getIntToBCD(day)[0]; |
| | | data[12] = bcdYear; |
| | | data[13] = bcdMonth; |
| | | data[14] = bcdDay; |
| | |
| | | this.cardType = cardType; |
| | | } |
| | | |
| | | public short getArerNumber() { |
| | | public int getArerNumber() { |
| | | return arerNumber; |
| | | } |
| | | |
| | | public void setArerNumber(short arerNumber) { |
| | | public void setArerNumber(int arerNumber) { |
| | | this.arerNumber = arerNumber; |
| | | } |
| | | |
| | | public short getDeviceNumberl() { |
| | | public int getDeviceNumberl() { |
| | | return deviceNumberl; |
| | | } |
| | | |
| | | public void setDeviceNumberl(short deviceNumberl) { |
| | | public void setDeviceNumberl(int deviceNumberl) { |
| | | this.deviceNumberl = deviceNumberl; |
| | | } |
| | | |
| | | public byte getRechargeTimes() { |
| | | public short getRechargeTimes() { |
| | | return rechargeTimes; |
| | | } |
| | | |
| | | public void setRechargeTimes(byte rechargeTimes) { |
| | | public void setRechargeTimes(short rechargeTimes) { |
| | | this.rechargeTimes = rechargeTimes; |
| | | } |
| | | |