def to_xml_tag(self, decodings, participants, tag_name="protocol", include_message_type=False, write_bits=False, messages=None, modulators=None) -> ET.Element: root = ET.Element(tag_name) messages = self.messages if messages is None else messages # Save modulators if modulators is not None: # For protocol analyzer container root.append(Modulator.modulators_to_xml_tag(modulators)) root.append(Encoding.decodings_to_xml_tag(decodings)) root.append(Participant.participants_to_xml_tag(participants)) # Save data data_tag = ET.SubElement(root, "messages") for i, message in enumerate(messages): message_tag = message.to_xml( decoders=decodings, include_message_type=include_message_type, write_bits=write_bits) data_tag.append(message_tag) # Save message types separatively as not saved in messages already if not include_message_type: message_types_tag = ET.SubElement(root, "message_types") for message_type in self.message_types: message_types_tag.append(message_type.to_xml()) return root
def to_xml_tag(self, decodings, participants, tag_name="protocol", include_message_type=False, write_bits=False, messages=None, modulators=None) -> ET.Element: root = ET.Element(tag_name) messages = self.messages if messages is None else messages # Save modulators if modulators is not None: # For protocol analyzer container root.append(Modulator.modulators_to_xml_tag(modulators)) root.append(Encoding.decodings_to_xml_tag(decodings)) root.append(Participant.participants_to_xml_tag(participants)) # Save data data_tag = ET.SubElement(root, "messages") for i, message in enumerate(messages): message_tag = message.to_xml(decoders=decodings, include_message_type=include_message_type, write_bits=write_bits) data_tag.append(message_tag) # Save message types separatively as not saved in messages already if not include_message_type: message_types_tag = ET.SubElement(root, "message_types") for message_type in self.message_types: message_types_tag.append(message_type.to_xml()) return root
def write_modulators_to_project_file(self, tree=None): """ :type modulators: list of Modulator :return: """ if self.project_file is None or not self.modulators: return if tree is None: tree = ET.parse(self.project_file) root = tree.getroot() root.append(Modulator.modulators_to_xml_tag(self.modulators)) tree.write(self.project_file)
def save_to_xml(self, standalone=False) -> ET.Element: result = ET.Element("simulator_config") if standalone: result.append(Modulator.modulators_to_xml_tag(self.project_manager.modulators)) result.append(Encoding.decodings_to_xml_tag(self.project_manager.decodings)) result.append(Participant.participants_to_xml_tag(self.project_manager.participants)) result.append(self.project_manager.simulator_rx_conf_to_xml()) result.append(self.project_manager.simulator_tx_conf_to_xml()) items_tag = ET.SubElement(result, "items") for item in self.rootItem.children: self.__save_item_to_xml(items_tag, item) return result