2025-06-01 14:46:12 -05:00
|
|
|
use anyhow::Result;
|
|
|
|
|
use navka_common::navka::HidReport;
|
|
|
|
|
use navka_common::navka::relay_client::RelayClient;
|
|
|
|
|
use tokio::sync::mpsc;
|
|
|
|
|
use tokio_stream::wrappers::ReceiverStream;
|
|
|
|
|
use tonic::{Request, transport::Channel};
|
2025-06-01 13:31:22 -05:00
|
|
|
|
|
|
|
|
#[tokio::main]
|
2025-06-01 14:46:12 -05:00
|
|
|
async fn main() -> Result<()> {
|
|
|
|
|
// 1) connect to the navka-server gRPC endpoint
|
|
|
|
|
let channel = Channel::from_static("http://127.0.0.1:50051").connect().await?;
|
|
|
|
|
let mut client = RelayClient::new(channel);
|
|
|
|
|
|
|
|
|
|
// 2) create an mpsc channel that we can push HID reports into
|
|
|
|
|
let (tx_request, rx_request) = mpsc::channel::<HidReport>(32);
|
|
|
|
|
let outbound = ReceiverStream::new(rx_request);
|
|
|
|
|
|
|
|
|
|
// 3) start the bi-directional stream (note the REQUIRED argument)
|
|
|
|
|
let response = client.stream(Request::new(outbound)).await?;
|
|
|
|
|
let mut inbound = response.into_inner(); // Streaming<HidReport>
|
|
|
|
|
|
|
|
|
|
// 4) demo: send “press A”, wait 100 ms, send “release”
|
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
let press_a = HidReport { data: vec![0x00,0x00,0x04,0,0,0,0,0] };
|
|
|
|
|
let release = HidReport { data: vec![0x00; 8] };
|
2025-06-01 13:31:22 -05:00
|
|
|
|
2025-06-01 14:46:12 -05:00
|
|
|
tx_request.send(press_a).await.ok();
|
|
|
|
|
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
|
|
|
|
tx_request.send(release).await.ok();
|
|
|
|
|
});
|
2025-06-01 13:31:22 -05:00
|
|
|
|
2025-06-01 14:46:12 -05:00
|
|
|
// 5) print anything the server echoes back
|
|
|
|
|
while let Some(msg) = inbound.message().await? {
|
|
|
|
|
println!("🔄 got report from server: {:?}", msg.data);
|
2025-06-01 13:31:22 -05:00
|
|
|
}
|
2025-06-01 14:46:12 -05:00
|
|
|
Ok(())
|
2025-06-01 13:31:22 -05:00
|
|
|
}
|