def test_parse_two_packets(self): xp = XSensParser(None) data = bytes.fromhex( "FA FF 36 53 10 20 02 89 90 10 60 04 00 26 C7 33 40 20 0C 3D 0A 5D 4A BD 28 44 1C 41 1D " "09 AF 40 10 0C 38 B0 80 00 B8 D7 28 00 3C C9 02 28 80 20 0C BA E5 4C 02 BB 9A 3F 83 BA " "D8 04 03 80 30 10 3F 80 00 01 B6 12 C0 01 B6 C5 70 00 B6 0A 40 00 E0 20 04 00 00 00 05 " "F4" "FA FF 36 53 10 20 02 89 90 10 60 04 00 26 C7 33 40 20 0C 3D 0A 5D 4A BD 28 44 1C 41 1D " "09 AF 40 10 0C 38 B0 80 00 B8 D7 28 00 3C C9 02 28 80 20 0C BA E5 4C 02 BB 9A 3F 83 BA " "D8 04 03 80 30 10 3F 80 00 01 B6 12 C0 01 B6 C5 70 00 B6 0A 40 00 E0 20 04 00 00 00 05 " "F4") xp.parse(data) packet1 = xp.get() packet2 = xp.get() errors = object_hierarchy_equals(packet1, self.correct_single_packet) # print("\n".join(errors)) self.assertEqual(len(errors), 0) errors = object_hierarchy_equals(packet2, self.correct_single_packet) # print("\n".join(errors)) self.assertEqual(len(errors), 0)
def test_single_packet_file_like(self): bytes_io = BytesIO( bytes.fromhex( "FA FF 36 53 10 20 02 89 90 10 60 04 00 26 C7 33 40 20 0C 3D 0A 5D 4A BD 28 44 1C 41 1D " "09 AF 40 10 0C 38 B0 80 00 B8 D7 28 00 3C C9 02 28 80 20 0C BA E5 4C 02 BB 9A 3F 83 BA " "D8 04 03 80 30 10 3F 80 00 01 B6 12 C0 01 B6 C5 70 00 B6 0A 40 00 E0 20 04 00 00 00 05 " "F4")) xp = XSensParser(bytes_io) xp.start() packet = xp.get() errors = object_hierarchy_equals(packet, self.correct_single_packet) # print("\n".join(errors)) self.assertEqual(len(errors), 0)
def test_file(self): with open(test_dir_path / "data_files" / "xsens_raw_data.bin", "rb") as f: xp = XSensParser(f) xp.start() tables = xp.get_tables() # Uncomment this line to update the tables in the data file. # File(test_dir_path / "data_files" / "correct_xsens_tables.msgp.gz").dump(tables) correct_tables = flex_load(test_dir_path / "data_files" / "correct_xsens_tables.msgp.gz") errors = object_hierarchy_equals(tables, correct_tables) # print("\n".join(errors)) self.assertEqual(len(errors), 0)
def main(cls, args: argparse.Namespace): # Load calibration data if provided. calibration_data = None if args.calibration_data is not None: calibration_data = flex_load(args.calibration_data) if args.input_file is not None: if args.large_file: output_path = pathlib.PurePath(args.output_file[0]) output_format = "".join(output_path.suffixes) output_format = None if output_format == '' else output_format output_path = output_path.stem with open(args.input_file, "rb") as f: xp = XSensLargeFileParser( f, output_path=output_path, output_format=output_format, calibration_data=calibration_data, verbose=args.verbose) xp.start() else: with open(args.input_file, "rb") as f: xp = XSensParser(f, verbose=args.verbose, calibration_data=calibration_data) xp.start() if args.verbose: print("device_id:", xp.device_id) tables = xp.get_tables() for key, value in tables.items(): if isinstance(value, str): continue # print(key, type(value['time']), type(value['data'][0])) for output_path in map(pathlib.Path, args.output_file): flex_dump(tables, output_path) else: raise ValueError("No input source given.")