languang.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. import logging
  4. import time
  5. import random
  6. from apilib.utils_datetime import timestamp_to_dt
  7. from apps.web.constant import DeviceCmdCode, Const, MQTT_TIMEOUT
  8. from apps.web.core.adapter.base import SmartBox, fill_2_hexByte, hexbyte_2_bin
  9. from apps.web.core.exceptions import ServiceException
  10. from apps.web.core.networking import MessageSender
  11. from apps.web.device.models import Device
  12. logger = logging.getLogger(__name__)
  13. class LanguangBox(SmartBox):
  14. def __init__(self, device):
  15. super(LanguangBox, self).__init__(device)
  16. def test(self, coins):
  17. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  18. {'IMEI': self._device['devNo'], "funCode": '00', 'data': '<020002>'})
  19. return devInfo
  20. #主要是处理设备状态发生变化的事件,直接把设备状态报文上报
  21. #(0D0300010000000001B901F70041)
  22. def analyze_event_data(self,data):
  23. status = data[5:9]
  24. if status == '0001':
  25. return {'status':Const.DEV_WORK_STATUS_IDLE,'statusInfo':u'空闲'}
  26. elif status == '0002':
  27. return {'status':Const.DEV_WORK_STATUS_WORKING,'statusInfo':u'等待卡消费'}
  28. elif status == '0004':
  29. return {'status':Const.DEV_WORK_STATUS_WORKING,'statusInfo':u'卡消费'}
  30. elif status == '0008':
  31. return {'status':Const.DEV_WORK_STATUS_WORKING,'statusInfo':u'卡消费结束'}
  32. elif status == '0010':
  33. return {'status':Const.DEV_WORK_STATUS_WORKING,'statusInfo':u'投币后等待按键消费'}
  34. elif status == '0020':
  35. return {'status':Const.DEV_WORK_STATUS_WORKING,'statusInfo':u'投币消费'}
  36. elif status == '0040':
  37. return {'status':Const.DEV_WORK_STATUS_WORKING,'statusInfo':u'投币消费结束'}
  38. elif status == '0080':
  39. return {'status':Const.DEV_WORK_STATUS_WORKING,'statusInfo':u'虚拟消费'}
  40. elif status == '0100':
  41. return {'status':Const.DEV_WORK_STATUS_WORKING,'statusInfo':u'虚拟消费结束'}
  42. elif status == '0200':
  43. return {'status':Const.DEV_WORK_STATUS_WORKING,'statusInfo':u'卡值操作状态'}
  44. elif status == '0400':
  45. return {'status':Const.DEV_WORK_STATUS_WORKING,'statusInfo':u'等待取卡'}
  46. elif status == '0800':
  47. return {'status':Const.DEV_WORK_STATUS_WORKING,'statusInfo':u'存在消费卡'}
  48. elif status == '1000':
  49. return {'status':Const.DEV_WORK_STATUS_WORKING,'statusInfo':u'低水位'}
  50. else:
  51. return {'status':Const.DEV_WORK_STATUS_IDLE,'statusInfo':u'空闲'}
  52. def get_dev_config(self):
  53. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  54. {'IMEI': self._device['devNo'], "funCode": '01', 'data': '<03015153>'})
  55. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  56. if devInfo['rst'] == -1:
  57. raise ServiceException({'result': 2, 'description': u'当前机器正在玩命找网络,稍后再试哦'})
  58. elif devInfo['rst'] == 1:
  59. raise ServiceException({'result': 2, 'description': u'当前机器正在忙,无响应,请稍后再试哦'})
  60. #(2301 01 02BC00000000000A000A06500690000A000A00005460000000080014012C00144C)
  61. data = devInfo['data'][5::]
  62. result = data[0:2]
  63. if result == '00':
  64. raise ServiceException({'result': 2, 'description': u'当前机器返回错误,建议您请稍后再试哦'})
  65. g_g_mid = int(data[2:6],16)
  66. g_g_work_tmr = int(data[6:14],16)
  67. g_g_chk_on_tmr = int(data[14:18],16)
  68. g_g_chk_off_tmr = int(data[18:22],16)
  69. # j_w_down = int(data[22:26],16)/16 - 100
  70. # j_w_up = int(data[26:30],16)/16 - 100
  71. j_w_down = int(data[22:26],16)
  72. j_w_up = int(data[26:30],16)
  73. j_w_chk_on_tmr = int(data[30:34],16)
  74. j_w_chk_off_tmr = int(data[34:38],16)
  75. c_y_wait_tmr = int(data[38:46],16)
  76. c_y_work_tmr = int(data[46:54],16)
  77. z_s_chk_on_tmr = int(data[54:58],16)
  78. z_s_chk_off_tmr = int(data[58:62],16)
  79. c_s_delay = int(data[62:66],16)
  80. return {
  81. 'g_g_mid':g_g_mid,'g_g_work_tmr':g_g_work_tmr,'g_g_chk_on_tmr':g_g_chk_on_tmr,'g_g_chk_off_tmr':g_g_chk_off_tmr,
  82. 'j_w_down':j_w_down,'j_w_up':j_w_up,'j_w_chk_on_tmr':j_w_chk_on_tmr,'j_w_chk_off_tmr':j_w_chk_off_tmr,
  83. 'c_y_wait_tmr':c_y_wait_tmr,'c_y_work_tmr':c_y_work_tmr,'z_s_chk_on_tmr':z_s_chk_on_tmr,'z_s_chk_off_tmr':z_s_chk_off_tmr,
  84. 'c_s_delay':c_s_delay
  85. }
  86. def calc_crc(self,data):
  87. checkSum = 0
  88. for ii in range(len(data)/2):
  89. hexByte = int(data[2*ii:2*ii + 2],16)
  90. checkSum = checkSum ^ hexByte
  91. checkSum = fill_2_hexByte(hex(checkSum), 2)
  92. return str(checkSum)
  93. def set_dev_config(self,conf):
  94. data = '230101'
  95. data += fill_2_hexByte(hex(int(conf['g_g_mid'])), 4)
  96. data += fill_2_hexByte(hex(int(conf['g_g_work_tmr'])), 8)
  97. data += fill_2_hexByte(hex(int(conf['g_g_chk_on_tmr'])), 4)
  98. data += fill_2_hexByte(hex(int(conf['g_g_chk_off_tmr'])), 4)
  99. # downT = (int(conf['j_w_down']) + 100) * 16
  100. # data += fill_2_hexByte(hex(int(downT)), 4)
  101. # upT = (int(conf['j_w_up']) + 100) * 16
  102. # data += fill_2_hexByte(hex(int(upT)), 4)
  103. downT = (int(conf['j_w_down']))
  104. data += fill_2_hexByte(hex(int(downT)), 4)
  105. upT = (int(conf['j_w_up']))
  106. data += fill_2_hexByte(hex(int(upT)), 4)
  107. data += fill_2_hexByte(hex(int(conf['j_w_chk_on_tmr'])), 4)
  108. data += fill_2_hexByte(hex(int(conf['j_w_chk_off_tmr'])), 4)
  109. data += fill_2_hexByte(hex(int(conf['c_y_wait_tmr'])), 8)
  110. data += fill_2_hexByte(hex(int(conf['c_y_work_tmr'])), 8)
  111. data += fill_2_hexByte(hex(int(conf['z_s_chk_on_tmr'])), 4)
  112. data += fill_2_hexByte(hex(int(conf['z_s_chk_off_tmr'])), 4)
  113. data += fill_2_hexByte(hex(int(conf['c_s_delay'])), 4)
  114. crc = self.calc_crc(data)
  115. data += crc
  116. data = '<' + data + '>'
  117. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  118. {'IMEI': self._device['devNo'], "funCode": '01', 'data': data})
  119. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  120. if devInfo['rst'] == -1:
  121. raise ServiceException({'result': 2, 'description': u'当前机器正在玩命找网络,稍后再试哦'})
  122. elif devInfo['rst'] == 1:
  123. raise ServiceException({'result': 2, 'description': u'当前机器正在忙,无响应,或者请稍后再试哦'})
  124. data = devInfo['data'][6::]
  125. result = data[0:2]
  126. if result == '00':
  127. raise ServiceException({'result': 2, 'description': u'当前机器返回错误,建议您请稍后再试哦'})
  128. return devInfo
  129. def get_usr_pwd_fee(self):
  130. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  131. {'IMEI': self._device['devNo'], "funCode": '02', 'data': '<03025150>'})
  132. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  133. if devInfo['rst'] == -1:
  134. raise ServiceException({'result': 2, 'description': u'当前机器正在玩命找网络,稍后再试哦'})
  135. elif devInfo['rst'] == 1:
  136. raise ServiceException({'result': 2, 'description': u'当前机器正在忙,无响应,或者请稍后再试哦'})
  137. data = devInfo['data'][5::]
  138. result = data[0:2]
  139. if result == '00':
  140. raise ServiceException({'result': 2, 'description': u'当前机器返回错误,建议您请稍后再试哦'})
  141. tempPwd = data[2:14]
  142. usr_pwd = ''
  143. if tempPwd != 'FFFFFFFFFFFF':
  144. for ii in range(6):
  145. index = (ii + 1) * 2 -1
  146. num = str(int(tempPwd[index]))
  147. usr_pwd += num
  148. f_l_1_litres = int(data[14:18],16)
  149. f_l_1_cents = int(data[18:22],16)
  150. f_l_2_litre = int(data[22:26],16)
  151. f_l_2_cents = int(data[26:30],16)
  152. f_l_3_litre = int(data[30:34],16)
  153. f_l_3_cents = int(data[34:38],16)
  154. f_l_4_litre = int(data[38:42],16)
  155. f_l_4_cents = int(data[42:46],16)
  156. return {
  157. 'usr_pwd':usr_pwd,
  158. 'f_l_1_litres':f_l_1_litres,'f_l_1_cents':f_l_1_cents,
  159. 'f_l_2_litres':f_l_2_litre,'f_l_2_cents':f_l_2_cents,
  160. 'f_l_3_litres':f_l_3_litre,'f_l_3_cents':f_l_3_cents,
  161. 'f_l_4_litres':f_l_4_litre,'f_l_4_cents':f_l_4_cents
  162. }
  163. def set_usr_pwd_fee(self,conf):
  164. data = '190201'
  165. if len(conf['usr_pwd']) == 0:
  166. data += 'FFFFFFFFFFFF'
  167. elif len(conf['usr_pwd']) != 6:
  168. raise ServiceException({'result': 2, 'description': u'密码必须是6位数字或者空密码'})
  169. else:
  170. strPwd = conf['usr_pwd']
  171. for num in strPwd:
  172. if num < '0' or num > '9':
  173. raise ServiceException({'result': 2, 'description': u'密码必须是6位数字或者空密码'})
  174. data += '0%s' % num
  175. data += fill_2_hexByte(hex(int(conf['f_l_1_litres'])), 4)
  176. data += fill_2_hexByte(hex(int(conf['f_l_1_cents'])), 4)
  177. data += fill_2_hexByte(hex(int(conf['f_l_2_litres'])), 4)
  178. data += fill_2_hexByte(hex(int(conf['f_l_2_cents'])), 4)
  179. data += fill_2_hexByte(hex(int(conf['f_l_3_litres'])), 4)
  180. data += fill_2_hexByte(hex(int(conf['f_l_3_cents'])), 4)
  181. data += fill_2_hexByte(hex(int(conf['f_l_4_litres'])), 4)
  182. data += fill_2_hexByte(hex(int(conf['f_l_4_cents'])), 4)
  183. crc = self.calc_crc(data)
  184. data +=crc
  185. data = '<' + data + '>'
  186. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  187. {'IMEI': self._device['devNo'], "funCode": '01', 'data': data})
  188. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  189. if devInfo['rst'] == -1:
  190. raise ServiceException({'result': 2, 'description': u'当前机器正在玩命找网络,稍后再试哦'})
  191. elif devInfo['rst'] == 1:
  192. raise ServiceException({'result': 2, 'description': u'当前机器正在忙,无响应,或者请稍后再试哦'})
  193. data = devInfo['data'][6::]
  194. result = data[0:2]
  195. if result == '00':
  196. raise ServiceException({'result': 2, 'description': u'当前机器返回错误,建议您请稍后再试哦'})
  197. return devInfo
  198. def get_dev_status(self):
  199. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  200. {'IMEI': self._device['devNo'], "funCode": '03', 'data': '<020301>'})
  201. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  202. if devInfo['rst'] == -1:
  203. raise ServiceException({'result': 2, 'description': u'当前机器正在玩命找网络,稍后再试哦'})
  204. elif devInfo['rst'] == 1:
  205. raise ServiceException({'result': 2, 'description': u'当前机器正在忙,无响应,或者请稍后再试哦'})
  206. data = devInfo['data'][5::]
  207. xf_status = '0x' + data[0:4]
  208. io_jdq = data[4:6]
  209. io_fmq = int(data[6:8],16)
  210. io_sw = data[8:10]
  211. io_aj = data[10:12]
  212. hBin = hexbyte_2_bin(data[12:14])
  213. lBin = hexbyte_2_bin(data[14:16])
  214. if hBin[0] == '1':
  215. temp = ''
  216. for ch in hBin + lBin:
  217. if ch == '1':
  218. temp += '0'
  219. else:
  220. temp += '1'
  221. io_wd = round(-(int(temp[0:4],2)*4096+int(temp[4:8],2)*256+int(temp[8:12],2)*16 + int(temp[12:16],2) + 1)/16.0,2)
  222. else:
  223. io_wd = round(int(data[12:16],16)/16.0,2)
  224. io_hd = int(data[16:20],16)
  225. io_llj = int(data[20:22],16)
  226. return {'xf_status':xf_status,'io_jdq':io_jdq,'io_fmq':io_fmq,'io_sw':io_sw,
  227. 'io_aj':io_aj,'io_wd':io_wd,'io_hd':io_hd,'io_llj':io_llj}
  228. def get_consume_info(self):
  229. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  230. {'IMEI': self._device['devNo'], "funCode": '04', 'data': '<020406>'})
  231. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  232. if devInfo['rst'] == -1:
  233. raise ServiceException({'result': 2, 'description': u'当前机器正在玩命找网络,稍后再试哦'})
  234. elif devInfo['rst'] == 1:
  235. raise ServiceException({'result': 2, 'description': u'当前机器正在忙,无响应,或者请稍后再试哦'})
  236. data = devInfo['data'][9::]
  237. c_id = data[0:8]
  238. c_ye = int(data[8:16],16)
  239. tbq_ye = int(data[16:20],16)
  240. xn_ye = int(data[20:28],16)
  241. end_ye = int(data[28:36],16)
  242. return {'c_id':c_id,'c_ye':c_ye,'tbq_ye':tbq_ye,'xn_ye':xn_ye,'end_ye':end_ye}
  243. def get_consume_stats(self):
  244. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  245. {'IMEI': self._device['devNo'], "funCode": '09', 'data': '<0309515B>'})
  246. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  247. if devInfo['rst'] == -1:
  248. raise ServiceException({'result': 2, 'description': u'当前机器正在玩命找网络,稍后再试哦'})
  249. elif devInfo['rst'] == 1:
  250. raise ServiceException({'result': 2, 'description': u'当前机器正在忙,无响应,或者请稍后再试哦'})
  251. data = devInfo['data'][5::]
  252. sum_all = int(data[0:8],16)/100.0
  253. sum_card = int(data[8:16],16)/100.0
  254. sum_xn_xf = int(data[16:24],16)/100.0
  255. sum_tbq = int(data[24:32],16)/100.0
  256. return {'sum_all':sum_all,'sum_card':sum_card,'sum_xn_xf':sum_xn_xf,'sum_tbq':sum_tbq}
  257. def clear_consume_info(self):
  258. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  259. {'IMEI': self._device['devNo'], "funCode": '09', 'data': '<0309000A>'})
  260. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  261. if devInfo['rst'] == -1:
  262. raise ServiceException({'result': 2, 'description': u'当前机器正在玩命找网络,稍后再试哦'})
  263. elif devInfo['rst'] == 1:
  264. raise ServiceException({'result': 2, 'description': u'当前机器正在忙,无响应,或者请稍后再试哦'})
  265. return devInfo
  266. def stop(self,port):
  267. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  268. {'IMEI': self._device['devNo'], "funCode": '08', 'data': '<0708FF0000006494>'})
  269. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  270. if devInfo['rst'] == -1:
  271. raise ServiceException({'result': 2, 'description': u'当前机器正在玩命找网络,稍后再试哦'})
  272. elif devInfo['rst'] == 1:
  273. raise ServiceException({'result': 2, 'description': u'当前机器正在忙,无响应,或者请稍后再试哦'})
  274. data = devInfo['data'][6::]
  275. result = data[0:2]
  276. if result == '00':
  277. raise ServiceException({'result': 2, 'description': u'当前机器返回错误,建议您请稍后再试哦'})
  278. devInfo['remainder_time'] = 0
  279. return devInfo
  280. def start_device(self, package, openId, attachParas):
  281. needCoins = int(float(package['coins'])*100)
  282. data = '070801'
  283. data += fill_2_hexByte(hex(needCoins),8)
  284. crc = self.calc_crc(data)
  285. data += crc
  286. data = '<' + data + '>'
  287. devInfo = MessageSender.send(device = self.device, cmd = DeviceCmdCode.OPERATE_DEV_SYNC, payload = {
  288. 'IMEI': self._device['devNo'],
  289. "funCode": '08',
  290. 'data': data
  291. }, timeout = MQTT_TIMEOUT.START_DEVICE)
  292. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  293. if devInfo['rst'] == -1:
  294. raise ServiceException({'result': 2, 'description': u'设备正在玩命找网络,您的金币还在,重试不需要重新付款,建议您试试旁边其他设备,或者稍后再试哦'})
  295. elif devInfo['rst'] == 1:
  296. raise ServiceException({'result': 2, 'description': u'设备正在忙,无响应,您的金币还在,请试试其他线路,或者请稍后再试哦'})
  297. start_timestamp = int(time.time())
  298. devInfo['finishedTime'] = start_timestamp + 60 * 60
  299. Device.update_dev_control_cache(
  300. self._device['devNo'],
  301. {
  302. 'startTime': timestamp_to_dt(start_timestamp).strftime('%Y-%m-%d %H:%M:%S'),
  303. 'status': Const.DEV_WORK_STATUS_WORKING,
  304. 'finishedTime': devInfo['finishedTime'],
  305. 'isStart': True,
  306. 'openId': openId,
  307. 'refunded': False,
  308. 'coins': needCoins,
  309. 'vCardId': self._vcard_id
  310. })
  311. return devInfo
  312. def remote_charge_card(self, money, rechargeRecord=None):
  313. result = self.get_dev_status()
  314. if result['xf_status'] != u"0x0001":
  315. raise ServiceException({'result': 2, 'description': u'设备正忙,请稍后再试'})
  316. data = '0D0701'
  317. logger.info('i have money ooooo,money=%s' % money)
  318. orderNo = fill_2_hexByte(hex(random.randint(0, 0xFFFF)),4)
  319. data += orderNo
  320. data += '00000000'
  321. data += fill_2_hexByte(hex(int(money*100)),8)
  322. crc = self.calc_crc(data)
  323. data += crc
  324. data = '<' + data + '>'
  325. devInfo = MessageSender.send(self.device, DeviceCmdCode.OPERATE_DEV_SYNC,
  326. {'IMEI': self._device['devNo'], "funCode": '07', 'data': data})
  327. if devInfo.has_key('rst') and devInfo['rst'] != 0:
  328. if devInfo['rst'] == -1:
  329. raise ServiceException({'result': 2, 'description': u'设备正在玩命找网络,您的金币还在,重试不需要重新付款,建议您试试旁边其他设备,或者稍后再试哦'})
  330. elif devInfo['rst'] == 1:
  331. raise ServiceException({'result': 2, 'description': u'设备正在忙,无响应,您的金币还在,请试试其他线路,或者请稍后再试哦'})
  332. # todo 不能带状态判断,因为第一时间的主板返回一定是失败
  333. # if devInfo['data'] != '(020701)':
  334. # raise ServiceException({'result': 2, 'description': u'设备返回实体卡失败'})
  335. def get_dev_setting(self):
  336. conf = self.get_dev_config()
  337. conf2 = self.get_usr_pwd_fee()
  338. conf.update(conf2)
  339. return conf
  340. def get_device_function_by_key(self,keyName):
  341. devInfo = {}
  342. if 'g_g_mid' in keyName:
  343. devInfo = self.get_dev_config()
  344. elif 'f_l_1_litres' in keyName:
  345. devInfo = self.get_usr_pwd_fee()
  346. elif 'io_fmq' in keyName or 'io_llj' in keyName:
  347. devInfo = self.get_dev_status()
  348. elif 'c_id' in keyName:
  349. devInfo = self.get_consume_info()
  350. elif 'sum_all' in keyName:
  351. devInfo = self.get_consume_stats()
  352. elif 'io_kzq1' in keyName:
  353. devInfo = self.get_dev_status()
  354. jdqInfo = devInfo['io_jdq']
  355. kzqBin = hexbyte_2_bin(jdqInfo)
  356. devInfo['io_kzq1'] = kzqBin[7]
  357. devInfo['io_kzq2'] = kzqBin[6]
  358. devInfo['io_kzq3'] = kzqBin[5]
  359. devInfo['io_kzq4'] = kzqBin[4]
  360. devInfo['io_kzq5'] = kzqBin[3]
  361. devInfo['io_kzq6'] = kzqBin[2]
  362. devInfo['io_kzq7'] = kzqBin[1]
  363. devInfo['io_kzq8'] = kzqBin[0]
  364. elif 'io_sw1' in keyName:
  365. devInfo = self.get_dev_status()
  366. swInfo = devInfo['io_sw']
  367. swBin = hexbyte_2_bin(swInfo)
  368. devInfo['io_sw1'] = swBin[7]
  369. devInfo['io_sw2'] = swBin[6]
  370. devInfo['io_sw3'] = swBin[5]
  371. devInfo['io_sw4'] = swBin[4]
  372. elif 'io_aj1' in keyName:
  373. devInfo = self.get_dev_status()
  374. swInfo = devInfo['io_aj']
  375. swBin = hexbyte_2_bin(swInfo)
  376. devInfo['io_aj1'] = swBin[7]
  377. devInfo['io_aj2'] = swBin[6]
  378. devInfo['io_aj3'] = swBin[5]
  379. elif 'xf_status' in keyName:
  380. devInfo = self.get_dev_status()
  381. return devInfo
  382. def set_device_function_param(self,request,lastSetConf):
  383. if request.POST.has_key('g_g_mid'):
  384. lastSetConf.update({'g_g_mid': int(request.POST.get('g_g_mid', 0))})
  385. lastSetConf.update({'g_g_work_tmr': int(request.POST.get('g_g_work_tmr', 0))})
  386. lastSetConf.update({'g_g_chk_on_tmr': int(request.POST.get('g_g_chk_on_tmr', 0))})
  387. lastSetConf.update({'g_g_chk_off_tmr': int(request.POST.get('g_g_chk_off_tmr', 0))})
  388. lastSetConf.update({'j_w_down': int(request.POST.get('j_w_down', 0))})
  389. lastSetConf.update({'j_w_up': int(request.POST.get('j_w_up', 0))})
  390. lastSetConf.update({'j_w_chk_on_tmr': int(request.POST.get('j_w_chk_on_tmr', 0))})
  391. lastSetConf.update({'j_w_chk_off_tmr': int(request.POST.get('j_w_chk_off_tmr', 0))})
  392. lastSetConf.update({'c_y_wait_tmr': int(request.POST.get('c_y_wait_tmr', 0))})
  393. lastSetConf.update({'c_y_work_tmr': int(request.POST.get('c_y_work_tmr', 0))})
  394. lastSetConf.update({'z_s_chk_on_tmr': int(request.POST.get('z_s_chk_on_tmr', 0))})
  395. lastSetConf.update({'z_s_chk_off_tmr': int(request.POST.get('z_s_chk_off_tmr', 0))})
  396. lastSetConf.update({'c_s_delay': int(request.POST.get('c_s_delay', 0))})
  397. self.set_dev_config(lastSetConf)
  398. if request.POST.has_key('f_l_1_litres') and request.POST.has_key('f_l_1_litres'):
  399. lastSetConf.update({'usr_pwd': str(request.POST.get('usr_pwd', ''))})
  400. lastSetConf.update({'f_l_1_litres': int(request.POST.get('f_l_1_litres', 0))})
  401. lastSetConf.update({'f_l_1_cents': int(request.POST.get('f_l_1_cents', 0))})
  402. lastSetConf.update({'f_l_2_litres': int(request.POST.get('f_l_2_litres', 0))})
  403. lastSetConf.update({'f_l_2_cents': int(request.POST.get('f_l_2_cents', 0))})
  404. lastSetConf.update({'f_l_3_litres': int(request.POST.get('f_l_3_litres', 0))})
  405. lastSetConf.update({'f_l_3_cents': int(request.POST.get('f_l_3_cents', 0))})
  406. lastSetConf.update({'f_l_4_litres': int(request.POST.get('f_l_4_litres', 0))})
  407. lastSetConf.update({'f_l_4_cents': int(request.POST.get('f_l_4_cents', 0))})
  408. self.set_usr_pwd_fee(lastSetConf)
  409. def set_device_function(self,request,lastSetConf):
  410. # if request.POST.has_key('clearSum') and request.POST.get('clearSum') == 'true':
  411. if request.POST.get('clearSum', False):
  412. self.clear_consume_info()
  413. def check_dev_status(self, attachParas = None):
  414. info = self.get_dev_status()
  415. if info['xf_status'] != '0x0001':
  416. raise ServiceException({'result': 2, 'description': u'当前设备正忙,需要设备空闲,您才可以操作哦'})