pub struct LagerBox { /* private fields */ }Expand description
A connection to one Lager box, over blocking HTTP.
Cheap to construct: no network traffic happens until the first call.
Net handles borrow the client, so a typical test creates one LagerBox
and any number of handles from it.
use lager::LagerBox;
fn main() -> lager::Result<()> {
let lager = LagerBox::connect("192.168.1.42")?;
let supply = lager.supply("supply1");
supply.set_voltage(3.3)?;
supply.enable()?;
let v = lager.adc("vbat_sense").read()?;
assert!((v - 3.3).abs() < 0.1);
supply.disable()
}Implementations§
Source§impl LagerBox
impl LagerBox
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>) -> LagerBoxBuilder
pub fn builder(host: impl Into<String>) -> LagerBoxBuilder
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 fn nets(&self) -> Result<Vec<NetRecord>>
pub 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 fn status(&self) -> Result<BoxStatus>
pub fn status(&self) -> Result<BoxStatus>
Box status: version, configured nets, and endpoint capabilities.
Sourcepub fn usb_devices(&self) -> Result<Vec<UsbDeviceInfo>>
pub 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 fn usb_devices_matching(
&self,
filter: &UsbDeviceFilter,
) -> Result<Vec<UsbDeviceInfo>>
pub fn usb_devices_matching( &self, filter: &UsbDeviceFilter, ) -> Result<Vec<UsbDeviceInfo>>
Like LagerBox::usb_devices, with box-side vid/pid/serial
filters.
Sourcepub fn lock_status(&self) -> Result<BoxLock>
pub fn lock_status(&self) -> Result<BoxLock>
Current box lock state (GET /lock); locked: false when free.
Sourcepub fn lock(&self, user: &str) -> Result<BoxLock>
pub 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 fn lock_with(
&self,
user: &str,
holder_type: &str,
ttl_seconds: Option<u64>,
) -> Result<BoxLock>
pub 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 LagerBox::lock_heartbeat.
Sourcepub fn lock_heartbeat(&self, user: &str) -> Result<BoxLock>
pub 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 fn unlock(&self, user: &str) -> Result<()>
pub 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 fn unlock_force(&self, user: &str) -> Result<()>
pub fn unlock_force(&self, user: &str) -> Result<()>
Release the box lock even when held by another user
(lager boxes unlock --force).
Sourcepub fn lock_guard(&self, user: impl Into<String>) -> Result<BoxLockGuard<'_>>
pub fn lock_guard(&self, user: impl Into<String>) -> Result<BoxLockGuard<'_>>
Claim the box for user and release the claim when the returned
guard drops (best-effort; call BoxLockGuard::unlock to surface
release errors).
Sourcepub fn set_safety_limits(
&self,
name: &str,
limits: &SafetyLimits,
) -> Result<Option<SafetyLimits>>
pub 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 (LagerBox::safety_limits) if you mean to change one
ceiling and keep the rest. An all-None limits clears the record,
same as LagerBox::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 fn clear_safety_limits(&self, name: &str) -> Result<()>
pub fn clear_safety_limits(&self, name: &str) -> Result<()>
Remove a net’s safety limits, returning it to unrestricted.
Sourcepub fn safety_limits(&self, name: &str) -> Result<Option<SafetyLimits>>
pub 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 battery(&self, name: impl Into<String>) -> Battery<'_>
pub fn battery(&self, name: impl Into<String>) -> Battery<'_>
Handle for a battery-simulator net.
Sourcepub fn solar(&self, name: impl Into<String>) -> Solar<'_>
pub fn solar(&self, name: impl Into<String>) -> Solar<'_>
Handle for a solar-simulator net (EA PSB photovoltaic mode).
Sourcepub fn thermocouple(&self, name: impl Into<String>) -> Thermocouple<'_>
pub fn thermocouple(&self, name: impl Into<String>) -> Thermocouple<'_>
Handle for a thermocouple net.
Sourcepub fn watt_meter(&self, name: impl Into<String>) -> WattMeter<'_>
pub fn watt_meter(&self, name: impl Into<String>) -> WattMeter<'_>
Handle for a watt-meter net.
Sourcepub fn energy_analyzer(&self, name: impl Into<String>) -> EnergyAnalyzer<'_>
pub fn energy_analyzer(&self, name: impl Into<String>) -> EnergyAnalyzer<'_>
Handle for an energy-analyzer net.
Sourcepub fn arm(&self, name: impl Into<String>) -> Arm<'_>
pub fn arm(&self, name: impl Into<String>) -> Arm<'_>
Handle for a robot-arm net (Rotrics Dexarm).
Sourcepub fn webcam(&self, name: impl Into<String>) -> Webcam<'_>
pub fn webcam(&self, name: impl Into<String>) -> Webcam<'_>
Handle for a webcam net (MJPEG streaming).
Sourcepub fn router(&self, name: impl Into<String>) -> Router<'_>
pub fn router(&self, name: impl Into<String>) -> Router<'_>
Handle for a router net (MikroTik RouterOS).
Sourcepub fn wifi(&self) -> Wifi<'_>
pub fn wifi(&self) -> Wifi<'_>
Handle for the box’s WiFi interface (box-level, not a saved net).
Sourcepub fn blufi(&self) -> Blufi<'_>
pub fn blufi(&self) -> Blufi<'_>
Handle for BluFi (ESP32 WiFi provisioning over BLE; box-level).
Sourcepub fn dfu(&self) -> Dfu<'_>
pub fn dfu(&self) -> Dfu<'_>
Handle for box-side DFU via dfu-util (box-level, not a saved net).
Sourcepub fn debug(&self, name: impl Into<String>) -> DebugNet<'_>
pub fn debug(&self, name: impl Into<String>) -> DebugNet<'_>
Handle for a debug-probe net (flash/erase/reset/read_memory/RTT). Talks to the box debug service on port 8765.