Skip to main content

CloudDecoder

Struct CloudDecoder 

Source
pub struct CloudDecoder { /* private fields */ }
Expand description

IDUN Cloud WebSocket client for server-side EEG packet decoding.

Manages the full lifecycle: connect → start recording → subscribe to live insights → send raw packets → receive decoded data → end recording.

Implementations§

Source§

impl CloudDecoder

Source

pub fn new(api_token: String, device_id: String) -> Self

Create a new cloud decoder.

§Arguments
  • api_token — IDUN API token (or set IDUN_API_TOKEN env var)
  • device_id — Guardian MAC address (format: "AA-BB-CC-DD-EE-FF")
Source

pub fn from_env(device_id: String) -> Result<Self>

Create a cloud decoder from the IDUN_API_TOKEN environment variable.

Returns Err if the env var is not set.

Source

pub async fn connect(&mut self) -> Result<()>

Connect to the IDUN Cloud WebSocket and start a recording session.

This method:

  1. Opens the WebSocket connection with authentication
  2. Spawns reader/writer tasks
  3. Sends startNewRecording
  4. Waits for the recording ID to be assigned
  5. Subscribes to FILTERED_EEG live stream insights
Source

pub async fn send_raw_packet( &mut self, raw_data: &[u8], device_ts: f64, sequence: u64, ) -> Result<()>

Send a raw BLE packet to the cloud for decoding.

The packet is base64-encoded and wrapped in a publishRawMeasurements message, matching the format used by the official Python SDK.

Returns Err if the WebSocket is not connected or the send fails.

Source

pub fn try_recv_decoded(&mut self) -> Result<Option<CloudDecodedEeg>>

Try to receive the next decoded EEG event from the cloud.

Returns Ok(None) if no data is available yet (non-blocking). Returns Ok(Some(decoded)) with the cloud-decoded data. Returns Err if the channel is closed (cloud disconnected).

Source

pub async fn recv_decoded(&mut self) -> Result<Option<CloudDecodedEeg>>

Receive the next decoded EEG event from the cloud (blocking).

Returns Ok(None) if the cloud disconnected.

Source

pub async fn disconnect(&mut self) -> Result<()>

End the recording session and close the WebSocket.

Source

pub fn is_connected(&self) -> bool

Check if the cloud session is active and ready to send/receive data.

Source

pub fn recording_id(&self) -> Option<&str>

Get the current recording ID, if a session is active.

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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