harp-protocol
The Harp Protocol is a binary communication protocol created to facilitate and unify the interaction between different devices. It was designed with efficiency and ease of parsing in mind.
For more detail please check the official Harp Tech documentation.
harp-protocol provides the building blocks: message framing and the typed register/payload DSL. Each register builds its frames with format and decodes them with parse.
import numpy as np
from harp.protocol import HarpMessage, RegisterU16
class WhoAmI(RegisterU16):
address = 0
frame = WhoAmI.format(np.uint16(1216)) # build a Write frame
value = WhoAmI.parse(HarpMessage.parse(frame)) # -> np.uint16(1216)
Register value types
parse returns numpy scalars rather than plain int or float, so a value carries the width its register declares. A Python int has no width and no upper bound, so it cannot distinguish a U8 from a U32, nor detect a value leaving the register range.
np.uint16(65535) + 1 # RuntimeWarning: overflow encountered in scalar add
65535 + 1 # 65536, wider than the register can hold
Numpy scalars behave like plain Python numbers in arithmetic, comparison, and formatting. Use int() or float() where a built-in type is required.
Read an address no schema describes
A register class is normally declared with its address, as above, or generated from a device.yml. Calling a register base with an address instead builds a one-off register for that address, which is how a payload outside any schema is read and written:
from harp.protocol import RegisterU8Array, RegisterU16
uid = RegisterU8Array(0x10, length=16) # R_UID, named by no schema
tag = RegisterU8Array(0x11, length=16) # R_TAG, the firmware git hash
version = RegisterU16(0x08) # any address, as a scalar
The result is an ordinary register, so it goes through read and write on a device exactly as a declared one does. length is keyword-only for the array form, and it is the element count rather than a byte count. An already-addressed register rejects the call, so WhoAmI(44) raises rather than quietly producing a register at another address.
It carries no transport or device logic. See harp-device for the device layer.
harp-protocol is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file harp_protocol-0.5.0.tar.gz.
File metadata
- Download URL: harp_protocol-0.5.0.tar.gz
- Upload date:
- Size: 29.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1109c82e4766ae579cec150da125540343dac9c33e8ac171b69f22b3485b1b75
|
|
| MD5 |
b1639ebeaa86baad39a2f158a08aaf39
|
|
| BLAKE2b-256 |
6d7d48e9ba2d0b8182966a1cc8bba573201ef5256c57b2a172c32e071f34a087
|
File details
Details for the file harp_protocol-0.5.0-py3-none-any.whl.
File metadata
- Download URL: harp_protocol-0.5.0-py3-none-any.whl
- Upload date:
- Size: 31.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f06d3c69e31c5a5ac5d530006ad003ebf5e552de5eed521a83fb85526d68a152
|
|
| MD5 |
5a1312bdd84893f4454ed9fd063371a7
|
|
| BLAKE2b-256 |
0e309c92a60a89fbc0360a456201931cfa8002e15c6cbb4a6b252e478eb3f834
|