Skip to main content

netget/server/bluetooth_ble_data_stream/
mod.rs

1//! BLE Data Stream Service (custom GATT for real-time streaming)
2pub mod actions;
3use anyhow::Result;
4use std::sync::Arc;
5use tokio::sync::mpsc;
6
7pub struct BluetoothBleDataStream;
8impl BluetoothBleDataStream {
9    #[cfg(all(unix, feature = "bluetooth"))]
10    pub async fn spawn_with_llm_actions(
11        device_name: String,
12        llm: crate::llm::ollama_client::OllamaClient,
13        state: Arc<crate::state::app_state::AppState>,
14        tx: mpsc::UnboundedSender<String>,
15        id: crate::state::ServerId,
16        inst: String,
17    ) -> Result<std::net::SocketAddr> {
18        // The user's instruction leads and the profile sentence is appended to it; an empty
19        // instruction gets the sentence alone. This was `format!("{}. Configure as ...", inst)`,
20        // which put a stray leading period in front of the sentence when the instruction was
21        // empty and a doubled one after it when the instruction already ended in a full stop —
22        // in the prompt the model actually reads.
23        const SENTENCE: &str = "Configure as a BLE data streaming service with custom GATT \
24                                characteristics for real-time sensor data.";
25        let inst = inst.trim().trim_end_matches('.').trim();
26        let instruction = if inst.is_empty() {
27            SENTENCE.to_string()
28        } else {
29            format!("{inst}. {SENTENCE}")
30        };
31        crate::server::bluetooth_ble::BluetoothBle::spawn_with_llm_actions(
32            device_name,
33            llm,
34            state,
35            tx,
36            id,
37            instruction,
38        )
39        .await
40    }
41}
42#[cfg(any(all(unix, not(feature = "bluetooth")), not(unix)))]
43impl BluetoothBleDataStream {
44    pub async fn spawn_with_llm_actions(
45        _: String,
46        _: crate::llm::ollama_client::OllamaClient,
47        _: Arc<crate::state::app_state::AppState>,
48        _: mpsc::UnboundedSender<String>,
49        _: crate::state::ServerId,
50        _: String,
51    ) -> Result<std::net::SocketAddr> {
52        anyhow::bail!("BLE data-stream not enabled")
53    }
54}