def get(self): try: imei = self.get_argument("imei") except Exception as e: self.write("arg error ") return type = self.get_argument("type", "1") command_num = self.get_argument("command_num", "005") logger.info("imei:%s, type:%s command_num:%s", imei, type, command_num) broadcastor = self.settings["broadcastor"] if type == "0": command_pk = TEST_S2C_COMMAND_DATA.get(command_num, None) #print "command_pk", command_pk if command_pk is None: self.write("arg error ") return else: pk = terminal_packets.SendCommandReq(imei, command_pk) else: pk = terminal_packets.GetLocationAck(terminal_proto.GenSN(), imei) send_data = str(pk) ret = yield broadcastor.send_msg_multicast((imei, ), send_data) ret_str = "send ok" if ret else "send fail" self._OnOpLog("s2c send_data:%s ret:%s" % (send_data, ret_str), imei) self.write(ret_str)
def get(self): terminal_rpc = self.settings["terminal_rpc"] terminal_imei_dao = self.settings["terminal_imei_dao"] try: imei = self.get_argument("imei") except Exception as e: self.write("arg error ") return type = self.get_argument("type", "1") command_num = self.get_argument("command_num", "005") logger.info("imei:%s, type:%s command_num:%s", imei, type, command_num) if type == "0": command_pk = TEST_S2C_COMMAND_DATA.get(command_num, None) if command_pk is None: self.write("arg error ") return else: pk = terminal_packets.SendCommandReq(imei, command_pk) else: pk = terminal_packets.GetLocationAck(terminal_proto.GenSN(), imei) send_data = str(pk) ok = True try: server_id = yield self.call_func(terminal_imei_dao, "get_server_id", imei) ret = yield terminal_rpc.unicast(server_id, imei=imei, content=send_data) if ret["status"] != error_codes.EC_SUCCESS: ok = False except Exception, e: status = error_codes.EC_SYS_ERROR logger.exception(e) ok = False
def post(self): terminal_rpc = self.settings["terminal_rpc"] terminal_imei_dao = self.settings["terminal_imei_dao"] try: imei = self.get_argument("imei") content = self.get_argument("command_content") except Exception as e: self.write("arg error ") return content = base64.decodestring(content) pk = terminal_packets.SendCommandReq(imei, content) send_data = str(pk) ok = True try: server_id = yield self.call_func(terminal_imei_dao, "get_server_id", imei) ret = yield terminal_rpc.unicast(server_id, imei=imei, content=send_data) if ret["status"] != error_codes.EC_SUCCESS: ok = False except Exception, e: status = error_codes.EC_SYS_ERROR logger.exception(e) ok = False
def do_request(self): terminal_rpc = self.settings["terminal_rpc"] terminal_imei_dao = self.settings["terminal_imei_dao"] res = {"status": error_codes.EC_SUCCESS} try: imei = self.get_argument("imei") content = self.get_argument("command_content") except Exception as e: res["status"] = error_codes.EC_INVALID_ARGS else: pk = terminal_packets.SendCommandReq(imei, content) send_data = str(pk) ok = True try: server_id = yield self.call_func(terminal_imei_dao, "get_server_id", imei) ret = yield terminal_rpc.unicast(server_id, imei=imei, content=send_data) res["status"] = ret["status"] if res["status"] != error_codes.EC_SUCCESS: ok = False except Exception, e: status = error_codes.EC_SYS_ERROR res["status"] = status logger.exception(e) ok = False ret_str = "send ok" if ok else "send fail" self.on_log( "[broadcast_srv_d] s2c send_data:%s ret:%s" % (send_data, ret_str), imei)
def get(self): try: imei = self.get_argument("imei") except Exception as e: self.write("arg error ") return broadcastor = self.settings["broadcastor"] command_pk = terminal_commands.RemotePowerOff() pk = terminal_packets.SendCommandReq(imei, command_pk) yield broadcastor.send_msg_multicast((imei, ), str(pk)) logger.info(pk) self.write("ok")
def post(self): try: imei = self.get_argument("imei") content = self.get_argument("command_content") except Exception as e: self.write("arg error ") return content = base64.decodestring(content) logger.info("content :%s", content) broadcastor = self.settings["broadcastor"] pk = terminal_packets.SendCommandReq(imei, content) send_data = str(pk) #send_data = send_data.replace("*", "#") ret = yield broadcastor.send_msg_multicast((imei, ), send_data) ret_str = "send ok" if ret else "send fail" self._OnOpLog("s2c send_data:%s ret:%s" % (send_data, ret_str), imei) self.write(ret_str)
def do_request(self): res = {"status": error_codes.EC_SUCCESS} try: imei = self.get_argument("imei") content = self.get_argument("command_content") except Exception as e: res["status"] = error_codes.EC_INVALID_ARGS else: broadcastor = self.settings["broadcastor"] pk = terminal_packets.SendCommandReq(imei, content) send_data = str(pk) device_setting_mgr = self.settings.get("device_setting_mgr", None) if device_setting_mgr is not None: device_setting = device_setting_mgr.get_device_setting(imei) yield device_setting.load() device_setting_str = str(device_setting) #device_setting_new.parse(content) logger.debug("imei:%s old setting:%s ,new setting:%s ", imei, device_setting_str, content) if content != device_setting_str: ret = yield broadcastor.send_msg_multicast((imei, ), send_data) if ret: ret_str = "send ok" if device_setting.parse(content): device_setting.save() else: ret_str = "send fail" # res["status"] = error_codes.EC_SEND_CMD_FAIL self._OnOpLog( "s2c send_data:%s ret:%s" % (send_data, ret_str), imei) unreply_msg_mgr = self.settings["unreply_msg_mgr"] msg_type = content[0:3] unreply_msg_mgr.add_unreply_msg(pk.sn, imei, send_data, msg_type) else: logger.debug( "the msg(%s) send to imei:%s has not changed.skip send.", content, imei) data = json.dumps(res, ensure_ascii=False, encoding='utf8') self.write(data)
def do_request(self): res = {"status": error_codes.EC_SUCCESS} try: imei = self.get_argument("imei") content = self.get_argument("command_content") except Exception as e: res["status"] = error_codes.EC_INVALID_ARGS else: broadcastor = self.settings["broadcastor"] pk = terminal_packets.SendCommandReq(imei, content) send_data = str(pk) ret = yield broadcastor.send_msg_multicast((imei, ), send_data) if ret: ret_str = "send ok" else: ret_str = "send fail" res["status"] = error_codes.EC_SEND_CMD_FAIL self.on_log("s2c send_data:%s ret:%s" % (send_data, ret_str), imei) #unreply_msg_mgr = self.settings["unreply_msg_mgr"] #msg_type = content[0:3] #unreply_msg_mgr.add_unreply_msg(pk.sn, imei, send_data, msg_type) self.write_obj(res)