Skip to main content

Python utility library for Lightweight Communications and Marshalling (LCM).

Project description

lcmutils

Python utility library for Lightweight Communications and Marshalling (LCM).

Installation

pip install lcmutils

Usage

Typing

lcmutils defines the LCMType protocol for LCM type classes generated via lcm-gen. You can use this protocol to type hint LCM type classes in your Python code.

from lcmutils import LCMType

def publish_lcm_message(lcm: LCM, message: LCMType) -> None:
    lcm.publish("channel", message.encode())

LCM Daemon

For many applications, it's desirable to run LCM handling in a background thread. lcmutils provides a LCMDaemon class that wraps an LCM instance and repeatedly calls its the handle method in a background thread.

from lcmutils import LCMDaemon

lcm = LCMDaemon()

@lcm.subscribe("channel1", "channel2")
def handle_message(channel: str, data: bytes) -> None:
    print(f"Received message {data} on channel {channel}")

lcm.start()
...
lcm.stop()  # will stop when the next message is handled

By default, the LCMDaemon instance will use the blocking LCM.handle method. If you want to use the LCM.handle_timeout method instead, you can pass a timeout_millis argument to the constructor. You can also pass a start argument to automatically start the daemon.

from lcmutils import LCMDaemon

# Use LCM.handle_timeout with a 100ms timeout and start the daemon
lcm = LCMDaemon(timeout_millis=100, start=True)
...
lcm.stop()  # will stop within 100ms

LCMDaemon can be passed an existing LCM instance to wrap, or it will create a new LCM instance if none is provided.

from lcm import LCM
from lcmutils import LCMDaemon

lcm = LCM("udpm://239.255.76.67:7667?ttl=1")  # create an LCM instance with ttl=1
lcm_daemon = LCMDaemon(lcm, start=True)
...
lcm_daemon.stop()

Type Registry

lcmutils provides an LCMTypeRegistry class that can be used to register and lookup LCM type classes by fingerprint.

from lcmutils import LCMTypeRegistry
from my_lcm_types import MyLCMType

registry = LCMTypeRegistry(MyLCMType)
# or:
#   registry = LCMTypeRegistry()
#   registry.register(MyLCMType)

msg = MyLCMType()
msg_encoded = msg.encode()

print(registry.detect(msg_encoded))         # MyLCMType
print(registry.decode(msg_encoded) == msg)  # True

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

lcmutils-0.1.1.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

lcmutils-0.1.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file lcmutils-0.1.1.tar.gz.

File metadata

  • Download URL: lcmutils-0.1.1.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for lcmutils-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f62b273ae3107d4f6e5893b33ca0eb025238b58d032b1b2ea8660a1302f0c960
MD5 dab827a48cc5576ec2782704bb03cc6d
BLAKE2b-256 be0f719c2fa06a642ff1adb33cd8a2f28f79d3229248f471060397a756242f07

See more details on using hashes here.

File details

Details for the file lcmutils-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: lcmutils-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for lcmutils-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 900f31e917e3caa265d20a12dfcb6a67465255008c3a5c669b1ac6a0bf569ffc
MD5 03da12fb457701e6742a89ba735a5b63
BLAKE2b-256 3e8372a890260d56cb409593b220ece939c597a7cb9443cc619704a33d7c8707

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