#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@文件    :bms_home_ctl.py
@时间    :2022/02/21 16:56:26
@作者    :None
@版本    :1.0
@说明    :主页面 CTL
'''

from controller.bms_cell_ctl import BmsCellControll
from controller.bms_double_ccu_ctl import BmsDoubleCcuControll
from controller.bms_protect_ctl import BmsProtectControll
from controller.bms_hard_ctl import BmsHardControll
from controller.bms_balance_ctl import BmsBalanceControll
from controller.bms_record_ctl import BmsRecordControll
from controller.bms_download_ctl import BmsDownloadControll
from controller.bms_set_ctl import BmsSetControll
from controller.bms_status_ctl import BmsStatusControll
from model.record_model import RecordModel
from widget.bms_home import Win_GotionBMS
from utils.globalvar import SD
from controller.bms_main_ctl import BmsMainControll
from utils.qt import QTimer, QThread, QColor, Qt, QDateTime, QtGui, QtWidgets, QPixmap,QApplication
from utils.hex_bit import a_bit
from worker.bms_work import BmsSend, BmsReceived
from ui.own.palette_theme import set_edt_bg

class BmsHomeControll:
    def __init__(self):
        self._view = Win_GotionBMS()
        self._model = RecordModel()
        self.bms_sn_version = ["" for i in range(16)]
        self.battery_sn_version = ["" for i in range(16)]
        self.cell_single_volt = [0 for i in range(396)]
        self.cell_single_temp = [0 for i in range(360)]
        self.init()

    def init(self):
        self.bms_main_ctl = BmsMainControll()
        self._view.bms_tab.addWidget(self.bms_main_ctl._view.main)
        self.bms_cell_ctl = BmsCellControll()
        self._view.bms_tab.addWidget(self.bms_cell_ctl._view.cell)
        self.bms_double_ccu_ctl = BmsDoubleCcuControll()
        self._view.bms_tab.addWidget(self.bms_double_ccu_ctl._view.double_ccu)
        self.bms_protect_ctl = BmsProtectControll()
        self._view.bms_tab.addWidget(self.bms_protect_ctl._view.protect)
        self.bms_hard_ctl = BmsHardControll()
        self._view.bms_tab.addWidget(self.bms_hard_ctl._view.hard)
        self.bms_balance_ctl = BmsBalanceControll()
        self._view.bms_tab.addWidget(self.bms_balance_ctl._view.balance)
        self.bms_record_ctl = BmsRecordControll()
        self._view.bms_tab.addWidget(self.bms_record_ctl._view.record)
        self.bms_download_ctl = BmsDownloadControll()
        self._view.bms_tab.addWidget(self.bms_download_ctl._view.download)
        self.bms_set_ctl = BmsSetControll()
        self._view.bms_tab.addWidget(self.bms_set_ctl._view.set)
        self.bms_status = BmsStatusControll()
        self._view.setStatusBar(self.bms_status._view.statusbar)
        self._view.main_control_signal.connect(self._page_index)
        self._view.cell_inf_signal.connect(self._page_index)
        self._view.double_ccu_signal.connect(self._page_index)
        self._view.protect_inf_signal.connect(self._page_index)
        self._view.hard_cali_signal.connect(self._page_index)
        self._view.balance_inf_signal.connect(self._page_index)
        self._view.data_inf_signal.connect(self._page_index)
        self._view.download_signal.connect(self._page_index)
        self._view.set_inf_signal.connect(self._page_index)
        self._view.can_start_signal.connect(self.bcu_connect)
        self._view.can_stop_signal.connect(self.bcu_disconnect)
        self._view.cut_start_signal.connect(self.app_cut)
        self._view.bcu_online_list_signal.connect(self._view._bcu_connect_get)


    def _page_index(self,index):
        self._view.bms_tab.setCurrentIndex(index)

    def bcu_connect(self):
        try:
            SD.CAN_ON_OFF = SD.CAN_CONTROL.open_device()
        except:
            SD.CAN_ON_OFF = 0

        if SD.CAN_ON_OFF:
            self.bms_status._view.label_bms_connect.setText("通讯已连接" if SD.SYSTEM_LANGUAGE == 0 else "BMS Connected")
            SD.START_RUN = True
            # CAN数据发送类
            # self.bms_send_thread = QThread()
            # self.bms_send = BmsSend()
            # self.bms_send.moveToThread(self.bms_send_thread)
            # self.bms_send_thread.started.connect(self.bms_send.send)
            # CAN数据接收类
            self.bms_received_thread = QThread()
            self.bms_received = BmsReceived()
            self.bms_received.moveToThread(self.bms_received_thread)
            self.bms_received_thread.started.connect(self.bms_received.received)
            # 启动线程
            # self.bms_send_thread.start()
            self.bms_received_thread.start()

            self.bms_received.to_show_masterid_signal.connect(self._get_master_id)
            self.bms_received.to_show_0000_signal.connect(self._inf_0000_signal)
            self.bms_received.to_show_0001_signal.connect(self._inf_0001_signal)
            self.bms_received.to_show_0002_signal.connect(self._inf_0002_signal)
            self.bms_received.to_show_0003_signal.connect(self._inf_0003_signal)
            self.bms_received.to_show_0004_signal.connect(self._inf_0004_signal)
            self.bms_received.to_show_0005_signal.connect(self._inf_0005_signal)
            self.bms_received.to_show_0006_signal.connect(self._inf_0006_signal)
            self.bms_received.to_show_0007_signal.connect(self._inf_0007_signal)
            self.bms_received.to_show_0008_signal.connect(self._inf_0008_signal)
            self.bms_received.to_show_0009_signal.connect(self._inf_0009_signal)
            self.bms_received.to_show_000A_signal.connect(self._inf_000A_signal)
            self.bms_received.to_show_000B_signal.connect(self._inf_000B_signal)
            self.bms_received.to_show_000C_signal.connect(self._inf_000C_signal)
            self.bms_received.to_show_000D_signal.connect(self._inf_000D_signal)
            self.bms_received.to_show_000E_signal.connect(self._inf_000E_signal)
            self.bms_received.to_show_000F_signal.connect(self._inf_000F_signal)
            self.bms_received.to_show_0010_signal.connect(self._inf_0010_signal)
            self.bms_received.to_show_0011_signal.connect(self._inf_0011_signal)
            self.bms_received.to_show_0012_signal.connect(self._inf_0012_signal)
            self.bms_received.to_show_0013_signal.connect(self._inf_0013_signal)
            self.bms_received.to_show_0014_signal.connect(self._inf_0014_signal)
            self.bms_received.to_show_0015_signal.connect(self._inf_0015_signal)
            self.bms_received.to_show_0016_signal.connect(self._inf_0016_signal)
            self.bms_received.to_show_0017_signal.connect(self._inf_0017_signal)
            self.bms_received.to_show_0018_signal.connect(self._inf_0018_signal)
            self.bms_received.to_show_0019_signal.connect(self._inf_0019_signal)
            self.bms_received.to_show_001A_signal.connect(self._inf_001A_signal)
            self.bms_received.to_show_001B_signal.connect(self._inf_001B_signal)
            self.bms_received.to_show_001C_signal.connect(self._inf_001C_signal)
            self.bms_received.to_show_001D_signal.connect(self._inf_001D_signal)
            self.bms_received.to_show_001E_signal.connect(self._inf_001E_signal)
            self.bms_received.to_show_001F_signal.connect(self._inf_001F_signal)
            self.bms_received.to_show_0020_signal.connect(self._inf_0020_signal)
            self.bms_received.to_show_0021_signal.connect(self._inf_0021_signal)
            self.bms_received.to_show_0022_signal.connect(self._inf_0022_signal)
            self.bms_received.to_show_0023_signal.connect(self._inf_0023_signal)
            self._view.btn_start.setDisabled(True)
            self._view.btn_stop.setDisabled(False)
        else:
            self._view.can_connect_error()
            
    def bcu_disconnect(self):
        if SD.CAN_ON_OFF:
            SD.CAN_ON_OFF = False
            SD.START_RUN = False
            SD.CAN_CONTROL.close_can()

            # if self.bms_send_thread.isRunning():
            #     self.bms_send_thread.quit()
            #     self.bms_send_thread.wait()

            # if self.bms_send_thread.isFinished():
            #     del self.bms_send
            #     del self.bms_send_thread

            if self.bms_received_thread.isRunning():
                self.bms_received_thread.quit()
                self.bms_received_thread.wait()

            if self.bms_received_thread.isFinished():
                del self.bms_received
                del self.bms_received_thread
            self._view.btn_start.setDisabled(False)
            self._view.btn_stop.setDisabled(True)
            self.bms_status._view.label_bms_connect.setText("通讯未连接" if SD.SYSTEM_LANGUAGE == 0 else "Not Connected")
            
        else:
            self._view.can_connect_error() 


    def app_cut(self):
        # return
        main_window = QApplication.primaryScreen()
        pixmap = main_window.grabWindow(QtWidgets.QApplication.desktop().winId())
        pixmap.save("screenshot.png"); 
        # QtWidgets.QWidget.screen().grabWindow(0).save()

    def _get_master_id(self, data):
        SD.BCU_LIST[data - 1] = 1
        SD.BCU_LIFE_STATE[data - 1] = QDateTime.currentMSecsSinceEpoch()
        current_secs_since_epoch = QDateTime.currentMSecsSinceEpoch()
        for i in range(9):
            if current_secs_since_epoch - SD.BCU_LIFE_STATE[i] > 2000:
                SD.BCU_LIST[i] = 0
        self._view.bcu_online_list_signal.emit(SD.BCU_LIST)

    def _inf_0000_signal(self, data):
        self._model.ccu_id = SD.BCU_ID

        if SD.CCU_TYPE == 1:
            set_edt_bg(self.bms_main_ctl._view.under_widget.di_1, QColor(Qt.gray) if (data[0] & 0x01 == 0) else QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.di_2, QColor(Qt.gray) if (data[0] & 0x02 == 0) else QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.di_3, QColor(Qt.gray) if (data[0] & 0x04 == 0) else QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.di_4, QColor(Qt.gray) if (data[0] & 0x08 == 0) else QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.di_5, QColor(Qt.gray) if (data[0] & 0x10 == 0) else QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.di_6, QColor(Qt.gray) if (data[0] & 0x20 == 0) else QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.di_7, QColor(Qt.gray) if (data[0] & 0x40 == 0) else QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.di_8, QColor(Qt.gray) if (data[0] & 0x80 == 0) else QColor(Qt.green))

            set_edt_bg(self.bms_main_ctl._view.under_widget.do_1, QColor(Qt.gray) if (data[1] & 0x01 == 0) else QColor(Qt.green))
            self._model.p = data[1] & 0x01
            set_edt_bg(self.bms_main_ctl._view.under_widget.do_2, QColor(Qt.gray) if (data[1] & 0x02 == 0) else QColor(Qt.green))
            self._model.n = (data[1] & 0x02) >> 1
            set_edt_bg(self.bms_main_ctl._view.under_widget.do_3, QColor(Qt.gray) if (data[1] & 0x04 == 0) else QColor(Qt.green))
            self._model.pre = (data[1] & 0x04) >> 2
            set_edt_bg(self.bms_main_ctl._view.under_widget.do_4, QColor(Qt.gray) if (data[1] & 0x08 == 0) else QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.do_5, QColor(Qt.gray) if (data[1] & 0x10 == 0) else QColor(Qt.green))
            self._model.dlq = (data[1] & 0x10) >> 4
            set_edt_bg(self.bms_main_ctl._view.under_widget.do_6, QColor(Qt.gray) if (data[1] & 0x20 == 0) else QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.do_7, QColor(Qt.gray) if (data[1] & 0x40 == 0) else QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.do_8, QColor(Qt.gray) if (data[1] & 0x80 == 0) else QColor(Qt.green))
        else:
            set_edt_bg(self.bms_main_ctl._view.under_widget.fjd_1, QColor(Qt.gray) if (data[2] & 0x01 == 0) else QColor(Qt.green))
            self._model.gjd_first = data[2] & 0x01
            set_edt_bg(self.bms_main_ctl._view.under_widget.fjd_1, QColor(Qt.gray) if (data[2] & 0x02 == 0) else QColor(Qt.green))
            self._model.gjd_second = (data[2] & 0x02) >> 1
            

    def _inf_0001_signal(self, data):
        # 系统状态
        if data[0] & 0x0F == 0x00:
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_no, QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_high_no, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_chg, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_dchg, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_stop, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_sleep, QColor(Qt.gray))
        elif data[0] & 0x0F == 0x01:
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_no, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_high_no, QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_chg, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_dchg, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_stop, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_sleep, QColor(Qt.gray))
        elif data[0] & 0x0F == 0x02:
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_no, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_high_no, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_chg, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_dchg, QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_stop, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_sleep, QColor(Qt.gray))
        elif data[0] & 0x0F == 0x03:
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_no, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_high_no, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_chg, QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_dchg, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_stop, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_sleep, QColor(Qt.gray))
        elif data[0] & 0x0F == 0x04:
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_no, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_high_no, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_chg, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_dchg, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_stop, QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_sleep, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_no, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_high_no, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_chg, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_dchg, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_stop, QColor(Qt.gray))
            set_edt_bg(self.bms_main_ctl._view.under_widget.sys_status_sleep, QColor(Qt.green))
        
        # 最高报警等级
        if (data[0] & 0x30) >> 4 == 0x00:
            self.bms_status._view.qrb_status_normal.setChecked(1)
            self.bms_status._view.qrb_status_warn.setChecked(0)
            self.bms_status._view.qrb_status_warner.setChecked(0)
            self.bms_status._view.qrb_status_warnest.setChecked(0)
        elif (data[0] & 0x30) >> 4 == 0x01:
            self.bms_status._view.qrb_status_normal.setChecked(0)
            self.bms_status._view.qrb_status_warn.setChecked(1)
            self.bms_status._view.qrb_status_warner.setChecked(0)
            self.bms_status._view.qrb_status_warnest.setChecked(0)
        elif (data[0] & 0x30) >> 4 == 0x02:
            self.bms_status._view.qrb_status_normal.setChecked(0)
            self.bms_status._view.qrb_status_warn.setChecked(0)
            self.bms_status._view.qrb_status_warner.setChecked(1)
            self.bms_status._view.qrb_status_warnest.setChecked(0)
        else:
            self.bms_status._view.qrb_status_normal.setChecked(0)
            self.bms_status._view.qrb_status_warn.setChecked(0)
            self.bms_status._view.qrb_status_warner.setChecked(0)
            self.bms_status._view.qrb_status_warnest.setChecked(1)
    
        self._model.fault_level = (data[0] & 0x30) >> 4

        # 继电器
        if SD.CCU_TYPE == 1:
            set_edt_bg(self.bms_main_ctl._view.under_widget.do_1, QColor(Qt.gray) if (data[0] & 0x40 == 0) else QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.do_2, QColor(Qt.gray) if (data[0] & 0x80 == 0) else QColor(Qt.green))

        # SOC
        self.bms_main_ctl._view.top_widget.lb_soc_value.setText(str(round(data[1] * 0.4, 1)))
        self._model.soc = round(data[1] * 0.4, 1)

        # 总压
        self.bms_main_ctl._view.top_widget.lb_tv_value.setText(str(round((data[3] << 8 | data[2]) * 0.1, 1)))
        self._model.volt = round((data[3] << 8 | data[2]) * 0.1, 1)

        # 电流
        self.bms_main_ctl._view.top_widget.lb_tcur_value.setText(str(round((data[5] << 8 | data[4]) * 0.1 - 3200, 1)))
        self._model.cur = round((data[5] << 8 | data[4]) * 0.1 - 3200, 1)

        # SOH
        self.bms_main_ctl._view.top_widget.lb_tsoh_value.setText(str(round(data[6] * 0.4, 1)))
        self._model.soh = round(data[6] * 0.4, 1)

        # MOS标志
        if SD.CCU_TYPE == 0: 
            set_edt_bg(self.bms_main_ctl._view.under_widget.mos_dchg, QColor(Qt.gray) if (data[7] & 0x01 == 0) else QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.mos_chg, QColor(Qt.gray) if (data[7] & 0x02 == 0) else QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.mos_pre, QColor(Qt.gray) if (data[7] & 0x04 == 0) else QColor(Qt.green))
        
        if SD.CCU_TYPE == 1: 
            set_edt_bg(self.bms_main_ctl._view.under_widget.do_4, QColor(Qt.gray) if (data[7] & 0x08 == 0) else QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.do_3, QColor(Qt.gray) if (data[7] & 0x40 == 0) else QColor(Qt.green))
            set_edt_bg(self.bms_main_ctl._view.under_widget.do_5, QColor(Qt.gray) if (data[7] & 0x80 == 0) else QColor(Qt.green))

        set_edt_bg(self.bms_main_ctl._view.under_widget.permit_chg, QColor(Qt.gray) if (data[0] & 0x40 == 0) else QColor(Qt.red))
        set_edt_bg(self.bms_main_ctl._view.under_widget.permit_dchg, QColor(Qt.gray) if (data[0] & 0x80 == 0) else QColor(Qt.red))


    def _inf_0002_signal(self, data):
        # 单体过压告警
        if data[0] & 0x03 == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.over_cell_warn, QColor(Qt.gray))
        elif data[0] & 0x03 == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.over_cell_warn, QColor(Qt.red))
        elif data[0] & 0x03 == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.over_cell_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.over_cell_warn, QColor(Qt.yellow))

        # 总压过压告警
        if (data[0] & 0x0C >> 2) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.hv_warn, QColor(Qt.gray))
        elif (data[0] & 0x0C >> 2) == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.hv_warn, QColor(Qt.red))
        elif (data[0] & 0x0C >> 2) == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.hv_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.hv_warn, QColor(Qt.yellow))

        # 单体欠压告警
        if (data[0] & 0x30 >> 4) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.under_cell_warn, QColor(Qt.gray))
        elif (data[0] & 0x30 >> 4) == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.under_cell_warn, QColor(Qt.red))
        elif (data[0] & 0x30 >> 4) == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.under_cell_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.under_cell_warn, QColor(Qt.yellow))

        # 总压欠压告警
        if (data[0] & 0xC0 >> 6) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.lv_warn, QColor(Qt.gray))
        elif (data[0] & 0xC0 >> 6) == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.lv_warn, QColor(Qt.red))
        elif (data[0] & 0xC0 >> 6) == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.lv_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.lv_warn, QColor(Qt.yellow))

        # =====================================================================================
        # 充电低温告警
        if data[1] & 0x03 == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.chg_lt_warn, QColor(Qt.gray))
        elif data[1] & 0x03 == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.chg_lt_warn, QColor(Qt.red))
        elif data[1] & 0x03 == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.chg_lt_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.chg_lt_warn, QColor(Qt.yellow))

        # 充电高温告警
        if (data[1] & 0x0C >> 2) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.chg_ht_warn, QColor(Qt.gray))
        elif (data[1] & 0x0C >> 2) == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.chg_ht_warn, QColor(Qt.red))
        elif (data[1] & 0x0C >> 2) == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.chg_ht_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.chg_ht_warn, QColor(Qt.yellow))

        # 放电低温告警
        if (data[1] & 0x30 >> 4) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.dchg_lt_warn, QColor(Qt.gray))
        elif (data[1] & 0x30 >> 4) == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.dchg_lt_warn, QColor(Qt.red))
        elif (data[1] & 0x30 >> 4) == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.dchg_lt_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.dchg_lt_warn, QColor(Qt.yellow))

        # 放电高温告警
        if (data[1] & 0xC0 >> 6) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.dchg_ht_warn, QColor(Qt.gray))
        elif (data[1] & 0xC0 >> 6) == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.dchg_ht_warn, QColor(Qt.red))
        elif (data[1] & 0xC0 >> 6) == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.dchg_ht_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.dchg_ht_warn, QColor(Qt.yellow))

        # =====================================================================================
        # 充电过流告警
        if data[2] & 0x03 == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.chg_hcur_warn, QColor(Qt.gray))
        elif data[2] & 0x03 == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.chg_hcur_warn, QColor(Qt.red))
        elif data[2] & 0x03 == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.chg_hcur_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.chg_hcur_warn, QColor(Qt.yellow))

        # 放电过流告警
        if (data[2] & 0x0C >> 2) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.dchg_hcur_warn, QColor(Qt.gray))
        elif (data[2] & 0x0C >> 2) == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.dchg_hcur_warn, QColor(Qt.red))
        elif (data[2] & 0x0C >> 2) == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.dchg_hcur_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.dchg_hcur_warn, QColor(Qt.yellow))

        # 单体压差告警
        if (data[2] & 0x30 >> 4) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.diff_cell_vol_warn, QColor(Qt.gray))
        elif (data[2] & 0x30 >> 4) == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.diff_cell_vol_warn, QColor(Qt.red))
        elif (data[2] & 0x30 >> 4) == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.diff_cell_vol_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.diff_cell_vol_warn, QColor(Qt.yellow))

        # 单体温差告警
        if (data[2] & 0xC0 >> 6) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.diff_cell_temp_warn, QColor(Qt.gray))
        elif (data[2] & 0xC0 >> 6) == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.diff_cell_temp_warn, QColor(Qt.red))
        elif (data[2] & 0xC0 >> 6) == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.diff_cell_temp_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.diff_cell_temp_warn, QColor(Qt.yellow))

        # =====================================================================================
        # 绝缘过低报警
        if data[3] & 0x03 == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.against_warn, QColor(Qt.gray))
        elif data[3] & 0x03 == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.against_warn, QColor(Qt.red))
        elif data[3] & 0x03 == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.against_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.against_warn, QColor(Qt.yellow))

        # 正极绝缘过低报警
        if (data[3] & 0x0C >> 2) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.p_against_warn, QColor(Qt.gray))
        elif (data[3] & 0x0C >> 2) == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.p_against_warn, QColor(Qt.red))
        elif (data[3] & 0x0C >> 2) == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.p_against_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.p_against_warn, QColor(Qt.yellow))

        # 负极绝缘过低报警
        if (data[3] & 0x30 >> 4) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.p_against_warn, QColor(Qt.gray))
        elif (data[3] & 0x30 >> 4) == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.p_against_warn, QColor(Qt.red))
        elif (data[3] & 0x30 >> 4) == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.p_against_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.p_against_warn, QColor(Qt.yellow))

        # 极柱温度过高
        if (data[3] & 0xC0 >> 6) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.jz_ht_warn, QColor(Qt.gray))
        elif (data[3] & 0xC0 >> 6) == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.jz_ht_warn, QColor(Qt.red))
        elif (data[3] & 0xC0 >> 6) == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.jz_ht_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.jz_ht_warn, QColor(Qt.yellow))

        # =====================================================================================
        # 总压检测故障
        if a_bit(data[4], 1) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.vol_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.vol_fault, QColor(Qt.red))
        
        # 总压检测故障
        if a_bit(data[4], 2) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.cur_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.cur_fault, QColor(Qt.red))

        # 总控通讯故障
        if a_bit(data[4], 3) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.ccu_control_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.ccu_control_fault, QColor(Qt.red))

        # BMU通讯故障
        if a_bit(data[4], 4) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.bmu_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.bmu_fault, QColor(Qt.red))

        # 急停
        if a_bit(data[4], 5) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.stop_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.stop_fault, QColor(Qt.red))

        # NTC故障
        if a_bit(data[4], 6) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.ntc_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.ntc_fault, QColor(Qt.red))

        # AFE失效
        if a_bit(data[4], 7) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.afe_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.afe_fault, QColor(Qt.red))

        # 主正接触器故障
        if a_bit(data[4], 8) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.p_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.p_fault, QColor(Qt.red))

        # =====================================================================================
        # 主负接触器故障
        if a_bit(data[5], 1) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.n_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.n_fault, QColor(Qt.red))
        
        # 预充故障
        if a_bit(data[5], 2) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.pre_chg_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.pre_chg_fault, QColor(Qt.red))

        # 充电MOS故障
        if a_bit(data[5], 3) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.chg_mos_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.chg_mos_fault, QColor(Qt.red))

        # 放电MOS故障
        if a_bit(data[5], 4) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.dchg_mos_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.dchg_mos_fault, QColor(Qt.red))

        # 风扇控制失效
        if a_bit(data[5], 5) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.fan_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.fan_fault, QColor(Qt.red))

        # 热失控故障
        if a_bit(data[5], 6) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.temp_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.temp_fault, QColor(Qt.red))

        # 温升过高故障
        if a_bit(data[5], 7) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.temp_up_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.temp_up_fault, QColor(Qt.red))

        # 中间接触器故障
        if a_bit(data[5], 8) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.center_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.center_fault, QColor(Qt.red))

        # =====================================================================================
        # 单体断线故障
        if a_bit(data[6], 1) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.cell_single_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.cell_single_fault, QColor(Qt.red))
        
        # 主控硬件故障
        if a_bit(data[6], 2) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.ccu_hard_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.ccu_hard_fault, QColor(Qt.red))

        # 主控初始化故障
        if a_bit(data[6], 3) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.ccu_start_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.ccu_start_fault, QColor(Qt.red))

        # EEPROM故障
        if a_bit(data[6], 4) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.eeprom_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.eeprom_fault, QColor(Qt.red))

        # 熔断器故障
        if a_bit(data[6], 5) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.rdq_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.rdq_fault, QColor(Qt.red))

        # 断路器反馈故障
        if a_bit(data[6], 6) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.dlq_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.dlq_fault, QColor(Qt.red))

        # 簇间压差故障
        if a_bit(data[6], 7) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.ccu_diff_vol_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.ccu_diff_vol_fault, QColor(Qt.red))

        # PCS通讯故障
        if a_bit(data[6], 8) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.pcs_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.pcs_fault, QColor(Qt.red))

        # =====================================================================================
        # 跳机故障
        if a_bit(data[7], 1) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.jump_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.jump_fault, QColor(Qt.red))
        
        # 极柱温度过高故障
        if a_bit(data[7], 2) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.jz_ht_warn, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.jz_ht_warn, QColor(Qt.red))

        # 主控检测温度过高故障
        if a_bit(data[7], 3) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.ccu_ht_warn, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.ccu_ht_warn, QColor(Qt.red))

        # MOS温度过高故障
        if (data[7] & 0x18 >> 3) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.mos_ht_warn, QColor(Qt.gray))
        elif (data[7] & 0x18 >> 3) == 1:
            set_edt_bg(self.bms_main_ctl._view.center_widget.mos_ht_warn, QColor(Qt.red))
        elif (data[2] & 0x18 >> 3) == 2:
            set_edt_bg(self.bms_main_ctl._view.center_widget.mos_ht_warn, QColor(Qt.magenta))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.mos_ht_warn, QColor(Qt.yellow))

        # 电芯故障
        if a_bit(data[7], 6) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.cell_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.cell_fault, QColor(Qt.red))

        # SOC过低故障
        if a_bit(data[7], 7) == 0:
            set_edt_bg(self.bms_main_ctl._view.center_widget.soc_fault, QColor(Qt.gray))
        else:
            set_edt_bg(self.bms_main_ctl._view.center_widget.soc_fault, QColor(Qt.red))


    def _inf_0003_signal(self, data):
        # 最高单体电压值
        self.bms_main_ctl._view.top_widget.lb_tcellhv_value.setText(str(data[1] << 8 | data[0]))
        self._model.max_cell_volt = data[1] << 8 | data[0]
        # 最高单体电压所在编号
        self.bms_main_ctl._view.top_widget.lb_tcellhv_index_value.setText(str(data[3] << 8 | data[2]))
        self._model.max_cell_volt_id = data[3] << 8 | data[2]
        # 最低单体电压值
        self.bms_main_ctl._view.top_widget.lb_tcelllv_value.setText(str(data[5] << 8 | data[4]))
        self._model.min_cell_volt = data[5] << 8 | data[4]
        # 最低单体电压所在编号
        self.bms_main_ctl._view.top_widget.lb_tcelllv_index_value.setText(str(data[7] << 8 | data[6]))
        self._model.min_cell_volt_id = data[7] << 8 | data[6]


    def _inf_0004_signal(self, data):
        # 最大压差
        self.bms_main_ctl._view.top_widget.lb_diff_vol_value.setText(str(data[1] << 8 | data[0]))
        # 平均电压
        self.bms_main_ctl._view.top_widget.lb_avg_vol_value.setText(str(data[3] << 8 | data[2]))
        self._model.avg_cell_volt = data[3] << 8 | data[2]
        # 最大温差
        self.bms_main_ctl._view.top_widget.lb_diff_temp_value.setText(str(round((data[5] << 8 | data[4]) * 0.1 - 40, 1)))
        # 平均温度
        self.bms_main_ctl._view.top_widget.lb_avg_temp_value.setText(str(round((data[7] << 8 | data[6]) * 0.1 - 40, 1)))
        self._model.avg_cell_temp = round((data[7] << 8 | data[6]) * 0.1 - 40, 1)

    def _inf_0005_signal(self, data):
        # 最高单体温度值
        self.bms_main_ctl._view.top_widget.lb_h_temp_value.setText(str(round((data[1] << 8 | data[0]) * 0.1 - 40, 1)))
        self._model.max_cell_temp = round((data[1] << 8 | data[0]) * 0.1 - 40, 1)
        # 最高单体温度所在编号
        self.bms_main_ctl._view.top_widget.lb_h_temp_index_value.setText(str(data[3] << 8 | data[2]))
        self._model.max_cell_temp_id = data[3] << 8 | data[2]
        # 最低单体温度值
        self.bms_main_ctl._view.top_widget.lb_l_temp_value.setText(str(round((data[5] << 8 | data[4]) * 0.1 - 40, 1)))
        self._model.min_cell_temp = round((data[5] << 8 | data[4]) * 0.1 - 40, 1)
        # # 最低单体温度所在编号
        # self.bms_main_ctl._view.top_widget.lb_tcelllv_index_value.setText(str(data[7] << 8 | data[6]))
        self._model.min_cell_temp_id = data[7] << 8 | data[6]


    def _inf_0006_signal(self, data):
        # 当前允许最大放电功率
        self.bms_main_ctl._view.top_widget.lb_dchg_kw_value.setText(str(round((data[1] << 8 | data[0]) * 0.1, 1)))
        # 当前允许最大充电功率
        self.bms_main_ctl._view.top_widget.lb_chg_kw_value.setText(str(round((data[3] << 8 | data[2]) * 0.1, 1)))
        # # 当前可放电量
        # self.bms_main_ctl._view.top_widget.lb_.setText(str((data[5] << 8 | data[4]) * 0.1 - 40))
        # # 当前可充电量
        # self.bms_main_ctl._view.top_widget.lb_avg_temp_value.setText(str((data[7] << 8 | data[6]) * 0.1 - 40))


    def _inf_0007_signal(self, data):
        # 当前允许最大充电电压
        self.bms_main_ctl._view.top_widget.lb_max_chg_vol_value.setText(str(round((data[1] << 8 | data[0]) * 0.1, 1)))
        # 当前允许最大充电电流
        self.bms_main_ctl._view.top_widget.lb_max_chg_cur_value.setText(str(round((data[3] << 8 | data[2]) * 0.1 - 3200, 1)))
        # 当前允许最大放电电流
        self.bms_main_ctl._view.top_widget.lb_max_dchg_cur_value.setText(str(round((data[5] << 8 | data[4]) * 0.1 - 3200, 1)))
        # 当前允许放电限制电压
        self.bms_main_ctl._view.top_widget.lb_max_dchg_vol_value.setText(str(round((data[7] << 8 | data[6]) * 0.1, 1)))

    def _inf_0008_signal(self, data):
        # 电池组单体电压累加和
        self.bms_main_ctl._view.top_widget.lb_sum_vol_value.setText(str(round((data[1] << 8 | data[0]) * 0.1, 1)))
        # 总压一检测
        self.bms_main_ctl._view.top_widget.lb_tv_value.setText(str(round((data[3] << 8 | data[2]) * 0.1, 1)))
        # 总压二检测
        self.bms_main_ctl._view.top_widget.lb_tv_2_value.setText(str(round((data[5] << 8 | data[4]) * 0.1, 1)))
        # 总压三检测
        self.bms_main_ctl._view.top_widget.lb_tv_3_value.setText(str(round((data[7] << 8 | data[6]) * 0.1, 1)))
    

    def _inf_0009_signal(self, data):
        # 电池组标称容量
        self.bms_main_ctl._view.top_widget.lb_nom_cap_value.setText(str(round((data[1] << 8 | data[0]) * 0.1, 1)))
        # 电池组总容量
        self.bms_main_ctl._view.top_widget.lb_all_cap_value.setText(str(round((data[3] << 8 | data[2]) * 0.1, 1)))
        # 电池组剩余容量
        self.bms_main_ctl._view.top_widget.lb_left_cap_value.setText(str(round((data[5] << 8 | data[4]) * 0.1, 1)))
        # SOE
        self.bms_main_ctl._view.top_widget.lb_tsoe_value.setText(str(round(data[6] * 0.4, 1)))
   

    def _inf_000A_signal(self, data):
        # 最高单体SOC
        self.bms_main_ctl._view.top_widget.lb_soc_high_value.setText(str(round((data[1] << 8 | data[0]) * 0.4, 1)))
        self._model.max_soc = round((data[1] << 8 | data[0]) * 0.4, 1)
        # 最低单体SOC
        self.bms_main_ctl._view.top_widget.lb_soc_low_value.setText(str(round((data[3] << 8 | data[2]) * 0.4, 1)))
        self._model.min_soc = round((data[3] << 8 | data[2]) * 0.4, 1)
        # 平均单体SOC
        self.bms_main_ctl._view.top_widget.lb_soc_avg_value.setText(str(round((data[5] << 8 | data[4]) * 0.4, 1)))
        self._model.avg_soc = round((data[5] << 8 | data[4]) * 0.4, 1)
        # 循环次数
        self.bms_main_ctl._view.top_widget.lb_circle_num_value.setText(str(data[7] << 8 | data[6]))

    def _inf_000B_signal(self, data):
        # 电池组标称能量
        self.bms_main_ctl._view.top_widget.lb_nom_energy_value.setText(str(round((data[1] << 8 | data[0]) * 0.1, 1)))
        # 电池组总能量
        self.bms_main_ctl._view.top_widget.lb_all_energy_value.setText(str(round((data[3] << 8 | data[2]) * 0.1, 1)))
        # 电池组剩余能量
        self.bms_main_ctl._view.top_widget.lb_left_energy_value.setText(str(round((data[5] << 8 | data[4]) * 0.1, 1)))
        # 供电采样电压
        self.bms_main_ctl._view.top_widget.lb_gdcy_vol_value.setText(str(round((data[7] << 8 | data[6]) * 0.1, 1)))


    def _inf_000C_signal(self, data):
        # 累计放电电量
        self.bms_main_ctl._view.top_widget.lb_chg_kwh_value.setText(str(round((data[3] << 24 | data[2] << 16 | data[1] << 8 | data[0]) * 0.01, 2)))
        # 累计充电电量
        self.bms_main_ctl._view.top_widget.lb_dchg_kwh_value.setText(str(round((data[7] << 24 | data[6] << 16 | data[5] << 8 | data[4]) * 0.01, 2)))
    

    def _inf_000D_signal(self, data):
        # 当天累计放电电量
        self.bms_main_ctl._view.top_widget.lb_nowday_chg_energy_value.setText(str(round((data[3] << 24 | data[2] << 16 | data[1] << 8 | data[0]) * 0.01, 2)))
        # 当天累计充电电量
        self.bms_main_ctl._view.top_widget.lb_nowday_dchg_energy_value.setText(str(round((data[7] << 24 | data[6] << 16 | data[5] << 8 | data[4]) * 0.01, 2)))
    

    def _inf_000E_signal(self, data):
        # 系统对地绝缘阻值
        self.bms_main_ctl._view.top_widget.lb_sys_against_value.setText(str(data[1] << 8 | data[0]))
        # 正母线对地绝缘阻值
        self.bms_main_ctl._view.top_widget.lb_sys_p_against_value.setText(str(data[3] << 8 | data[2]))
        # 负母线对地绝缘阻值
        self.bms_main_ctl._view.top_widget.lb_sys_n_against_value.setText(str(data[5] << 8 | data[4]))


    def _inf_000F_signal(self, data):
        # 单体电压
        if data[1] == 0:
            self.bms_cell_ctl._view.home_cell_table.cellWidget(0, 1).setText(str(data[3] << 8 | data[2]) + " mV")
            self.bms_cell_ctl._view.home_cell_table.cellWidget(1, 1).setText(str(data[5] << 8 | data[4]) + " mV")   
            self.bms_cell_ctl._view.home_cell_table.cellWidget(2, 1).setText(str(data[7] << 8 | data[6]) + " mV")   

        if data[1] == 1:
            self.bms_cell_ctl._view.home_cell_table.cellWidget(3, 1).setText(str(data[3] << 8 | data[2]) + " mV")
            self.bms_cell_ctl._view.home_cell_table.cellWidget(0, 4).setText(str(data[5] << 8 | data[4]) + " mV")   
            self.bms_cell_ctl._view.home_cell_table.cellWidget(1, 4).setText(str(data[7] << 8 | data[6]) + " mV")   

        if data[1] == 2:
            self.bms_cell_ctl._view.home_cell_table.cellWidget(2, 4).setText(str(data[3] << 8 | data[2]) + " mV")
            self.bms_cell_ctl._view.home_cell_table.cellWidget(3, 4).setText(str(data[5] << 8 | data[4]) + " mV")   
            self.bms_cell_ctl._view.home_cell_table.cellWidget(0, 7).setText(str(data[7] << 8 | data[6]) + " mV")   

        if data[1] == 3:
            self.bms_cell_ctl._view.home_cell_table.cellWidget(1, 7).setText(str(data[3] << 8 | data[2]) + " mV")
            self.bms_cell_ctl._view.home_cell_table.cellWidget(2, 7).setText(str(data[5] << 8 | data[4]) + " mV")   
            self.bms_cell_ctl._view.home_cell_table.cellWidget(3, 7).setText(str(data[7] << 8 | data[6]) + " mV") 

        if data[1] == 4:
            self.bms_cell_ctl._view.home_cell_table.cellWidget(0, 10).setText(str(data[3] << 8 | data[2]) + " mV")
            self.bms_cell_ctl._view.home_cell_table.cellWidget(1, 10).setText(str(data[5] << 8 | data[4]) + " mV")   
            self.bms_cell_ctl._view.home_cell_table.cellWidget(2, 10).setText(str(data[7] << 8 | data[6]) + " mV") 

        if data[1] == 5:
            self.bms_cell_ctl._view.home_cell_table.cellWidget(3, 10).setText(str(data[3] << 8 | data[2]) + " mV")

        if data[0] < 25:
            # 单体信息页面
            self.bms_cell_ctl._view.cell_vol_table.cellWidget(3 * data[1], data[0] + 1).setText(str(data[3] << 8 | data[2]) + " mV")
            self.bms_cell_ctl._view.cell_vol_table.cellWidget(3 * data[1] + 1, data[0] + 1).setText(str(data[5] << 8 | data[4]) + " mV")   
            self.bms_cell_ctl._view.cell_vol_table.cellWidget(3 * data[1] + 2, data[0] + 1).setText(str(data[7] << 8 | data[6]) + " mV")   
            
            self.cell_single_volt[3 * data[1]] = data[3] << 8 | data[2]
            self.cell_single_volt[3 * data[1] + 1] = data[5] << 8 | data[4]
            self.cell_single_volt[3 * data[1] + 2] = data[7] << 8 | data[6]

            self._model.cell_volt = self.cell_single_volt

            # 硬件校准页面
            if (self.bms_hard_ctl._view.cb_bmu_index.currentIndex() == data[0]):
                self.bms_hard_ctl._view.hard_table.item(3 * data[1], 3).setText(str(data[3] << 8 | data[2]))
                self.bms_hard_ctl._view.hard_table.item(3 * data[1] + 1, 3).setText(str(data[5] << 8 | data[4]))
                self.bms_hard_ctl._view.hard_table.item(3 * data[1] + 2, 3).setText(str(data[7] << 8 | data[6]))


    def _inf_0010_signal(self, data):
        # 单体温度
        if data[1] == 0:
            self.bms_cell_ctl._view.home_cell_table.cellWidget(0, 2).setText(str(round((data[3] << 8 | data[2]) * 0.1 - 40, 1)) + " ℃")
            self.bms_cell_ctl._view.home_cell_table.cellWidget(1, 2).setText(str(round((data[5] << 8 | data[4]) * 0.1 - 40, 1)) + " ℃")
            self.bms_cell_ctl._view.home_cell_table.cellWidget(2, 2).setText(str(round((data[7] << 8 | data[6]) * 0.1 - 40, 1)) + " ℃")

        if data[1] == 1:
            self.bms_cell_ctl._view.home_cell_table.cellWidget(3, 2).setText(str(round((data[3] << 8 | data[2]) * 0.1 - 40, 1)) + " ℃")
            self.bms_cell_ctl._view.home_cell_table.cellWidget(0, 5).setText(str(round((data[5] << 8 | data[4]) * 0.1 - 40, 1)) + " ℃")  
            self.bms_cell_ctl._view.home_cell_table.cellWidget(1, 5).setText(str(round((data[7] << 8 | data[6]) * 0.1 - 40, 1)) + " ℃")

        if data[1] == 2:
            self.bms_cell_ctl._view.home_cell_table.cellWidget(2, 5).setText(str(round((data[3] << 8 | data[2]) * 0.1 - 40, 1)) + " ℃")
            self.bms_cell_ctl._view.home_cell_table.cellWidget(3, 5).setText(str(round((data[5] << 8 | data[4]) * 0.1 - 40, 1)) + " ℃")
            self.bms_cell_ctl._view.home_cell_table.cellWidget(0, 8).setText(str(round((data[7] << 8 | data[6]) * 0.1 - 40, 1)) + " ℃")
        if data[1] == 3:
            self.bms_cell_ctl._view.home_cell_table.cellWidget(1, 8).setText(str(round((data[3] << 8 | data[2]) * 0.1 - 40, 1)) + " ℃")
            self.bms_cell_ctl._view.home_cell_table.cellWidget(2, 8).setText(str(round((data[5] << 8 | data[4]) * 0.1 - 40, 1)) + " ℃")
            self.bms_cell_ctl._view.home_cell_table.cellWidget(3, 8).setText(str(round((data[7] << 8 | data[6]) * 0.1 - 40, 1)) + " ℃")

        if data[1] == 4:
            self.bms_cell_ctl._view.home_cell_table.cellWidget(0, 11).setText(str(round((data[3] << 8 | data[2]) * 0.1 - 40, 1)) + " ℃")
            self.bms_cell_ctl._view.home_cell_table.cellWidget(1, 11).setText(str(round((data[5] << 8 | data[4]) * 0.1 - 40, 1)) + " ℃")
            self.bms_cell_ctl._view.home_cell_table.cellWidget(2, 11).setText(str(round((data[7] << 8 | data[6]) * 0.1 - 40, 1)) + " ℃")

        if data[1] == 5:
            self.bms_cell_ctl._view.home_cell_table.cellWidget(3, 11).setText(str(round((data[3] << 8 | data[2]) * 0.1 - 40, 1)) + " ℃")

        if data[0] < 25: 
            self.bms_cell_ctl._view.cell_temp_table.cellWidget(3 * data[1], data[0] + 1).setText(str(round((data[3] << 8 | data[2]) * 0.1 - 40, 1)) + " ℃")
            self.bms_cell_ctl._view.cell_temp_table.cellWidget(3 * data[1] + 1, data[0] + 1).setText(str(round((data[5] << 8 | data[4]) * 0.1 - 40, 1)) + " ℃")
            self.bms_cell_ctl._view.cell_temp_table.cellWidget(3 * data[1] + 2, data[0] + 1).setText(str(round((data[7] << 8 | data[6]) * 0.1 - 40, 1)) + " ℃")   

            self.cell_single_temp[3 * data[1]] = round((data[3] << 8 | data[2]) * 0.1 - 40, 1)
            self.cell_single_temp[3 * data[1] + 1] = round((data[5] << 8 | data[4]) * 0.1 - 40, 1)
            self.cell_single_temp[3 * data[1] + 2] = round((data[7] << 8 | data[6]) * 0.1 - 40, 1)

            self._model.cell_temp = self.cell_single_temp

    # to do
    def _inf_0011_signal(self, data):
        # 最高单体电压所在从控编号
        self.bms_main_ctl._view.top_widget.lb_tcellhv_slave_index_value.setText(str(data[0]))
        # 最高单体电压所在从控内编号
        self.bms_main_ctl._view.top_widget.lb_tcellhv_in_index_value.setText(str(data[1]))
        # 最高单体温度所在从控编号
        self.bms_main_ctl._view.top_widget.lb_h_temp_slave_index_value.setText(str(data[2]))
        # 最高单体温度所在从控内编号
        self.bms_main_ctl._view.top_widget.lb_h_temp_in_index_value.setText(str(data[3]))
        # 最低单体电压所在从控编号
        self.bms_main_ctl._view.top_widget.lb_tcelllv_slave_index_value.setText(str(data[4]))
        # 最低单体电压所在从控内编号
        self.bms_main_ctl._view.top_widget.lb_tcelllv_in_index_value.setText(str(data[5]))
        # to do
        # # 最低单体温度所在从控编号
        # self.bms_main_ctl._view.top_widget.lb_l_temp_slave_index_value.setText(str(data[6]))
        # # 最低单体温度所在从控内编号
        # self.bms_main_ctl._view.top_widget.lb_h_temp_in_index_value.setText(str(data[7]))

    def _inf_0012_signal(self, data):
        return
        # if SD.CCU_TYPE == 1:
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.di_1, QColor(Qt.gray) if (data[0] & 0x01 == 0) else QColor(Qt.green))
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.di_2, QColor(Qt.gray) if (data[0] & 0x02 == 0) else QColor(Qt.green))
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.di_3, QColor(Qt.gray) if (data[0] & 0x04 == 0) else QColor(Qt.green))
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.di_4, QColor(Qt.gray) if (data[0] & 0x08 == 0) else QColor(Qt.green))
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.di_5, QColor(Qt.gray) if (data[0] & 0x10 == 0) else QColor(Qt.green))
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.di_6, QColor(Qt.gray) if (data[0] & 0x20 == 0) else QColor(Qt.green))
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.di_7, QColor(Qt.gray) if (data[0] & 0x40 == 0) else QColor(Qt.green))
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.di_8, QColor(Qt.gray) if (data[0] & 0x80 == 0) else QColor(Qt.green))

        #     set_edt_bg(self.bms_main_ctl._view.under_widget.do_1, QColor(Qt.gray) if (data[1] & 0x01 == 0) else QColor(Qt.green))
        #     self._model.p(data[1] & 0x01)
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.do_2, QColor(Qt.gray) if (data[1] & 0x02 == 0) else QColor(Qt.green))
        #     self._model.n((data[1] & 0x02) >> 1)
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.do_3, QColor(Qt.gray) if (data[1] & 0x04 == 0) else QColor(Qt.green))
        #     self._model.pre((data[1] & 0x04) >> 2)
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.do_4, QColor(Qt.gray) if (data[1] & 0x08 == 0) else QColor(Qt.green))
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.do_5, QColor(Qt.gray) if (data[1] & 0x10 == 0) else QColor(Qt.green))
        #     self._model.dlq((data[1] & 0x10) >> 4)
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.do_6, QColor(Qt.gray) if (data[1] & 0x20 == 0) else QColor(Qt.green))
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.do_7, QColor(Qt.gray) if (data[1] & 0x40 == 0) else QColor(Qt.green))
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.do_8, QColor(Qt.gray) if (data[1] & 0x80 == 0) else QColor(Qt.green))
        # else:
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.fjd_1, QColor(Qt.gray) if (data[2] & 0x01 == 0) else QColor(Qt.green))
        #     self._model.gjd_first(data[2] & 0x01)
        #     set_edt_bg(self.bms_main_ctl._view.under_widget.fjd_1, QColor(Qt.gray) if (data[2] & 0x02 == 0) else QColor(Qt.green))
        #     self._model.gjd_second((data[2] & 0x02) >> 1)
              

    # def _inf_0013_signal(self, data):
    #     # BMS 电池编码								
    #     self.bms_sn_version = ["" for i in range(8)]
    #     self.bms_sn_version[0] = chr(data[0])
    #     self.bms_sn_version[1] = chr(data[1])
    #     self.bms_sn_version[2] = chr(data[2])
    #     self.bms_sn_version[3] = chr(data[3])
    #     self.bms_sn_version[4] = chr(data[4])
    #     self.bms_sn_version[5] = chr(data[5])
    #     self.bms_sn_version[6] = chr(data[6])
    #     self.bms_sn_version[7] = chr(data[7])
    #     bms_sn_version = ''.join(self.bms_sn_version)
    #     self.bms_download_ctl._view.message_table.cellWidget(5, 2).setText(bms_sn_version)


    def _inf_0013_signal(self, data):
        # BMS 硬件版本号
        self.bms_hard_version = ["" for i in range(8)]
        self.bms_hard_version[0] = chr(data[0])
        self.bms_hard_version[1] = chr(data[1])
        self.bms_hard_version[2] = chr(data[2])
        self.bms_hard_version[3] = chr(data[3])
        self.bms_hard_version[4] = chr(data[4])
        self.bms_hard_version[5] = chr(data[5])
        self.bms_hard_version[6] = chr(data[6])
        self.bms_hard_version[7] = chr(data[7])
        bms_hard_version = ''.join(self.bms_hard_version)
        self.bms_download_ctl._view.message_table.item(3, 2).setText(bms_hard_version)
    

    def _inf_0014_signal(self, data):
        # BMS Boot版本号
        self.bms_boot_version = ["" for i in range(8)]
        self.bms_boot_version[0] = chr(data[0])
        self.bms_boot_version[1] = chr(data[1])
        self.bms_boot_version[2] = chr(data[2])
        self.bms_boot_version[3] = chr(data[3])
        self.bms_boot_version[4] = chr(data[4])
        self.bms_boot_version[5] = chr(data[5])
        self.bms_boot_version[6] = chr(data[6])
        self.bms_boot_version[7] = chr(data[7])
        bms_boot_version = ''.join(self.bms_boot_version)
        self.bms_download_ctl._view.message_table.item(0, 2).setText(bms_boot_version)


    def _inf_0016_signal(self, data):
        # BMS 软件版本号
        self.bms_soft_version = ["" for i in range(8)]
        self.bms_soft_version[0] = chr(data[0])
        self.bms_soft_version[1] = chr(data[1])
        self.bms_soft_version[2] = chr(data[2])
        self.bms_soft_version[3] = chr(data[3])
        self.bms_soft_version[4] = chr(data[4])
        self.bms_soft_version[5] = chr(data[5])
        self.bms_soft_version[6] = chr(data[6])
        self.bms_soft_version[7] = chr(data[7])
        bms_soft_version = ''.join(self.bms_soft_version)
        self.bms_download_ctl._view.message_table.item(1, 2).setText(bms_soft_version)


    def _inf_0015_signal(self, data):
        # BMS 算法版本号								
        self.bms_sf_version = ["" for i in range(8)]
        self.bms_sf_version[0] = chr(data[0])
        self.bms_sf_version[1] = chr(data[1])
        self.bms_sf_version[2] = chr(data[2])
        self.bms_sf_version[3] = chr(data[3])
        self.bms_sf_version[4] = chr(data[4])
        self.bms_sf_version[5] = chr(data[5])
        self.bms_sf_version[6] = chr(data[6])
        self.bms_sf_version[7] = chr(data[7])
        bms_sf_version = ''.join(self.bms_sf_version)
        self.bms_download_ctl._view.message_table.item(2, 2).setText(bms_sf_version)


    def _inf_0017_signal(self, data):
        # RTC时钟
        self.bms_hard_ctl._view.lb_rtc.setText(str(data[0] + 2000)+ "-" + str(data[1]) + "-" + str(data[2])+ " " + str(data[3]) + ":" + str(data[4]) + ":" + str(data[5]))


    def _inf_0018_signal(self, data):
        # 电池均衡状态
        for i in range(8):
            if a_bit(data[1], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 1).widget(), QtGui.QColor(Qt.green))
            else:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 1).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[2], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 9).widget(), QtGui.QColor(Qt.green))
            else:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 9).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[3], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 17).widget(), QtGui.QColor(Qt.green))
            else:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 17).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[4], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 25).widget(), QtGui.QColor(Qt.green))
            else:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 25).widget(), QtGui.QColor(Qt.white))


    def _inf_0019_signal(self, data):
        # 电池均衡状态
        for i in range(8):
            if a_bit(data[1], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 33).widget(), QtGui.QColor(Qt.green))
            else:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 33).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[2], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 41).widget(), QtGui.QColor(Qt.green))
            else:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 41).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[3], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 49).widget(), QtGui.QColor(Qt.green))
            else:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 49).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[4], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 57).widget(), QtGui.QColor(Qt.green))
            else:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 57).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[5], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 65).widget(), QtGui.QColor(Qt.green))
            else:
                set_edt_bg(self.bms_balance_ctl._view.on_off_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 65).widget(), QtGui.QColor(Qt.white))


    def _inf_001A_signal(self, data):
        # 电池均衡故障
        for i in range(8):
            if a_bit(data[1], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 1).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 1).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[2], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 9).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 9).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[3], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 17).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 17).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[4], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 25).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 25).widget(), QtGui.QColor(Qt.white))


    def _inf_001B_signal(self, data):
        # 电池均衡故障
        for i in range(8):
            if a_bit(data[1], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 33).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 33).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[2], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 41).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 41).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[3], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 49).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 49).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[4], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 57).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 57).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[5], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 65).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.balance_fault_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 65).widget(), QtGui.QColor(Qt.white))


    def _inf_001C_signal(self, data):
        # 电池连接线状态
        for i in range(8):
            if a_bit(data[1], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 1).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 1).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[2], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 9).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 9).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[3], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 17).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 17).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[4], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 25).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 25).widget(), QtGui.QColor(Qt.white))
        # for i in range(8):
        #     if a_bit(data[1], i + 1) == 1:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 1, data[0] + 1).widget(), QtGui.QColor(Qt.red))
        #     else:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 1, data[0] + 1).widget(), QtGui.QColor(Qt.white))
        #     if a_bit(data[2], i + 1) == 1:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 9, data[0] + 1).widget(), QtGui.QColor(Qt.red))
        #     else:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 9, data[0] + 1).widget(), QtGui.QColor(Qt.white))
        #     if a_bit(data[3], i + 1) == 1:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 17, data[0] + 1).widget(), QtGui.QColor(Qt.red))
        #     else:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 17, data[0] + 1).widget(), QtGui.QColor(Qt.white))
        #     if a_bit(data[4], i + 1) == 1:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 25, data[0] + 1).widget(), QtGui.QColor(Qt.red))
        #     else:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 25, data[0] + 1).widget(), QtGui.QColor(Qt.white))


    def _inf_001D_signal(self, data):
        # 电池连接线状态
        for i in range(8):
            if a_bit(data[1], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 33).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 33).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[2], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 41).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 41).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[3], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 49).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 49).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[4], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 57).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 57).widget(), QtGui.QColor(Qt.white))
            if a_bit(data[5], i + 1) == 1:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 65).widget(), QtGui.QColor(Qt.red))
            else:
                set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(data[0] - 1, i + 65).widget(), QtGui.QColor(Qt.white))
        # for i in range(8):
        #     if a_bit(data[1], i + 1) == 1:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 33, data[0] + 1).widget(), QtGui.QColor(Qt.red))
        #     else:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 33, data[0] + 1).widget(), QtGui.QColor(Qt.white))
        #     if a_bit(data[2], i + 1) == 1:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 41, data[0] + 1).widget(), QtGui.QColor(Qt.red))
        #     else:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 41, data[0] + 1).widget(), QtGui.QColor(Qt.white))
        #     if a_bit(data[3], i + 1) == 1:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 49, data[0] + 1).widget(), QtGui.QColor(Qt.red))
        #     else:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 49, data[0] + 1).widget(), QtGui.QColor(Qt.white))
        #     if a_bit(data[4], i + 1) == 1:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 57, data[0] + 1).widget(), QtGui.QColor(Qt.red))
        #     else:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 57, data[0] + 1).widget(), QtGui.QColor(Qt.white))
        #     if a_bit(data[5], i + 1) == 1:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 65, data[0] + 1).widget(), QtGui.QColor(Qt.red))
        #     else:
        #         set_edt_bg(self.bms_balance_ctl._view.line_qscrollarea_layout.itemAtPosition(i + 65, data[0] + 1).widget(), QtGui.QColor(Qt.white))


    def _inf_001E_signal(self, data):
        return  

    def _inf_001F_signal(self, data):
        return

    def _inf_0020_signal(self, data):
        # BMS 电池编码								
        self.bms_sn_version[0] = chr(data[0])
        self.bms_sn_version[1] = chr(data[1])
        self.bms_sn_version[2] = chr(data[2])
        self.bms_sn_version[3] = chr(data[3])
        self.bms_sn_version[4] = chr(data[4])
        self.bms_sn_version[5] = chr(data[5])
        self.bms_sn_version[6] = chr(data[6])
        self.bms_sn_version[7] = chr(data[7])

    def _inf_0021_signal(self, data):
        self.bms_sn_version[8] = chr(data[0])
        self.bms_sn_version[9] = chr(data[1])
        self.bms_sn_version[10] = chr(data[2])
        self.bms_sn_version[11] = chr(data[3])
        self.bms_sn_version[12] = chr(data[4])
        self.bms_sn_version[13] = chr(data[5])
        self.bms_sn_version[14] = chr(data[6])
        self.bms_sn_version[15] = chr(data[7])

        bms_sn_version = ''.join(self.bms_sn_version)
        self.bms_download_ctl._view.message_table.item(4, 2).setText(bms_sn_version)

    def _inf_0022_signal(self, data):
        # BMS 电池编码								
        self.battery_sn_version[0] = chr(data[0])
        self.battery_sn_version[1] = chr(data[1])
        self.battery_sn_version[2] = chr(data[2])
        self.battery_sn_version[3] = chr(data[3])
        self.battery_sn_version[4] = chr(data[4])
        self.battery_sn_version[5] = chr(data[5])
        self.battery_sn_version[6] = chr(data[6])
        self.battery_sn_version[7] = chr(data[7])

    def _inf_0023_signal(self, data):
        self.battery_sn_version[8] = chr(data[0])
        self.battery_sn_version[9] = chr(data[1])
        self.battery_sn_version[10] = chr(data[2])
        self.battery_sn_version[11] = chr(data[3])
        self.battery_sn_version[12] = chr(data[4])
        self.battery_sn_version[13] = chr(data[5])
        self.battery_sn_version[14] = chr(data[6])
        self.battery_sn_version[15] = chr(data[7])

        battery_sn_version = ''.join(self.battery_sn_version)
        self.bms_download_ctl._view.message_table.item(5, 2).setText(battery_sn_version)
        self.bms_status._view.lb_bms_sn.setText("BATSN:" + battery_sn_version)

        dataTime = QDateTime.currentDateTime()
        text = dataTime.toString("yyyy-MM-dd HH:mm:ss")
        self._model.now_time = text

    
    def run(self):
        self._view.show()
