Class SifiBridge

Manages the sifibridge CLI process for communicating with SiFi BLE devices.

Inheritance
SifiBridge
Implements
Namespace: MOSAIC.Components.Devices.SiFi
Assembly: MOSAIC.dll
Syntax
public sealed class SifiBridge : IDisposable
Remarks

This class owns the process lifecycle: starting, sending commands via stdin, receiving responses via stdout/stderr, and terminating. It is used internally by MOSAIC.Components.Devices.SiFi and has no dependency on BaseBlock or any MOSAIC infrastructure — it is a pure process wrapper.

The bridge process is started lazily on the first call to EnsureRunning() and is killed on Dispose(). If the process exits unexpectedly, the Exited event is raised.

Constructors

SifiBridge(string)

Initializes a new SifiBridge wrapper.

Declaration
public SifiBridge(string bridgePath = "sifibridge")
Parameters
Type Name Description
string bridgePath

Path to the sifibridge executable. If just a filename (e.g. "sifibridge"), it must be on the system PATH.

Fields

_bridgePath

Declaration
private readonly string _bridgePath
Field Value
Type Description
string

_disposed

Declaration
private bool _disposed
Field Value
Type Description
bool

_process

Declaration
private Process? _process
Field Value
Type Description
Process

Properties

IsRunning

Whether the bridge process is currently running.

Declaration
public bool IsRunning { get; }
Property Value
Type Description
bool

Methods

Dispose()

Shuts down the bridge process and releases resources.

Declaration
public void Dispose()

EnsureRunning()

Ensures the bridge process is running. Starts it if not already running.

Declaration
public void EnsureRunning()
Exceptions
Type Condition
ObjectDisposedException

Thrown if the wrapper has been disposed.

SendAsync(string)

Sends a command string to the bridge's stdin.

Declaration
public Task SendAsync(string command)
Parameters
Type Name Description
string command

The CLI command to send (e.g. "connect AA:BB:CC:DD:EE:FF").

Returns
Type Description
Task

SendSync(string)

Sends a command synchronously. Use for shutdown sequences where async is impractical.

Declaration
public void SendSync(string command)
Parameters
Type Name Description
string command

The CLI command to send.

Shutdown(int)

Attempts a graceful shutdown: sends stop + disconnect, waits briefly, then kills if needed.

Declaration
public void Shutdown(int waitMs = 2000)
Parameters
Type Name Description
int waitMs

Maximum milliseconds to wait for the process to exit. Default: 2000.

Events

ErrorReceived

Raised for each line of stderr from the bridge.

Declaration
public event Action<string>? ErrorReceived
Event Type
Type Description
Action<string>

Exited

Raised when the bridge process exits (expected or unexpected).

Declaration
public event Action? Exited
Event Type
Type Description
Action

OutputReceived

Raised for each line of stdout from the bridge (JSON packets, status, etc.).

Declaration
public event Action<string>? OutputReceived
Event Type
Type Description
Action<string>

Implements

IDisposable

Search documentation

Start typing to search the documentation.