Skip to content

Commit

Permalink
Introduce team.toml (#1463)
Browse files Browse the repository at this point in the history
* introduce team.toml

* Require HULKs-OS 7.5.7

* update lock files

* update documentation

* adjust structs for hostnames

* parse toml not json

* renaming
  • Loading branch information
schmidma authored Oct 29, 2024
1 parent 40a65a4 commit 215fef1
Show file tree
Hide file tree
Showing 14 changed files with 408 additions and 248 deletions.
5 changes: 4 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/constants/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ homepage.workspace = true
[dependencies]
lazy_static = {workspace = true}
serde = {workspace = true}
serde_json = {workspace = true}
toml = {workspace = true}
29 changes: 18 additions & 11 deletions crates/constants/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(Debug, Serialize, Deserialize)]
pub struct HardwareId {
pub body_id: String,
pub head_id: String,
}

pub const HULA_DBUS_INTERFACE: &str = "org.hulks.hula";
pub const HULA_DBUS_PATH: &str = "/org/hulks/HuLA";
pub const HULA_DBUS_SERVICE: &str = "org.hulks.hula";
pub const HULA_SOCKET_PATH: &str = "/tmp/hula";
pub const OS_IS_NOT_LINUX: bool = !cfg!(target_os = "linux");
pub const OS_RELEASE_PATH: &str = "/etc/os-release";
pub const OS_VERSION: &str = "7.5.6";
pub const OS_VERSION: &str = "7.5.7";
pub const SDK_VERSION: &str = "7.5.0";

#[derive(Serialize, Deserialize)]
pub struct Team {
pub team_number: u8,
pub naos: Vec<Nao>,
}

#[derive(Serialize, Deserialize)]
pub struct Nao {
pub number: u8,
pub hostname: String,
pub body_id: String,
pub head_id: String,
}

lazy_static! {
pub static ref HARDWARE_IDS: HashMap<u8, HardwareId> = {
let content = include_str!("../../../etc/parameters/hardware_ids.json");
serde_json::from_str(content).unwrap()
pub static ref TEAM: Team = {
let content = include_str!("../../../etc/parameters/team.toml");
toml::from_str(content).unwrap()
};
}
31 changes: 10 additions & 21 deletions crates/repository/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use parameters::{
};
use semver::Version;
use serde::Deserialize;
use serde_json::{from_slice, from_str, to_string_pretty, to_value, Value};
use serde_json::{from_str, to_string_pretty, to_value, Value};
use tempfile::{tempdir, TempDir};
use tokio::{
fs::{
Expand All @@ -35,7 +35,7 @@ use tokio::{
process::Command,
};

use constants::{OS_IS_NOT_LINUX, SDK_VERSION};
use constants::{Team, OS_IS_NOT_LINUX, SDK_VERSION};
use spl_network_messages::PlayerNumber;
use types::hardware::Ids;

Expand Down Expand Up @@ -423,26 +423,15 @@ impl Repository {
Ok((upload_directory, hulk_directory))
}

pub async fn get_hardware_ids(&self) -> Result<HashMap<u8, Ids>> {
let hardware_ids_path = self.root.join("etc/parameters/hardware_ids.json");
let mut hardware_ids = File::open(&hardware_ids_path)
pub async fn get_configured_team(&self) -> Result<Team> {
let team_toml = self.root.join("etc/parameters/team.toml");
let mut team_file = File::open(&team_toml)
.await
.wrap_err_with(|| format!("failed to open {}", hardware_ids_path.display()))?;
let mut contents = vec![];
hardware_ids.read_to_end(&mut contents).await?;
let hardware_ids_with_string_keys: HashMap<String, Ids> = from_slice(&contents)?;
let hardware_ids_with_nao_number_keys = hardware_ids_with_string_keys
.into_iter()
.map(|(nao_number, hardware_ids)| {
Ok((
nao_number
.parse()
.wrap_err_with(|| format!("failed to parse NAO number: {nao_number:?}"))?,
hardware_ids,
))
})
.collect::<Result<HashMap<_, _>>>()?;
Ok(hardware_ids_with_nao_number_keys)
.wrap_err_with(|| format!("failed to open {}", team_toml.display()))?;
let mut contents = String::new();
team_file.read_to_string(&mut contents).await?;
let team: Team = toml::from_str(&contents).wrap_err("failed to parse team.toml")?;
Ok(team)
}

pub async fn get_configured_locations(&self) -> Result<BTreeMap<String, Option<String>>> {
Expand Down
2 changes: 1 addition & 1 deletion docs/setup/configure_team.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ The tooling around our framework expects each NAO robot to have a number associa
This number also determines the last octet of a robot's IP addresses.
For example robot number `21` will always have the IPv4 addresses `10.0.X.21` (wireless) and `10.1.X.21` (ethernet) where X is the team number.

For each robot you must determine it's head and body IDs and enter them in `etc/parameters/hardware_ids.json`.
For each robot you must determine it's head and body IDs and enter them in `etc/parameters/team.toml`.
This file is used by [pepsi](../tooling/pepsi.md) and other tools to find the hardware ids belonging to a robot number.
Loading

0 comments on commit 215fef1

Please sign in to comment.