Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions packet-sender/RANDOM_FEATURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Random Packet Generation Feature

The packet-sender now supports sending random packets from all boards when no specific board is specified.

## Usage

### Command Line

```bash
# Send random packets from all boards at default rate (100 pps)
packet-sender random

# Send random packets from all boards at specific rate
packet-sender random --rate 200

# Send random packets from a specific board (existing behavior)
packet-sender random --board LCU --rate 150
```

### Interactive Mode

```bash
# Start interactive mode
packet-sender interactive

# In the interactive prompt:
> random # Random from all boards at 100 pps
> random 200 # Random from all boards at 200 pps
> random LCU # Random from LCU board at 100 pps
> random LCU 150 # Random from LCU board at 150 pps
```

## How it Works

When no board is specified, the packet-sender will:
1. Randomly select a board from all available boards
2. Generate a random data packet from that board
3. Send the packet with appropriate random values for all measurements
4. Repeat the process at the specified rate

This simulates a more realistic scenario where packets arrive from different boards in an unpredictable order.
41 changes: 31 additions & 10 deletions packet-sender/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,42 @@ impl InteractiveMode {
}
}
"random" | "r" => {
if parts.len() >= 2 {
let rate = parts.get(2)
.and_then(|s| s.parse().ok())
.unwrap_or(100);

if parts.len() == 1 {
// No board specified - random from all boards
let rate = 100;
let mut sender = self.sender.clone();
let board = parts[1].to_string();

println!("Starting random generation for {} at {} pps (Ctrl+C to stop)", board, rate);
println!("Starting random generation from all boards at {} pps (Ctrl+C to stop)", rate);

task::spawn(async move {
let _ = sender.start_random_single(&board, rate).await;
let _ = sender.start_random_all(rate).await;
});
} else {
println!("Usage: random <board_name> [rate]");
// Check if first argument is a number (rate) or board name
if let Ok(rate) = parts[1].parse::<u32>() {
// First argument is rate - random from all boards
let mut sender = self.sender.clone();

println!("Starting random generation from all boards at {} pps (Ctrl+C to stop)", rate);

task::spawn(async move {
let _ = sender.start_random_all(rate).await;
});
} else {
// First argument is board name
let rate = parts.get(2)
.and_then(|s| s.parse().ok())
.unwrap_or(100);

let mut sender = self.sender.clone();
let board = parts[1].to_string();

println!("Starting random generation for {} at {} pps (Ctrl+C to stop)", board, rate);

task::spawn(async move {
let _ = sender.start_random_single(&board, rate).await;
});
}
}
}
"simulate" | "sim" => {
Expand Down Expand Up @@ -104,7 +125,7 @@ impl InteractiveMode {
println!(" list, l - List all boards");
println!(" board, b <name> - Show board information");
println!(" send, s <board> <id> - Send a specific packet");
println!(" random, r <board> [rate] - Start random packet generation");
println!(" random, r [board] [rate] - Start random packet generation (all boards if none specified)");
println!(" simulate <board> <mode> - Start simulation (modes: random, sine, sequence)");
println!(" quit, q, exit - Exit the program");
}
Expand Down
6 changes: 5 additions & 1 deletion packet-sender/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use tokio::net::UdpSocket;
use tokio::sync::Mutex;
use tokio::time::{interval, Duration};
use tracing::{debug, error, info, trace};
use rand::Rng;

mod macos;
mod sender;
Expand Down Expand Up @@ -95,7 +96,10 @@ impl NetworkManager {
}

// Select random board
let idx = rand::random::<usize>() % sockets.len();
let idx = {
let mut rng = rand::thread_rng();
rng.gen_range(0..sockets.len())
};
let board_socket = &sockets[idx];

// Generate random packet
Expand Down