From 8eae03336d800298ef3a5c0779c0eb44929bd033 Mon Sep 17 00:00:00 2001 From: decentclock Date: Mon, 7 Nov 2022 12:08:32 -0500 Subject: [PATCH] Remove all led messages --- sphinx-key/src/core/events.rs | 29 ++++++++++++++++------------- sphinx-key/src/main.rs | 28 ++++++++++++++-------------- sphinx-key/src/ota.rs | 12 ++++++------ sphinx-key/src/periph/mod.rs | 2 +- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/sphinx-key/src/core/events.rs b/sphinx-key/src/core/events.rs index 368fc3b..2adc878 100644 --- a/sphinx-key/src/core/events.rs +++ b/sphinx-key/src/core/events.rs @@ -30,6 +30,7 @@ pub enum Event { Control(Vec), } +/* #[derive(Debug, Ord, PartialOrd, Eq, PartialEq)] pub enum Status { Starting, @@ -43,6 +44,7 @@ pub enum Status { Signing, Ota, } +*/ pub const ROOT_STORE: &str = "/sdcard/store"; @@ -53,7 +55,7 @@ pub fn make_event_loop( rx: mpsc::Receiver, network: Network, do_log: bool, - led_tx: mpsc::Sender, + //led_tx: mpsc::Sender, config: Config, seed: [u8; 32], policy: &Policy, @@ -69,7 +71,7 @@ pub fn make_event_loop( .expect("could not MQTT subscribe"); mqtt.subscribe(topics::CONTROL, QOS) .expect("could not MQTT subscribe"); - led_tx.send(Status::Connected).unwrap(); + //led_tx.send(Status::Connected).unwrap(); break; } _ => (), @@ -94,14 +96,14 @@ pub fn make_event_loop( .expect("could not MQTT subscribe"); mqtt.subscribe(topics::CONTROL, QOS) .expect("could not MQTT subscribe"); - led_tx.send(Status::Connected).unwrap(); + //led_tx.send(Status::Connected).unwrap(); } Event::Disconnected => { - led_tx.send(Status::ConnectingToMqtt).unwrap(); + //led_tx.send(Status::ConnectingToMqtt).unwrap(); log::info!("GOT A Event::Disconnected msg!"); } Event::VlsMessage(ref msg_bytes) => { - led_tx.send(Status::Signing).unwrap(); + //led_tx.send(Status::Signing).unwrap(); let _ret = match sphinx_signer::root::handle( &root_handler, msg_bytes.clone(), @@ -125,7 +127,8 @@ pub fn make_event_loop( log::info!("GOT A CONTROL MSG"); let cres = ctrlr.handle(msg_bytes); if let Some(res) = - handle_control_response(&root_handler, cres, network, led_tx.clone()) + handle_control_response(&root_handler, cres, network) + //handle_control_response(&root_handler, cres, network, led_tx.clone()) { let res_data = rmp_serde::to_vec_named(&res).expect("could not publish control response"); @@ -143,7 +146,7 @@ fn handle_control_response( root_handler: &RootHandler, cres: anyhow::Result<(ControlMessage, ControlResponse)>, network: Network, - led_tx: mpsc::Sender, + //led_tx: mpsc::Sender, ) -> Option { match cres { Ok((control_msg, mut control_res)) => { @@ -182,8 +185,8 @@ fn handle_control_response( ControlResponse::Error(format!("OTA update cannot launch {:?}", e)) } else { thread::spawn(move || { - led_tx.send(Status::Ota).unwrap(); - if let Err(e) = update_sphinx_key(params, led_tx) { + //led_tx.send(Status::Ota).unwrap(); + if let Err(e) = update_sphinx_key(params) { log::error!("OTA update failed {:?}", e.to_string()); } else { log::info!("OTA flow complete, restarting esp..."); @@ -211,7 +214,7 @@ pub fn make_event_loop( rx: mpsc::Receiver, _network: Network, do_log: bool, - led_tx: mpsc::Sender, + //led_tx: mpsc::Sender, _config: Config, _seed: [u8; 32], _policy: &Policy, @@ -221,13 +224,13 @@ pub fn make_event_loop( while let Ok(event) = rx.recv() { match event { Event::Connected => { - led_tx.send(Status::ConnectedToMqtt).unwrap(); + //led_tx.send(Status::ConnectedToMqtt).unwrap(); log::info!("SUBSCRIBE TO {}", topics::VLS); mqtt.subscribe(topics::VLS, QOS) .expect("could not MQTT subscribe"); } Event::VlsMessage(msg_bytes) => { - led_tx.send(Status::Signing).unwrap(); + //led_tx.send(Status::Signing).unwrap(); let b = sphinx_signer::parse_ping_and_form_response(msg_bytes); if do_log { log::info!("GOT A PING MESSAGE! returning pong now..."); @@ -236,7 +239,7 @@ pub fn make_event_loop( .expect("could not publish ping response"); } Event::Disconnected => { - led_tx.send(Status::ConnectingToMqtt).unwrap(); + //led_tx.send(Status::ConnectingToMqtt).unwrap(); log::info!("GOT A Event::Disconnected msg!"); } Event::Control(_) => (), diff --git a/sphinx-key/src/main.rs b/sphinx-key/src/main.rs index c345693..1f62253 100644 --- a/sphinx-key/src/main.rs +++ b/sphinx-key/src/main.rs @@ -6,7 +6,7 @@ mod periph; use crate::core::control::{controller_from_seed, FlashPersister}; use crate::core::{config::*, events::*}; -use crate::periph::led::led_control_loop; +//use crate::periph::led::led_control_loop; #[allow(unused_imports)] use crate::periph::sd::{mount_sd_card, simple_fs_test}; @@ -17,7 +17,7 @@ use std::thread; use std::time::Duration; use std::time::SystemTime; -use esp_idf_hal::peripherals::Peripherals; +//use esp_idf_hal::peripherals::Peripherals; use esp_idf_svc::nvs::*; use sphinx_signer::sphinx_glyph::control::{Config, ControlPersist, Policy}; @@ -38,14 +38,14 @@ fn main() -> Result<()> { thread::sleep(Duration::from_secs(1)); - let peripherals = Peripherals::take().unwrap(); - let pins = peripherals.pins; + //let peripherals = Peripherals::take().unwrap(); + //let pins = peripherals.pins; - let (led_tx, led_rx) = mpsc::channel(); + //let (led_tx, led_rx) = mpsc::channel(); // LED control thread - led_control_loop(pins.gpio0, peripherals.rmt.channel0, led_rx); + //led_control_loop(pins.gpio0, peripherals.rmt.channel0, led_rx); - led_tx.send(Status::MountingSDCard).unwrap(); + //led_tx.send(Status::MountingSDCard).unwrap(); println!("About to mount the sdcard..."); while let Err(_e) = mount_sd_card() { println!("Failed to mount sd card. Make sure it is connected, trying again..."); @@ -62,7 +62,7 @@ fn main() -> Result<()> { "=============> START CLIENT NOW <============== {:?}", exist ); - led_tx.send(Status::ConnectingToWifi).unwrap(); + //led_tx.send(Status::ConnectingToWifi).unwrap(); let _wifi = loop { if let Ok(wifi) = start_wifi_client(default_nvs.clone(), &exist) { println!("Wifi connected!"); @@ -73,7 +73,7 @@ fn main() -> Result<()> { } }; - led_tx.send(Status::SyncingTime).unwrap(); + //led_tx.send(Status::SyncingTime).unwrap(); conn::sntp::sync_time(); let now = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) @@ -83,7 +83,7 @@ fn main() -> Result<()> { now.as_secs(), ); - led_tx.send(Status::ConnectingToMqtt).unwrap(); + //led_tx.send(Status::ConnectingToMqtt).unwrap(); let flash_arc = Arc::new(Mutex::new(flash)); loop { @@ -91,7 +91,7 @@ fn main() -> Result<()> { exist.clone(), seed, &policy, - led_tx.clone(), + //led_tx.clone(), flash_arc.clone(), ) { println!("Exited out of the event loop, trying again in 5 seconds..."); @@ -102,7 +102,7 @@ fn main() -> Result<()> { } } } else { - led_tx.send(Status::WifiAccessPoint).unwrap(); + //led_tx.send(Status::WifiAccessPoint).unwrap(); println!("=============> START SERVER NOW AND WAIT <=============="); match start_config_server_and_wait(default_nvs.clone()) { Ok((_wifi, config, seed)) => { @@ -122,7 +122,7 @@ fn make_and_launch_client( config: Config, seed: [u8; 32], policy: &Policy, - led_tx: mpsc::Sender, + //led_tx: mpsc::Sender, flash: Arc>, ) -> anyhow::Result<()> { let (tx, rx) = mpsc::channel(); @@ -156,7 +156,7 @@ fn make_and_launch_client( rx, network, do_log, - led_tx, + //led_tx, config, seed, policy, diff --git a/sphinx-key/src/ota.rs b/sphinx-key/src/ota.rs index 5a77b4b..0e29687 100644 --- a/sphinx-key/src/ota.rs +++ b/sphinx-key/src/ota.rs @@ -1,4 +1,4 @@ -use crate::core::events::Status; +//use crate::core::events::Status; use anyhow::{anyhow, Result}; use embedded_svc::http::client::Client; use embedded_svc::http::client::Request; @@ -15,7 +15,7 @@ use sphinx_signer::sphinx_glyph::control::OtaParams; use std::fs::{remove_file, File}; use std::io::BufWriter; use std::io::Write; -use std::sync::mpsc; +//use std::sync::mpsc; const BUFFER_LEN: usize = 3072; const UPDATE_BIN_PATH: &str = "/sdcard/update.bin"; @@ -33,7 +33,7 @@ fn factory_reset() -> Result<()> { } } -fn get_update(params: OtaParams, led_tx: mpsc::Sender) -> Result<()> { +fn get_update(params: OtaParams) -> Result<()> { let configuration = EspHttpClientConfiguration { buffer_size: Some(BUFFER_LEN), buffer_size_tx: Some(BUFFER_LEN / 3), @@ -64,7 +64,7 @@ fn get_update(params: OtaParams, led_tx: mpsc::Sender) -> Result<()> { write_tot += w; i += 1; if i % 20 == 0 { - led_tx.send(Status::Ota).unwrap(); + //led_tx.send(Status::Ota).unwrap(); info!("Cumulative bytes read: {}", read_tot); info!("Cumulative bytes written: {}", write_tot); } @@ -74,9 +74,9 @@ fn get_update(params: OtaParams, led_tx: mpsc::Sender) -> Result<()> { Ok(()) } -pub fn update_sphinx_key(params: OtaParams, led_tx: mpsc::Sender) -> Result<()> { +pub fn update_sphinx_key(params: OtaParams) -> Result<()> { info!("Getting the update..."); - get_update(params, led_tx)?; + get_update(params)?; info!("Update written to sd card, performing factory reset"); factory_reset()?; info!("Factory reset completed!"); diff --git a/sphinx-key/src/periph/mod.rs b/sphinx-key/src/periph/mod.rs index bb1f34b..0e3b267 100644 --- a/sphinx-key/src/periph/mod.rs +++ b/sphinx-key/src/periph/mod.rs @@ -1,2 +1,2 @@ -pub mod led; +//pub mod led; pub mod sd;