123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- # -*- coding: utf-8 -*-
- # !/usr/bin/env python
- from apps.web.constant import DeviceCmdCode, Const
- from apps.web.core.adapter.base import SmartBox, fill_2_hexByte
- from apps.web.core.exceptions import ServiceException
- from apps.web.core.networking import MessageSender
- from apps.web.device.models import Device
- class DaQiang(SmartBox):
- def _send_data(self, funCode, data, cmd=DeviceCmdCode.OPERATE_DEV_SYNC, timeout=30):
- result = MessageSender.send(
- device=self.device,
- cmd=cmd,
- payload={"IMEI": self.device.devNo, "funCode": funCode, "data": data},
- timeout=timeout
- )
- if result.get("rst") == -1:
- raise ServiceException({'result': 2, 'description': u'充电桩正在玩命找网络,请您稍候再试'})
- if result.get("rst") == 1:
- raise ServiceException({'result': 2, 'description': u'充电桩忙,无响应,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'})
- return result
- @staticmethod
- def _suit_package(package):
- pass
- def _start(self, coins):
- data = fill_2_hexByte(hex(int(coins)), 2)
- result = self._send_data("FD", data)
- if result['data'][2:4] == 'F1':
- raise ServiceException({'result': 2, 'description': u'未知错误,设备启动失败'})
- errorCode = result['data'][4:-2]
- if errorCode != "02":
- raise ServiceException({'result': 2, 'description': u'设备启动失败'})
- return result
- def _status_check(self):
- data = "01"
- result = self._send_data("FE", data)
- if result['data'][2:4] == 'F1':
- raise ServiceException({'result': 2, 'description': u'未知错误,设备状态查询失败'})
- sys_st = result["data"][4:-2]
- return sys_st
- def check_dev_status(self, attachParas=None):
- sys_st = self._status_check()
- if sys_st != "01":
- if sys_st == '02':
- raise ServiceException({'result': 2, 'description': u'设备已被启动,请将子弹用完后再试。'})
- else:
- raise ServiceException({'result': 2, 'description': u'设备无法使用,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'})
- washConf = self.device['washConfig']
- for _, _info in washConf.items():
- if _info.get('unit') != "次":
- raise ServiceException(
- {'result': 2, 'description': u'设备单位配置错误({}),请联系经销商修改套餐配置(次)'.format(_info.get('unit'))})
- return sys_st
- def start_device(self, package, openId, attachParas):
- times = int(package['time'])
- result = self._start(times)
- devDict = {
- 'status': Const.DEV_WORK_STATUS_IDLE,
- 'times': times,
- 'openId': openId,
- }
- Device.update_dev_control_cache(self._device['devNo'], devDict)
- result["finishedTime"] = 12 * 60 * 60
- return result
- def analyze_event_data(self, data):
- cmdCode = data[2:4]
- if cmdCode == 'FF':
- status_code = data[4:6]
- if status_code == '01':
- desc = u'设备等待使用中'
- elif status_code == '02':
- desc = u'设备正在使用中'
- else:
- desc = u'设备状态异常,请稍候再试'
- return {
- 'cmdCode': 'FF',
- 'status': status_code,
- }
- elif cmdCode == 'F1':
- return {
- "cmdCode": 'F1'
- }
- def update_dq_status(self, status):
- data = Device.get_dev_control_cache(self._device['devNo'])
- data['status'] = status
- Device.update_dev_control_cache(self._device['devNo'], data)
- def get_port_status_from_dev(self):
- return {'status': Const.DEV_WORK_STATUS_IDLE}
|