diff --git a/fsrc-core/src/events.rs b/fsrc-core/src/events.rs index 4a27cf0..2523a2e 100644 --- a/fsrc-core/src/events.rs +++ b/fsrc-core/src/events.rs @@ -279,6 +279,17 @@ impl EventU32 { }, } } + + pub const fn const_from_info(event: EventU32TypedSev) -> Self { + Self { + base: event.event.base + } + } + pub const fn const_from_medium(event: EventU32TypedSev) -> Self { + Self { + base: event.event.base + } + } } impl EventU32TypedSev { diff --git a/fsrc-core/tests/pus_events.rs b/fsrc-core/tests/pus_events.rs index db82b52..f0edbe2 100644 --- a/fsrc-core/tests/pus_events.rs +++ b/fsrc-core/tests/pus_events.rs @@ -1,32 +1,34 @@ #![allow(dead_code, unused_imports)] -use fsrc_core::events::{ - EventU32TypedSev, GenericEvent, HasSeverity, LargestEventRaw, LargestGroupIdRaw, Severity, - SeverityInfo, SeverityLow, SeverityMedium, -}; +use std::convert::AsRef; +use fsrc_core::events::{EventU32, EventU32TypedSev, GenericEvent, HasSeverity, LargestEventRaw, LargestGroupIdRaw, Severity, SeverityInfo, SeverityLow, SeverityMedium}; + +#[derive(Debug)] struct GroupIdIntrospection { name: &'static str, id: LargestGroupIdRaw, } -struct EventIntrospection { +#[derive(Debug)] +struct EventIntrospection { name: &'static str, group_id: GroupIdIntrospection, - event: &'static EventU32TypedSev, + event: &'static EventU32, info: &'static str, } //#[event(descr="This is some info event")] const INFO_EVENT_0: EventU32TypedSev = EventU32TypedSev::const_new(0, 0); +const INFO_EVENT_0_ERASED: EventU32 = EventU32::const_from_info(INFO_EVENT_0); // This is ideally auto-generated -const INFO_EVENT_0_INTROSPECTION: EventIntrospection = EventIntrospection { +const INFO_EVENT_0_INTROSPECTION: EventIntrospection = EventIntrospection { name: "INFO_EVENT_0", group_id: GroupIdIntrospection { id: 0, name: "Group ID 0 without name", }, - event: &INFO_EVENT_0, + event: &INFO_EVENT_0_ERASED, info: "This is some info event", }; @@ -43,19 +45,38 @@ const TEST_GROUP_NAME_NAME: &'static str = "TEST_GROUP_NAME"; //#[event(desc="Some medium severity event")] const MEDIUM_SEV_EVENT_IN_OTHER_GROUP: EventU32TypedSev = EventU32TypedSev::const_new(TEST_GROUP_NAME, 0); +const MEDIUM_SEV_EVENT_IN_OTHER_GROUP_REDUCED: EventU32 = EventU32::const_from_medium(MEDIUM_SEV_EVENT_IN_OTHER_GROUP); // Also auto-generated -const MEDIUM_SEV_EVENT_IN_OTHER_GROUP_INTROSPECTION: EventIntrospection = +const MEDIUM_SEV_EVENT_IN_OTHER_GROUP_INTROSPECTION: EventIntrospection = EventIntrospection { name: "MEDIUM_SEV_EVENT_IN_OTHER_GROUP", group_id: GroupIdIntrospection { name: TEST_GROUP_NAME_NAME, id: TEST_GROUP_NAME, }, - event: &MEDIUM_SEV_EVENT_IN_OTHER_GROUP, + event: &MEDIUM_SEV_EVENT_IN_OTHER_GROUP_REDUCED, info: "Some medium severity event", }; +const CONST_SLICE: &'static [u8] = &[0, 1, 2, 3]; +const INTROSPECTION_FOR_TEST_GROUP_0: [&'static EventIntrospection; 2] = [ + &INFO_EVENT_0_INTROSPECTION, + &INFO_EVENT_0_INTROSPECTION +]; + +const INTROSPECTION_FOR_TABLE: &'static [&EventIntrospection] = &INTROSPECTION_FOR_TEST_GROUP_0; + +const INTROSPECTION_FOR_TEST_GROUP_NAME: [&'static EventIntrospection; 1] = [ + &MEDIUM_SEV_EVENT_IN_OTHER_GROUP_INTROSPECTION +]; +const BLAH: &'static [&EventIntrospection] = &INTROSPECTION_FOR_TEST_GROUP_NAME; + +const ALL_EVENTS: [&'static [&EventIntrospection]; 2] = [ + INTROSPECTION_FOR_TABLE, + BLAH +]; + #[test] fn main() { //let test = stringify!(INFO_EVENT); @@ -63,5 +84,11 @@ fn main() { //for event in EVENT_LIST { // println!("{:?}", event); //} + for events in ALL_EVENTS.into_iter().flatten() { + dbg!("{:?}", events); + } + //for introspection_info in INTROSPECTION_FOR_TEST_GROUP { + // dbg!("{:?}", introspection_info); + //} //let test_struct = }