def parse_project_file(file_path: str): import xml.etree.ElementTree as ET from urh.util.ProjectManager import ProjectManager result = defaultdict(lambda: None) if not file_path or not os.path.isfile(file_path): return result try: tree = ET.parse(file_path) root = tree.getroot() except Exception as e: logger.error("Could not read project file {}: {}".format(file_path, e)) return result ProjectManager.read_device_conf_dict(root.find("device_conf"), target_dict=result) result["device"] = result["name"] modulators = Modulator.modulators_from_xml_tag(root) if len(modulators) > 0: modulator = modulators[0] result["carrier_frequency"] = modulator.carrier_freq_hz result["carrier_amplitude"] = modulator.carrier_amplitude result["carrier_phase"] = modulator.carrier_phase_deg result["parameter_zero"] = modulator.param_for_zero result["parameter_one"] = modulator.param_for_one result["modulation_type"] = modulator.modulation_type_str return result
def load_from_xml(self, xml_tag: ET.Element, message_types): assert xml_tag.tag == "simulator_config" items = [] modulators_tag = xml_tag.find("modulators") if modulators_tag: self.project_manager.modulators = Modulator.modulators_from_xml_tag(modulators_tag) participants_tag = xml_tag.find("participants") if participants_tag: for participant in Participant.read_participants_from_xml_tag(participants_tag): if participant not in self.project_manager.participants: self.project_manager.participants.append(participant) self.participants_changed.emit() decodings_tag = xml_tag.find("decodings") if decodings_tag: self.project_manager.decodings = Encoding.read_decoders_from_xml_tag(decodings_tag) rx_config_tag = xml_tag.find("simulator_rx_conf") if rx_config_tag: ProjectManager.read_device_conf_dict(rx_config_tag, self.project_manager.simulator_rx_conf) tx_config_tag = xml_tag.find("simulator_tx_conf") if tx_config_tag: ProjectManager.read_device_conf_dict(tx_config_tag, self.project_manager.simulator_tx_conf) for child_tag in xml_tag.find("items"): items.append(self.load_item_from_xml(child_tag, message_types)) self.add_items(items, pos=0, parent_item=None)
def load_from_xml(self, xml_tag: ET.Element, message_types): assert xml_tag.tag == "simulator_config" items = [] modulators_tag = xml_tag.find("modulators") if modulators_tag: self.project_manager.modulators = Modulator.modulators_from_xml_tag(modulators_tag) participants_tag = xml_tag.find("participants") if participants_tag: self.project_manager.participants[:] = Participant.read_participants_from_xml_tag(participants_tag) self.participants_changed.emit() decodings_tag = xml_tag.find("decodings") if decodings_tag: self.project_manager.decodings = Encoding.read_decoders_from_xml_tag(decodings_tag) rx_config_tag = xml_tag.find("simulator_rx_conf") if rx_config_tag: ProjectManager.read_device_conf_dict(rx_config_tag, self.project_manager.simulator_rx_conf) tx_config_tag = xml_tag.find("simulator_tx_conf") if tx_config_tag: ProjectManager.read_device_conf_dict(tx_config_tag, self.project_manager.simulator_tx_conf) for child_tag in xml_tag.find("items"): items.append(self.load_item_from_xml(child_tag, message_types)) self.add_items(items, pos=0, parent_item=None)
def read_modulators_from_file(filename: str): if not filename: return [] tree = ET.parse(filename) root = tree.getroot() return Modulator.modulators_from_xml_tag(root)