예제 #1
0
    def _resorting_data(self, n_img, imgs_tcpdump, file_content):
        """
        orders packets coming from tcpdump files
        according to (img, datatype, subframe, packetnumber)
        """

        shape_img_pack = (n_img, self._n_smpl_rst, self._n_subframe,
                          (self._n_grp * self._n_packs_in_rowgrp //
                           self._n_subframe))

        shape_data = shape_img_pack + (self._gooddata_size, )
        shape_header = shape_img_pack + (self._header_size, )

        pack_check = np.zeros(shape_img_pack).astype(bool)
        data = np.zeros(shape_data).astype('uint8')
        header = np.zeros(shape_header).astype('uint8')

        for i, img_dump in enumerate(imgs_tcpdump):
            if self._verbose:
                print(".", end="", flush=True)

            for ifile, _ in enumerate(self._input_fnames):
                n_packs = len(file_content[ifile]) // self._fullpack_size

                for ipack in range(n_packs):
                    start = ipack * self._fullpack_size
                    end = (ipack + 1) * self._fullpack_size

                    file_data = file_content[ifile][start:end]

                    # if this pack (header) has a Img (frame) number
                    bytel = file_data[self._img_counter - 2:self._img_counter +
                                      2]
                    conv_bytel = utils.convert_bytelist_to_int(bytelist=bytel)

                    if conv_bytel == img_dump:
                        idx = slice(self._pack_counter, self._pack_counter + 2)
                        bytel = file_data[idx]
                        pack_id = utils.convert_bytelist_to_int(bytelist=bytel)

                        # datatype_id = file_data[self._datatype_counter]
                        # this is wrong because on header datatype_id=0 means Reset
                        # but dat is organized so that data[x, 0, ...] means Sample
                        # it needs to be changed as:
                        inverted_datatype_id = file_data[
                            self._datatype_counter]
                        datatype_id = np.absolute(inverted_datatype_id - 1)

                        subframe_id = file_data[self._subframe_counter]

                        # then save it in the appropriate position
                        data[i, datatype_id, subframe_id,
                             pack_id, :] = file_data[self._header_size:]
                        header[i, datatype_id, subframe_id,
                               pack_id, :] = file_data[:self._header_size]
                        # and flag that (Img,datatype,subframe,pack_id) as good
                        pack_check[i, datatype_id, subframe_id, pack_id] = True

        return data, header, pack_check
예제 #2
0
    def _resorting_data(self, n_img, imgs_tcpdump, file_content):
        """
        """

        shape_img_pack = (n_img, 2 * self._n_grp * self._n_packs_in_rowgrp)
        shape_data = shape_img_pack + (self._gooddata_size, )
        shape_header = shape_img_pack + (self._header_size, )

        pack_check = np.zeros(shape_img_pack).astype(bool)
        data = np.zeros(shape_data).astype('uint8')
        header = np.zeros(shape_header).astype('uint8')

        for i, img_dump in enumerate(imgs_tcpdump):
            if self._verbose:
                print(".", end="", flush=True)

            for ifile, _ in enumerate(self._input_fnames):
                n_packs = len(file_content[ifile]) // self._fullpack_size

                for ipack in range(n_packs):
                    start = ipack * self._fullpack_size
                    end = (ipack + 1) * self._fullpack_size

                    file_data = file_content[ifile][start:end]

                    # if this pack (header) has a Img (frame) number
                    bytel = file_data[self._img_counter - 2:self._img_counter +
                                      2]
                    conv_bytel = utils.convert_bytelist_to_int(bytelist=bytel)

                    if conv_bytel == img_dump:
                        idx = slice(self._pack_counter, self._pack_counter + 2)
                        bytel = file_data[idx]
                        pack_id = utils.convert_bytelist_to_int(bytelist=bytel)

                        # then save it in the appropriate position
                        data[i, pack_id, :] = file_data[self._header_size:]
                        header[i, pack_id, :] = file_data[:self._header_size]
                        # and flag that (pack,Img) as good
                        pack_check[i, pack_id] = True

        return data, header, pack_check
예제 #3
0
    def _scanning_files(self, n_packets, file_content):
        """Scanning the files for errors and determining first and last image.
        """

        first_img = (2**32) - 1
        last_img = 0
        for i, n_pack in enumerate(n_packets):
            # n_pack is 0 for all non existing files
            for ipack in range(n_pack):
                start = ipack * self._fullpack_size
                end = (ipack + 1) * self._fullpack_size
                file_data = file_content[i][start:end]

                # the frame (Img) number in this pack header (4-Bytes)
                bytelist = file_data[self._img_counter - 2:self._img_counter +
                                     2]
                img = utils.convert_bytelist_to_int(bytelist=bytelist)

                if img <= first_img:
                    first_img = img
                if img >= last_img:
                    last_img = img

                # the packet number in this pack header (2-Bytes)
                bitlist = file_data[self._pack_counter:self._pack_counter + 2]
                pack_nmbr = utils.convert_bitlist_to_int(bitlist=bitlist)

                if pack_nmbr > self._max_n_pack:  # fatal error in the data
                    msg = ("Inconsistent packet in {}\n"
                           "(packet {}-th in the file is identified as "
                           "pack_nmbr={} > {})").format(
                               self._input_fnames[i], ipack, pack_nmbr,
                               self._max_n_pack)
                    print(Fore.RED + msg)
                    raise Exception(msg)

        return first_img, last_img