objutils 0.10.1__tar.gz → 0.10.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. {objutils-0.10.1 → objutils-0.10.2}/PKG-INFO +1 -1
  2. {objutils-0.10.1 → objutils-0.10.2}/objutils/__init__.py +1 -1
  3. {objutils-0.10.1 → objutils-0.10.2}/objutils/image.py +47 -0
  4. {objutils-0.10.1 → objutils-0.10.2}/objutils/section.py +100 -7
  5. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_image.py +27 -0
  6. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_section.py +44 -0
  7. {objutils-0.10.1 → objutils-0.10.2}/objutils/version.py +1 -1
  8. {objutils-0.10.1 → objutils-0.10.2}/pyproject.toml +2 -2
  9. {objutils-0.10.1 → objutils-0.10.2}/CMakeLists.txt +0 -0
  10. {objutils-0.10.1 → objutils-0.10.2}/LICENSE +0 -0
  11. {objutils-0.10.1 → objutils-0.10.2}/build_ext.py +0 -0
  12. {objutils-0.10.1 → objutils-0.10.2}/docs/README.rst +0 -0
  13. {objutils-0.10.1 → objutils-0.10.2}/objutils/.coveragerc +0 -0
  14. {objutils-0.10.1 → objutils-0.10.2}/objutils/.vscode/launch.json +0 -0
  15. {objutils-0.10.1 → objutils-0.10.2}/objutils/.vscode/settings.json +0 -0
  16. {objutils-0.10.1 → objutils-0.10.2}/objutils/a2l_test.shf +0 -0
  17. {objutils-0.10.1 → objutils-0.10.2}/objutils/ash.py +0 -0
  18. {objutils-0.10.1 → objutils-0.10.2}/objutils/binfile.py +0 -0
  19. {objutils-0.10.1 → objutils-0.10.2}/objutils/checksums.py +0 -0
  20. {objutils-0.10.1 → objutils-0.10.2}/objutils/cosmac.py +0 -0
  21. {objutils-0.10.1 → objutils-0.10.2}/objutils/dwarf/.traverser.py.un~ +0 -0
  22. {objutils-0.10.1 → objutils-0.10.2}/objutils/dwarf/__init__.py +0 -0
  23. {objutils-0.10.1 → objutils-0.10.2}/objutils/dwarf/attrparser.py +0 -0
  24. {objutils-0.10.1 → objutils-0.10.2}/objutils/dwarf/c_generator.py +0 -0
  25. {objutils-0.10.1 → objutils-0.10.2}/objutils/dwarf/constants.py +0 -0
  26. {objutils-0.10.1 → objutils-0.10.2}/objutils/dwarf/encoding.py +0 -0
  27. {objutils-0.10.1 → objutils-0.10.2}/objutils/dwarf/lineprog.py +0 -0
  28. {objutils-0.10.1 → objutils-0.10.2}/objutils/dwarf/readers.py +0 -0
  29. {objutils-0.10.1 → objutils-0.10.2}/objutils/dwarf/sm.py +0 -0
  30. {objutils-0.10.1 → objutils-0.10.2}/objutils/dwarf/traverser.py +0 -0
  31. {objutils-0.10.1 → objutils-0.10.2}/objutils/elf/__init__.py +0 -0
  32. {objutils-0.10.1 → objutils-0.10.2}/objutils/elf/arm/__init__.py +0 -0
  33. {objutils-0.10.1 → objutils-0.10.2}/objutils/elf/arm/attributes.py +0 -0
  34. {objutils-0.10.1 → objutils-0.10.2}/objutils/elf/defs.py +0 -0
  35. {objutils-0.10.1 → objutils-0.10.2}/objutils/elf/model.py +0 -0
  36. {objutils-0.10.1 → objutils-0.10.2}/objutils/emon52.py +0 -0
  37. {objutils-0.10.1 → objutils-0.10.2}/objutils/etek.py +0 -0
  38. {objutils-0.10.1 → objutils-0.10.2}/objutils/exceptions.py +0 -0
  39. {objutils-0.10.1 → objutils-0.10.2}/objutils/extensions/__init__.py +0 -0
  40. {objutils-0.10.1 → objutils-0.10.2}/objutils/extensions/ctre.hpp +0 -0
  41. {objutils-0.10.1 → objutils-0.10.2}/objutils/extensions/difflib.h +0 -0
  42. {objutils-0.10.1 → objutils-0.10.2}/objutils/extensions/exceptions.cpp +0 -0
  43. {objutils-0.10.1 → objutils-0.10.2}/objutils/extensions/exceptions.hpp +0 -0
  44. {objutils-0.10.1 → objutils-0.10.2}/objutils/extensions/hexfile.cpp +0 -0
  45. {objutils-0.10.1 → objutils-0.10.2}/objutils/extensions/wrapper.cpp +0 -0
  46. {objutils-0.10.1 → objutils-0.10.2}/objutils/fpc.py +0 -0
  47. {objutils-0.10.1 → objutils-0.10.2}/objutils/hexdump.py +0 -0
  48. {objutils-0.10.1 → objutils-0.10.2}/objutils/hexfile.py +0 -0
  49. {objutils-0.10.1 → objutils-0.10.2}/objutils/ieee695.py +0 -0
  50. {objutils-0.10.1 → objutils-0.10.2}/objutils/ihex.py +0 -0
  51. {objutils-0.10.1 → objutils-0.10.2}/objutils/logger.py +0 -0
  52. {objutils-0.10.1 → objutils-0.10.2}/objutils/mostec.py +0 -0
  53. {objutils-0.10.1 → objutils-0.10.2}/objutils/objutils.code-workspace +0 -0
  54. {objutils-0.10.1 → objutils-0.10.2}/objutils/pecoff/__init__.py +0 -0
  55. {objutils-0.10.1 → objutils-0.10.2}/objutils/pecoff/defs.py +0 -0
  56. {objutils-0.10.1 → objutils-0.10.2}/objutils/pecoff/model.py +0 -0
  57. {objutils-0.10.1 → objutils-0.10.2}/objutils/pecoff/pdb/__init__.py +0 -0
  58. {objutils-0.10.1 → objutils-0.10.2}/objutils/pickleif.py +0 -0
  59. {objutils-0.10.1 → objutils-0.10.2}/objutils/rca.py +0 -0
  60. {objutils-0.10.1 → objutils-0.10.2}/objutils/readers.py +0 -0
  61. {objutils-0.10.1 → objutils-0.10.2}/objutils/registry.py +0 -0
  62. {objutils-0.10.1 → objutils-0.10.2}/objutils/scripts/arduino_build_artifacts.py +0 -0
  63. {objutils-0.10.1 → objutils-0.10.2}/objutils/scripts/oj_cgen.py +0 -0
  64. {objutils-0.10.1 → objutils-0.10.2}/objutils/scripts/oj_coff_extract.py +0 -0
  65. {objutils-0.10.1 → objutils-0.10.2}/objutils/scripts/oj_coff_import.py +0 -0
  66. {objutils-0.10.1 → objutils-0.10.2}/objutils/scripts/oj_coff_info.py +0 -0
  67. {objutils-0.10.1 → objutils-0.10.2}/objutils/scripts/oj_coff_syms.py +0 -0
  68. {objutils-0.10.1 → objutils-0.10.2}/objutils/scripts/oj_dwarf_import.py +0 -0
  69. {objutils-0.10.1 → objutils-0.10.2}/objutils/scripts/oj_elf_arm_attrs.py +0 -0
  70. {objutils-0.10.1 → objutils-0.10.2}/objutils/scripts/oj_elf_extract.py +0 -0
  71. {objutils-0.10.1 → objutils-0.10.2}/objutils/scripts/oj_elf_import.py +0 -0
  72. {objutils-0.10.1 → objutils-0.10.2}/objutils/scripts/oj_elf_info.py +0 -0
  73. {objutils-0.10.1 → objutils-0.10.2}/objutils/scripts/oj_elf_syms.py +0 -0
  74. {objutils-0.10.1 → objutils-0.10.2}/objutils/scripts/oj_hex_info.py +0 -0
  75. {objutils-0.10.1 → objutils-0.10.2}/objutils/shf.py +0 -0
  76. {objutils-0.10.1 → objutils-0.10.2}/objutils/sig.py +0 -0
  77. {objutils-0.10.1 → objutils-0.10.2}/objutils/srec.py +0 -0
  78. {objutils-0.10.1 → objutils-0.10.2}/objutils/tek.py +0 -0
  79. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/__init__.py +0 -0
  80. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_arm_attributes.py +0 -0
  81. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_ash.py +0 -0
  82. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_c_generator.py +0 -0
  83. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_checksums.py +0 -0
  84. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_cygpath.py +0 -0
  85. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_diff_bin.py +0 -0
  86. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_elf.py +0 -0
  87. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_emon52.py +0 -0
  88. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_examples_cgen.py +0 -0
  89. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_fpc.py +0 -0
  90. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_hexdump.py +0 -0
  91. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_hexfile.py +0 -0
  92. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_ihex.py +0 -0
  93. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_mostec.py +0 -0
  94. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_readers.py +0 -0
  95. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_registry.py +0 -0
  96. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_repr.py +0 -0
  97. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_section_join.py +0 -0
  98. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_shf.py +0 -0
  99. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_sm.py +0 -0
  100. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_srec.py +0 -0
  101. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_tek.py +0 -0
  102. {objutils-0.10.1 → objutils-0.10.2}/objutils/tests/test_titext.py +0 -0
  103. {objutils-0.10.1 → objutils-0.10.2}/objutils/titxt.py +0 -0
  104. {objutils-0.10.1 → objutils-0.10.2}/objutils/utils/__init__.py +0 -0
  105. {objutils-0.10.1 → objutils-0.10.2}/objutils/utils/arduino.py +0 -0
  106. {objutils-0.10.1 → objutils-0.10.2}/objutils/utils/diff.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: objutils
3
- Version: 0.10.1
3
+ Version: 0.10.2
4
4
  Summary: Objectfile library for Python
5
5
  License: GPLv2
6
6
  License-File: LICENSE
@@ -13,7 +13,7 @@ Registers CODECS and implements an interface to them.
13
13
  The first parameter is always the codec name.
14
14
  """
15
15
 
16
- __version__ = "0.10.1"
16
+ __version__ = "0.10.2"
17
17
 
18
18
  __all__ = [
19
19
  "Image",
@@ -640,6 +640,28 @@ class Image:
640
640
  """Write an ASAM string datatype (ASCII/UTF8/UTF16/UTF32)."""
641
641
  self._call_address_function("write_asam_string", addr, value, dtype, **kws)
642
642
 
643
+ def read_asam_numeric_array(
644
+ self,
645
+ addr: int,
646
+ length: int,
647
+ dtype: str,
648
+ byte_order: str = "MSB_LAST",
649
+ **kws: Any,
650
+ ) -> list[Union[int, float]]:
651
+ """Read an ASAM numeric array with ECU byte order semantics."""
652
+ return self._call_address_function("read_asam_numeric_array", addr, length, dtype, byte_order, **kws)
653
+
654
+ def write_asam_numeric_array(
655
+ self,
656
+ addr: int,
657
+ data: Iterable[Union[int, float]],
658
+ dtype: str,
659
+ byte_order: str = "MSB_LAST",
660
+ **kws: Any,
661
+ ) -> None:
662
+ """Write an ASAM numeric array with ECU byte order semantics."""
663
+ self._call_address_function("write_asam_numeric_array", addr, data, dtype, byte_order, **kws)
664
+
643
665
  def read_numeric_array(self, addr: int, length: int, dtype: str, **kws: Any) -> list[Union[int, float]]:
644
666
  """Read array of numeric values from image.
645
667
 
@@ -688,6 +710,18 @@ class Image:
688
710
  """
689
711
  self._call_address_function("write_ndarray", addr, array, order=order, **kws)
690
712
 
713
+ def write_asam_ndarray(
714
+ self,
715
+ addr: int,
716
+ array: Any,
717
+ dtype: str,
718
+ byte_order: str = "MSB_LAST",
719
+ order: Optional[str] = None,
720
+ **kws: Any,
721
+ ) -> None:
722
+ """Write a NumPy ndarray using ASAM datatype and ECU byte order semantics."""
723
+ self._call_address_function("write_asam_ndarray", addr, array, dtype, byte_order, order=order, **kws)
724
+
691
725
  def read_ndarray(
692
726
  self,
693
727
  addr: int,
@@ -715,6 +749,19 @@ class Image:
715
749
  """
716
750
  return self._call_address_function("read_ndarray", addr, length, dtype, shape, order, **kws)
717
751
 
752
+ def read_asam_ndarray(
753
+ self,
754
+ addr: int,
755
+ length: int,
756
+ dtype: str,
757
+ shape: Optional[tuple[int, ...]] = None,
758
+ order: Optional[str] = None,
759
+ byte_order: str = "MSB_LAST",
760
+ **kws: Any,
761
+ ) -> Any:
762
+ """Read a NumPy ndarray using ASAM datatype and ECU byte order semantics."""
763
+ return self._call_address_function("read_asam_ndarray", addr, length, dtype, shape, order, byte_order, **kws)
764
+
718
765
  def read_string(self, addr: int, encoding: str = "latin1", length: int = -1, **kws: Any) -> str:
719
766
  """Read string from image.
720
767
 
@@ -32,6 +32,9 @@ Architecture
32
32
  ├── read/write(addr, length) # Raw bytes
33
33
  ├── read_numeric/write_numeric(addr, dtype) # Single values
34
34
  ├── read_numeric_array/write_numeric_array() # Arrays
35
+ ├── read_asam_numeric/write_asam_numeric() # ASAM scalars
36
+ ├── read_asam_numeric_array/write_asam_numeric_array() # ASAM arrays
37
+ ├── read_asam_ndarray/write_asam_ndarray() # ASAM NumPy arrays
35
38
  ├── read_string/write_string() # Null-terminated strings
36
39
  └── read_ndarray/write_ndarray() # NumPy arrays
37
40
 
@@ -587,10 +590,24 @@ class Section:
587
590
  internal_dtype = ASAM_NUMERIC_DTYPES.get(normalized_dtype)
588
591
  if internal_dtype is None:
589
592
  raise TypeError(f"Unsupported ASAM datatype {asam_dtype!r}")
590
- if internal_dtype in ("uint8", "int8"):
591
- return internal_dtype
592
593
  return f"{internal_dtype}_{ASAM_ENDIAN_FOR_BYTEORDER[asam_byte_order]}"
593
594
 
595
+ def _numpy_dtype_from_internal(self, dtype: str) -> np.dtype:
596
+ type_, byte_order = self._verify_dtype(dtype)
597
+ return np.dtype(type_).newbyteorder(BYTEORDER[byte_order])
598
+
599
+ def _permute_asam_buffer(self, data: bytes, internal_dtype: str, byte_order: str) -> bytes:
600
+ type_name = internal_dtype.split("_")[0]
601
+ element_size = TYPE_SIZES.get(type_name, 0)
602
+ if element_size <= 1 or not data:
603
+ return data
604
+ if len(data) % element_size != 0:
605
+ raise ValueError("ASAM buffer length must be a multiple of the element size")
606
+ return b"".join(
607
+ self._permute_asam_bytes_for_read(data[idx : idx + element_size], byte_order)
608
+ for idx in range(0, len(data), element_size)
609
+ )
610
+
594
611
  def read(self, addr: int, length: int, **kws) -> bytes:
595
612
  """Read raw bytes from section at specified address.
596
613
 
@@ -763,7 +780,7 @@ class Section:
763
780
 
764
781
  fmt = self._getformat(internal_dtype)
765
782
  packed = struct.pack(fmt, value)
766
- permuted = self._permute_asam_bytes_for_read(packed, asam_byte_order)
783
+ permuted = self._permute_asam_buffer(packed, internal_dtype, asam_byte_order)
767
784
  return struct.unpack(fmt, permuted)[0]
768
785
 
769
786
  def write_asam_numeric(
@@ -782,9 +799,44 @@ class Section:
782
799
 
783
800
  fmt = self._getformat(internal_dtype)
784
801
  packed = struct.pack(fmt, value)
785
- permuted = self._permute_asam_bytes_for_write(packed, asam_byte_order)
802
+ permuted = self._permute_asam_buffer(packed, internal_dtype, asam_byte_order)
786
803
  self.write(addr, permuted)
787
804
 
805
+ def read_asam_numeric_array(
806
+ self,
807
+ addr: int,
808
+ length: int,
809
+ dtype: str,
810
+ byte_order: str = "MSB_LAST",
811
+ **kws,
812
+ ) -> Union[tuple[int, ...], tuple[float, ...]]:
813
+ asam_byte_order = self._resolve_asam_byteorder(byte_order)
814
+ internal_dtype = self._asam_numeric_dtype_to_internal(dtype, asam_byte_order)
815
+ fmt = self._getformat(internal_dtype, length)
816
+ data_size = struct.calcsize(fmt)
817
+ raw_data = self.read(addr, data_size, **kws)
818
+ permuted = self._permute_asam_buffer(raw_data, internal_dtype, asam_byte_order)
819
+ return struct.unpack(fmt, permuted)
820
+
821
+ def write_asam_numeric_array(
822
+ self,
823
+ addr: int,
824
+ data: Union[list[int], list[float]],
825
+ dtype: str,
826
+ byte_order: str = "MSB_LAST",
827
+ **kws,
828
+ ) -> None:
829
+ if not hasattr(data, "__iter__"):
830
+ raise TypeError("data must be iterable")
831
+
832
+ values = tuple(data)
833
+ asam_byte_order = self._resolve_asam_byteorder(byte_order)
834
+ internal_dtype = self._asam_numeric_dtype_to_internal(dtype, asam_byte_order)
835
+ fmt = self._getformat(internal_dtype, len(values))
836
+ packed = struct.pack(fmt, *values)
837
+ permuted = self._permute_asam_buffer(packed, internal_dtype, asam_byte_order)
838
+ self.write(addr, permuted, **kws)
839
+
788
840
  def read_asam_string(self, addr: int, dtype: str, length: int = -1, **kws) -> str:
789
841
  encoding = ASAM_STRING_ENCODINGS.get(dtype.strip().upper())
790
842
  if encoding is None:
@@ -920,6 +972,28 @@ class Section:
920
972
  else:
921
973
  self.data[offset : offset + data_size] = array.tobytes()
922
974
 
975
+ def write_asam_ndarray(
976
+ self,
977
+ addr: int,
978
+ array: np.ndarray,
979
+ dtype: str,
980
+ byte_order: str = "MSB_LAST",
981
+ order: str = None,
982
+ **kws,
983
+ ) -> None:
984
+ if not isinstance(array, np.ndarray):
985
+ raise TypeError("array must be of type numpy.ndarray.")
986
+
987
+ asam_byte_order = self._resolve_asam_byteorder(byte_order)
988
+ internal_dtype = self._asam_numeric_dtype_to_internal(dtype, asam_byte_order)
989
+ typed_array = np.asarray(array, dtype=self._numpy_dtype_from_internal(internal_dtype))
990
+ if order is not None and order == "F":
991
+ raw_data = fortran_array_to_buffer(array=typed_array)
992
+ else:
993
+ raw_data = typed_array.tobytes()
994
+ permuted = self._permute_asam_buffer(raw_data, internal_dtype, asam_byte_order)
995
+ self.write(addr, permuted, **kws)
996
+
923
997
  def read_ndarray(self, addr: int, length: int, dtype: str, shape: tuple = None, order: str = None, **kws) -> np.ndarray:
924
998
  """ """
925
999
  offset = addr - self.start_address
@@ -927,9 +1001,7 @@ class Section:
927
1001
  raise InvalidAddressError(f"read_ndarray(0x{addr:08x}) access out of bounds.")
928
1002
  if offset + length > self.length:
929
1003
  raise InvalidAddressError(f"read_ndarray(0x{addr:08x}) access out of bounds.")
930
- type_, byte_order = self._verify_dtype(dtype)
931
- dt = np.dtype(type_)
932
- dt = dt.newbyteorder(BYTEORDER.get(byte_order))
1004
+ dt = self._numpy_dtype_from_internal(dtype)
933
1005
  if order is not None and order == "F":
934
1006
  arr = fortran_array_from_buffer(arr=self.data[offset : offset + length], shape=shape, dtype=dt)
935
1007
  else:
@@ -937,6 +1009,27 @@ class Section:
937
1009
  arr = flat.reshape(shape) if shape else flat
938
1010
  return arr
939
1011
 
1012
+ def read_asam_ndarray(
1013
+ self,
1014
+ addr: int,
1015
+ length: int,
1016
+ dtype: str,
1017
+ shape: tuple = None,
1018
+ order: str = None,
1019
+ byte_order: str = "MSB_LAST",
1020
+ **kws,
1021
+ ) -> np.ndarray:
1022
+ asam_byte_order = self._resolve_asam_byteorder(byte_order)
1023
+ internal_dtype = self._asam_numeric_dtype_to_internal(dtype, asam_byte_order)
1024
+ dt = self._numpy_dtype_from_internal(internal_dtype)
1025
+ raw_data = self.read(addr, length, **kws)
1026
+ permuted = self._permute_asam_buffer(raw_data, internal_dtype, asam_byte_order)
1027
+ if order is not None and order == "F":
1028
+ return fortran_array_from_buffer(arr=permuted, shape=shape, dtype=dt)
1029
+
1030
+ flat = np.frombuffer(permuted, dtype=dt)
1031
+ return flat.reshape(shape) if shape else flat
1032
+
940
1033
  """
941
1034
  def write_timestamp():
942
1035
  pass
@@ -6,6 +6,13 @@ from array import array
6
6
 
7
7
  import pytest
8
8
 
9
+ try:
10
+ import numpy as np
11
+ except ImportError:
12
+ NUMPY_SUPPORT = False
13
+ else:
14
+ NUMPY_SUPPORT = True
15
+
9
16
  from objutils import dumps
10
17
  from objutils.exceptions import InvalidAddressError
11
18
  from objutils.image import Image
@@ -1343,5 +1350,25 @@ def test_image_asam_string_ascii_roundtrip():
1343
1350
  assert img.read_asam_string(0x1000, "ASCII") == "ABC"
1344
1351
 
1345
1352
 
1353
+ def test_image_asam_numeric_array_word_swap_32bit():
1354
+ img = Image(Section(data=bytearray(16), start_address=0x1000))
1355
+ img.write_asam_numeric_array(0x1000, [0x11223344, 0x55667788], "ULONG", byte_order="MSB_LAST_MSW_FIRST")
1356
+ assert img.read(0x1000, 8) == b"\x33\x44\x11\x22\x77\x88\x55\x66"
1357
+ assert img.read_asam_numeric_array(0x1000, 2, "ULONG", byte_order="MSB_LAST_MSW_FIRST") == (
1358
+ 0x11223344,
1359
+ 0x55667788,
1360
+ )
1361
+
1362
+
1363
+ @pytest.mark.skipif("NUMPY_SUPPORT == False")
1364
+ def test_image_asam_ndarray_fortran_roundtrip():
1365
+ img = Image(Section(data=bytearray(32), start_address=0x1000))
1366
+ arr = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.uint16)
1367
+ img.write_asam_ndarray(0x1000, arr, "UWORD", byte_order="MSB_FIRST_MSW_LAST", order="F")
1368
+ assert img.read(0x1000, 12) == b"\x01\x00\x04\x00\x02\x00\x05\x00\x03\x00\x06\x00"
1369
+ result = img.read_asam_ndarray(0x1000, 12, "UWORD", shape=(3, 2), order="F", byte_order="MSB_FIRST_MSW_LAST")
1370
+ assert np.array_equal(result, arr)
1371
+
1372
+
1346
1373
  if __name__ == "__main__":
1347
1374
  unittest.main()
@@ -638,6 +638,24 @@ def test_asam_float16_ieee_roundtrip():
638
638
  assert sec.read_asam_numeric(0, "FLOAT16_IEEE", byte_order="MSB_LAST") == pytest.approx(1.5, rel=1e-3)
639
639
 
640
640
 
641
+ def test_write_asam_numeric_array_msb_last_msw_first_ulong():
642
+ sec = Section(data=bytearray(16))
643
+ sec.write_asam_numeric_array(0, [0x11223344, 0x55667788], "ULONG", byte_order="MSB_LAST_MSW_FIRST")
644
+ assert sec.data[:8] == bytearray([0x33, 0x44, 0x11, 0x22, 0x77, 0x88, 0x55, 0x66])
645
+
646
+
647
+ def test_read_asam_numeric_array_msb_last_msw_first_ulong():
648
+ sec = Section(data=bytearray([0x33, 0x44, 0x11, 0x22, 0x77, 0x88, 0x55, 0x66] + [0x00] * 8))
649
+ assert sec.read_asam_numeric_array(0, 2, "ULONG", byte_order="MSB_LAST_MSW_FIRST") == (0x11223344, 0x55667788)
650
+
651
+
652
+ def test_asam_numeric_array_signed_roundtrip():
653
+ sec = Section(data=bytearray(16))
654
+ sec.write_asam_numeric_array(0, [-1, -2, 3], "SWORD", byte_order="MSB_FIRST")
655
+ assert sec.data[:6] == bytearray([0xFF, 0xFF, 0xFF, 0xFE, 0x00, 0x03])
656
+ assert sec.read_asam_numeric_array(0, 3, "SWORD", byte_order="MSB_FIRST") == (-1, -2, 3)
657
+
658
+
641
659
  @pytest.mark.skipif("NUMPY_SUPPORT == False")
642
660
  def test_write_ndarray1():
643
661
  sec = Section(start_address=0x1000, data=bytearray(32))
@@ -819,3 +837,29 @@ def test_write_ndarray_fortan_02():
819
837
  assert sec.read(0x1000, 24) == bytearray(
820
838
  b"\x01\x00\x04\x00\x07\x00\n\x00\x02\x00\x05\x00\x08\x00\x0b\x00\x03\x00\x06\x00\t\x00\x0c\x00"
821
839
  )
840
+
841
+
842
+ @pytest.mark.skipif("NUMPY_SUPPORT == False")
843
+ def test_write_asam_ndarray_msb_last_msw_first_ulong():
844
+ sec = Section(start_address=0x1000, data=bytearray(32))
845
+ arr = np.array([0x11223344, 0x55667788], dtype=np.uint32)
846
+ sec.write_asam_ndarray(0x1000, arr, "ULONG", byte_order="MSB_LAST_MSW_FIRST")
847
+ assert sec.read(0x1000, 8) == bytearray([0x33, 0x44, 0x11, 0x22, 0x77, 0x88, 0x55, 0x66])
848
+
849
+
850
+ @pytest.mark.skipif("NUMPY_SUPPORT == False")
851
+ def test_read_asam_ndarray_msb_last_msw_first_ulong():
852
+ sec = Section(start_address=0x1000, data=bytearray([0x33, 0x44, 0x11, 0x22, 0x77, 0x88, 0x55, 0x66] + [0x00] * 24))
853
+ result = sec.read_asam_ndarray(0x1000, 8, "ULONG", shape=(2,), byte_order="MSB_LAST_MSW_FIRST")
854
+ assert np.array_equal(result, np.array([0x11223344, 0x55667788], dtype=np.uint32))
855
+
856
+
857
+ @pytest.mark.skipif("NUMPY_SUPPORT == False")
858
+ def test_asam_ndarray_fortran_roundtrip():
859
+ sec = Section(start_address=0x1000, data=bytearray(32))
860
+ arr = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.uint16)
861
+ sec.write_asam_ndarray(0x1000, arr, "UWORD", byte_order="MSB_FIRST_MSW_LAST", order="F")
862
+ assert sec.read(0x1000, 12) == bytearray(b"\x01\x00\x04\x00\x02\x00\x05\x00\x03\x00\x06\x00")
863
+ result = sec.read_asam_ndarray(0x1000, 12, "UWORD", shape=(3, 2), order="F", byte_order="MSB_FIRST_MSW_LAST")
864
+ assert np.array_equal(result, arr)
865
+
@@ -1,3 +1,3 @@
1
1
  """objutils version module"""
2
2
 
3
- __version__ = "0.10.1"
3
+ __version__ = "0.10.2"
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "objutils"
3
- version = "0.10.1"
3
+ version = "0.10.2"
4
4
  description = "Objectfile library for Python"
5
5
  authors = ["Christoph Schueler <cpu12.gems@googlemail.com>"]
6
6
  license = "GPLv2"
@@ -121,7 +121,7 @@ skip = ["*_i686", "*-musllinux*"]
121
121
  build-frontend = "build"
122
122
 
123
123
  [tool.bumpver]
124
- current_version = "0.10.1"
124
+ current_version = "0.10.2"
125
125
  version_pattern = "MAJOR.MINOR.PATCH"
126
126
  commit_message = "bump version {old_version} -> {new_version}"
127
127
  commit = true
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes