左晓为主开发手持机充值管理机
zuojincheng
2025-03-26 1bc1acff2127d61b359800096ad5b904370d9176
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
package com.dayu.general.bean.card
 
import com.dayu.baselibrary.tools.BaseCard
import com.dayu.general.bean.db.CardData
import com.dayu.general.dao.AppDataBase
import com.dayu.general.tool.CardCommon
import com.tencent.bugly.crashreport.CrashReport
 
open class BaseCard : BaseCard() {
    var cardData: String? = null //标识码
 
    companion object {
 
        const val IDENTIFY_CODE_A0 = 0xA0.toByte()  // 识别码A0
        const val IDENTIFY_CODE_B1 = 0xB1.toByte()  // 识别码B1
        const val IDENTIFY_CODE_C2 = 0xC2.toByte()  // 识别码C2
        const val IDENTIFY_CODE_89 = 0x89.toByte()  // 识别码89
    }
 
 
    fun setCardData(baseDao: AppDataBase, cardType: String?) {
        try {
            val cardDataBean: CardData =
                baseDao.cardDataDao().findFirst(cardType)
            cardData = if (cardDataBean != null) {
                cardDataBean.cardIdentifying
            } else {
                CardCommon.getDefaultCardData(cardType)
            }
        } catch (e: Exception) {
            CrashReport.postCatchedException(e)
        }
    }
 
 
//    /**
//     * 前15个字节算术累加和 不含进位
//     *
//     * @param data 源数据
//     * @return 16进制
//     */
//    fun getByteSum(data: ByteArray?): Byte {
//        if (data != null) {
//            var sum = 0
//            for (b in data) {
//                sum += b.toInt() and 0xFF // & 0xFF 可以将字节扩展为正整数,避免符号位的影响
//            }
//            var hex = HexUtil.get10to16CompleteHex(sum)
//            hex = HexUtil.spaceHex(hex)
//            val hexArr = hex.split(" ".toRegex()).dropLastWhile { it.isEmpty() }
//                .toTypedArray()
//            return HexUtil.hexToByte(hexArr[hexArr.size - 1])
//        }
//        return 0
//    }
 
}