mirror of
https://github.com/ratspeak/rsReticulum
synced 2026-11-27 13:52:16 +00:00
rnode: send detach sequence on BLE stop
This commit is contained in:
1 parent
8328393a5f
commit
4df2e6581f
2 files changed
+28
-5
No files matched your search
@@ -1074,10 +1074,10 @@ pub(crate) async fn ble_write(
|
||||
}
|
||||
|
||||
async fn ble_send_radio_off(conn: &BleRNodeConnection) {
|
||||
let seq = rnode::build_radio_off_sequence();
|
||||
let seq = rnode::build_detach_sequence();
|
||||
match ble_write(&conn.peripheral, &conn.rx_char, &seq, conn.write_mtu).await {
|
||||
Ok(()) => ble_diag("[ble] radio-off sent before disconnect"),
|
||||
Err(e) => ble_diag(format!("[ble] radio-off before disconnect failed: {e}")),
|
||||
Ok(()) => ble_diag("[ble] detach sent before disconnect"),
|
||||
Err(e) => ble_diag(format!("[ble] detach before disconnect failed: {e}")),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1602,7 +1602,7 @@ pub async fn spawn_ble_rnode_interface_native(
|
||||
}
|
||||
if !running_task.load(Ordering::SeqCst) {
|
||||
let _ = conn_tx_for_stop
|
||||
.send(NativeBridgeWrite::Raw(rnode::build_radio_off_sequence()))
|
||||
.send(NativeBridgeWrite::Raw(rnode::build_detach_sequence()))
|
||||
.await;
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
break 'read;
|
||||
@@ -1627,7 +1627,7 @@ pub async fn spawn_ble_rnode_interface_native(
|
||||
// shutdown flag cleared.
|
||||
if !running_task.load(Ordering::SeqCst) {
|
||||
let _ = conn_tx_for_stop
|
||||
.send(NativeBridgeWrite::Raw(rnode::build_radio_off_sequence()))
|
||||
.send(NativeBridgeWrite::Raw(rnode::build_detach_sequence()))
|
||||
.await;
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
break 'read;
|
||||
|
||||
@@ -566,6 +566,15 @@ pub fn build_radio_off_sequence() -> Vec<u8> {
|
||||
out
|
||||
}
|
||||
|
||||
/// KISS sequence matching upstream RNodeInterface.detach(): radio off, then
|
||||
/// leave host-controlled mode so device UI state is reset before disconnect.
|
||||
pub fn build_detach_sequence() -> Vec<u8> {
|
||||
let mut out = Vec::with_capacity(8);
|
||||
kiss::frame_with_command_into(CMD_RADIO_STATE, &[RADIO_STATE_OFF], &mut out);
|
||||
kiss::frame_with_command_into(CMD_LEAVE, &[0xFF], &mut out);
|
||||
out
|
||||
}
|
||||
|
||||
// Hot-path interface adapters pass this enum around directly; boxing the
|
||||
// packet variant would add allocation to every received frame.
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
@@ -993,6 +1002,20 @@ mod tests {
|
||||
assert_eq!(frames, vec![(CMD_RADIO_STATE, vec![RADIO_STATE_OFF])]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_detach_sequence() {
|
||||
let seq = build_detach_sequence();
|
||||
let mut deframer = kiss::RawKissDeframer::new();
|
||||
let frames = deframer.feed(&seq);
|
||||
assert_eq!(
|
||||
frames,
|
||||
vec![
|
||||
(CMD_RADIO_STATE, vec![RADIO_STATE_OFF]),
|
||||
(CMD_LEAVE, vec![0xFF]),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_airtime_sequence() {
|
||||
let mut cfg = RNodeConfig::new("rnode0", "/dev/ttyACM0");
|
||||
|
||||
Reference in new issue
Block a user