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.1.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.1-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: yivo-2025.8.23.1.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.1.tar.gz
Algorithm Hash digest
SHA256 41ae7ec5f30a8ff4da6a40b30e1556395904169979bb902608ac1b2e1cbcdfa8
MD5 3d1f7a66bb3143b2d408509a6b5ecb87
BLAKE2b-256 0732492dba73598995f31d7072f9bf81dd97e837b5305990c9e9944b1084b5b2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: yivo-2025.8.23.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d187dd1eb3d4cb254681b3840c4861220e64d815369be081425b42f369402efb
MD5 c381a0dbc21eff52a3e782e62c5fe3fd
BLAKE2b-256 fd3d61a6298591b97b288b033ec417e887d6cf24af82f7d294f62d4320168047

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