|
6 | 6 |
|
7 | 7 | from harp.protocol import ( |
8 | 8 | AnonymousPayload, |
| 9 | + ArrayConverter, |
9 | 10 | BitMask, |
10 | 11 | BoolConverter, |
11 | 12 | Converter, |
@@ -109,9 +110,7 @@ class AnalogDataPayload(StructPayload[np.float32], length=6): |
109 | 110 | analog0: np.float32 = Field(IdentityConverter(np.float32), offset=0) |
110 | 111 | analog1: np.float32 = Field(IdentityConverter(np.float32), offset=1) |
111 | 112 | analog2: np.float32 = Field(IdentityConverter(np.float32), offset=2) |
112 | | - accelerometer: NDArray[np.float32] = Field( |
113 | | - IdentityConverter(np.dtype((np.float32, (3,)))), offset=3 |
114 | | - ) |
| 113 | + accelerometer: NDArray[np.float32] = Field(ArrayConverter(np.float32, 3), offset=3) |
115 | 114 |
|
116 | 115 |
|
117 | 116 | class AnalogData(RegisterBase[AnalogDataPayload]): |
@@ -149,9 +148,7 @@ class VersionPayload(StructPayload[np.uint8], length=32): |
149 | 148 | firmware_version: HarpVersion = Field(HarpVersionConverter(np.uint8), offset=3) |
150 | 149 | hardware_version: HarpVersion = Field(HarpVersionConverter(np.uint8), offset=6) |
151 | 150 | core_id: str = Field(StringConverter(3), offset=9) |
152 | | - interface_hash: NDArray[np.uint8] = Field( |
153 | | - IdentityConverter(np.dtype((np.uint8, (20,)))), offset=12 |
154 | | - ) |
| 151 | + interface_hash: NDArray[np.uint8] = Field(ArrayConverter(np.uint8, 20), offset=12) |
155 | 152 |
|
156 | 153 |
|
157 | 154 | class Version(RegisterBase[VersionPayload]): |
@@ -375,7 +372,7 @@ def main() -> None: # pragma: no cover - manual exploration entry point |
375 | 372 | assert int(p.header) == 7 and int(p.data) == -1234 |
376 | 373 | print("CustomMemberConverter OK") |
377 | 374 |
|
378 | | - p = _roundtrip(BitmaskSplitter, BitmaskSplitterPayload(low=0xA, high=0x5)) |
| 375 | + p = _roundtrip(BitmaskSplitter, BitmaskSplitterPayload(low=np.int32(0xA), high=np.int32(0x5))) |
379 | 376 | assert int(p.low) == 0xA and int(p.high) == 0x5 |
380 | 377 | assert p.payload_array.tobytes() == bytes([0x5A]) |
381 | 378 | print("BitmaskSplitter OK") |
@@ -411,7 +408,10 @@ def main() -> None: # pragma: no cover - manual exploration entry point |
411 | 408 | assert p.digital_output == PwmPort.PWM1 and int(p.pulse_width) == 300 |
412 | 409 | assert int(p.frequency) == 200 and int(p.pulse_count) == 50 |
413 | 410 | assert StartPulseTrainPayload.payload_dtype.itemsize == 4 |
414 | | - assert int(StartPulseTrainPayload(pulse_count=np.uint8(3)).frequency) == 1 # defaultValue |
| 411 | + partial = StartPulseTrainPayload( |
| 412 | + digital_output=PwmPort.PWM0, pulse_width=np.uint16(0), pulse_count=np.uint8(3) |
| 413 | + ) |
| 414 | + assert int(partial.frequency) == 1 # defaultValue |
415 | 415 | print("StartPulseTrain OK (4 masked members, 2 words, default frequency=1)") |
416 | 416 |
|
417 | 417 | p = _roundtrip(EncoderMode, EncoderModeMask.DISPLACEMENT) |
|
0 commit comments