fix mppt to not self destruct, log output
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use std::{collections::HashMap, sync::Mutex};
|
||||
use serde::Serialize;
|
||||
use strum_macros::IntoStaticStr;
|
||||
|
||||
use esp_idf_svc::systime::EspSystemTime;
|
||||
@@ -17,6 +18,7 @@ static mut BUFFER:ConstGenericRingBuffer::<LogEntry, BUFFER_SIZE> = ConstGeneric
|
||||
static BUFFER_ACCESS: Lazy<Mutex<&mut ConstGenericRingBuffer::<LogEntry, BUFFER_SIZE>>> = Lazy::new(|| unsafe { Mutex::new(&mut BUFFER) });
|
||||
|
||||
|
||||
#[derive(Serialize, Debug, Clone)]
|
||||
pub struct LogEntry {
|
||||
pub timestamp: u64,
|
||||
pub message_id: u32,
|
||||
@@ -52,6 +54,17 @@ fn limit_length <const LIMIT:usize> (input: &str, target: &mut heapless::String<
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_log() -> Vec<LogEntry>{
|
||||
let buffer = BUFFER_ACCESS.lock().unwrap();
|
||||
let mut read_copy = Vec::new();
|
||||
for entry in buffer.iter() {
|
||||
let copy = entry.clone();
|
||||
read_copy.push(copy);
|
||||
}
|
||||
drop(buffer);
|
||||
return read_copy;
|
||||
}
|
||||
|
||||
pub fn log(message_key: LogMessage, number_a: u32, number_b: u32, txt_short:&str, txt_long:&str){
|
||||
let mut txt_short_stack:heapless::String<TXT_SHORT_LENGTH> = heapless::String::new();
|
||||
let mut txt_long_stack:heapless::String<TXT_LONG_LENGTH> = heapless::String::new();
|
||||
@@ -94,6 +107,8 @@ pub fn log(message_key: LogMessage, number_a: u32, number_b: u32, txt_short:&str
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
Reference in New Issue
Block a user