pycyphal.application.heartbeat_publisher module
Publishes uavcan.node.Heartbeat periodically and provides a couple of basic auxiliary services;
see pycyphal.application.heartbeat_publisher.HeartbeatPublisher.
- pycyphal.application.heartbeat_publisher.handle_internal_error(logger: Logger, e: BaseException, msg: str = '', *args: object) None[source]
Report an internal error: log it via the provided logger and invoke the registered error handler.
- Parameters:
logger – The logger to use for
logger.exception.e – The exception to report.
msg – Optional context message describing where/why the error occurred. Defer any formatting for this functions, to also properly handle cases where you print something and its __repr__/__str__ raises an exception.
args – Optional arguments for the context message.
- class pycyphal.application.heartbeat_publisher.Health(value)[source]
Bases:
IntEnumMirrors the health enumeration defined in
uavcan.node.Heartbeat. When enumerations are natively supported in DSDL, this will be replaced with an alias.- NOMINAL = 0
- ADVISORY = 1
- CAUTION = 2
- WARNING = 3
- class pycyphal.application.heartbeat_publisher.Mode(value)[source]
Bases:
IntEnumMirrors the mode enumeration defined in
uavcan.node.Heartbeat. When enumerations are natively supported in DSDL, this will be replaced with an alias.- OPERATIONAL = 0
- INITIALIZATION = 1
- MAINTENANCE = 2
- SOFTWARE_UPDATE = 3
- class pycyphal.application.heartbeat_publisher.HeartbeatPublisher(node: Node)[source]
Bases:
objectThis class manages periodic publication of the node heartbeat message. Also it subscribes to heartbeat messages from other nodes and logs cautionary messages if a node-ID conflict is detected on the bus.
The default states are as follows:
Health is NOMINAL.
Mode is OPERATIONAL.
Vendor-specific status code is zero.
Period is MAX_PUBLICATION_PERIOD (see the DSDL definition).
Priority is default (i.e., NOMINAL).
- property uptime: float[source]
The current amount of time, in seconds, elapsed since the object was instantiated.
- property vendor_specific_status_code: int[source]
The vendor-specific status code (VSSC) value to report with Heartbeat.
- property period: float[source]
How often the Heartbeat messages should be published. The upper limit (i.e., the lowest frequency) is constrained by the Cyphal specification; please see the DSDL source of
uavcan.node.Heartbeat.
- property priority: Priority[source]
The transfer priority level to use when publishing Heartbeat messages.
- add_pre_heartbeat_handler(handler: Callable[[], None]) None[source]
Adds a new handler to be invoked immediately before a heartbeat message is published. The number of such handlers is unlimited. The handler invocation order follows the order of their registration. Handlers are invoked from a task running on the node’s event loop. Handlers are not invoked until the instance is started.
The handler can be used to synchronize the heartbeat message data (health, mode, vendor-specific status code) with external states. Observe that the handler will be invoked even if the heartbeat is not to be published, e.g., if the node is anonymous (does not have a node ID). If the handler throws an exception, it will be suppressed and logged. Note that the handler is to be not a coroutine but a regular function.
This is a good method of scheduling periodic status checks on the node.