RadioInterfaceService

Interface for the low-level radio interface that handles raw byte communication.

This is the transport layer — it manages the raw hardware connection (BLE, TCP, Serial, USB) to a Meshtastic radio. Its connectionState reflects whether the physical link is up or down, before any handshake or config-loading logic is applied.

Important: UI and feature modules should never observe connectionState directly. Instead, they should use ServiceRepository.connectionState, which is the canonical app-level connection state that accounts for handshake progress, light-sleep policy, and other higher-level concerns. The only legitimate consumer of this transport-level flow is MeshConnectionManager, which bridges transport state changes into the app-level ServiceRepository.connectionState.

See also

Properties

Link copied to clipboard
abstract val connectionError: SharedFlow<String>

Flow of user-facing connection error messages (e.g. permission failures).

Link copied to clipboard
abstract val connectionState: StateFlow<ConnectionState>

Transport-level connection state of the radio hardware.

Link copied to clipboard
abstract val currentDeviceAddressFlow: StateFlow<String?>

Flow of the current device address.

Link copied to clipboard
abstract val meshActivity: SharedFlow<MeshActivity>

Flow of radio activity events.

Link copied to clipboard
abstract val receivedData: Flow<ByteArray>

Flow of raw data received from the radio.

Link copied to clipboard
abstract val serviceScope: CoroutineScope

The scope in which interface-related coroutines should run.

Link copied to clipboard

The device types supported by this platform's radio interface.

Functions

Link copied to clipboard
abstract fun connect()

Initiates the connection to the radio.

Link copied to clipboard
abstract suspend fun disconnect()

Explicitly tears down the active transport, sending a polite ToRadio(disconnect = true) goodbye frame first when a transport is live. Safe to call when nothing is connected — implementations must no-op in that case. Suspends until the teardown completes.

Link copied to clipboard
abstract fun getDeviceAddress(): String?

Returns the current device address.

Link copied to clipboard
abstract fun handleFromRadio(bytes: ByteArray)

Called when the transport has received raw data from the radio.

Link copied to clipboard
abstract fun isMockTransport(): Boolean

Whether we are currently using a mock transport.

Link copied to clipboard
abstract fun onConnect()

Called when the transport has successfully established a connection.

Link copied to clipboard
abstract fun onDisconnect(isPermanent: Boolean, errorMessage: String? = null)

Called when the transport has disconnected.

Link copied to clipboard
abstract fun resetReceivedBuffer()

Drains any bytes currently buffered in receivedData without emitting them to collectors.

Link copied to clipboard
abstract fun sendToRadio(bytes: ByteArray)

Sends a raw byte array to the radio.

Link copied to clipboard
abstract fun setDeviceAddress(deviceAddr: String?): Boolean

Sets the device address to connect to.

Link copied to clipboard
abstract fun toInterfaceAddress(interfaceId: InterfaceId, rest: String): String

Constructs a full radio address for the specific interface type.