pub struct AsyncLagerBox { /* private fields */ }Expand description
A connection to one Lager box, over async HTTP (reqwest/tokio).
use lager::AsyncLagerBox;
#[tokio::main]
async fn main() -> lager::Result<()> {
let lager = AsyncLagerBox::connect("192.168.1.42")?;
let supply = lager.supply("supply1");
supply.set_voltage(3.3).await?;
supply.enable().await?;
let v = lager.adc("vbat_sense").read().await?;
assert!((v - 3.3).abs() < 0.1);
supply.disable().await
}Implementations§
Source§impl AsyncLagerBox
impl AsyncLagerBox
Sourcepub fn connect(host: impl Into<String>) -> Result<Self>
pub fn connect(host: impl Into<String>) -> Result<Self>
Connect to a box by host name, IP, host:port, or full URL.
The port defaults to 9000 (the box HTTP server).
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Connect to the box named by the LAGER_BOX_HOST environment
variable.
Sourcepub fn builder(host: impl Into<String>) -> AsyncLagerBoxBuilder
pub fn builder(host: impl Into<String>) -> AsyncLagerBoxBuilder
Start building a client with non-default settings.
Sourcepub fn base_url(&self) -> &str
pub fn base_url(&self) -> &str
The base URL this client talks to, e.g. http://192.168.1.42:9000.
Sourcepub async fn nets(&self) -> Result<Vec<NetRecord>>
pub async fn nets(&self) -> Result<Vec<NetRecord>>
List every net configured on the box (full saved records).
Falls back to the older /uart/nets/list shape for box images that
predate /nets/list, like the Lager CLI does.
Sourcepub async fn status(&self) -> Result<BoxStatus>
pub async fn status(&self) -> Result<BoxStatus>
Box status: version, configured nets, and endpoint capabilities.
Sourcepub async fn usb_devices(&self) -> Result<Vec<UsbDeviceInfo>>
pub async fn usb_devices(&self) -> Result<Vec<UsbDeviceInfo>>
Enumerate USB devices on the box’s bus from sysfs (lsusb-like).
A few milliseconds per call with no exclusive device access, so it is safe to poll frequently — e.g. reading the DUT’s iSerial to see what it re-enumerated as after a hub power-cycle or DFU detach.
Requires box software >= 0.33.0; older boxes fail with
Error::UnsupportedByBox.
Sourcepub async fn usb_devices_matching(
&self,
filter: &UsbDeviceFilter,
) -> Result<Vec<UsbDeviceInfo>>
pub async fn usb_devices_matching( &self, filter: &UsbDeviceFilter, ) -> Result<Vec<UsbDeviceInfo>>
Like AsyncLagerBox::usb_devices, with box-side vid/pid/serial
filters.
Sourcepub async fn lock_status(&self) -> Result<BoxLock>
pub async fn lock_status(&self) -> Result<BoxLock>
Current box lock state (GET /lock); locked: false when free.
Sourcepub async fn lock(&self, user: &str) -> Result<BoxLock>
pub async fn lock(&self, user: &str) -> Result<BoxLock>
Claim the box for user (an eternal holder_type: "user" lock,
exactly like lager boxes lock). Re-acquiring your own lock
refreshes it; a box held by someone else fails with
Error::Box (HTTP 409) naming the holder.
Sourcepub async fn lock_with(
&self,
user: &str,
holder_type: &str,
ttl_seconds: Option<u64>,
) -> Result<BoxLock>
pub async fn lock_with( &self, user: &str, holder_type: &str, ttl_seconds: Option<u64>, ) -> Result<BoxLock>
Claim the box with an explicit holder type and TTL.
ttl_seconds: None means the lock never auto-expires; with a TTL,
keep the lock alive via AsyncLagerBox::lock_heartbeat.
Sourcepub async fn lock_heartbeat(&self, user: &str) -> Result<BoxLock>
pub async fn lock_heartbeat(&self, user: &str) -> Result<BoxLock>
Refresh a TTL lock’s heartbeat. Fails with Error::Box when the
box is not locked (HTTP 404) or held by someone else (HTTP 403).
Sourcepub async fn unlock(&self, user: &str) -> Result<()>
pub async fn unlock(&self, user: &str) -> Result<()>
Release user’s box lock. Releasing an already-unlocked box
succeeds; a box held by someone else fails with Error::Box
(HTTP 403).
Sourcepub async fn unlock_force(&self, user: &str) -> Result<()>
pub async fn unlock_force(&self, user: &str) -> Result<()>
Release the box lock even when held by another user
(lager boxes unlock --force).
Sourcepub async fn set_safety_limits(
&self,
name: &str,
limits: &SafetyLimits,
) -> Result<Option<SafetyLimits>>
pub async fn set_safety_limits( &self, name: &str, limits: &SafetyLimits, ) -> Result<Option<SafetyLimits>>
Set the safety limits on a saved net (PUT /nets/<name>/safety-limits,
box >= 0.35.0). Returns the limits the box applied.
The PUT replaces the net’s whole limits record: fields left None
in limits are removed from the net, not preserved. Read the current
limits first (AsyncLagerBox::safety_limits) if you mean to change
one ceiling and keep the rest. An all-None limits clears the
record, same as AsyncLagerBox::clear_safety_limits.
The ceilings are enforced by the box’s hardware service, out of reach
of test scripts; a setpoint (or inline ovp=/ocp= trip) above a
ceiling is refused before it touches the instrument. Older boxes fail
with Error::UnsupportedByBox; validation refusals (max_power,
non-positive ceilings) and an unknown net come back as Error::Box.
Sourcepub async fn clear_safety_limits(&self, name: &str) -> Result<()>
pub async fn clear_safety_limits(&self, name: &str) -> Result<()>
Remove a net’s safety limits, returning it to unrestricted.
Sourcepub async fn safety_limits(&self, name: &str) -> Result<Option<SafetyLimits>>
pub async fn safety_limits(&self, name: &str) -> Result<Option<SafetyLimits>>
Read the safety limits configured on a saved net, via /nets/list.
Ok(None) means the net exists and is unrestricted; a missing net is
an Error::Box with status 404.
Sourcepub fn supply(&self, name: impl Into<String>) -> AsyncSupply<'_>
pub fn supply(&self, name: impl Into<String>) -> AsyncSupply<'_>
Handle for a power-supply net.
Sourcepub fn battery(&self, name: impl Into<String>) -> AsyncBattery<'_>
pub fn battery(&self, name: impl Into<String>) -> AsyncBattery<'_>
Handle for a battery-simulator net.
Sourcepub fn eload(&self, name: impl Into<String>) -> AsyncEload<'_>
pub fn eload(&self, name: impl Into<String>) -> AsyncEload<'_>
Handle for an electronic-load net.
Sourcepub fn solar(&self, name: impl Into<String>) -> AsyncSolar<'_>
pub fn solar(&self, name: impl Into<String>) -> AsyncSolar<'_>
Handle for a solar-simulator net (EA PSB photovoltaic mode).
Sourcepub fn thermocouple(&self, name: impl Into<String>) -> AsyncThermocouple<'_>
pub fn thermocouple(&self, name: impl Into<String>) -> AsyncThermocouple<'_>
Handle for a thermocouple net.
Sourcepub fn watt_meter(&self, name: impl Into<String>) -> AsyncWattMeter<'_>
pub fn watt_meter(&self, name: impl Into<String>) -> AsyncWattMeter<'_>
Handle for a watt-meter net.
Sourcepub fn energy_analyzer(
&self,
name: impl Into<String>,
) -> AsyncEnergyAnalyzer<'_>
pub fn energy_analyzer( &self, name: impl Into<String>, ) -> AsyncEnergyAnalyzer<'_>
Handle for an energy-analyzer net.
Sourcepub fn usb(&self, name: impl Into<String>) -> AsyncUsbPort<'_>
pub fn usb(&self, name: impl Into<String>) -> AsyncUsbPort<'_>
Handle for a USB hub port net.
Sourcepub fn arm(&self, name: impl Into<String>) -> AsyncArm<'_>
pub fn arm(&self, name: impl Into<String>) -> AsyncArm<'_>
Handle for a robot-arm net (Rotrics Dexarm).
Sourcepub fn webcam(&self, name: impl Into<String>) -> AsyncWebcam<'_>
pub fn webcam(&self, name: impl Into<String>) -> AsyncWebcam<'_>
Handle for a webcam net (MJPEG streaming).
Sourcepub fn router(&self, name: impl Into<String>) -> AsyncRouter<'_>
pub fn router(&self, name: impl Into<String>) -> AsyncRouter<'_>
Handle for a router net (MikroTik RouterOS).
Sourcepub fn ble(&self) -> AsyncBle<'_>
pub fn ble(&self) -> AsyncBle<'_>
Handle for the box’s BLE adapter (box-level, not a saved net).
Sourcepub fn wifi(&self) -> AsyncWifi<'_>
pub fn wifi(&self) -> AsyncWifi<'_>
Handle for the box’s WiFi interface (box-level, not a saved net).
Sourcepub fn blufi(&self) -> AsyncBlufi<'_>
pub fn blufi(&self) -> AsyncBlufi<'_>
Handle for BluFi (ESP32 WiFi provisioning over BLE; box-level).
Sourcepub fn dfu(&self) -> AsyncDfu<'_>
pub fn dfu(&self) -> AsyncDfu<'_>
Handle for box-side DFU via dfu-util (box-level, not a saved net).
Sourcepub fn debug(&self, name: impl Into<String>) -> AsyncDebugNet<'_>
pub fn debug(&self, name: impl Into<String>) -> AsyncDebugNet<'_>
Handle for a debug-probe net (flash/erase/reset/read_memory). Talks to the box debug service on port 8765.