#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@文件    :emv_work.py
@时间    :2022/11/16 13:32:02
@作者    :None
@版本    :1.0
@说明    :
'''


from utils.globalvar import SD
from utils.qt import QObject, Signal
from utils.delay import m_delay


class EmvCanReceived(QObject):

    show_emv_ce_signal = Signal(object, int)
    show_emv_cf_signal = Signal(object)

    def __init__(self):
        super(EmvCanReceived, self).__init__()

    # 接收数据
    def received(self):
        while SD.CAN_ON_OFF:
            restNum = SD.CAN_CONTROL.get_undeal_number()
            if restNum <= 0:
                continue
            revRet = SD.CAN_CONTROL.receive(restNum)
            for i in revRet:
                if int(i.RemoteFlag) != 0:
                    continue

                if i.ID == 0x1800CF00 | SD.EMV_ID:
                    self.show_emv_cf_signal.emit(i.Data)
                elif i.ID == 0x1800CE00 | SD.EMV_ID:
                    self.show_emv_ce_signal.emit(i.Data, 0)
                else:
                    continue


class EmvComWork(QObject):

    show_com_signal = Signal(int, int, int)

    def __init__(self):
        super(EmvComWork, self).__init__()

    # 接收数据
    def work(self):
        while SD.CAN_ON_OFF:
            ver = SD.COM_CONTROL.reveive_env_version()
            if ver[0] == 1:
                self.show_com_signal.emit(ver[1], ver[2], ver[3])
            m_delay(10)
