jacdac.bus
Module Contents
Classes
A Jacdac bus that managed devices, service client, registers. |
|
Incoming pipe |
|
Out going packet pipe |
|
A Jacdac register client |
|
A server for the control service, used internally by the bus. |
|
A server for the unique brain service, used internally by the bus |
|
A server for the role manager service |
|
Base class to define service clients. |
|
A client for a sensor service |
|
A device on the bus |
|
Base class to define service clients. |
Functions
|
|
|
|
Attributes
- jacdac.bus.EV_CHANGE = 'change'
- jacdac.bus.EV_DEVICE_CONNECT = 'deviceConnect'
- jacdac.bus.EV_DEVICE_CHANGE = 'deviceChange'
- jacdac.bus.EV_DEVICE_ANNOUNCE = 'deviceAnnounce'
- jacdac.bus.EV_SELF_ANNOUNCE = 'selfAnnounce'
- jacdac.bus.EV_PACKET_PROCESS = 'packetProcess'
- jacdac.bus.EV_REPORT_RECEIVE = 'reportReceive'
- jacdac.bus.EV_REPORT_UPDATE = 'reportUpdate'
- jacdac.bus.EV_RESTART = 'restart'
- jacdac.bus.EV_PACKET_RECEIVE = 'packetReceive'
- jacdac.bus.EV_EVENT = 'packetEvent'
- jacdac.bus.EV_STATUS_EVENT = 'statusEvent'
- jacdac.bus.EV_IDENTIFY = 'identify'
- jacdac.bus.EV_CONNECTED = 'connected'
- jacdac.bus.EV_DISCONNECTED = 'disconnected'
- jacdac.bus.RegType
- jacdac.bus.HandlerFn
- jacdac.bus.EventHandlerFn
- jacdac.bus.UnsubscribeFn
- class jacdac.bus.EventEmitter(bus: Bus)
-
- _init_emitter()
- on(id: str, fn: HandlerFn) UnsubscribeFn
Subscribes an event to a handler. Returns a callback to unsubscribe.
- Args:
id (str): event identifier fn (HandlerFn): event callback
Returns: callback to unsubscribe
- once(id: str, fn: HandlerFn)
Subscribes an event to run once; then get unsubscribed
- Args:
id (str): event identifier fn (HandlerFn): event callback
- jacdac.bus.rand_u64()
- jacdac.bus.is_raspberrypi()
- class jacdac.bus.Bus(*, transports: jacdac.packet.Optional[List[jacdac.transport.Transport]] = None, device_id: jacdac.packet.Optional[str] = None, product_identifier: jacdac.packet.Optional[int] = None, firmware_version: jacdac.packet.Optional[str] = None, device_description: jacdac.packet.Optional[str] = None, disable_logger: bool = False, disable_role_manager: bool = False, disable_settings: bool = False, disable_brain: bool = False, disable_dev_tools: bool = False, spi: jacdac.packet.Optional[bool] = None, hf2_portname: jacdac.packet.Optional[str] = None, transport_cmd: jacdac.packet.Optional[str] = None, default_logger_min_priority: jacdac.packet.Optional[int] = None, storage_dir: jacdac.packet.Optional[str] = None, logger_name: jacdac.packet.Optional[str] = None)
Bases:
EventEmitter
A Jacdac bus that managed devices, service client, registers.
- _sender()
- _process_task()
- process_frame(sender: jacdac.transport.Transport, frame: bytes)
- force_jd_thread()
- force_non_jd_thread()
- debug_dump()
- _gc_devices()
- _queue_core(pkt: jacdac.packet.JDPacket)
- _send_core(pkt: jacdac.packet.JDPacket)
- clear_attach_cache()
- process_packet(pkt: jacdac.packet.JDPacket)
- class jacdac.bus.InPipe(bus: Bus)
Bases:
EventEmitter
Incoming pipe
- _close()
- close()
- meta(pkt: jacdac.packet.JDPacket)
- handle_packet(pkt: jacdac.packet.JDPacket)
- class jacdac.bus.OutPipe(bus: Bus, pkt: jacdac.packet.JDPacket)
Bases:
EventEmitter
Out going packet pipe
- property open
- close()
- class jacdac.bus.RawRegisterClient(client: Client, code: int, pack_format: jacdac.packet.Optional[str])
Bases:
EventEmitter
A Jacdac register client
- clear()
- values() jacdac.packet.Optional[jacdac.pack.PackTuple]
- set_values(*args: jacdac.pack.PackType)
- value(default_value: jacdac.packet.Any = None) jacdac.packet.Optional[jacdac.packet.Any]
Extracts the value of the first field.
- bool_value(default_value: jacdac.packet.Optional[bool] = None) jacdac.packet.Optional[bool]
Extracts the value of the first field as a boolean.
- float_value(default_value: jacdac.packet.Optional[float] = None, scale: int = 1) jacdac.packet.Optional[float]
- _query()
- refresh()
- handle_packet(pkt: jacdac.packet.JDPacket)
- class jacdac.bus.Server(bus: Bus, service_class: int, *, instance_name: str = None)
Bases:
EventEmitter
- status_code()
- handle_packet_outer(pkt: jacdac.packet.JDPacket)
- handle_packet(pkt: jacdac.packet.JDPacket)
- send_report(pkt: jacdac.packet.JDPacket)
- send_change_event()
- handle_status_code(pkt: jacdac.packet.JDPacket)
- handle_reg_u8(pkt: jacdac.packet.JDPacket, register: int, current: int)
- handle_reg_u32(pkt: jacdac.packet.JDPacket, register: int, current: int)
- handle_reg_i32(pkt: jacdac.packet.JDPacket, register: int, current: int)
- handle_reg(pkt: jacdac.packet.JDPacket, register: int, fmt: str, current: RegType) RegType
- _handle_instance_name(pkt: jacdac.packet.JDPacket)
- class jacdac.bus.SensorServer(bus: Bus, service_class: int, streaming_interval: int, *, instance_name: str = None, streaming_preferred_interval: int = None)
Bases:
Server
- abstract send_reading()
- _start_streaming()
- async _stream()
- handle_packet(pkt: jacdac.packet.JDPacket)
- _handle_streaming_samples(pkt: jacdac.packet.JDPacket)
- _handle_streaming_interval(pkt: jacdac.packet.JDPacket)
- _handle_streaming_preferred_interval(pkt: jacdac.packet.JDPacket)
- class jacdac.bus.ControlServer(bus: Bus)
Bases:
Server
A server for the control service, used internally by the bus.
- queue_announce()
- handle_packet(pkt: jacdac.packet.JDPacket)
- class jacdac.bus.LoggerServer(bus: Bus)
Bases:
Server
- handle_packet(pkt: jacdac.packet.JDPacket)
- class jacdac.bus.UniqueBrainServer(bus: Bus)
Bases:
Server
A server for the unique brain service, used internally by the bus
- class jacdac.bus.RoleBinding(role_manager: RoleManagerServer, role: str, service_class: int)
-
- select(devwrap: DeviceWrapper, service_idx: int)
- class jacdac.bus.ServerBindings(host: str)
-
- score_for(devwrap: DeviceWrapper, select: jacdac.packet.Optional[bool] = False)
candidate devices are ordered by [numBound, numPossible, device_id] where numBound is number of clients already bound to this device and numPossible is number of clients that can possibly be additionally bound
- class jacdac.bus.RoleManagerServer(bus: Bus)
Bases:
Server
A server for the role manager service
- handle_packet(pkt: jacdac.packet.JDPacket)
- handle_list_roles(pkt: jacdac.packet.JDPacket)
- handle_all_roles_allocated(pkt: jacdac.packet.JDPacket)
- handle_clear_all_roles(pkt: jacdac.packet.JDPacket)
- handle_set_role(pkt: jacdac.packet.JDPacket)
- _binding_hash()
- _check_changes()
- bind_roles()
- class jacdac.bus.Client(bus: Bus, service_class: int, pack_formats: Dict[int, str], role: str)
Bases:
EventEmitter
Base class to define service clients.
- handle_packet(pkt: jacdac.packet.JDPacket)
- handle_packet_outer(pkt: jacdac.packet.JDPacket)
- send_cmd(pkt: jacdac.packet.JDPacket)
Sends a command packet to the server
- _detach()
- on_connect(handler: EventHandlerFn) UnsubscribeFn
Registers an event handler when the client connects to a server
- Args:
handler (EventHandlerFn): function to run with client connects
- Returns:
UnsubscribeFn: function to call to unregister handler
- on_disconnect(handler: EventHandlerFn) UnsubscribeFn
Registers an event handler when the client disconnects from a server
- Args:
handler (EventHandlerFn): function to run with client connects
- Returns:
UnsubscribeFn: function to call to unregister handler
- class jacdac.bus.SensorClient(bus: Bus, service_class: int, pack_formats: Dict[int, str], role: str, *, preferred_interval: int = None)
Bases:
Client
A client for a sensor service
- class jacdac.bus.Device(bus: Bus, device_id: str, services: bytearray)
Bases:
EventEmitter
A device on the bus
- property ctrl_client
- property announce_flags
- property reset_count
- property packet_count
- property is_connected
- property short_id
- property num_service_classes
- debug_info()
- _destroy()
- process_packet(pkt: jacdac.packet.JDPacket)