Skip to main content

LagerBox

Struct LagerBox 

Source
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

Source

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).

Source

pub fn from_env() -> Result<Self>

Connect to the box named by the LAGER_BOX_HOST environment variable.

Source

pub fn builder(host: impl Into<String>) -> LagerBoxBuilder

Start building a client with non-default settings.

Source

pub fn base_url(&self) -> &str

The base URL this client talks to, e.g. http://192.168.1.42:9000.

Source

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.

Source

pub fn health(&self) -> Result<Health>

Check that the box HTTP server is up.

Source

pub fn status(&self) -> Result<BoxStatus>

Box status: version, configured nets, and endpoint capabilities.

Source

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.

Source

pub fn usb_devices_matching( &self, filter: &UsbDeviceFilter, ) -> Result<Vec<UsbDeviceInfo>>

Like LagerBox::usb_devices, with box-side vid/pid/serial filters.

Source

pub fn lock_status(&self) -> Result<BoxLock>

Current box lock state (GET /lock); locked: false when free.

Source

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.

Source

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.

Source

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).

Source

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).

Source

pub fn unlock_force(&self, user: &str) -> Result<()>

Release the box lock even when held by another user (lager boxes unlock --force).

Source

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).

Source

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.

Source

pub fn clear_safety_limits(&self, name: &str) -> Result<()>

Remove a net’s safety limits, returning it to unrestricted.

Source

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.

Source

pub fn supply(&self, name: impl Into<String>) -> Supply<'_>

Handle for a power-supply net.

Source

pub fn battery(&self, name: impl Into<String>) -> Battery<'_>

Handle for a battery-simulator net.

Source

pub fn eload(&self, name: impl Into<String>) -> Eload<'_>

Handle for an electronic-load net.

Source

pub fn solar(&self, name: impl Into<String>) -> Solar<'_>

Handle for a solar-simulator net (EA PSB photovoltaic mode).

Source

pub fn gpio(&self, name: impl Into<String>) -> Gpio<'_>

Handle for a GPIO net.

Source

pub fn adc(&self, name: impl Into<String>) -> Adc<'_>

Handle for an ADC net.

Source

pub fn dac(&self, name: impl Into<String>) -> Dac<'_>

Handle for a DAC net.

Source

pub fn thermocouple(&self, name: impl Into<String>) -> Thermocouple<'_>

Handle for a thermocouple net.

Source

pub fn watt_meter(&self, name: impl Into<String>) -> WattMeter<'_>

Handle for a watt-meter net.

Source

pub fn energy_analyzer(&self, name: impl Into<String>) -> EnergyAnalyzer<'_>

Handle for an energy-analyzer net.

Source

pub fn spi(&self, name: impl Into<String>) -> Spi<'_>

Handle for an SPI bus net.

Source

pub fn i2c(&self, name: impl Into<String>) -> I2c<'_>

Handle for an I2C bus net.

Source

pub fn usb(&self, name: impl Into<String>) -> UsbPort<'_>

Handle for a USB hub port net.

Source

pub fn arm(&self, name: impl Into<String>) -> Arm<'_>

Handle for a robot-arm net (Rotrics Dexarm).

Source

pub fn webcam(&self, name: impl Into<String>) -> Webcam<'_>

Handle for a webcam net (MJPEG streaming).

Source

pub fn router(&self, name: impl Into<String>) -> Router<'_>

Handle for a router net (MikroTik RouterOS).

Source

pub fn ble(&self) -> Ble<'_>

Handle for the box’s BLE adapter (box-level, not a saved net).

Source

pub fn wifi(&self) -> Wifi<'_>

Handle for the box’s WiFi interface (box-level, not a saved net).

Source

pub fn blufi(&self) -> Blufi<'_>

Handle for BluFi (ESP32 WiFi provisioning over BLE; box-level).

Source

pub fn dfu(&self) -> Dfu<'_>

Handle for box-side DFU via dfu-util (box-level, not a saved net).

Source

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.

Source

pub fn scope(&self, name: impl Into<String>) -> Scope

Handle for an oscilloscope net. Stub: see Scope.

Source

pub fn uart(&self, name: impl Into<String>) -> Result<Uart>

Open a streaming UART session on a UART net.

Connects a Socket.IO session to the box’s /uart namespace and starts streaming. Only one session per net (box-enforced).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more