1use color_eyre::Result;
2use thiserror::Error;
3
4pub fn find_rio_with_number(team_number: u16) -> Result<String> {
5 let (first, second) = {
8 let stringified = team_number.to_string();
9 let first: String = stringified.chars().take(2).collect();
10 let second: String = stringified.chars().skip(2).collect();
11 (first, second)
12 };
13
14 let mut possible_addresses = vec![
15 "172.22.11.2".to_string(),
16 format!("roborio-{team_number}-FRC.local"),
17 format!("10.{first}.{second}.2"),
18 ]
19 .into_iter();
20
21 let address: Option<String> = loop {
22 match possible_addresses.next() {
23 Some(address) => {
24 break Some(address);
30 }
31 None => break None,
32 };
33 };
34
35 address.ok_or(RemoteError::RIONotFound.try_into()?)
36}
37
38#[derive(Error, Debug)]
39pub enum RemoteError {
40 #[error("could not find a connected RIO")]
41 RIONotFound,
42}