core — API Reference¶
The core package is the cortex runtime plus shared infrastructure. No
hardware dependencies — importable on any machine (hardware libs load lazily).
sensor_base¶
core.sensor_base.SensorBase(sensor_id, config)
¶
Bases: ABC
Abstract base class for all sensor plugins.
Subclasses implement the hardware-specific start/stop/read loop. Broadcasting to HTTP clients is handled here via Broadcaster — subclasses call self._broadcast(reading) after each successful reading.
Source code in core/sensor_base.py
analog_array¶
core.analog_array.AnalogArrayBase(sensor_id, config)
¶
Bases: SensorBase
Base for device-fed analog array sensors. Subclasses set sensor_type and
may override enrich().
Source code in core/analog_array.py
device_ids
property
¶
Device ids referenced by this sensor's channels.
enrich(data, raw)
¶
ingest(device_id, frame)
¶
Record a device's latest samples, compose + broadcast a reading.
Called from the device read thread (and directly in tests). Returns the composed reading.
Source code in core/analog_array.py
device¶
The base class, registry, and factory for devices. Concrete kinds
(McuSerialDevice, Ads1115Device, SaraR5Device, Si5351Device) live in the devices/
plugin tree, auto-discovered like sensors.
core.device.Device(device_id, config)
¶
Bases: ABC
Base class for shared peripherals.
Subclasses decorate with @register_device("kind") and implement the
lifecycle. Push devices (e.g. an MCU link, a modem's NMEA stream) fan decoded
data to subscribe*() callbacks; pull devices (e.g. an ADS1115) expose a read
method. Either way the device owns the transport — sensors and effectors bind
to it by id and never open the port themselves.
Source code in core/device.py
core.device.create_device(config)
¶
Instantiate a device from its config. Raises ValueError for unknown kinds.
The kind must be registered, which happens when its package under devices/
is imported. If a kind is missing, check that import devices ran and the
package's hardware deps are installed (failed imports are skipped, not fatal).
Source code in core/device.py
devices.mcu_serial¶
devices.mcu_serial.device.McuSerialDevice(device_id, config)
¶
Bases: Device
An MCU on a serial link: streams sample frames in, takes command frames out.
Source code in devices/mcu_serial/device.py
send_command(cmd_id, args=())
¶
Send a command frame to the MCU. Returns False if the link is down.
Source code in devices/mcu_serial/device.py
subscribe(callback)
¶
Register a callback invoked (in the read thread) for every decoded frame.
devices.ads1115¶
devices.ads1115.device.Ads1115Device(device_id, config)
¶
Bases: Device
An ADS1115 ADC chip on the SBC's I2C bus (pull model).
Source code in devices/ads1115/device.py
read_channel(channel, gain=1)
¶
Single-shot read of single-ended AINx. Returns signed counts, or None.
Source code in devices/ads1115/device.py
devices.sara_r5¶
devices.sara_r5.device.SaraR5Device(device_id, config)
¶
Bases: Device
u-blox SARA-R5 modem over UART.
DeviceConfig fields
port — UART device path, e.g. /dev/ttyS5 baud — baud rate (default 115200) params: power_line — core.gpio spec for the LTE power-enable pin (optional) reset_line — core.gpio spec for the reset pin (optional) init — list of AT commands sent on connect (default enables GNSS) power_on_delay_s / reset_settle_s — timing overrides (optional)
Source code in devices/sara_r5/device.py
reset_modem()
¶
Pulse the reset line low→high and wait for the modem to boot.
Source code in devices/sara_r5/device.py
send_at(cmd, timeout=5.0)
¶
Send an AT command; return the response lines (excluding the final OK/ERROR terminator). Thread-safe. Returns [] on timeout or a down link.
Source code in devices/sara_r5/device.py
subscribe_gnss(callback)
¶
Register a callback invoked (in the read thread) for each NMEA sentence.
devices.si5351¶
devices.si5351.device.Si5351Device(device_id, config)
¶
Bases: Device
Si5351A on I2C: program CLK0–CLK2 from params.clk_hz, then health-check.
Source code in devices/si5351/device.py
devices.si5351.device.plan_clock(target_hz, xtal_hz=_XTAL_HZ)
¶
Choose (fb_int, fb_num, fb_denom, out_div) for one output frequency.
out_div is the smallest even integer divider that puts the PLL in range; the feedback fraction then hits the PLL exactly enough for audio use (error < 1 Hz at 12.288 MHz). Raises ValueError when out of range.
Source code in devices/si5351/device.py
gpio¶
Portable digital output lines for devices that toggle SBC/MCU pins (libgpiod / mcu / null backends), so a device never hard-codes how a pin is driven.
core.gpio.make_output_line(spec, devices=None)
¶
Build an OutputLine from a spec dict.
Returns a NullOutputLine (never raises) when no pin is configured or the
backend can't be opened — failures are logged. backend defaults to
libgpiod; none/null force a no-op; mcu drives a pin through a
device's command sink and needs the devices registry passed in.
Source code in core/gpio.py
effector_base¶
The base class and registry for effectors. Full API — including concrete plugin
types (PwmEffector, FanArray, StreamSink) — is on the
effectors reference page.
core.effector_base.create_effector(config)
¶
policy¶
The base class, PolicyRuntime, and registry for policies. Full API — including
concrete plugin types (CurvePolicy) — is on the
policies reference page.
core.policy.create_policy(config)
¶
relay¶
core.relay.Relay(gate=None)
¶
Latest-value pub/sub keyed by dotted signal name, with an optional gate.
Source code in core/relay.py
publish_tree(prefix, data)
¶
Flatten a nested reading dict into dotted signal names and publish each.
Source code in core/relay.py
mcu_link¶
core.mcu_link.encode(samples, seq=0)
¶
Serialize one frame of int16 samples. Raises ValueError on >255 channels.
Source code in core/mcu_link.py
core.mcu_link.decode(frame)
¶
Decode one complete frame.
Returns None if the bytes are not exactly one well-formed frame (bad magic, unknown version, wrong length, or checksum mismatch).
Source code in core/mcu_link.py
core.mcu_link.FrameStream(max_buffer=4096)
¶
Stateful, resyncing decoder for a raw serial byte stream.
Feed it whatever bytes arrive; it returns complete, checksum-valid frames and keeps partial data buffered, resyncing on the magic marker after garbage or a corrupt frame. This is what the node-side read loop uses (the MCU emits a continuous stream with no external framing).
Source code in core/mcu_link.py
feed(data)
¶
Append bytes and return every complete frame now available.
Source code in core/mcu_link.py
core.mcu_link.encode_command(cmd_id, args=())
¶
Serialize a command frame (e.g. encode_command(CMD_SET_DUTY, [ch, duty])).
Source code in core/mcu_link.py
core.mcu_link.decode_command(frame)
¶
Decode one complete command frame, or None if malformed.
Source code in core/mcu_link.py
broadcaster¶
core.broadcaster.Broadcaster(maxsize=10)
¶
Queue-per-subscriber pub/sub utility.
Replaces the _clients / _clients_lock pattern duplicated across all sensor servers. SSE and WebSocket route handlers subscribe a queue when a client connects; the sensor's background thread calls broadcast() after each reading. Stale queues from disconnected clients are pruned automatically.
Source code in core/broadcaster.py
registry¶
core.registry.register(sensor_type)
¶
Class decorator that registers a SensorBase subclass under a type key.
Usage
@register("tf_mini") class TFminiSensor(SensorBase): ...
The key must match the type field used in config.yaml sensor entries.
Source code in core/registry.py
core.registry.create(config)
¶
Instantiate a sensor from its config. Raises ValueError for unknown types.
Source code in core/registry.py
core.registry.registered_types()
¶
models¶
core.models.SensorReading
¶
Bases: BaseModel
Standardized reading emitted by every sensor.
Standardized data keys per sensor type
tf_mini, lv_maxsonar, vl53l1x: distance_mm: int strength: int | None temp_c: float | None mlx90640: pixels: list[float] (768 values, row-major 32×24) min_temp: float max_temp: float width: int (32) height: int (24) ir_xcvr: protocol : str — "NEC" | "NECX" | "NEC32" | "RC5" | … | "PROTO_N" address : int — decoded device address command : int — decoded command byte scancode : int — raw kernel scancode (address << 8 | command for NEC) repeat : bool — True when this is a held-key repeat frame
core.models.SensorConfig
¶
Bases: BaseModel
Configuration for a single sensor instance on this node.
core.models.ConnectionConfig
¶
Bases: BaseModel
Hardware connection parameters for a sensor.
core.models.SensorChannel
¶
Bases: BaseModel
One channel of an array sensor — its source, meaning, and calibration.
Array sensors read a flat vector of raw values from one or more devices.
device is the device id this channel comes from (a logical sensor may span
several — e.g. cranial pressure across 4 MCUs); index is the position within
that device's frame; signal is the node-side name; calibration is applied
in Python. Authored consistently with the MCU's config/mcus/
core.models.DeviceConfig
¶
Bases: BaseModel
A shared peripheral on this node — an MCU link, an ADS1115 chip, etc.
A device owns its transport; sensors read through it and effectors write through it. Created at node startup and bound to sensors/effectors by id.
core.models.EffectorConfig
¶
Bases: BaseModel
An output device on this node (fans, LEDs, motors, …).
backend selects where it writes: {device:
core.models.PolicyConfig
¶
Bases: BaseModel
A control loop on this node. The behavior is code (a registered PolicyBase
subclass named by type); this only declares the wiring + params.
observation is a list of relay signal names (e.g. "gas_array.raw.mq135",
"board_temp.cpu_c"); action targets an effector ({effector: always_on marks a reflex that should keep running when cortical policies are
absent. Learned policies reference weights via params.
core.models.NodeConfig
¶
Bases: BaseModel
Complete per-board configuration loaded from config.yaml.
core.models.CameraConfig
¶
Bases: BaseModel
core.models.NetworkConfig
¶
Bases: BaseModel
config¶
core.config.load_node_config(path='config/config.yaml')
¶
Load and validate a per-board node configuration.
Used by the node agent at startup and by the fleet tool when reading
staging copies from config/boards/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to a board config YAML file. |
'config/config.yaml'
|
Returns:
| Type | Description |
|---|---|
NodeConfig
|
Validated NodeConfig instance. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
if the config file does not exist. |
ValidationError
|
if the config is malformed. |