def update(device_id, data): mongodb.device.update_one({'uuid': device_id}, {'$set': data}) if device.is_edge_proxy(): Middle.CldT.report_cam_setting(device_id) Middle.CldT.report_function_cam(device_id) get_all({}) return get_one(device_id)
def report_function(self, msg_id=None, device_id=None): """ 更新边侧设备告警设置 需要边侧启动并连接成功后向云侧主动报告一次 """ data = {} if msg_id: data["msg_id"] = msg_id if device_id: data["function"] = camctl.get_one(device_id).function elif device.is_edge_proxy(): data["function"] = functl.get("") else: cam = device.get_edge_ipc_cam() data["function"] = cam.function logging.info("report function: {}".format(data)) self.publish(Cloud.topic_pub_function, data)
def open_stream(self): if online_stream_mgr.is_open(self.uuid): online_stream_mgr.add_stream(self.uuid) return if device.is_edge_proxy(): stream_cmd = FORWARD_PATTERN.format(self.stream(), self.forward_stream()) logging.info("gen stream command: {}".format(stream_cmd)) online_stream = subprocess.Popen(stream_cmd.split(' '), shell=False) online_stream_mgr.add_stream(self.uuid, online_stream) else: preview_address = SYS_CONF['stream'].get('push', "127.0.0.1") stream_cmd = FORWARD_PATTERN.format( "rtsp://{}/0".format(preview_address), self.forward_stream()) logging.info("td201 gen stream command: {}".format(stream_cmd)) online_stream = subprocess.Popen(stream_cmd.split(' '), shell=False) online_stream_mgr.add_stream(self.uuid, online_stream)
def add(cam_type, address, username, password, cam_uuid=None, cam_port=554, cam_channel=1): for c in get_all( {})[0]: # take this structure to handle more complicated scenario if c.cam_address == address and c.cam_channel == cam_channel: return c.uuid _, _, ts = clock.now() init_func_list = {} for f, v in functl.get("").items(): init_func_list[f] = { "enable": True, "zones": [], "reverse": False, "detection_cycle": v["detection_cycle"], "alert_level": v["alert_level"], "threshold": v["init_threshold"], "aggreagate": v["aggreagate"], "aggreagate_times": v["aggreagate_times"], } if not cam_uuid: cam_uuid = _gen_id(address) camera_data = { "uuid": cam_uuid, "name": address, "edgex_name": "", "type": "camera", "cam_type": cam_type, "cam_address": address, "cam_port": cam_port, "cam_username": username, "cam_passwd": password, "cam_channel": cam_channel, "host_id": SYS_CONF['host_id'], "host_ip": SYS_CONF['host_ip'], "location": '未指定', "wakeup_time": ts, "status": "normal", "interval": SYS_CONF['default_capture_interval'], "function": init_func_list, "flavour": False, "history": SYS_CONF['history'], "alert": SYS_CONF["alert"], "upload": SYS_CONF["upload"], "detected_times": [ts], } mongodb.device.insert_one(camera_data) get_all({}) warning_count = { camera_data["uuid"]: {func: [] for func in functl.get("").keys()} } memory.WARNING_COUNT.update(warning_count) # RT.insert_subtask(camera_data['uuid']) Middle.RT.insert_subtask(camera_data['uuid']) if device.is_edge_proxy(): Middle.CldT.report_cam_setting(cam_uuid) Middle.CldT.report_function_cam(cam_uuid)
def update_all(data): mongodb.device.update_many({}, {'$set': data}) if device.is_edge_proxy(): Middle.CldT.report_setting() Middle.CldT.report_function()