humpback-dds/src/config.rs
2021-01-29 16:47:28 +08:00

94 lines
2.2 KiB
Rust

use smoltcp as net;
use net::wire::IpCidr;
use net::wire::EthernetAddress;
use embedded_nal as nal;
use nal::IpAddr;
use heapless::{ String, consts::* };
use serde::{ Serialize, Deserialize };
use crate::urukul::ClockSource;
use crate::flash_store::FlashStore;
use core::str::FromStr;
#[derive(Debug)]
pub struct NetConfig {
pub ip_cidr: IpCidr,
pub eth_addr: EthernetAddress,
pub broker_ip: IpAddr,
pub name: String<U64>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct UrukulConfig {
pub clk_src: ClockSource,
pub clk_freq: f64,
pub clk_div: u8,
pub profile: u8,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ChannelConfig {
pub sw: bool,
pub att: f32,
pub sys_clk: f64,
pub freq: f64,
pub asf: f64,
pub profile: ProfileSetup,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SingleTone {
pub freq: f64,
pub phase: f64,
pub asf: f64,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RAM {
pub start: u16,
pub end: u16,
pub stride: u16,
pub op_mode: u8,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum ProfileSetup {
Singletone(SingleTone),
RAM(RAM),
}
pub fn get_net_config(store: &mut FlashStore) -> NetConfig {
let net_config = NetConfig {
ip_cidr: {
match store.read_str("CIDR").unwrap() {
Some(cidr) => IpCidr::from_str(cidr).unwrap(),
None => IpCidr::from_str("192.168.1.200/24").unwrap(),
}
},
eth_addr: {
match store.read_str("MAC").unwrap() {
Some(mac) => EthernetAddress::from_str(mac).unwrap(),
None => EthernetAddress::from_str("AC:6F:7A:DE:D6:C8").unwrap()
}
},
broker_ip: {
match store.read_str("BrokerIP").unwrap() {
Some(ip) => IpAddr::from_str(ip).unwrap(),
None => IpAddr::from_str("192.168.1.125").unwrap(),
}
},
name: {
match store.read_str("Name").unwrap() {
Some(name) => String::from(name),
None => String::from("HumpbackDDS")
}
}
};
log::info!("Net config: {:?}", net_config);
net_config
}