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
impl CloudDecoder
Sourcepub fn new(api_token: String, device_id: String) -> Self
pub fn new(api_token: String, device_id: String) -> Self
Create a new cloud decoder.
§Arguments
api_token— IDUN API token (or setIDUN_API_TOKENenv var)device_id— Guardian MAC address (format:"AA-BB-CC-DD-EE-FF")
Sourcepub fn from_env(device_id: String) -> Result<Self>
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.
Sourcepub async fn connect(&mut self) -> Result<()>
pub async fn connect(&mut self) -> Result<()>
Connect to the IDUN Cloud WebSocket and start a recording session.
This method:
- Opens the WebSocket connection with authentication
- Spawns reader/writer tasks
- Sends
startNewRecording - Waits for the recording ID to be assigned
- Subscribes to
FILTERED_EEGlive stream insights
Sourcepub async fn send_raw_packet(
&mut self,
raw_data: &[u8],
device_ts: f64,
sequence: u64,
) -> Result<()>
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.
Sourcepub fn try_recv_decoded(&mut self) -> Result<Option<CloudDecodedEeg>>
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).
Sourcepub async fn recv_decoded(&mut self) -> Result<Option<CloudDecodedEeg>>
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.
Sourcepub async fn disconnect(&mut self) -> Result<()>
pub async fn disconnect(&mut self) -> Result<()>
End the recording session and close the WebSocket.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if the cloud session is active and ready to send/receive data.
Sourcepub fn recording_id(&self) -> Option<&str>
pub fn recording_id(&self) -> Option<&str>
Get the current recording ID, if a session is active.