xueying.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. # -*- coding: utf-8 -*-
  2. from apps.web.core.adapter.base import *
  3. from apps.web.device.models import Device
  4. from apps.web.user.models import MyUser
  5. class ChargingXUEYINGBox(SmartBox):
  6. def __init__(self, device):
  7. super(ChargingXUEYINGBox, self).__init__(device)
  8. def translate_funcode(self, funCode):
  9. funCodeDict = {
  10. 'A8': u'回复卡余额',
  11. 'A7': u'移动支付',
  12. 'C1': u'获取设备投币统计',
  13. 'C2': u'获取设备刷卡统计',
  14. 'B3': u'获取设备端口信息',
  15. 'D4': u'获取端口状态',
  16. 'C3': u'获取电流标准',
  17. 'A4': u'设置电流标准',
  18. 'B8': u'获取消费标准配置',
  19. 'B7': u'设置消费标准配置',
  20. 'B2': u'获取空载关闭时间',
  21. 'B1': u'设置线路空载关闭时间',
  22. 'D8': u'充满自停标记',
  23. 'F4': u'获取设备版本',
  24. 'F5': u'回复出厂设置',
  25. 'D6': u'清理通道时间',
  26. 'D7': u'复位设备',
  27. 'D1': u'设置浮充功率',
  28. 'E2': u'获取4.5安培的AD功率',
  29. 'E1': u'设置4.5安培的AD功率',
  30. 'E4': u'查询空载断电功率值',
  31. 'E5': u'设置空载断时间值',
  32. 'E7': u'获取设备时间',
  33. }
  34. for k, v in funCodeDict.items():
  35. if k in funCode:
  36. return v
  37. return ''
  38. def translate_event_cmdcode(self, cmdCode):
  39. cmdDict = {
  40. 'B4': u'上报修改后的消费标准',
  41. 'A8': u'刷卡上报',
  42. 'C4': u'上报设备状态',
  43. 'B5': u'主动上报投币订单结束',
  44. 'B6': u'用户刷卡上报的信息结束',
  45. 'C8': u'刷网络钱包卡完成上传消费订单',
  46. 'C9': u'网络任务完成上传消费订单',
  47. }
  48. return cmdDict.get(cmdCode, '')
  49. def test(self, coins):
  50. data = '00 00 00 00 00 00 00 00 00 00 0A 00 00 0A'
  51. data = data.replace(' ', '')
  52. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  53. {'IMEI': self._device['devNo'], "funCode": 'A7', 'data': data})
  54. return devInfo
  55. def reply_event_response(self, funCode, port = None, result = True):
  56. if port is not None:
  57. funCode = fill_2_hexByte(hex(int(port)), 2) + '00' + funCode
  58. data = '01'
  59. if not result:
  60. data = '00'
  61. MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_NO_RESPONSE,
  62. {'IMEI': self._device['devNo'], "funCode": funCode, 'data': data})
  63. def reply_card_balance(self, res, orderNo, balance):
  64. data = res
  65. data += orderNo
  66. data += fill_2_hexByte(hex(int(balance)), 6)
  67. MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_NO_RESPONSE,
  68. {'IMEI': self._device['devNo'], "funCode": '0101A8', 'data': data})
  69. def start_device(self, package, openId, attachParas):
  70. if attachParas is None:
  71. raise ServiceException({'result': 2, 'description': u'请您选择合适的充电线路、电池类型信息'})
  72. if not attachParas.has_key('chargeIndex'):
  73. raise ServiceException({'result': 2, 'description': u'请您选择合适的充电线路'})
  74. port = int(attachParas['chargeIndex'])
  75. hexPort = fill_2_hexByte(hex(port), 2)
  76. orderNo = attachParas.get('orderNo')
  77. hexOrderNo = fill_2_hexByte(hex(int(orderNo)), 16)
  78. coins = float(package['coins'])
  79. hexCoins = fill_2_hexByte(hex(int(coins * 100)), 6)
  80. needTime = int(package['time'])
  81. if 'onPoints' not in attachParas:
  82. try:
  83. user = MyUser.objects.get(groupId = self._device['groupId'], openId = openId)
  84. hexBalance = fill_2_hexByte(hex(int(user.balance * 100)), 6)
  85. except Exception, e:
  86. logger.info('get user error=%s' % e)
  87. raise ServiceException({'result': 2, 'description': u'系统异常,没有查询到用户'})
  88. else:
  89. hexBalance = fill_2_hexByte(hex(int(1 * 100)), 6)
  90. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  91. {'IMEI': self._device['devNo'], "funCode": hexPort + '00' + 'A7',
  92. 'data': hexOrderNo + hexCoins + hexBalance}, timeout = MQTT_TIMEOUT.START_DEVICE)
  93. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  94. if devInfo['rst'] == -1:
  95. raise ServiceException({'result': 2, 'description': u'充电桩正在玩命找网络,您的金币还在,重试不需要重新付款,建议您试试旁边其他设备,或者稍后再试哦'})
  96. elif devInfo['rst'] == 1:
  97. raise ServiceException({'result': 2, 'description': u'充电桩正在忙,无响应,您的金币还在,请试试其他线路,或者请稍后再试哦'})
  98. result = devInfo['data'][10:12]
  99. if result == '00': # 成功
  100. raise ServiceException({'result': 2, 'description': u'充电站付款失败,可能是设备忙,或者设备故障'})
  101. start_timestamp = int(time.time())
  102. Device.update_dev_control_cache(
  103. self._device['devNo'],
  104. {
  105. str(port):
  106. {
  107. 'startTime': timestamp_to_dt(start_timestamp).strftime('%Y-%m-%d %H:%M:%S'),
  108. 'status': Const.DEV_WORK_STATUS_WORKING,
  109. 'finishedTime': start_timestamp + needTime * 60,
  110. 'coins': coins,
  111. 'needTime': needTime,
  112. 'isStart': True,
  113. 'openId': openId,
  114. 'refunded': False,
  115. 'vCardId': self._vcard_id
  116. }
  117. })
  118. devInfo['consumeOrderNo'] = orderNo
  119. return devInfo
  120. def analyze_event_data(self, data):
  121. cmdCode = data[6:8]
  122. if cmdCode in ['B4']: # 本地修改消费标准时,设备主动上报修改后的消费标准
  123. mobilePrice = int(data[10:14], 16)
  124. mobileTime = int(data[14:18], 16)
  125. mobileOnsale = int(data[18:20], 16)
  126. icPrice = int(data[20:24], 16)
  127. icTime = int(data[24:28], 16)
  128. coinPrice = int(data[28:32], 16)
  129. coinTime = int(data[32:36], 16)
  130. return {'cmdCode': cmdCode, 'mobilePrice': mobilePrice, 'mobileTime': mobileTime,
  131. 'mobileOnsale': mobileOnsale, 'icPrice': icPrice, 'icTime': icTime, 'coinPrice': coinPrice,
  132. 'coinTime': coinTime}
  133. elif cmdCode == 'A8':
  134. check = int(data[34:36], 16) ^ int(data[36:38], 16) ^ int(data[38:40], 16) ^ int(data[40:42], 16)
  135. strCheck = fill_2_hexByte(hex(check), 2)
  136. cardNo = data[34:42] + strCheck
  137. orderNo = str(data[42:46])
  138. coins = int(data[46:52], 16)
  139. return {'cmdCode': cmdCode, 'cardNo': cardNo, 'orderNo': orderNo, 'coins': coins}
  140. elif cmdCode == 'C4': # 上报设备状态
  141. port = int(data[2:4], 16)
  142. status = int(data[10:12], 16)
  143. if status == 1:
  144. return {'status': Const.DEV_WORK_STATUS_WORKING, 'cmdCode': cmdCode, 'port': port}
  145. elif status == 0:
  146. return {'status': Const.DEV_WORK_STATUS_IDLE, 'cmdCode': cmdCode, 'port': port}
  147. elif status >= 55:
  148. return {'status': Const.DEV_WORK_STATUS_FAULT, 'cmdCode': cmdCode, 'port': port, 'FaultCode': status}
  149. elif cmdCode == 'B5': # 主动上报投币订单结束
  150. port = int(data[2:4], 16)
  151. orderNo = int(data[10:14], 16)
  152. coins = int(data[14:22], 16)
  153. duration = int(data[22:30], 16)
  154. finishedTime = int(data[30:38], 16)
  155. return {'cmdCode': cmdCode, 'port': port, 'orderNo': orderNo, 'coins': coins, 'duration': duration,
  156. 'finishedTime': finishedTime}
  157. elif cmdCode == 'B6': # 用户刷卡上报的信息结束
  158. port = int(data[2:4], 16)
  159. orderNo = int(data[10:14], 16)
  160. cardNo = data[14:24]
  161. coins = int(data[24:32], 16)
  162. balance = int(data[32:40], 16)
  163. duration = int(data[40:48], 16)
  164. finishedTime = int(data[48:56], 16)
  165. return {'cmdCode': cmdCode, 'port': port, 'orderNo': orderNo, 'cardNo': cardNo, 'coins': coins,
  166. 'balance': balance, 'duration': duration, 'finishedTime': finishedTime}
  167. elif cmdCode == 'C8': # 刷网络钱包卡完成上传消费订单
  168. port = int(data[2:4], 16)
  169. check = int(data[34:36], 16) ^ int(data[36:38], 16) ^ int(data[38:40], 16) ^ int(data[40:42], 16)
  170. strCheck = fill_2_hexByte(hex(check), 2)
  171. cardNo = data[34:42] + strCheck
  172. orderNo = str(data[42:46])
  173. coins = int(data[46:52], 16)
  174. duration = int(data[52:56], 16)
  175. finishedTime = int(data[56:64], 16)
  176. return {'cmdCode': cmdCode, 'port': port, 'orderNo': orderNo, 'cardNo': cardNo, 'coins': coins,
  177. 'duration': duration, 'finishedTime': finishedTime}
  178. elif cmdCode == 'C9': # 网络任务完成上传消费订单
  179. port = int(data[2:4], 16)
  180. orderNo = int(data[10:26], 16)
  181. orderSequance = int(data[26:30], 16)
  182. coins = int(data[30:36], 16)
  183. duration = int(data[36:40], 16)
  184. finishedTime = int(data[40:48], 16)
  185. return {'cmdCode': cmdCode, 'port': port, 'orderNo': orderNo, 'orderSequance': orderSequance,
  186. 'coins': coins, 'duration': duration, 'finishedTime': finishedTime}
  187. def get_dev_consume_count(self):
  188. data = self.get_info_base('C1')
  189. coinFee = int(data[12:18], 16) / 10.0 # 以角为单位
  190. data = self.get_info_base('C2')
  191. cardFee = int(data[12:18], 16) / 10.0 # 以角为单位
  192. return {'cardFee': cardFee, 'coinFee': coinFee}
  193. def get_port_info(self, line):
  194. hexPort = fill_2_hexByte(hex(int(line)), 2)
  195. devInfo = MessageSender.send(self.device, self.make_random_cmdcode(),
  196. {'IMEI': self._device['devNo'], "funCode": hexPort + '00' + 'B3', 'data': '01'})
  197. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  198. if devInfo['rst'] == -1:
  199. raise ServiceException({'result': 2, 'description': u'充电桩正在玩命找网络,请您稍候再试'})
  200. elif devInfo['rst'] == 1:
  201. raise ServiceException({'result': 2, 'description': u'充电桩忙,无响应,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'})
  202. result = devInfo['data'][10:12]
  203. if result == '00':
  204. raise ServiceException({'result': 2, 'description': u'充电桩查询端口失败,请您重试'})
  205. elec = int(devInfo['data'][12:14], 16)
  206. return {'port': line, 'elec': elec}
  207. # 访问设备,获取设备端口信息
  208. def get_port_status_from_dev(self):
  209. devInfo = MessageSender.send(self.device, self.make_random_cmdcode(),
  210. {'IMEI': self._device['devNo'], "funCode": '0100D4', 'data': '01'})
  211. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  212. if devInfo['rst'] == -1:
  213. raise ServiceException(
  214. {'result': 2, 'description': u'充电桩正在玩命找网络,请您稍候再试'})
  215. elif devInfo['rst'] == 1:
  216. raise ServiceException(
  217. {'result': 2, 'description': u'充电桩忙,无响应,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'})
  218. result = devInfo['data'][10:12]
  219. if result == '00':
  220. raise ServiceException({'result': 2, 'description': u'充电桩查询端口失败,请您重试'})
  221. result = {}
  222. portData = devInfo['data'][12:32]
  223. ii = 0
  224. while ii < 10:
  225. statusTemp = portData[ii * 2:ii * 2 + 2]
  226. if statusTemp == '00':
  227. status = {'status': Const.DEV_WORK_STATUS_IDLE}
  228. elif statusTemp == '01':
  229. status = {'status': Const.DEV_WORK_STATUS_WORKING}
  230. ii += 1
  231. result[str(ii)] = status
  232. allPorts, usedPorts, usePorts = self.get_port_static_info(result)
  233. Device.update_dev_control_cache(self._device['devNo'],
  234. {'allPorts': allPorts, 'usedPorts': usedPorts, 'usePorts': usePorts})
  235. # 这里存在多线程更新缓存的场景,可能性比较低,但是必须先取出来,然后逐个更新状态,然后再记录缓存
  236. ctrInfo = Device.get_dev_control_cache(self._device['devNo'])
  237. for strPort, info in result.items():
  238. if ctrInfo.has_key(strPort):
  239. ctrInfo[strPort].update({'status': info['status']})
  240. else:
  241. ctrInfo[strPort] = info
  242. Device.update_dev_control_cache(self._device['devNo'], ctrInfo)
  243. return result
  244. def get_port_status(self, force = False):
  245. if force:
  246. return self.get_port_status_from_dev()
  247. ctrInfo = Device.get_dev_control_cache(self._device['devNo'])
  248. if not ctrInfo.has_key('allPorts'):
  249. self.get_port_status_from_dev()
  250. ctrInfo = Device.get_dev_control_cache(self._device['devNo'])
  251. allPorts = 10
  252. statusDict = {}
  253. for ii in range(allPorts):
  254. tempDict = ctrInfo.get(str(ii + 1), {})
  255. if tempDict.has_key('status'):
  256. statusDict[str(ii + 1)] = {'status': tempDict.get('status')}
  257. elif tempDict.has_key('isStart'):
  258. if tempDict['isStart']:
  259. statusDict[str(ii + 1)] = {'status': Const.DEV_WORK_STATUS_WORKING}
  260. else:
  261. statusDict[str(ii + 1)] = {'status': Const.DEV_WORK_STATUS_IDLE}
  262. else:
  263. statusDict[str(ii + 1)] = {'status': Const.DEV_WORK_STATUS_IDLE}
  264. allPorts, usedPorts, usePorts = self.get_port_static_info(statusDict)
  265. Device.update_dev_control_cache(self._device['devNo'],
  266. {'allPorts': allPorts, 'usedPorts': usedPorts, 'usePorts': usePorts})
  267. return statusDict
  268. def get_info_base(self, funCode):
  269. devInfo = MessageSender.send(self.device, self.make_random_cmdcode(),
  270. {'IMEI': self._device['devNo'], "funCode": '0100' + funCode, 'data': '01'})
  271. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  272. if devInfo['rst'] == -1:
  273. raise ServiceException(
  274. {'result': 2, 'description': u'充电桩正在玩命找网络,请您稍候再试'})
  275. elif devInfo['rst'] == 1:
  276. raise ServiceException(
  277. {'result': 2, 'description': u'充电桩忙,无响应,请您稍候再试。也可能是您的设备版本过低,暂时不支持此功能'})
  278. result = devInfo['data'][10:12]
  279. if result == '00':
  280. raise ServiceException({'result': 2, 'description': u'充电桩串口通讯失败,请您重试'})
  281. return devInfo['data']
  282. def set_info_base(self, funCode, data):
  283. devInfo = MessageSender.send(self.device, self.make_random_cmdcode(),
  284. {'IMEI': self._device['devNo'], "funCode": '0100' + funCode, 'data': data})
  285. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  286. if devInfo['rst'] == -1:
  287. raise ServiceException(
  288. {'result': 2, 'description': u'充电桩正在玩命找网络,请您稍候再试'})
  289. elif devInfo['rst'] == 1:
  290. raise ServiceException(
  291. {'result': 2, 'description': u'充电桩忙,无响应,请您稍候再试'})
  292. result = devInfo['data'][10:12]
  293. if result == '00':
  294. raise ServiceException({'result': 2, 'description': u'充电桩设置失败,请您重试'})
  295. # 获取电流标准
  296. def get_elec_config(self):
  297. data = self.get_info_base('C3')
  298. standElec = int(data[12:14], 16) # 单位毫安
  299. maxElec = int(data[14:16], 16) # 单位毫安
  300. return {'standElec': standElec, 'maxElec': maxElec}
  301. def set_elec_config(self, infoDict):
  302. data = fill_2_hexByte(hex(int(infoDict['standElec'])), 2)
  303. data += fill_2_hexByte(hex(int(infoDict['maxElec'])), 2)
  304. self.set_info_base('A4', data)
  305. # 获取消费标准
  306. def get_consume_config(self):
  307. data = self.get_info_base('B8')
  308. mobilePrice = int(data[12:16], 16)
  309. mobileTime = int(data[16:20], 16)
  310. mobileOnsale = int(data[20:22], 16)
  311. icPrice = int(data[22:26], 16)
  312. icTime = int(data[26:30], 16)
  313. coinPrice = int(data[30:34], 16)
  314. coinTime = int(data[34:38], 16)
  315. return {'mobilePrice': mobilePrice, 'mobileTime': mobileTime, 'mobileOnsale': mobileOnsale, 'icPrice': icPrice,
  316. 'icTime': icTime, 'coinPrice': coinPrice, 'coinTime': coinTime}
  317. def set_consume_config(self, infoDict):
  318. data = fill_2_hexByte(hex(int(infoDict['mobilePrice'])), 4)
  319. data += fill_2_hexByte(hex(int(infoDict['mobileTime'])), 4)
  320. data += fill_2_hexByte(hex(int(infoDict['mobileOnsale'])), 2)
  321. data += fill_2_hexByte(hex(int(infoDict['icPrice'])), 4)
  322. data += fill_2_hexByte(hex(int(infoDict['icTime'])), 4)
  323. data += fill_2_hexByte(hex(int(infoDict['coinPrice'])), 4)
  324. data += fill_2_hexByte(hex(int(infoDict['coinTime'])), 4)
  325. self.set_info_base('B7', data)
  326. # 获取设备断电时长
  327. def get_line_poweroff_time(self):
  328. data = self.get_info_base('B2')
  329. return {'poweroffTime': int(data[12:20], 16)}
  330. # 设置设备断电时长
  331. def set_line_poweroff_time(self, infoDict):
  332. data = fill_2_hexByte(hex(int(infoDict['poweroffTime'])), 8)
  333. self.set_info_base('B1', data)
  334. # 下发断电自停标记
  335. def set_fullstop(self, setConf):
  336. data = fill_2_hexByte(hex(int(setConf['fullstop'])), 2)
  337. self.set_info_base('D8', data)
  338. def get_dev_version(self):
  339. data = self.get_info_base('F4')
  340. return {'version': str(data[12:28])}
  341. # 恢复出厂设置
  342. def recover_factory_set(self):
  343. self.set_info_base('F5', '01')
  344. # 清除通道时间
  345. def clear_line_time(self):
  346. self.set_info_base('D6', '01')
  347. # 复位设备
  348. def reboot_dev(self):
  349. self.set_info_base('D7', '01')
  350. # 查询浮充功率
  351. def get_fuchong_power(self):
  352. data = self.get_info_base('D2')
  353. return {'fuchongPower': int(data[12:16], 16)}
  354. # 下发浮充功率
  355. def set_fuchong_power(self, setConf):
  356. data = fill_2_hexByte(hex(int(setConf['fuchongPower'])), 4)
  357. self.set_info_base('D1', data)
  358. # 查询4.5A AD功率
  359. def get_45AD_power(self):
  360. data = self.get_info_base('E2')
  361. return {'power45': int(data[12:16], 16)}
  362. # 下发浮充功率
  363. def set_45AD_power(self, setConf):
  364. data = fill_2_hexByte(hex(int(setConf['power45'])), 4)
  365. self.set_info_base('E1', data)
  366. # 查询空载断电功率值
  367. def get_emptyoff_power(self):
  368. data = self.get_info_base('E4')
  369. return {'emptyPower': int(data[12:16], 16)}
  370. # 设置空载断电功率值
  371. def set_emptyoff_power(self, setConf):
  372. data = fill_2_hexByte(hex(int(setConf['emptyPower'])), 4)
  373. self.set_info_base('E3', data)
  374. # 查询空载断电时间值
  375. def get_emptyoff_time(self):
  376. data = self.get_info_base('E6')
  377. return {'emptyTime': int(data[12:16], 16)}
  378. # 设置空载断电时间值
  379. def set_emptyoff_time(self, setConf):
  380. data = fill_2_hexByte(hex(int(setConf['emptyTime'])), 4)
  381. self.set_info_base('E5', data)
  382. def get_dev_time(self):
  383. data = self.get_info_base('E7')
  384. year = '20' + str(int(data[12:14], 16))
  385. month = str(int(data[14:16], 16))
  386. day = str(int(data[16:18], 16))
  387. hour = str(int(data[18:20], 16))
  388. minute = str(int(data[20:22], 16))
  389. second = str(int(data[22:24], 16))
  390. return {'devTime': '%s-%s-%s %s:%s:%s' % (year, month, day, hour, minute, second)}
  391. def get_device_function_by_key(self, keyName):
  392. resultDict = {}
  393. if 'power45' in keyName:
  394. resultDict.update(self.get_45AD_power())
  395. if ('mobilePrice' in keyName) or ('mobileTime' in keyName) \
  396. or ('mobileOnsale' in keyName) or ('icPrice' in keyName) \
  397. or ('icTime' in keyName) or ('coinPrice' in keyName) \
  398. or ('coinTime' in keyName):
  399. resultDict.update(self.get_consume_config())
  400. if 'standElec' in keyName or 'maxElec' in keyName:
  401. resultDict.update(self.get_elec_config())
  402. if 'emptyPower' in keyName:
  403. resultDict.update(self.get_emptyoff_power())
  404. if 'emptyTime' in keyName:
  405. resultDict.update(self.get_emptyoff_time())
  406. if 'fuchongPower' in keyName:
  407. resultDict.update(self.get_fuchong_power())
  408. if 'poweroffTime' in keyName:
  409. resultDict.update(self.get_line_poweroff_time())
  410. if 'version' in keyName:
  411. resultDict.update(self.get_dev_version())
  412. return resultDict
  413. def get_dev_setting(self):
  414. resultDict = self.get_45AD_power()
  415. tempDict = self.get_consume_config()
  416. resultDict.update(tempDict)
  417. tempDict = self.get_dev_consume_count()
  418. resultDict.update(tempDict)
  419. tempDict = self.get_elec_config()
  420. resultDict.update(tempDict)
  421. tempDict = self.get_emptyoff_power()
  422. resultDict.update(tempDict)
  423. tempDict = self.get_emptyoff_time()
  424. resultDict.update(tempDict)
  425. tempDict = self.get_fuchong_power()
  426. resultDict.update(tempDict)
  427. tempDict = self.get_line_poweroff_time()
  428. resultDict.update(tempDict)
  429. tempDict = self.get_dev_version()
  430. resultDict.update(tempDict)
  431. return resultDict
  432. def set_coin_card_enable(self, infoDict):
  433. pass
  434. def set_IC_coin_power_config(self, infoDict):
  435. pass
  436. def set_fullstop_cardrefund(self, infoDict):
  437. pass
  438. def set_gear_conf(self, infoDict):
  439. pass
  440. def set_dev_setting(self, setConf):
  441. keys = setConf.keys()
  442. if 'putCoins' in keys or 'icCard' in keys:
  443. self.set_coin_card_enable(setConf)
  444. if 'maxPower' in keys or 'icMoney' in keys or 'time1' in keys or 'time2' in keys or 'time3' in keys:
  445. self.set_IC_coin_power_config(setConf)
  446. def set_device_function(self, request, lastSetConf):
  447. if request.POST.has_key('recover'):
  448. # recover = True if request.POST.get('recover') == 'true' else False
  449. recover = request.POST.get("recover", False)
  450. if recover:
  451. self.recover_factory_set()
  452. if request.POST.has_key('clearLineTime'):
  453. # clearLineTime = True if request.POST.get('clearLineTime') == 'true' else False
  454. clearLineTime = request.POST.get("clearLineTime", False)
  455. if clearLineTime:
  456. self.clear_line_time()
  457. if request.POST.has_key('reboot'):
  458. # reboot = True if request.POST.get('reboot') == 'true' else False
  459. reboot = request.POST.get("reboot", False)
  460. if reboot:
  461. self.reboot_dev()
  462. if request.POST.has_key('cardRefund'):
  463. # cardRefund = True if request.POST.get('cardRefund') == 'true' else False
  464. cardRefund = request.POST.get("cardRefund", False)
  465. lastSetConf.update({'cardRefund': cardRefund})
  466. self.set_fullstop_cardrefund(lastSetConf)
  467. def set_device_function_param(self, request, lastSetConf):
  468. if request.POST.has_key('maxPower') and request.POST.has_key('icMoney'):
  469. lastSetConf.update({'maxPower': int(request.POST.get('maxPower', 0))})
  470. lastSetConf.update({'icMoney': int(request.POST.get('icMoney', 0))})
  471. self.set_IC_coin_power_config(lastSetConf)
  472. if request.POST.has_key('time1') and request.POST.has_key('time2') and request.POST.has_key('time3'):
  473. lastSetConf.update({'time1': int(request.POST.get('time1', 0))})
  474. lastSetConf.update({'time2': int(request.POST.get('time2', 0))})
  475. lastSetConf.update({'time3': int(request.POST.get('time3', 0))})
  476. self.set_IC_coin_power_config(lastSetConf)
  477. if request.POST.has_key('power1') and request.POST.has_key('power1ratio'):
  478. lastSetConf.update({'power1': int(request.POST.get('power1', 0))})
  479. lastSetConf.update({'power1ratio': int(request.POST.get('power1ratio', 0))})
  480. lastSetConf.update({'power2': int(request.POST.get('power2', 0))})
  481. lastSetConf.update({'power2ratio': int(request.POST.get('power2ratio', 0))})
  482. lastSetConf.update({'power3': int(request.POST.get('power3', 0))})
  483. lastSetConf.update({'power3ratio': int(request.POST.get('power3ratio', 0))})
  484. self.set_gear_conf(lastSetConf)
  485. if request.POST.has_key('mobilePrice') and request.POST.has_key('mobileTime') and request.POST.has_key(
  486. 'mobileOnsale'):
  487. lastSetConf.update({'mobilePrice': int(request.POST.get('mobilePrice', 0))})
  488. lastSetConf.update({'mobileTime': int(request.POST.get('mobileTime', 0))})
  489. lastSetConf.update({'mobileOnsale': int(request.POST.get('mobileOnsale', 0))})
  490. self.set_consume_config(lastSetConf)