This commit is contained in:
Brad Stein 2025-06-06 00:04:55 -05:00
parent 4237c90c65
commit 32a86353db
4 changed files with 18 additions and 3 deletions

View File

@ -7,12 +7,16 @@ use tokio::{sync::mpsc, time::sleep};
use tokio_stream::wrappers::ReceiverStream;
use tonic::{transport::Channel, Request};
tracing_subscriber::fmt::init();
tracing::info!(bytes=?data, len=%data.len(), "HID report received");
#[tokio::main]
async fn main() -> Result<()> {
// -- server address comes from CLI arg, env or falls back to localhost
let addr = std::env::args()
.nth(1)
.or_else(|| std::env::var("NAVKA_SERVER_ADDR").ok())
.or_else(|| std::env::var("NAVKA_SERVER_ADDR")
.or_else(|_| std::env::var("LAUNCHER_NAVKA_SERVER_ADDR")).ok())
.unwrap_or_else(|| "http://127.0.0.1:50051".to_owned());
let channel: Channel = Channel::from_shared(addr)?

View File

@ -39,10 +39,13 @@ sudo install -Dm755 "$SRC_DIR/scripts/navka-core.sh" /usr/local/bin
cat <<'UNIT' | sudo tee /etc/systemd/system/navka-core.service >/dev/null
[Unit]
Description=Navka USB gadget bring-up
After=sys-kernel-config.mount
Requires=sys-kernel-config.mount
[Service]
Type=oneshot
ExecStart=/usr/local/bin/navka-core.sh
RemainAfterExit=yes
CapabilityBoundingSet=CAP_SYS_ADMIN
[Install]
WantedBy=multi-user.target
UNIT
@ -61,4 +64,5 @@ UNIT
sudo systemctl daemon-reload
sudo systemctl enable --now navka-core.service navka-server.service
sudo systemctl restart navka-core.service navka-server.service
echo "✅ navka-server installed and running."

View File

@ -2,7 +2,7 @@
# Proven Pi-5 configfs gadget: HID keyboard+mouse + stereo UAC2
set -euo pipefail
modprobe libcomposite
mountpoint -q /sys/kernel/config || mount -t configfs configfs /sys/kernel/config
# mountpoint -q /sys/kernel/config || mount -t configfs configfs /sys/kernel/config
G=/sys/kernel/config/usb_gadget/navka
if [[ -d $G ]]; then

View File

@ -13,6 +13,9 @@ use navka_common::navka::{
HidReport,
};
tracing_subscriber::fmt::init();
tracing::info!(bytes=?data, len=%data.len(), "HID report received");
struct Handler {
/// shared async handle to /dev/hidg0
hid: Arc<tokio::sync::Mutex<tokio::fs::File>>,
@ -37,7 +40,9 @@ impl Relay for Handler {
while let Some(msg) = in_stream.next().await.transpose()? {
// 1) write to /dev/hidg0
let mut file = hid.lock().await;
file.write_all(&msg.data).await.map_err(|e| Status::internal(e.to_string()))?;
let data = &msg.data[..8];
file.write_all(data).await
.map_err(|e| Status::internal(e.to_string()))?;
file.flush().await.ok();
// 2) structured log (shows hex + length)
@ -60,6 +65,8 @@ async fn main() -> anyhow::Result<()> {
let file = OpenOptions::new()
.write(true)
.read(true)
.custom_flags(libc::O_NONBLOCK)
.open("/dev/hidg0")
.await?;
let hid = Arc::new(tokio::sync::Mutex::new(file));