Exemple #1
0
    def from_xml(cls, tag: ET.Element, field_types_by_type_id=None):
        """

        :param tag:
        :type field_types_by_type_id: dict[str, FieldType]
        :return:
        """
        field_types_by_type_id = dict() if field_types_by_type_id is None else field_types_by_type_id

        name = tag.get("name")
        start, end = int(tag.get("start", 0)), int(tag.get("end", 0)) - 1
        color_index = int(tag.get("color_index", 0))

        result = ProtocolLabel(name=name, start=start, end=end, color_index=color_index)
        result.apply_decoding = True if tag.get("apply_decoding", 'True') == "True" else False
        result.show = Qt.Checked if Formatter.str2val(tag.get("show", 0), int) else Qt.Unchecked
        result.fuzz_me = Qt.Checked if Formatter.str2val(tag.get("fuzz_me", 0), int) else Qt.Unchecked
        result.fuzz_values = tag.get("fuzz_values", "").split(",")
        result.display_format_index = int(tag.get("display_format_index", 0))
        result.auto_created = True if tag.get("auto_created", 'False') == "True" else False
        type_id = tag.get("type_id", None)

        if type_id and type_id in field_types_by_type_id:
            result.field_type = field_types_by_type_id[type_id]
        else:
            result.field_type = None

        return result
Exemple #2
0
    def from_xml(cls, tag: ET.Element, field_types_by_caption=None):
        """

        :param tag:
        :type field_types_by_caption: dict[str, FieldType]
        :return:
        """
        field_types_by_caption = dict() if field_types_by_caption is None else field_types_by_caption

        name = tag.get("name")
        start, end = int(tag.get("start", 0)), int(tag.get("end", 0)) - 1
        color_index = int(tag.get("color_index", 0))

        result = ProtocolLabel(name=name, start=start, end=end, color_index=color_index)
        result.apply_decoding = True if tag.get("apply_decoding", 'True') == "True" else False
        result.show = Qt.Checked if Formatter.str2val(tag.get("show", 0), int) else Qt.Unchecked
        result.fuzz_me = Qt.Checked if Formatter.str2val(tag.get("fuzz_me", 0), int) else Qt.Unchecked
        result.fuzz_values = tag.get("fuzz_values", "").split(",")
        result.auto_created = True if tag.get("auto_created", 'False') == "True" else False

        if result.name in field_types_by_caption:
            result.field_type = field_types_by_caption[result.name]
        else:
            result.field_type = None

        # set this after result.field_type because this would change display_format_index to field_types default
        result.display_format_index = int(tag.get("display_format_index", 0))
        result.display_bit_order_index = int(tag.get("display_bit_order_index", 0))
        result.display_endianness = tag.get("display_endianness", "big")

        return result
Exemple #3
0
 def from_xml(tag: ET.Element):
     result = Modulator("")
     for attrib, value in tag.attrib.items():
         if attrib == "index":
             continue
         elif attrib == "name":
             setattr(result, attrib, str(value))
         elif attrib == "modulation_type":
             setattr(result, attrib, Formatter.str2val(value, int, 0))
         elif attrib == "samples_per_bit":
             setattr(result, attrib, Formatter.str2val(value, int, 100))
         elif attrib == "sample_rate":
             result.sample_rate = Formatter.str2val(value, float, 1e6) if value != "None" else None
         else:
             setattr(result, attrib, Formatter.str2val(value, float, 1))
     return result
Exemple #4
0
    def add_fuzz_value(self):
        cur_val = self.fuzz_values[-1]
        format_string = "{0:0" + str(len(cur_val)) + "b}"
        maximum = 2 ** len(cur_val)
        cur_val = format_string.format((int(str(Formatter.str2val(cur_val, int)), 2) + 1) % maximum)

        self.fuzz_values.append(cur_val)
Exemple #5
0
    def add_fuzz_value(self):
        cur_val = self.fuzz_values[-1]
        format_string = "{0:0" + str(len(cur_val)) + "b}"
        maximum = 2**len(cur_val)
        cur_val = format_string.format(
            (int(str(Formatter.str2val(cur_val, int)), 2) + 1) % maximum)

        self.fuzz_values.append(cur_val)
Exemple #6
0
 def from_xml(tag: ET.Element):
     result = Modulator("")
     for attrib, value in tag.attrib.items():
         if attrib == "index":
             continue
         elif attrib == "name":
             setattr(result, attrib, str(value))
         elif attrib == "modulation_type":
             setattr(result, attrib, Formatter.str2val(value, int, 0))
         elif attrib == "samples_per_bit":
             setattr(result, attrib, Formatter.str2val(value, int, 100))
         elif attrib == "sample_rate":
             result.sample_rate = Formatter.str2val(
                 value, float, 1e6) if value != "None" else None
         else:
             setattr(result, attrib, Formatter.str2val(value, float, 1))
     return result
Exemple #7
0
 def from_xml(self,
              tag: ET.Element,
              participants,
              decoders=None,
              message_types=None):
     super().from_xml(tag, participants, decoders, message_types)
     self.destination = Participant.find_matching(
         tag.get("destination_id", ""), participants)
     self.repeat = Formatter.str2val(tag.get("repeat", "1"), int, 1)
Exemple #8
0
    def from_xml(cls, tag: ET.Element, field_types_by_caption=None):
        """

        :param tag:
        :type field_types_by_caption: dict[str, FieldType]
        :return:
        """
        label_tag = tag.find("label")
        if label_tag is not None:
            label = ProtocolLabel.from_xml(label_tag, field_types_by_caption)
        else:
            label = ChecksumLabel.from_xml(tag.find("checksum_label"), field_types_by_caption)
        result = SimulatorProtocolLabel(label)
        result.value_type_index = Formatter.str2val(tag.get("value_type_index", "0"), int)
        result.external_program = tag.get("external_program", "")
        result.formula = tag.get("formula", "")
        result.random_min = Formatter.str2val(tag.get("random_min", "0"), int)
        result.random_max = Formatter.str2val(tag.get("random_max", str(label.fuzz_maximum-1)), int)
        return result
Exemple #9
0
 def from_xml(tag: ET.Element):
     result = Modulator("")
     for attrib, value in sorted(tag.attrib.items()):
         if attrib == "index":
             continue
         elif attrib == "name" or attrib == "modulation_type":
             setattr(result, attrib, str(value))
         elif attrib == "samples_per_bit" or attrib == "samples_per_symbol":
             # samples_per_bit as legacy support for older project files
             result.samples_per_symbol = Formatter.str2val(value, int, 100)
         elif attrib == "sample_rate":
             result.sample_rate = Formatter.str2val(value, float, 1e6) if value != "None" else None
         elif attrib == "param_for_zero":
             result.parameters[0] = Formatter.str2val(value, float, 0)  # legacy
         elif attrib == "param_for_one":
             result.parameters[1] = Formatter.str2val(value, float, 100)  # legacy
         elif attrib == "bits_per_symbol":
             result.bits_per_symbol = Formatter.str2val(value, int, 1)
         elif attrib == "parameters":
             try:
                 result.parameters = array.array("f", map(float, value.split(",")))
             except ValueError:
                 continue
         elif not attrib.startswith("_Modulator__"):
             setattr(result, attrib, Formatter.str2val(value, float, 1))
     return result
Exemple #10
0
    def from_xml(cls, tag: ET.Element, field_types_by_caption=None):
        """

        :param tag:
        :type field_types_by_caption: dict[str, FieldType]
        :return:
        """
        field_types_by_caption = dict(
        ) if field_types_by_caption is None else field_types_by_caption

        name = tag.get("name")
        start, end = int(tag.get("start", 0)), int(tag.get("end", 0)) - 1
        color_index = int(tag.get("color_index", 0))

        result = ProtocolLabel(name=name,
                               start=start,
                               end=end,
                               color_index=color_index)
        result.apply_decoding = True if tag.get("apply_decoding",
                                                'True') == "True" else False
        result.show = Qt.Checked if Formatter.str2val(tag.get("show", 0),
                                                      int) else Qt.Unchecked
        result.fuzz_me = Qt.Checked if Formatter.str2val(
            tag.get("fuzz_me", 0), int) else Qt.Unchecked
        result.fuzz_values = tag.get("fuzz_values", "").split(",")
        result.auto_created = True if tag.get("auto_created",
                                              'False') == "True" else False

        if result.name in field_types_by_caption:
            result.field_type = field_types_by_caption[result.name]
        else:
            result.field_type = None

        # set this after result.field_type because this would change display_format_index to field_types default
        result.display_format_index = int(tag.get("display_format_index", 0))
        result.display_bit_order_index = int(
            tag.get("display_bit_order_index", 0))
        result.display_endianness = tag.get("display_endianness", "big")

        return result
Exemple #11
0
    def from_xml(cls, tag: ET.Element, field_types_by_caption=None):
        """

        :param tag:
        :type field_types_by_caption: dict[str, FieldType]
        :return:
        """
        label_tag = tag.find("label")
        if label_tag is not None:
            label = ProtocolLabel.from_xml(label_tag, field_types_by_caption)
        else:
            label = ChecksumLabel.from_xml(tag.find("checksum_label"),
                                           field_types_by_caption)
        result = SimulatorProtocolLabel(label)
        result.value_type_index = Formatter.str2val(
            tag.get("value_type_index", "0"), int)
        result.external_program = tag.get("external_program", "")
        result.formula = tag.get("formula", "")
        result.random_min = Formatter.str2val(tag.get("random_min", "0"), int)
        result.random_max = Formatter.str2val(
            tag.get("random_max", str(label.fuzz_maximum - 1)), int)
        return result
Exemple #12
0
    def from_xml(cls, tag: ET.Element, field_types_by_type_id=None):
        """

        :param tag:
        :type field_types_by_type_id: dict[str, FieldType]
        :return:
        """
        field_types_by_type_id = dict(
        ) if field_types_by_type_id is None else field_types_by_type_id

        name = tag.get("name")
        start, end = int(tag.get("start", 0)), int(tag.get("end", 0)) - 1
        color_index = int(tag.get("color_index", 0))

        result = ProtocolLabel(name=name,
                               start=start,
                               end=end,
                               color_index=color_index)
        result.apply_decoding = True if tag.get("apply_decoding",
                                                'True') == "True" else False
        result.show = Qt.Checked if Formatter.str2val(tag.get("show", 0),
                                                      int) else Qt.Unchecked
        result.fuzz_me = Qt.Checked if Formatter.str2val(
            tag.get("fuzz_me", 0), int) else Qt.Unchecked
        result.fuzz_values = tag.get("fuzz_values", "").split(",")
        result.display_format_index = int(tag.get("display_format_index", 0))
        result.auto_created = True if tag.get("auto_created",
                                              'False') == "True" else False
        type_id = tag.get("type_id", None)

        if type_id and type_id in field_types_by_type_id:
            result.field_type = field_types_by_type_id[type_id]
        else:
            result.field_type = None

        return result
Exemple #13
0
 def from_xml(cls, tag):
     result = SimulatorSleepAction()
     result.sleep_time = Formatter.str2val(tag.get("sleep_time", "1.0"), float, 1.0)
     return result
 def from_xml(cls, tag):
     result = SimulatorSleepAction()
     result.sleep_time = Formatter.str2val(tag.get("sleep_time", "1.0"),
                                           float, 1.0)
     return result
 def from_xml(cls, tag):
     result = SimulatorCounterAction()
     result.start = Formatter.str2val(tag.get("start", "1"), int, 1)
     result.step = Formatter.str2val(tag.get("step", "1"), int, 1)
     return result
Exemple #16
0
 def from_xml(self, tag: ET.Element, participants, decoders=None, message_types=None):
     super().from_xml(tag, participants, decoders, message_types)
     self.destination = Participant.find_matching(tag.get("destination_id", ""), participants)
     self.repeat = Formatter.str2val(tag.get("repeat", "1"), int, 1)