Remove all led messages

This commit is contained in:
decentclock
2022-11-07 12:08:32 -05:00
parent 28a9aa8d1b
commit 8eae03336d
4 changed files with 37 additions and 34 deletions

View File

@@ -30,6 +30,7 @@ pub enum Event {
Control(Vec<u8>),
}
/*
#[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<Event>,
network: Network,
do_log: bool,
led_tx: mpsc::Sender<Status>,
//led_tx: mpsc::Sender<Status>,
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<Status>,
//led_tx: mpsc::Sender<Status>,
) -> Option<ControlResponse> {
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<Event>,
_network: Network,
do_log: bool,
led_tx: mpsc::Sender<Status>,
//led_tx: mpsc::Sender<Status>,
_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(_) => (),

View File

@@ -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<Status>,
//led_tx: mpsc::Sender<Status>,
flash: Arc<Mutex<FlashPersister>>,
) -> 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,

View File

@@ -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<Status>) -> 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<Status>) -> 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<Status>) -> Result<()> {
Ok(())
}
pub fn update_sphinx_key(params: OtaParams, led_tx: mpsc::Sender<Status>) -> 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!");

View File

@@ -1,2 +1,2 @@
pub mod led;
//pub mod led;
pub mod sd;