Skip to content

Commit

Permalink
Move DNT_TEAM_NUMBER to constant crate (#84)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Honkoop <[email protected]>
  • Loading branch information
Fyor and Aemulation authored Jun 22, 2023
1 parent b240d59 commit 29be852
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 16 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pub const HULA_SOCKET_PATH: &str = "/tmp/hula";
pub const OS_RELEASE_PATH: &str = "/etc/os-release";
pub const OS_VERSION: &str = "5.7.1";
pub const SDK_VERSION: &str = "5.7.0";
pub const DNT_TEAM_NUMBER: u8 = 8;
1 change: 1 addition & 0 deletions crates/spl_network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ homepage = "https://github.com/hulks/hulk"

[dependencies]
color-eyre = { workspace = true }
constants = { workspace = true }
context_attribute = { workspace = true }
framework = { workspace = true }
log = { workspace = true }
Expand Down
9 changes: 6 additions & 3 deletions crates/spl_network/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use thiserror::Error;
use tokio::{net::UdpSocket, select, sync::Mutex};
use types::messages::{IncomingMessage, OutgoingMessage};

use constants::DNT_TEAM_NUMBER;

const SPL_PORT: u16 = 10000 + (DNT_TEAM_NUMBER as u16);

pub struct Endpoint {
ports: Ports,
game_controller_state_socket: UdpSocket,
Expand All @@ -34,7 +38,7 @@ impl Endpoint {
))
.await
.map_err(Error::CannotBind)?;
let spl_socket = UdpSocket::bind(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, parameters.spl))
let spl_socket = UdpSocket::bind(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, SPL_PORT))
.await
.map_err(Error::CannotBind)?;
spl_socket
Expand Down Expand Up @@ -111,7 +115,7 @@ impl Endpoint {
.spl_socket
.send_to(
message.as_slice(),
SocketAddr::new(Ipv4Addr::BROADCAST.into(), self.ports.spl),
SocketAddr::new(Ipv4Addr::BROADCAST.into(), SPL_PORT),
)
.await
{
Expand All @@ -126,5 +130,4 @@ impl Endpoint {
pub struct Ports {
game_controller_state: u16,
game_controller_return: u16,
spl: u16,
}
1 change: 1 addition & 0 deletions crates/spl_network_messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ approx = { workspace = true }
bifrost = { workspace = true }
byteorder = { workspace = true }
color-eyre = { workspace = true }
constants = { workspace = true }
nalgebra = { workspace = true }
serde = { workspace = true }
serialize_hierarchy = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::time::Duration;

use color_eyre::{Report, Result};
use constants::DNT_TEAM_NUMBER;
use nalgebra::{point, vector, Isometry2};
use serde::{Deserialize, Serialize};

use crate::{BallPosition, PlayerNumber, DNT_TEAM_NUMBER};
use crate::{BallPosition, PlayerNumber};

use bifrost::{
communication::RoboCupGameControlReturnData,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use color_eyre::{Report, Result};
use constants::DNT_TEAM_NUMBER;
use serde::{Deserialize, Serialize};
use serialize_hierarchy::SerializeHierarchy;
use std::time::Duration;

use crate::DNT_TEAM_NUMBER;

use bifrost::{
communication::{
CompetitionPhase as BifrostCompetitionPhase, CompetitionType as BifrostCompetitionType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ use std::{
};

use color_eyre::{eyre::bail, Report, Result};
use constants::DNT_TEAM_NUMBER;
use serde::{Deserialize, Serialize};
use serialize_hierarchy::SerializeHierarchy;

use crate::{
CompetitionPhase, CompetitionType, GamePhase, GameState, Half, PenaltyShoot, Player, SubState,
Team, TeamColor, TeamState, DNT_TEAM_NUMBER,
Team, TeamColor, TeamState,
};
use bifrost::{communication::RoboCupGameControlData, serialization::Decode};

Expand Down
2 changes: 0 additions & 2 deletions crates/spl_network_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ pub struct BallPosition {
pub age: Duration,
}

pub const DNT_TEAM_NUMBER: u8 = 8;

use bifrost::serialization::{Decode, Encode};

#[derive(
Expand Down
3 changes: 2 additions & 1 deletion crates/spl_network_messages/src/spl_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use std::{
};

use color_eyre::{eyre::bail, Report, Result};
use constants::DNT_TEAM_NUMBER;
use nalgebra::{point, vector, Isometry2};
use serde::{Deserialize, Serialize};
use serialize_hierarchy::SerializeHierarchy;

use crate::{BallPosition, PlayerNumber, DNT_TEAM_NUMBER};
use crate::{BallPosition, PlayerNumber};

use bifrost::communication::SPLStandardMessage;

Expand Down
3 changes: 1 addition & 2 deletions etc/configuration/hardware.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
},
"spl_network_ports": {
"game_controller_state": 3838,
"game_controller_return": 3939,
"spl": 10024
"game_controller_return": 3939
},
"camera_top": {
"width": 640,
Expand Down
5 changes: 3 additions & 2 deletions tools/pepsi/src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use color_eyre::{
eyre::{bail, eyre, WrapErr},
Report, Result,
};
use constants::DNT_TEAM_NUMBER;
use regex::Regex;

use nao::{Network, SystemctlAction};
Expand Down Expand Up @@ -100,7 +101,7 @@ pub fn number_to_ip(nao_number: u8, connection: Connection) -> Result<Ipv4Addr>
Connection::Wireless => 0,
Connection::Wired => 1,
};
Ok(Ipv4Addr::new(10, subnet, 8, nao_number))
Ok(Ipv4Addr::new(10, subnet, DNT_TEAM_NUMBER, nao_number))
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -130,7 +131,7 @@ impl TryFrom<NaoAddress> for NaoNumber {
fn try_from(nao_address: NaoAddress) -> Result<Self> {
if nao_address.ip.octets()[0] != 10
|| (nao_address.ip.octets()[1] != 0 && nao_address.ip.octets()[1] != 1)
|| nao_address.ip.octets()[2] != 8
|| nao_address.ip.octets()[2] != DNT_TEAM_NUMBER
{
bail!("failed to extract NAO number from IP {nao_address}");
}
Expand Down
1 change: 1 addition & 0 deletions tools/twix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ homepage = "https://github.com/hulks/hulk"
bincode = { workspace = true }
color-eyre = { workspace = true }
communication = { workspace = true }
constants = { workspace = true }
convert_case = { workspace = true }
eframe = { workspace = true }
egui_dock = { workspace = true }
Expand Down
7 changes: 5 additions & 2 deletions tools/twix/src/completion_edit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{iter::once, ops::Range};

use communication::messages::Fields;
use constants::DNT_TEAM_NUMBER;
use eframe::egui::{
text::CCursor, text_edit::CCursorRange, Area, Context, Frame, Id, Key, Modifiers, Order,
Response, ScrollArea, TextEdit, Ui, Widget,
Expand Down Expand Up @@ -41,8 +42,10 @@ impl<'key> CompletionEdit<'key> {
pub fn addresses(key: &'key mut String, numbers: Range<u8>) -> Self {
let completion_items = chain!(
once("localhost".to_string()),
numbers.clone().map(|number| format!("10.1.8.{number}")),
numbers.map(|number| format!("10.0.8.{number}"))
numbers
.clone()
.map(|number| format!("10.1.{DNT_TEAM_NUMBER}.{number}")),
numbers.map(|number| format!("10.0.{DNT_TEAM_NUMBER}.{number}"))
)
.collect();

Expand Down

0 comments on commit 29be852

Please sign in to comment.