Compare commits

...

3 Commits

Author SHA1 Message Date
occheung 5dc9ec5a08 mqtt_client: rm debug 2020-09-23 10:44:38 +08:00
occheung f1376cab07 mqtt_mux: fixed singletone parameter bug 2020-09-23 10:41:54 +08:00
occheung 39969e602c nix: rm aranche-pnr, add mosquitto 2020-09-23 10:40:55 +08:00
3 changed files with 19 additions and 37 deletions

View File

@ -129,10 +129,15 @@ fn main() -> ! {
let neighbor_cache = net::iface::NeighborCache::new(&mut store.neighbor_cache[..]); let neighbor_cache = net::iface::NeighborCache::new(&mut store.neighbor_cache[..]);
let mut routes = net::iface::Routes::new(&mut store.routes_cache[..]);
let default_v4_gw = net::wire::Ipv4Address::new(192, 168, 1, 1);
routes.add_default_ipv4_route(default_v4_gw).unwrap();
let mut net_interface = net::iface::EthernetInterfaceBuilder::new(eth_dma) let mut net_interface = net::iface::EthernetInterfaceBuilder::new(eth_dma)
.ethernet_addr(mac_addr) .ethernet_addr(mac_addr)
.neighbor_cache(neighbor_cache) .neighbor_cache(neighbor_cache)
.ip_addrs(&mut store.ip_addrs[..]) .ip_addrs(&mut store.ip_addrs[..])
.routes(routes)
.finalize(); .finalize();
/* /*
@ -173,9 +178,7 @@ fn main() -> ! {
cp.SCB.invalidate_icache(); cp.SCB.invalidate_icache();
cp.SCB.enable_icache(); cp.SCB.enable_icache();
// TODO: Remove this simple test
let mut mqtt_mux = MqttMux::new(urukul); let mut mqtt_mux = MqttMux::new(urukul);
info!("{:?}", mqtt_mux.handle_command("Urukul/Control/Channel0/Switch", "on".as_bytes()));
// Time unit in ms // Time unit in ms
let mut time: u32 = 0; let mut time: u32 = 0;
@ -220,16 +223,14 @@ fn main() -> ! {
} }
let connection = client let connection = client
.poll(|_client, topic, message, _properties| match topic { .poll(|_client, topic, message, _properties| {
topic => { info!("On '{:?}', received: {:?}", topic, message);
info!("On '{:?}', received: {:?}", topic, message); // Why is topic a string while message is a slice?
// Why is topic a string while message is a slice? mqtt_mux.process_mqtt(topic, message);
mqtt_mux.handle_command(topic, message).unwrap();
},
}).is_ok(); }).is_ok();
if connection && !has_subscribed && tick { if connection && !has_subscribed && tick {
match client.subscribe("Urukul/Control", &[]) { match client.subscribe("Urukul/Control/#", &[]) {
Ok(()) => has_subscribed = true, Ok(()) => has_subscribed = true,
Err(minimq::Error::NotReady) => {}, Err(minimq::Error::NotReady) => {},
e => warn!("{:?}", e), e => warn!("{:?}", e),

View File

@ -71,9 +71,9 @@ in
(pkgs.python3.withPackages(ps: [ migen ])) (pkgs.python3.withPackages(ps: [ migen ]))
pkgs.yosys pkgs.yosys
pkgs.nextpnr pkgs.nextpnr
pkgs.arachne-pnr
pkgs.icestorm pkgs.icestorm
pkgs.gdb pkgs.gdb
pkgs.mosquitto
openocd openocd
rustc rustc
cargo cargo

View File

@ -70,35 +70,13 @@ impl<SPI, E> MqttMux<SPI> where SPI: Transfer<u8, Error = E> {
pub fn process_mqtt(&mut self, topic: &str, message: &[u8]) -> Result<(), Error<E>> { pub fn process_mqtt(&mut self, topic: &str, message: &[u8]) -> Result<(), Error<E>> {
let header = self.parse_topic(topic) let header = self.parse_topic(topic)
.map_err(|_| Error::MqttTopicError)?; .map_err(|_| Error::MqttTopicError)?;
info!("{:?}", header); info!("Parsed command topic: {:?}", header);
let (_, command) = self.parse_message(header, message) let (_, command) = self.parse_message(header, message)
.map_err(|_| Error::MqttCommandError)?; .map_err(|_| Error::MqttCommandError)?;
info!("{:?}", command); info!("Parsed comamnd message: {:?}", command);
self.execute(command) self.execute(command)
} }
/*
fn parse_header<'a>(&mut self, topic: &'a str) -> IResult<&'a str, MqttTopic> {
preceded(
alt((
tag("Urukul/Control/"),
tag("/Urukul/Control/")
)),
alt((
switch,
attenuation,
clock,
clock_source,
clock_frequency,
clock_division,
singletone,
singletone_frequency,
singletone_amplitude,
singletone_phase,
profile
))
)(topic)
}
*/
fn parse_topic<'a>(&mut self, topic: &'a str) -> Result<MqttTopic, Error<E>> { fn parse_topic<'a>(&mut self, topic: &'a str) -> Result<MqttTopic, Error<E>> {
let mut assigned_channel = false; let mut assigned_channel = false;
let mut assigned_profile = false; let mut assigned_profile = false;
@ -423,6 +401,8 @@ fn clock_division_message(message: &[u8]) -> IResult<&[u8], MqttCommand> {
} }
// Parser for one-command master clock setup message // Parser for one-command master clock setup message
// Possible improvements: Chop off redundant braces and quotes
// Allow optional parameters/permutation of parameters
fn clock_message(message: &[u8]) -> IResult<&[u8], MqttCommand> { fn clock_message(message: &[u8]) -> IResult<&[u8], MqttCommand> {
all_consuming( all_consuming(
map( map(
@ -533,7 +513,8 @@ fn singletone_phase_message(channel: u8, profile: u8, message: &[u8]) -> IResult
// Parser for one-command singletone profile Command // Parser for one-command singletone profile Command
// Using JSON like command structure // Using JSON like command structure
// Possible enhancement: further modularize parsing of all separate fields // Possible improvements: Chop off redundant braces and quotes
// Allow optional parameters/permutation of parameters
fn singletone_message(channel: u8, profile: u8, message: &[u8]) -> IResult<&[u8], MqttCommand> { fn singletone_message(channel: u8, profile: u8, message: &[u8]) -> IResult<&[u8], MqttCommand> {
all_consuming( all_consuming(
map( map(
@ -592,7 +573,7 @@ fn singletone_message(channel: u8, profile: u8, message: &[u8]) -> IResult<&[u8]
) )
) )
)), )),
|(freq, ampl, phase): (f64, f64, f64)| MqttCommand::Singletone(channel, profile, freq, ampl, phase) |(freq, ampl, phase): (f64, f64, f64)| MqttCommand::Singletone(channel, profile, freq, phase, ampl)
) )
)(message) )(message)
} }