package com.dayu.qihealonelibrary.card; 
 | 
  
 | 
import com.dayu.baselibrary.tools.HexUtil; 
 | 
import com.dayu.qihealonelibrary.dao.QHAloneAppDatabase; 
 | 
import com.dayu.qihealonelibrary.dbBean.CardData; 
 | 
import com.dayu.qihealonelibrary.utils.CardCommon; 
 | 
import com.tencent.bugly.crashreport.CrashReport; 
 | 
  
 | 
import java.io.Serializable; 
 | 
  
 | 
/** 
 | 
 * Copyright (C), 2023, 
 | 
 * Author: zuo 
 | 
 * Date: 2023-11-07 20:52 
 | 
 * Description:所有卡结构的父类 
 | 
 */ 
 | 
public class BaseCard implements Serializable { 
 | 
    public String cardData;//标识码 
 | 
  
 | 
    public void setCardData(QHAloneAppDatabase baseDao, String cardType) { 
 | 
        try { 
 | 
            CardData cardDataBean = baseDao.cardDataDao().findFirst(cardType); 
 | 
            if (cardDataBean != null) { 
 | 
                cardData = cardDataBean.getCardIdentifying(); 
 | 
            } else { 
 | 
                cardData= CardCommon.getDefaultCardData(cardType); 
 | 
            } 
 | 
        } catch (Exception e) { 
 | 
            CrashReport.postCatchedException(e); 
 | 
        } 
 | 
    } 
 | 
  
 | 
  
 | 
    /** 
 | 
     * 前15个字节算术累加和 不含进位 
 | 
     * 
 | 
     * @param data 源数据 
 | 
     * @return 16进制 
 | 
     */ 
 | 
    public byte getByteSum(byte[] data) { 
 | 
        if (data != null) { 
 | 
            int sum = 0; 
 | 
            for (byte b : data) { 
 | 
                sum += b & 0xFF; // & 0xFF 可以将字节扩展为正整数,避免符号位的影响 
 | 
            } 
 | 
            String hex = HexUtil.get10to16CompleteHex(sum); 
 | 
            hex = HexUtil.spaceHex(hex); 
 | 
            String[] hexArr = hex.split(" "); 
 | 
            return HexUtil.hexToByte(hexArr[hexArr.length - 1]); 
 | 
        } 
 | 
        return 0; 
 | 
    } 
 | 
  
 | 
  
 | 
} 
 |