Exemple #1
0
 def to_register_dev(self):
     if self.dev_register:
         self.LOG.info(common_APIs.chinese_show("设备已经注册"))
     else:
         self.LOG.info(common_APIs.chinese_show("发送设备注册"))
         self.to_to_send_msg(json.dumps(
             self.get_send_msg('COM_DEV_REGISTER')), ack=b'\x00')
Exemple #2
0
    def dev_protocol_handler(self, msg, ack=False):
        if ack:
            self.update_msgst(msg['Command'], 'rsp')
            if msg['Command'] == 'COM_DEV_REGISTER':
                if msg['Result'] == 0:
                    self.dev_register = True
                    # decrypt
                    if self.encrypt_flag:
                        self.add_item('_encrypt_key', msg['Data'][0]['aeskey'])
                    self.LOG.warn(common_APIs.chinese_show("设备已经注册"))
                    return None
                else:
                    self.dev_register = False
                    self.LOG.warn(common_APIs.chinese_show("设备注册失败"))
                    return None
            else:
                return None
        else:
            self.update_msgst(msg['Command'], 'req')

        if msg['Command'] == 'COM_HEARTBEAT':
            pass
        elif msg['Command'] in self.command_list:
            self.set_items(msg['Command'], msg)
            rsp_msg = self.get_rsp_msg(msg['Command'])
            self.update_msgst(msg['Command'], 'rsp')
            return json.dumps(rsp_msg)
        else:
            self.LOG.warn('Unknow msg: %s!' % (msg['Command']))
            return None
 def to_register_dev(self):
     time.sleep(self.reg_dev_relay_s)
     if self.dev_register:
         self.LOG.warn(
             common_APIs.chinese_show("设备已经注册[{}]".format(self._deviceID)))
     else:
         time.sleep(self.reg_dev_relay_s
                    )  # wait the send_data_loop thread to start
         self.LOG.info(
             common_APIs.chinese_show("发送设备注册[{}]".format(self._deviceID)))
         self.send_msg(json.dumps(self.get_send_msg('COM_DEV_REGISTER')),
                       ack=b'\x00')
 def to_register_dev(self):
     if self.dev_register:
         self.LOG.debug(common_APIs.chinese_show("设备已经注册"))
     else:
         self.LOG.debug(common_APIs.chinese_show("发送设备注册"))
         self.send_msg(json.dumps(self.get_send_msg('COM_DEV_REGISTER')))
         time.sleep(4)
         if self.dev_register:
             self.LOG.warn(common_APIs.chinese_show("设备已经注册"))
         else:
             self.LOG.error(common_APIs.chinese_show("设备注册失败"))
             sys.exit()
Exemple #5
0
    def protocol_handler(self, msg, ack=False):
        if ack:
            self.update_msgst(msg['Command'], 'rsp')
            if msg['Command'] == 'COM_DEV_REGISTER':
                if msg['Result'] == 0:
                    self.dev_register = True
                    # decrypt
                    if self.encrypt_flag:
                        self.add_item('_encrypt_key', msg['Data'][0]['aeskey'])
                    self.LOG.warn(common_APIs.chinese_show("设备已经注册"))
                    return None
                else:
                    self.dev_register = False
                    self.LOG.warn(common_APIs.chinese_show("设备注册失败"))
                    return None
            else:
                return None
        else:
            self.update_msgst(msg['Command'], 'req')

        if msg['Command'] == 'COM_LOAD_CERTIFICATE':
            self._CredenceType[str(
                msg["Data"][0]["CredenceType"])] = msg["Data"][0]["credenceNo"]
            self.LOG.warn(self._CredenceType[str(
                msg["Data"][0]["CredenceType"])])

        if msg['Command'] == 'COM_DELETE_CERTIFICATE':
            self._CredenceType[str(msg["Data"][0]["CredenceType"])] = ""
            self.LOG.warn(
                'del ' +
                self._CredenceType[str(msg["Data"][0]["CredenceType"])])

        if msg['Command'] == 'COM_HEARTBEAT':
            pass

        elif msg['Command'] in self.command_list:
            self.set_items(msg['Command'], msg)
            rsp_msg = self.get_rsp_msg(msg['Command'])
            self.update_msgst(msg['Command'], 'rsp')
            return json.dumps(rsp_msg)
        else:
            self.LOG.warn('Unknow msg: %s!' % (msg['Command']))
            return None
Exemple #6
0
 def get_upload_record(self, record_type):
     self.LOG.warn(common_APIs.chinese_show("记录上传"))
     report_msg = self.get_send_msg('COM_UPLOAD_RECORD')
     report_msg["Data"][0]["RecordType"] = record_type
     report_msg["EventCode"] = record_type
     return json.dumps(report_msg)
Exemple #7
0
 def get_upload_status(self):
     self.LOG.warn(common_APIs.chinese_show("设备状态上报"))
     return json.dumps(self.get_send_msg('COM_UPLOAD_DEV_STATUS'))
 def get_upload_event(self, event_type):
     self.LOG.warn(common_APIs.chinese_show("事件上报"))
     report_msg = self.get_send_msg('COM_UPLOAD_EVENT')
     report_msg["Data"][0]["EventType"] = event_type
     report_msg["EventCode"] = event_type
     return json.dumps(report_msg)
 def check_register_dev(self):
     if self.dev_register:
         self.LOG.yinfo(common_APIs.chinese_show("设备已经注册"))
     else:
         self.LOG.error(common_APIs.chinese_show("设备注册失败"))
         sys.exit()
Exemple #10
0
 def protocol_handler(self, msg, ack=False):
     if ack:
         self.update_msgst(msg['Command'], 'rsp')
         if msg['Command'] == 'COM_DEV_REGISTER':
             if msg['Result'] == 0:
                 self.dev_register = True
                 # decrypt
                 if self.encrypt_flag:
                     self.add_item('_encrypt_key', msg['Data'][0]['aeskey'])
                 self.LOG.warn(
                     common_APIs.chinese_show("设备注册成功[{}]".format(
                         self._deviceID)))
                 return None
             else:
                 self.dev_register = False
                 self.LOG.error(
                     common_APIs.chinese_show("设备注册失败[{}]".format(
                         self._deviceID)))
                 return None
         elif msg['Command'] == 'COM_IC_CARD_REQ_CHARGE':
             if msg['Result'] == 0:
                 self.set_items(msg['Command'], msg)
                 if self.get_item("_icType" == 1):
                     #region 处理IC卡开始充电
                     tI = self.get_item("SwitchMinI")
                     self.set_item("_currentI", tI)
                     realTimeStr = self.sim_config.getDateStr()
                     self.set_item("_startTime", realTimeStr)
                     self.set_item("_currentTime", realTimeStr)
                     self.set_item("_lastReportTime", realTimeStr)
                     swStatus = self.getSwitchStatus()
                     if swStatus == SwitchStatus.Only3:
                         if self.try_set_item("_switch3Status", 2):
                             self.send_charging_report_onetime(
                                 ReportType.SWITCH3_CHANGE)
                     elif swStatus == SwitchStatus.Only7:
                         if self.try_set_item("_switch7Status", 4):
                             self.send_charging_report_onetime(
                                 ReportType.SWITCH7_CHANGE)
                     realPower = tI * self.get_item("_voltageOut") / 1000
                     self.set_item("_power", round(realPower))
                     self.send_msg(self.get_upload_start_result(),
                                   ack=b'\x00')
                     self.set_item("_isCharging", 1)
                     self.send_charging_report_by_thread()
                     #endregion
                 else:
                     #region 处理IC卡停止充电
                     self.set_endTime_to_currentTime()
                     self.set_charging_status(0)
                     self.set_item("_result", 0)
                     self.send_msg(self.get_upload_stop_result(),
                                   ack=b'\x00')
                     self.send_charging_report_onetime(
                         ReportType.CHARGE_RECORD_UPLOAD, isEndReport=True)
                     #endregion
             else:
                 self.LOG.error("COM_IC_CARD_REQ_CHARGE 返回失败")
             return None
         else:
             return None
     else:
         self.update_msgst(msg['Command'], 'req')
     if msg['Command'] == 'COM_HEARTBEAT' or msg[
             'Command'] == 'COM_IC_CARD_REQ_CHARGE':
         pass
     elif msg['Command'] in self.command_list:
         self.set_items(msg['Command'], msg)
         if msg['Command'] == 'COM_SET_QR_CODE':
             # 如果当前有打开图片,先关掉
             # os.system("taskkill /f /t /im dllhost.exe")
             common_APIs.save_ini_file(self.iniFile,
                                       self._deviceID,
                                       url=self.get_item("_url"),
                                       sn=self.get_item("_sn"))
             common_APIs.GetQrCodeByUrlAndSn(
                 self.get_item("_url"),
                 self.get_item("_sn"),
                 imgFile=self.get_item("_qcodeFile"))
         elif msg['Command'] == 'COM_START_CHARGE':
             self.handle_start_charge()
             # handle_start_charge已经发过了ACK,这里不需要返回再发了,所以返回None
             return None
         elif msg['Command'] == 'COM_STOP_CHARGE':
             self.handle_stop_charge()
             return None
         elif msg['Command'] == 'COM_POWER_CONTROL':
             self.handle_power_control()
         elif msg['Command'] == 'COM_SET_LOCK':
             self.handle_set_lock()
         rsp_msg = self.get_rsp_msg(msg['Command'])
         self.update_msgst(msg['Command'], 'rsp')
         return json.dumps(rsp_msg)
     else:
         self.LOG.warn('Unknow msg: %s!' % (msg['Command']))
         return None
Exemple #11
0
 def get_upload_IC_req(self, reqType=1):
     self.LOG.warn(common_APIs.chinese_show("8.4.6 IC卡充电申请"))
     self._icType = reqType
     report_msg = self.get_send_msg('COM_IC_CARD_REQ_CHARGE')
     report_msg["Data"][0] = report_msg["Data"][int(reqType)]
     return json.dumps(report_msg)
Exemple #12
0
 def get_upload_stop_event(self):
     self.LOG.warn(common_APIs.chinese_show("8.4.5 停止充电事件上报"))
     report_msg = self.get_send_msg('COM_UPLOAD_STOP_EVENT')
     return json.dumps(report_msg)
Exemple #13
0
 def get_upload_stop_result(self):
     self.LOG.warn(common_APIs.chinese_show("8.4.4 停止充电结果上报"))
     report_msg = self.get_send_msg('COM_UPLOAD_STOP_RESULT')
     return json.dumps(report_msg)
Exemple #14
0
 def get_upload_event(self, reportType):
     self.LOG.warn(common_APIs.chinese_show("8.4.2 事件上报"))
     self._type = reportType
     report_msg = self.get_send_msg('COM_UPLOAD_EVENT')
     return json.dumps(report_msg)
 def get_upload_ba_status(self,event_type):
     self.LOG.warn(common_APIs.chinese_show("BA_STATUS上报"))
     report_msg = self.get_send_msg('FAC_UPLOAD_BA_STATUS')
     #report_msg["Data"][0]["EventType"] = event_type
     #report_msg["EventCode"] = event_type
     return json.dumps(report_msg)