def redo(self): len_pattern = len(self.amble_pattern) amble_sequence = self.amble_pattern * self.min_occurences len_sequence = len(amble_sequence) labels = [] for group in self.groups: count = 0 for k, block in enumerate(group.blocks): bit_str = block.decoded_bits_str len_bit_str = len(bit_str) indx = bit_str.find(amble_sequence) labels.append([]) while indx != -1: start = indx end = indx + len_sequence for i in range(start + len_sequence, len_bit_str, len_pattern): if bit_str[i:i + len_pattern] != self.amble_pattern: end = i break start = start if start > 1 else 0 # Erstes Bit mitnehmen, wenn Preamble beim zweiten Bit beginnt if count == 0: name = "Preamble" else: name = "Amble #{0:d}".format(count) lbl = ProtocolLabel(name, start, end - 1, k, 0, -1, True) lbl.reference_bits = bit_str[start:end] lbl.apply_decoding = False labels[k].append(lbl) indx = bit_str.find(amble_sequence, end - 1) count += 1 group.add_label(lbl)
def add_protocol_label(self, start: int, end: int, refblock: int, type_index: int, restrictive: bool, name=None, color_ind=None) -> \ ProtocolLabel: if refblock >= self.num_blocks: refblock = 0 name = "Label {0:d}".format(len(self.labels) + 1) if not name else name used_colors = [p.color_index for p in self.labels] avail_colors = [i for i, _ in enumerate(constants.LABEL_COLORS) if i not in used_colors] if color_ind is None: if len(avail_colors) > 0: color_ind = avail_colors[random.randint(0, len(avail_colors)-1)] else: color_ind = random.randint(0, len(constants.LABEL_COLORS) - 1) proto_label = ProtocolLabel(name, start, end, refblock, type_index, color_ind, restrictive) try: proto_label.reference_bits = self.decoded_bits_str[refblock][proto_label.start:proto_label.end] except IndexError: return None proto_label.signals.apply_decoding_changed.connect(self.handle_plabel_apply_decoding_changed) proto_label.find_block_numbers(self.decoded_bits_str) self.labels.append(proto_label) self.labels.sort() return proto_label
def read_compare_frame_groups(self): if self.project_file is None: return tree = ET.parse(self.project_file) root = tree.getroot() proto_tree_model = self.maincontroller.compare_frame_controller.proto_tree_model tree_root = proto_tree_model.rootItem pfi = proto_tree_model.protocol_tree_items proto_frame_items = [item for item in pfi[0]] """:type: list of ProtocolTreeItem """ for group_tag in root.iter("group"): name = group_tag.attrib["name"] id = group_tag.attrib["id"] if id == "0": tree_root.child(0).setData(name) else: tree_root.addGroup(name=name) group = tree_root.child(int(id)) for proto_tag in group_tag.iter("cf_protocol"): filename = os.path.join(self.project_path, proto_tag.attrib["filename"]) show = proto_tag.attrib["show"] try: proto_frame_item = next((p for p in proto_frame_items if p.protocol.filename == filename)) except StopIteration: proto_frame_item = None if proto_frame_item is not None: group.appendChild(proto_frame_item) proto_frame_item.show_in_compare_frame = Qt.Checked if show == "1" else Qt.Unchecked group = proto_tree_model.groups[int(id)] for label_tag in group_tag.iter("label"): name = label_tag.attrib["name"] start = int(label_tag.attrib["start"]) end = int(label_tag.attrib["end"]) refblock = int(label_tag.attrib["refblock"]) color_index = int(label_tag.attrib["color_index"]) restrictive = int(label_tag.attrib["restrictive"]) == 1 proto_label = ProtocolLabel(name, start, end, refblock, 0, color_index, restrictive) proto_label.reference_bits = label_tag.attrib["refbits"] proto_label.display_type_index = int(label_tag.attrib["display_type_index"]) proto_label.apply_decoding = int(label_tag.attrib["apply_decoding"]) == 1 group.add_label(proto_label) self.maincontroller.compare_frame_controller.expand_group_node(int(id)) self.maincontroller.compare_frame_controller.refresh()