fix message templating
This commit is contained in:
		@@ -7,11 +7,12 @@ use esp_idf_svc::systime::EspSystemTime;
 | 
				
			|||||||
use once_cell::sync::Lazy;
 | 
					use once_cell::sync::Lazy;
 | 
				
			||||||
use ringbuffer::{ConstGenericRingBuffer, RingBuffer};
 | 
					use ringbuffer::{ConstGenericRingBuffer, RingBuffer};
 | 
				
			||||||
use text_template::Template;
 | 
					use text_template::Template;
 | 
				
			||||||
 | 
					use unit_enum::UnitEnum;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const TXT_SHORT_LENGTH:usize = 8;
 | 
					const TXT_SHORT_LENGTH:usize = 8;
 | 
				
			||||||
const TXT_LONG_LENGTH:usize = 32;
 | 
					const TXT_LONG_LENGTH:usize = 32;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const BUFFER_SIZE:usize = 210;
 | 
					const BUFFER_SIZE:usize = 220;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[link_section = ".rtc.data"]
 | 
					#[link_section = ".rtc.data"]
 | 
				
			||||||
static mut BUFFER:ConstGenericRingBuffer::<LogEntry, BUFFER_SIZE> = ConstGenericRingBuffer::<LogEntry, BUFFER_SIZE>::new();
 | 
					static mut BUFFER:ConstGenericRingBuffer::<LogEntry, BUFFER_SIZE> = ConstGenericRingBuffer::<LogEntry, BUFFER_SIZE>::new();
 | 
				
			||||||
@@ -22,7 +23,7 @@ static BUFFER_ACCESS: Lazy<Mutex<&mut ConstGenericRingBuffer::<LogEntry, BUFFER_
 | 
				
			|||||||
#[derive(Serialize, Debug, Clone)]
 | 
					#[derive(Serialize, Debug, Clone)]
 | 
				
			||||||
pub struct LogEntry {
 | 
					pub struct LogEntry {
 | 
				
			||||||
    pub timestamp: u64,
 | 
					    pub timestamp: u64,
 | 
				
			||||||
    pub message_id: u32,
 | 
					    pub message_id: u16,
 | 
				
			||||||
    pub a: u32,
 | 
					    pub a: u32,
 | 
				
			||||||
    pub b: u32,
 | 
					    pub b: u32,
 | 
				
			||||||
    pub txt_short: heapless::String<TXT_SHORT_LENGTH>,
 | 
					    pub txt_short: heapless::String<TXT_SHORT_LENGTH>,
 | 
				
			||||||
@@ -75,6 +76,8 @@ pub fn log(message_key: LogMessage, number_a: u32, number_b: u32, txt_short:&str
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    let time = EspSystemTime {}.now().as_millis() as u64;
 | 
					    let time = EspSystemTime {}.now().as_millis() as u64;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    let ordinal = message_key.ordinal() as u16;
 | 
				
			||||||
    let template_string:&str = message_key.into();
 | 
					    let template_string:&str = message_key.into();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -93,9 +96,10 @@ pub fn log(message_key: LogMessage, number_a: u32, number_b: u32, txt_short:&str
 | 
				
			|||||||
    println!("{serial_entry}");
 | 
					    println!("{serial_entry}");
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let entry = LogEntry{
 | 
					    let entry = LogEntry{
 | 
				
			||||||
        timestamp: time,
 | 
					        timestamp: time,
 | 
				
			||||||
        message_id: 1,
 | 
					        message_id: ordinal,
 | 
				
			||||||
        a: number_a,
 | 
					        a: number_a,
 | 
				
			||||||
        b: number_b,
 | 
					        b: number_b,
 | 
				
			||||||
        txt_short: txt_short_stack,
 | 
					        txt_short: txt_short_stack,
 | 
				
			||||||
@@ -130,35 +134,35 @@ mod tests {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(IntoStaticStr, EnumIter, Serialize, PartialEq, Eq, PartialOrd, Ord, Clone)]
 | 
					#[derive(IntoStaticStr, EnumIter, Serialize, PartialEq, Eq, PartialOrd, Ord, Clone, UnitEnum)]
 | 
				
			||||||
pub enum LogMessage {
 | 
					pub enum LogMessage {
 | 
				
			||||||
    #[strum(serialize = "Reset due to {{txt_long}} requires rtc clear {{a}} and force config mode {{b}}")]   
 | 
					    #[strum(serialize = "Reset due to ${txt_long} requires rtc clear ${number_a} and force config mode ${number_b}")]   
 | 
				
			||||||
    ResetReason,
 | 
					    ResetReason,
 | 
				
			||||||
    #[strum(serialize = "Current restart to conf mode {{a}}")]   
 | 
					    #[strum(serialize = "Current restart to conf mode ${number_a}")]   
 | 
				
			||||||
    RestartToConfig,
 | 
					    RestartToConfig,
 | 
				
			||||||
    #[strum(serialize = "Current low voltage detection is {{a}}")]   
 | 
					    #[strum(serialize = "Current low voltage detection is ${number_a}")]   
 | 
				
			||||||
    LowVoltage,
 | 
					    LowVoltage,
 | 
				
			||||||
    #[strum(serialize = "Error communicating with battery!! {{txt_long}}")]   
 | 
					    #[strum(serialize = "Error communicating with battery!! ${txt_long}")]   
 | 
				
			||||||
    BatteryCommunicationError,
 | 
					    BatteryCommunicationError,
 | 
				
			||||||
    #[strum(serialize = "Tank sensor raw {{a}} percent {{b}}")]   
 | 
					    #[strum(serialize = "Tank sensor raw ${number_a} percent ${number_b}")]   
 | 
				
			||||||
    SensorTankRaw,
 | 
					    SensorTankRaw,
 | 
				
			||||||
    #[strum(serialize = "raw measure unscaled {{a}} hz {{b}}, plant {{txt_short}} sensor {{txt_long}}")]   
 | 
					    #[strum(serialize = "raw measure unscaled ${number_a} hz ${number_b}, plant ${txt_short} sensor ${txt_long}")]   
 | 
				
			||||||
    RawMeasure,
 | 
					    RawMeasure,
 | 
				
			||||||
    #[strum(serialize = "IP info: {{txt_long}}")]   
 | 
					    #[strum(serialize = "IP info: ${txt_long}")]   
 | 
				
			||||||
    WifiInfo,
 | 
					    WifiInfo,
 | 
				
			||||||
    #[strum(serialize = "Plant:{{txt_short}} a:{{a}} b:{{b}}")]   
 | 
					    #[strum(serialize = "Plant:${txt_short} a:${number_a} b:${number_b}")]   
 | 
				
			||||||
    TestSensor,
 | 
					    TestSensor,
 | 
				
			||||||
    #[strum(serialize = "Stay alive topic is {{txt_long}}")]   
 | 
					    #[strum(serialize = "Stay alive topic is ${txt_long}")]   
 | 
				
			||||||
    StayAlive,
 | 
					    StayAlive,
 | 
				
			||||||
    #[strum(serialize = "Connecting mqtt {{txt_short}} with id {{txt_long}}")]   
 | 
					    #[strum(serialize = "Connecting mqtt ${txt_short} with id ${txt_long}")]   
 | 
				
			||||||
    MqttInfo,
 | 
					    MqttInfo,
 | 
				
			||||||
    #[strum(serialize = "Received stay alive with value {{txt_short}}")]   
 | 
					    #[strum(serialize = "Received stay alive with value ${txt_short}")]   
 | 
				
			||||||
    MqttStayAliveRec,
 | 
					    MqttStayAliveRec,
 | 
				
			||||||
    #[strum(serialize = "Unknown topic recieved {{txt_long}}")]   
 | 
					    #[strum(serialize = "Unknown topic recieved ${txt_long}")]   
 | 
				
			||||||
    UnknownTopic,
 | 
					    UnknownTopic,
 | 
				
			||||||
    #[strum(serialize = "Partition state is {{txt_long}}")]   
 | 
					    #[strum(serialize = "Partition state is ${txt_long}")]   
 | 
				
			||||||
    PartitionState,
 | 
					    PartitionState,
 | 
				
			||||||
    #[strum(serialize = "Mounted Filesystem free {{a}} total {{b}} use {{txt_short}}")]
 | 
					    #[strum(serialize = "Mounted Filesystem free ${number_a} total ${number_b} use ${txt_short}")]
 | 
				
			||||||
    FilesystemMount,
 | 
					    FilesystemMount,
 | 
				
			||||||
    #[strum(serialize = "Mounting Filesystem, this will format the first time and needs quite some time!")]
 | 
					    #[strum(serialize = "Mounting Filesystem, this will format the first time and needs quite some time!")]
 | 
				
			||||||
    MountingFilesystem,
 | 
					    MountingFilesystem,
 | 
				
			||||||
@@ -170,15 +174,15 @@ pub enum LogMessage {
 | 
				
			|||||||
    ConfigModeButtonOverride,
 | 
					    ConfigModeButtonOverride,
 | 
				
			||||||
    #[strum(serialize = "Going to normal mode")]
 | 
					    #[strum(serialize = "Going to normal mode")]
 | 
				
			||||||
    NormalRun,
 | 
					    NormalRun,
 | 
				
			||||||
    #[strum(serialize = "Missing normal config, entering config mode {{txt_long}}")]
 | 
					    #[strum(serialize = "Missing normal config, entering config mode ${txt_long}")]
 | 
				
			||||||
    ConfigModeMissingConfig,
 | 
					    ConfigModeMissingConfig,
 | 
				
			||||||
    #[strum(serialize = "startup state wifi {{a}} sntp {{b}} mqtt {{txt_short}}")]
 | 
					    #[strum(serialize = "startup state wifi ${number_a} sntp ${number_b} mqtt ${txt_short}")]
 | 
				
			||||||
    StartupInfo,
 | 
					    StartupInfo,
 | 
				
			||||||
    #[strum(serialize = "Trying to pump for {{b}}s with pump {{a}} now dryrun: {{txt_short}}")]
 | 
					    #[strum(serialize = "Trying to pump for ${number_b}s with pump ${number_a} now dryrun: ${txt_short}")]
 | 
				
			||||||
    PumpPlant,
 | 
					    PumpPlant,
 | 
				
			||||||
    #[strum(serialize = "Enable main power dryrun: {{a}}")]
 | 
					    #[strum(serialize = "Enable main power dryrun: ${number_a}")]
 | 
				
			||||||
    EnableMain,
 | 
					    EnableMain,
 | 
				
			||||||
    #[strum(serialize = "Pumped multiple times, but plant is still to try attempt: {{a}} limit :: {{b}} plant: {{txt_short}}")]
 | 
					    #[strum(serialize = "Pumped multiple times, but plant is still to try attempt: ${number_a} limit :: ${number_b} plant: ${txt_short}")]
 | 
				
			||||||
    ConsecutivePumpCountLimit
 | 
					    ConsecutivePumpCountLimit
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user