Addressing review feedback

master
Ryan Summers 2021-05-10 10:57:50 +02:00
parent 60b1b112b1
commit fcda2d5bd1
2 changed files with 10 additions and 40 deletions

View File

@ -22,6 +22,8 @@ use super::{
pub struct NetStorage {
pub ip_addrs: [smoltcp::wire::IpCidr; 1],
// Note: There is an additional socket set item required for the DHCP socket.
pub sockets:
[Option<smoltcp::socket::SocketSetItem<'static>>; NUM_SOCKETS + 1],
pub socket_storage: [SocketStorage; NUM_SOCKETS],
@ -38,15 +40,15 @@ pub struct NetStorage {
#[derive(Copy, Clone)]
pub struct SocketStorage {
rx_storage: [u8; 4096],
tx_storage: [u8; 4096],
rx_storage: [u8; 1024],
tx_storage: [u8; 1024],
}
impl SocketStorage {
const fn new() -> Self {
Self {
rx_storage: [0; 4096],
tx_storage: [0; 4096],
rx_storage: [0; 1024],
tx_storage: [0; 1024],
}
}
}
@ -167,8 +169,8 @@ pub fn setup(
system_timer::SystemTimer::initialize(tim15);
}
let mut delay = asm_delay::AsmDelay::new(asm_delay::bitrate::MegaHertz(
ccdr.clocks.c_ck().0 / 1_000_000,
let mut delay = asm_delay::AsmDelay::new(asm_delay::bitrate::Hertz(
ccdr.clocks.c_ck().0,
));
let gpioa = device.GPIOA.split(ccdr.peripheral.GPIOA);

View File

@ -126,24 +126,8 @@ fn get_client_id(
client: &str,
mac: smoltcp_nal::smoltcp::wire::EthernetAddress,
) -> String<consts::U64> {
let mac_string = {
let mut mac_string: String<consts::U32> = String::new();
let mac = mac.as_bytes();
// Note(unwrap): 32-bytes is guaranteed to be valid for any mac address, as the address has
// a fixed length.
write!(
&mut mac_string,
"{:02x}-{:02x}-{:02x}-{:02x}-{:02x}-{:02x}",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
)
.unwrap();
mac_string
};
let mut identifier = String::new();
write!(&mut identifier, "{}-{}-{}", app, mac_string, client).unwrap();
write!(&mut identifier, "{}-{}-{}", app, mac, client).unwrap();
identifier
}
@ -159,26 +143,10 @@ pub fn get_device_prefix(
app: &str,
mac: smoltcp_nal::smoltcp::wire::EthernetAddress,
) -> String<consts::U128> {
let mac_string = {
let mut mac_string: String<consts::U32> = String::new();
let mac = mac.as_bytes();
// Note(unwrap): 32-bytes is guaranteed to be valid for any mac address, as the address has
// a fixed length.
write!(
&mut mac_string,
"{:02x}-{:02x}-{:02x}-{:02x}-{:02x}-{:02x}",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
)
.unwrap();
mac_string
};
// Note(unwrap): The mac address + binary name must be short enough to fit into this string. If
// they are defined too long, this will panic and the device will fail to boot.
let mut prefix: String<consts::U128> = String::new();
write!(&mut prefix, "dt/sinara/{}/{}", app, mac_string).unwrap();
write!(&mut prefix, "dt/sinara/{}/{}", app, mac).unwrap();
prefix
}