Skip to main content

Message serialization

Project description

Yivo

Python GitHub

Trying to standardize the way I access sensors.

Python

from yivo import Yivo, MsgInfo

# make some messages we want to send/receive
A = namedtuple("A","x y")      # id = 1
B = namedtuple("B", "x y z t") # id = 2

msgdb = MsgInfo()
msgdb[1] = ("2f", A) # 2 floats
msgdb[2] = ("4f", B) # 4 floats

yivo = Yivo(msgdb)
pkt = yivo.pack(1, A(1.,2.))

id = 0
while id == 0:
    b = serial_read() # get a byte from somewhere
    id = yivo.parse(b) # 0 or msg_id

err, msg = yivo.unpack() # err > 0 if failure to unpack

API

Part In Checksum Type Description
Header uint8_t[2] default $K
Size x uint16_t 0-65,535 bytes, stored as [L,H] => `(H << 8)
Type x uint8_t 255 message IDs, 0 is not allowed as an ID
Data x uint8_t[Size] payload data array
Checksum uint8_t XOR of size, type, and data bytes
0 1 2 3 4 ... -1
$ K L H T ... checksum

gentools

Generate messages for python and C/C++.

Type Bytes Format Python C/C++
uint8 1 B int uint8_t
uint16 2 H int uint16_t
uint32 4 I int uint32_t
uint64 8 Q int uint64_t
int8 1 b int int8_t
int16 2 h int int16_t
int32 4 i int int32_t
int64 8 q int int64_t
float 4 f float float
double 8 d float double
# comment ...
# comment ...

float     a # comment about var
uint8     b
int16[12] c

<enum something uint16_t
bob=0
tom=2
jerry=32
enum>
{
    "namespace": "foobar",
    "license": "MIT Kevin Walchko (c) 2023",
    "output": "test",
    "1": "messages/vec.yivo",
    "2": "messages/quat.yivo",
    "4": "messages/imu.yivo",
    "5": "messages/cal.yivo"
}

MIT License

Copyright (c) 2020 Mom's Friendly Robot Company

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yivo-2025.8.23.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yivo-2025.8.23.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file yivo-2025.8.23.0.tar.gz.

File metadata

  • Download URL: yivo-2025.8.23.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.4 Darwin/24.6.0

File hashes

Hashes for yivo-2025.8.23.0.tar.gz
Algorithm Hash digest
SHA256 2f42d5dd2affc95c56abc490e6c5a4d0f2d2580f550f895d93277cc9158daf6f
MD5 35eebe99aee430762b7c5285a46b4a29
BLAKE2b-256 88bfa75d228b3d722b016aa8e5a64348a9b3c361dbff2276d9cfc65a2e901f93

See more details on using hashes here.

File details

Details for the file yivo-2025.8.23.0-py3-none-any.whl.

File metadata

  • Download URL: yivo-2025.8.23.0-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.4 Darwin/24.6.0

File hashes

Hashes for yivo-2025.8.23.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c1e8b54de7897776101e90823db65bb01e364c5835fb36347cff18f871ad9e9
MD5 a763c30cf1ee77a152339a3fc503ce08
BLAKE2b-256 23b9b8d89ac986e012f3842978aa2fe04f51bb13a0ff6d7fe1509a1ab4b46545

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page