diff --git a/README.md b/README.md index 9fd5df1..084a1d0 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,17 @@ Find the path to your `riscv32-esp-elf-gcc` binary within the `.embuild` dir: `cargo build --features pingpong` +### flash test + +`espflash target/riscv32imc-esp-espidf/debug/sphinx-key` + ### build release `cargo build --release` -### flash +### flash release -`espflash target/riscv32imc-esp-espidf/debug/sphinx-key` +`espflash target/riscv32imc-esp-espidf/release/sphinx-key` ### monitor diff --git a/sphinx-key/src/core/events.rs b/sphinx-key/src/core/events.rs index 0e9f0f9..75b1064 100644 --- a/sphinx-key/src/core/events.rs +++ b/sphinx-key/src/core/events.rs @@ -9,7 +9,6 @@ use embedded_svc::mqtt::client::utils::ConnState; use embedded_svc::mqtt::client::{MessageImpl, Publish}; use esp_idf_svc::mqtt::client::*; use esp_idf_sys::EspError; -use log::*; pub enum Event { Connected, @@ -18,27 +17,29 @@ pub enum Event { } #[cfg(not(feature = "pingpong"))] -pub fn make_event_loop(mut mqtt: EspMqttClient>, rx: mpsc::Receiver) -> Result<()> { +pub fn make_event_loop(mut mqtt: EspMqttClient>, rx: mpsc::Receiver, do_log: bool) -> Result<()> { // initialize the RootHandler - let root_handler = while let Ok(event) = rx.recv() { - if let Event::Message(msg_bytes) = event { - let InitResponse { root_handler, init_reply } = sphinx_key_signer::init(event.clone()).expect("failed to init signer"); - mqtt.publish(RETURN_TOPIC, QOS, false, init_reply).expect("could not publish init response"); - break root_handler + let root_handler = loop { + if let Ok(event) = rx.recv() { + if let Event::Message(msg_bytes) = event { + let InitResponse { root_handler, init_reply } = sphinx_key_signer::init(msg_bytes).expect("failed to init signer"); + mqtt.publish(RETURN_TOPIC, QOS, false, init_reply).expect("could not publish init response"); + break root_handler + } } }; // signing loop let dummy_peer = PubKey([0; 33]); - while let Ok(msg_bytes) = rx.recv() { + while let Ok(event) = rx.recv() { match event { Event::Connected => { log::info!("SUBSCRIBE TO {}", TOPIC); mqtt.subscribe(TOPIC, QOS).expect("could not MQTT subscribe"); }, Event::Message(ref msg_bytes) => { - let _ret = match sphinx_key_signer::handle(&root_handler, msg_bytes.clone(), dummy_peer.clone()) { + let _ret = match sphinx_key_signer::handle(&root_handler, msg_bytes.clone(), dummy_peer.clone(), do_log) { Ok(b) => mqtt.publish(RETURN_TOPIC, QOS, false, b).expect("could not publish init response"), Err(e) => panic!("HANDLE FAILED {:?}", e), }; @@ -53,7 +54,7 @@ pub fn make_event_loop(mut mqtt: EspMqttClient> } #[cfg(feature = "pingpong")] -pub fn make_event_loop(mut mqtt: EspMqttClient>, rx: mpsc::Receiver) -> Result<()> { +pub fn make_event_loop(mut mqtt: EspMqttClient>, rx: mpsc::Receiver, do_log: bool) -> Result<()> { info!("About to subscribe to the mpsc channel"); while let Ok(event) = rx.recv() { @@ -64,7 +65,9 @@ pub fn make_event_loop(mut mqtt: EspMqttClient> }, Event::Message(msg_bytes) => { let b = sphinx_key_signer::parse_ping_and_form_response(msg_bytes); - log::info!("GOT A PING MESSAGE! returning pong now..."); + if do_log { + log::info!("GOT A PING MESSAGE! returning pong now..."); + } mqtt.publish(RETURN_TOPIC, QOS, false, b).expect("could not publish init response"); }, Event::Disconnected => { diff --git a/sphinx-key/src/main.rs b/sphinx-key/src/main.rs index 987c59f..92264d6 100644 --- a/sphinx-key/src/main.rs +++ b/sphinx-key/src/main.rs @@ -49,7 +49,8 @@ fn main() -> Result<()> { // this blocks forever... the "main thread" log::info!(">>>>>>>>>>> blocking forever..."); - make_event_loop(mqtt_client, rx)?; + let do_log = true; + make_event_loop(mqtt_client, rx, do_log)?; let mut blue = Led::new(0x000001, 100); println!("{:?}", wifi.get_status());