reflect do vec
This commit is contained in:
@@ -24,5 +24,3 @@ bincode = { version = "2.0.0-rc.3", default-features = false, features = [
|
|||||||
simple_logger = "5.0.0"
|
simple_logger = "5.0.0"
|
||||||
rp2040-hal = "0.10.2"
|
rp2040-hal = "0.10.2"
|
||||||
rp2040-pac = "0.6.0"
|
rp2040-pac = "0.6.0"
|
||||||
serde = { version = "1.0.216", features = ["derive"] }
|
|
||||||
serde_json = "1.0.133"
|
|
||||||
|
|||||||
@@ -5,11 +5,9 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rfe.path = "../../rfe"
|
rfe.path = "../../rfe"
|
||||||
rfe.features = ["std", "serde"]
|
rfe.features = ["std", "reflect"]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
simple_logger = "5.0.0"
|
simple_logger = "5.0.0"
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
serde_json.workspace = true
|
|
||||||
serde.workspace = true
|
|
||||||
egui = "0.30.0"
|
egui = "0.30.0"
|
||||||
eframe = "0.30.0"
|
eframe = "0.30.0"
|
||||||
|
|||||||
+1
-2
@@ -7,7 +7,7 @@ edition = "2021"
|
|||||||
default = []
|
default = []
|
||||||
std = ["dep:mio"]
|
std = ["dep:mio"]
|
||||||
rp2040 = ["dep:rp2040-hal", "dep:rp2040-pac"]
|
rp2040 = ["dep:rp2040-hal", "dep:rp2040-pac"]
|
||||||
serde = ["dep:serde"]
|
reflect = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bincode.workspace = true
|
bincode.workspace = true
|
||||||
@@ -18,4 +18,3 @@ mio = { version = "1.0.2", features = ["net", "os-poll"], optional = true }
|
|||||||
rp2040-hal = { workspace = true, optional = true }
|
rp2040-hal = { workspace = true, optional = true }
|
||||||
rp2040-pac = { workspace = true, optional = true }
|
rp2040-pac = { workspace = true, optional = true }
|
||||||
macros.path = "macros"
|
macros.path = "macros"
|
||||||
serde = { workspace = true, optional = true }
|
|
||||||
|
|||||||
+29
-202
@@ -71,7 +71,7 @@ pub fn kind_derive(input: TokenStream) -> TokenStream {
|
|||||||
|
|
||||||
let expanded = quote! {
|
let expanded = quote! {
|
||||||
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash, Encode, Decode)]
|
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub enum #kind_name {
|
pub enum #kind_name {
|
||||||
#[default]
|
#[default]
|
||||||
#(#kind_enum_arms)*
|
#(#kind_enum_arms)*
|
||||||
@@ -103,161 +103,6 @@ pub fn kind_derive(input: TokenStream) -> TokenStream {
|
|||||||
TokenStream::from(expanded)
|
TokenStream::from(expanded)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[proc_macro_derive(ToCsv)]
|
|
||||||
pub fn to_csv_derive(input: TokenStream) -> TokenStream {
|
|
||||||
let input = parse_macro_input!(input as DeriveInput);
|
|
||||||
|
|
||||||
let name = input.ident;
|
|
||||||
let name_s = name.to_string();
|
|
||||||
|
|
||||||
let expanded = match input.data {
|
|
||||||
Data::Struct(data_struct) => {
|
|
||||||
let fields = data_struct.fields;
|
|
||||||
|
|
||||||
let arms = fields.iter().map(|field| {
|
|
||||||
let field_ident = field.clone().ident.unwrap();
|
|
||||||
let field_name = field_ident.to_string();
|
|
||||||
|
|
||||||
quote! { {
|
|
||||||
let mut field_csvs: alloc::vec::Vec<alloc::string::String> = (&self.#field_ident as &dyn ToCsv).to_csv();
|
|
||||||
for entry in &mut field_csvs {
|
|
||||||
*entry = format!("{}.{}", #field_name, &entry);
|
|
||||||
}
|
|
||||||
values.extend(field_csvs);
|
|
||||||
} }
|
|
||||||
});
|
|
||||||
|
|
||||||
let arms_enum = fields.iter().map(|field| {
|
|
||||||
let field_ident = field.clone().ident.unwrap();
|
|
||||||
let field_name = field_ident.to_string();
|
|
||||||
|
|
||||||
quote! { {
|
|
||||||
let mut field_csvs: alloc::vec::Vec<alloc::string::String> = (&self.#field_ident as &dyn ToCsv).enumerate();
|
|
||||||
|
|
||||||
for entry in &mut field_csvs {
|
|
||||||
*entry = format!("{}.{}", #field_name, &entry);
|
|
||||||
}
|
|
||||||
values.extend(field_csvs);
|
|
||||||
} }
|
|
||||||
});
|
|
||||||
|
|
||||||
quote! {
|
|
||||||
impl ToCsv for #name {
|
|
||||||
fn to_csv(&self) -> alloc::vec::Vec<alloc::string::String> {
|
|
||||||
extern crate alloc;
|
|
||||||
use alloc::format;
|
|
||||||
|
|
||||||
let mut values:alloc::vec::Vec<alloc::string::String> = alloc::vec::Vec::new();
|
|
||||||
#(#arms)*
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn enumerate(&self) -> alloc::vec::Vec<alloc::string::String> {
|
|
||||||
extern crate alloc;
|
|
||||||
use alloc::format;
|
|
||||||
let mut values:alloc::vec::Vec<alloc::string::String> = alloc::vec::Vec::new();
|
|
||||||
#(#arms_enum)*
|
|
||||||
return values;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Data::Enum(data_enum) => {
|
|
||||||
let variants = data_enum.variants;
|
|
||||||
let arms = variants.iter().map(|variant| {
|
|
||||||
let variant_name = &variant.ident;
|
|
||||||
let variant_name_s = variant_name.to_string();
|
|
||||||
|
|
||||||
match &variant.fields {
|
|
||||||
Fields::Unit => {
|
|
||||||
quote! { Self::#variant_name => values.push(format!(" = {}::{}", #name_s, #variant_name_s)), }
|
|
||||||
// quote! { Self::#variant_name => {}, }
|
|
||||||
}
|
|
||||||
Fields::Unnamed(_) => {
|
|
||||||
quote! {Self::#variant_name(l) => {
|
|
||||||
let mut field_csvs: alloc::vec::Vec<alloc::string::String> = (l as &dyn ToCsv).to_csv();
|
|
||||||
for entry in &mut field_csvs {
|
|
||||||
*entry = format!("{}.{}", #variant_name_s, &entry);
|
|
||||||
}
|
|
||||||
values.extend(field_csvs);
|
|
||||||
},}
|
|
||||||
}
|
|
||||||
Fields::Named(_) => {
|
|
||||||
panic!("Named fields not supported by ToCsv");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let arms_enum = variants.iter().map(|variant| {
|
|
||||||
let variant_name = &variant.ident;
|
|
||||||
let variant_name_s = variant_name.to_string();
|
|
||||||
|
|
||||||
match &variant.fields {
|
|
||||||
Fields::Unit => {
|
|
||||||
quote! { values.push(format!(" = {}::{}", #name_s, #variant_name_s)); }
|
|
||||||
}
|
|
||||||
Fields::Unnamed(var) => {
|
|
||||||
let var_type =
|
|
||||||
if let Some(first_field) = var.unnamed.first() {
|
|
||||||
first_field
|
|
||||||
} else {
|
|
||||||
panic!("Struct has no fields!");
|
|
||||||
};
|
|
||||||
quote! {
|
|
||||||
{
|
|
||||||
let l = #var_type::default();
|
|
||||||
let mut field_csvs: alloc::vec::Vec<alloc::string::String> = (&l as &dyn ToCsv).enumerate();
|
|
||||||
|
|
||||||
for entry in &mut field_csvs {
|
|
||||||
*entry = format!("{}.{}", #variant_name_s, &entry);
|
|
||||||
}
|
|
||||||
values.extend(field_csvs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Fields::Named(_) => {
|
|
||||||
panic!("Named fields not supported by ToCsv");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
quote! {
|
|
||||||
impl ToCsv for #name {
|
|
||||||
fn to_csv(&self) -> alloc::vec::Vec<alloc::string::String> {
|
|
||||||
extern crate alloc;
|
|
||||||
use alloc::format;
|
|
||||||
let mut values: alloc::vec::Vec<alloc::string::String> = alloc::vec::Vec::new();
|
|
||||||
|
|
||||||
match self {
|
|
||||||
#(#arms)*
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn enumerate(&self) -> alloc::vec::Vec<alloc::string::String> {
|
|
||||||
extern crate alloc;
|
|
||||||
use alloc::format;
|
|
||||||
|
|
||||||
let mut values:alloc::vec::Vec<alloc::string::String> = alloc::vec::Vec::new();
|
|
||||||
#(#arms_enum)*
|
|
||||||
return values;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Data::Union(_data_union) => {
|
|
||||||
return syn::Error::new_spanned(name, "ToCsv not implemented for unions")
|
|
||||||
.to_compile_error()
|
|
||||||
.into();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TokenStream::from(expanded)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[proc_macro_derive(Reflect)]
|
#[proc_macro_derive(Reflect)]
|
||||||
pub fn reflect_derive(input: TokenStream) -> TokenStream {
|
pub fn reflect_derive(input: TokenStream) -> TokenStream {
|
||||||
@@ -275,52 +120,38 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
|
|||||||
let field_name = field_ident.to_string();
|
let field_name = field_ident.to_string();
|
||||||
|
|
||||||
quote! { {
|
quote! { {
|
||||||
fields.push((#field_name, &mut self.#field_ident as &mut dyn Reflect));
|
fields.push((#field_name, &mut self.#field_ident as &mut dyn rfe::reflect::Reflect));
|
||||||
} }
|
|
||||||
});
|
|
||||||
|
|
||||||
let arms_enum = fields.iter().map(|field| {
|
|
||||||
let field_ident = field.clone().ident.unwrap();
|
|
||||||
let field_name = field_ident.to_string();
|
|
||||||
|
|
||||||
quote! { {
|
|
||||||
let mut field_csvs: alloc::vec::Vec<alloc::string::String> = (&self.#field_ident as &dyn ToCsv).enumerate();
|
|
||||||
|
|
||||||
for entry in &mut field_csvs {
|
|
||||||
*entry = format!("{}.{}", #field_name, &entry);
|
|
||||||
}
|
|
||||||
values.extend(field_csvs);
|
|
||||||
} }
|
} }
|
||||||
});
|
});
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl Reflect for #name {
|
impl rfe::reflect::Reflect for #name {
|
||||||
fn reflect_type(&self) -> ReflectType {
|
fn reflect_type(&self) -> rfe::reflect::ReflectType {
|
||||||
ReflectType::Structure
|
rfe::reflect::ReflectType::Structure
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_name(&self) -> &str {
|
fn type_name(&self) -> &str {
|
||||||
#name_s
|
#name_s
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fields(&mut self) -> Vec<(&str, &mut dyn Reflect)> {
|
fn fields(&mut self) -> alloc::vec::Vec<(&str, &mut dyn rfe::reflect::Reflect)> {
|
||||||
let mut fields = Vec::new();
|
let mut fields = alloc::vec::Vec::new();
|
||||||
#(#field_arms)*
|
#(#field_arms)*
|
||||||
fields
|
fields
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_value(&mut self, value: ReflectValue) {
|
fn set_value(&mut self, value: rfe::reflect::ReflectValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_value(&self) -> ReflectValue {
|
fn get_value(&self) -> rfe::reflect::ReflectValue {
|
||||||
ReflectValue::None
|
rfe::reflect::ReflectValue::None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> {
|
fn variants(&self) -> alloc::vec::Vec<(&str, alloc::boxed::Box<dyn rfe::reflect::Reflect>)> {
|
||||||
Vec::new()
|
alloc::vec::Vec::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> {
|
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn rfe::reflect::Reflect> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -329,13 +160,10 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Data::Enum(data_enum) => {
|
Data::Enum(data_enum) => {
|
||||||
let variants = data_enum.variants;
|
let variants = data_enum.variants;
|
||||||
let as_arms = variants.iter().enumerate().map(|(i, variant)| {
|
let as_arms = variants.iter().enumerate().map(|(i, variant)| {
|
||||||
let variant_name = &variant.ident;
|
let variant_name = &variant.ident;
|
||||||
let variant_name_s = variant_name.to_string();
|
|
||||||
|
|
||||||
match &variant.fields {
|
match &variant.fields {
|
||||||
Fields::Unit => {
|
Fields::Unit => {
|
||||||
@@ -345,7 +173,6 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
|
|||||||
return Some(self);
|
return Some(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// quote! { Self::#variant_name => {}, }
|
|
||||||
}
|
}
|
||||||
Fields::Unnamed(_) => {
|
Fields::Unnamed(_) => {
|
||||||
quote! {
|
quote! {
|
||||||
@@ -358,7 +185,7 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Fields::Named(_) => {
|
Fields::Named(_) => {
|
||||||
panic!("Named fields not supported by ToCsv");
|
panic!("Named fields not supported by Reflect");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -371,7 +198,7 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
|
|||||||
Fields::Unit => {
|
Fields::Unit => {
|
||||||
quote! {
|
quote! {
|
||||||
{
|
{
|
||||||
let value: Box<dyn Reflect> = Box::new(Self::#variant_name);
|
let value: alloc::boxed::Box<dyn rfe::reflect::Reflect> = alloc::boxed::Box::new(Self::#variant_name);
|
||||||
variants.push((#variant_name_s, value));
|
variants.push((#variant_name_s, value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -379,46 +206,46 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
|
|||||||
Fields::Unnamed(_) => {
|
Fields::Unnamed(_) => {
|
||||||
quote! {
|
quote! {
|
||||||
{
|
{
|
||||||
let value: Box<dyn Reflect> = Box::new(Self::#variant_name(Default::default()));
|
let value: alloc::boxed::Box<dyn rfe::reflect::Reflect> = alloc::boxed::Box::new(Self::#variant_name(Default::default()));
|
||||||
variants.push((#variant_name_s, value));
|
variants.push((#variant_name_s, value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Fields::Named(_) => {
|
Fields::Named(_) => {
|
||||||
panic!("Named fields not supported by ToCsv");
|
panic!("Named fields not supported by Reflect");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl Reflect for #name {
|
impl rfe::reflect::Reflect for #name {
|
||||||
fn reflect_type(&self) -> ReflectType {
|
fn reflect_type(&self) -> rfe::reflect::ReflectType {
|
||||||
ReflectType::Enumeration
|
rfe::reflect::ReflectType::Enumeration
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_name(&self) -> &str {
|
fn type_name(&self) -> &str {
|
||||||
#name_s
|
#name_s
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fields(&mut self) -> Vec<(&str, &mut dyn Reflect)> {
|
fn fields(&mut self) -> alloc::vec::Vec<(&str, &mut dyn rfe::reflect::Reflect)> {
|
||||||
Vec::new()
|
alloc::vec::Vec::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_value(&mut self, value: ReflectValue) {
|
fn set_value(&mut self, value: rfe::reflect::ReflectValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_value(&self) -> ReflectValue {
|
fn get_value(&self) -> rfe::reflect::ReflectValue {
|
||||||
ReflectValue::None
|
rfe::reflect::ReflectValue::None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> {
|
fn variants(&self) -> alloc::vec::Vec<(&str, alloc::boxed::Box<dyn rfe::reflect::Reflect>)> {
|
||||||
let mut variants = Vec::new();
|
let mut variants = alloc::vec::Vec::new();
|
||||||
#(#variant_arms)*
|
#(#variant_arms)*
|
||||||
variants
|
variants
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> {
|
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn rfe::reflect::Reflect> {
|
||||||
#(#as_arms)*
|
#(#as_arms)*
|
||||||
panic!("variant incorrect");
|
panic!("variant incorrect");
|
||||||
}
|
}
|
||||||
@@ -426,7 +253,7 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Data::Union(_data_union) => {
|
Data::Union(_data_union) => {
|
||||||
return syn::Error::new_spanned(name, "ToCsv not implemented for unions")
|
return syn::Error::new_spanned(name, "Reflect not implemented for unions")
|
||||||
.to_compile_error()
|
.to_compile_error()
|
||||||
.into();
|
.into();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ pub mod msg;
|
|||||||
mod rfe;
|
mod rfe;
|
||||||
pub use rfe::*;
|
pub use rfe::*;
|
||||||
|
|
||||||
|
#[cfg(feature = "reflect")]
|
||||||
pub mod reflect;
|
pub mod reflect;
|
||||||
|
|
||||||
pub use macros;
|
pub use macros;
|
||||||
|
|||||||
+7
-6
@@ -5,11 +5,12 @@ use alloc::string::String;
|
|||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
use super::{TlmSetId, TlmSetItem};
|
use super::{TlmSetId, TlmSetItem};
|
||||||
#[cfg(feature = "serde")]
|
use crate as rfe;
|
||||||
use serde::{Deserialize, Serialize};
|
#[cfg(feature = "reflect")]
|
||||||
|
use crate::macros::Reflect;
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Encode, Decode)]
|
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub struct DsTlmSet {
|
pub struct DsTlmSet {
|
||||||
pub items: Vec<TlmSetItem>,
|
pub items: Vec<TlmSetItem>,
|
||||||
pub id: TlmSetId,
|
pub id: TlmSetId,
|
||||||
@@ -18,14 +19,14 @@ pub struct DsTlmSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub struct DsHk {
|
pub struct DsHk {
|
||||||
pub perf: PerfData,
|
pub perf: PerfData,
|
||||||
pub counter: u32,
|
pub counter: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub struct DsOutData {
|
pub struct DsOutData {
|
||||||
pub counter: u32,
|
pub counter: u32,
|
||||||
pub bytes_written: u32,
|
pub bytes_written: u32,
|
||||||
@@ -33,7 +34,7 @@ pub struct DsOutData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub enum DsCmd {
|
pub enum DsCmd {
|
||||||
#[default]
|
#[default]
|
||||||
Noop,
|
Noop,
|
||||||
|
|||||||
@@ -1,23 +1,25 @@
|
|||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
use crate as rfe;
|
||||||
|
#[cfg(feature = "reflect")]
|
||||||
|
use crate::macros::Reflect;
|
||||||
use crate::utils::PerfData;
|
use crate::utils::PerfData;
|
||||||
use bincode::{Decode, Encode};
|
use bincode::{Decode, Encode};
|
||||||
#[cfg(feature = "serde")]
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub struct ExampleHk {
|
pub struct ExampleHk {
|
||||||
pub perf: PerfData,
|
pub perf: PerfData,
|
||||||
pub counter: u32,
|
pub counter: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub struct ExampleOutData {
|
pub struct ExampleOutData {
|
||||||
pub counter: u32,
|
pub counter: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub enum ExampleCmd {
|
pub enum ExampleCmd {
|
||||||
#[default]
|
#[default]
|
||||||
Noop,
|
Noop,
|
||||||
|
|||||||
+6
-5
@@ -2,12 +2,13 @@ use crate::utils::PerfData;
|
|||||||
use bincode::{Decode, Encode};
|
use bincode::{Decode, Encode};
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
use crate as rfe;
|
||||||
|
#[cfg(feature = "reflect")]
|
||||||
|
use crate::macros::Reflect;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
#[cfg(feature = "serde")]
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub struct HsHk {
|
pub struct HsHk {
|
||||||
pub perf: PerfData,
|
pub perf: PerfData,
|
||||||
pub counter: u32,
|
pub counter: u32,
|
||||||
@@ -22,13 +23,13 @@ pub struct HsHk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub struct HsOutData {
|
pub struct HsOutData {
|
||||||
pub counter: u32,
|
pub counter: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub enum HsCmd {
|
pub enum HsCmd {
|
||||||
#[default]
|
#[default]
|
||||||
Noop,
|
Noop,
|
||||||
|
|||||||
+10
-9
@@ -14,12 +14,13 @@ pub use to::*;
|
|||||||
mod ds;
|
mod ds;
|
||||||
pub use ds::*;
|
pub use ds::*;
|
||||||
|
|
||||||
|
use crate as rfe;
|
||||||
|
#[cfg(feature = "reflect")]
|
||||||
|
use crate::macros::Reflect;
|
||||||
use crate::time::Timestamp;
|
use crate::time::Timestamp;
|
||||||
#[cfg(feature = "serde")]
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Encode, Decode)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub struct TargetMsg {
|
pub struct TargetMsg {
|
||||||
// instance is FROM for tlm, is TO for cmds
|
// instance is FROM for tlm, is TO for cmds
|
||||||
pub instance: Instance,
|
pub instance: Instance,
|
||||||
@@ -33,7 +34,7 @@ impl TargetMsg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Encode, Decode)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub enum Instance {
|
pub enum Instance {
|
||||||
#[default]
|
#[default]
|
||||||
None,
|
None,
|
||||||
@@ -44,7 +45,7 @@ pub enum Instance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Kind, Encode, Decode)]
|
#[derive(Debug, Default, Clone, PartialEq, Kind, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub enum Msg {
|
pub enum Msg {
|
||||||
#[default]
|
#[default]
|
||||||
None,
|
None,
|
||||||
@@ -67,7 +68,7 @@ pub enum Msg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Encode, Decode)]
|
#[derive(Debug, Clone, PartialEq, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub struct MsgPacket {
|
pub struct MsgPacket {
|
||||||
pub instance: Instance,
|
pub instance: Instance,
|
||||||
pub msg: Msg,
|
pub msg: Msg,
|
||||||
@@ -93,13 +94,13 @@ impl MsgPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub struct SubList {
|
pub struct SubList {
|
||||||
pub subs: Vec<TargetMsg>,
|
pub subs: Vec<TargetMsg>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub struct ReinitAppCmd {
|
pub struct ReinitAppCmd {
|
||||||
app_name: String,
|
app_name: String,
|
||||||
}
|
}
|
||||||
@@ -107,7 +108,7 @@ pub struct ReinitAppCmd {
|
|||||||
pub type TlmSetId = u16;
|
pub type TlmSetId = u16;
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Encode, Decode)]
|
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub struct TlmSetItem {
|
pub struct TlmSetItem {
|
||||||
pub target: TargetMsg,
|
pub target: TargetMsg,
|
||||||
pub decimation: u16,
|
pub decimation: u16,
|
||||||
|
|||||||
+7
-6
@@ -1,14 +1,15 @@
|
|||||||
use crate::utils::PerfData;
|
use crate::utils::PerfData;
|
||||||
use bincode::{Decode, Encode};
|
use bincode::{Decode, Encode};
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
use crate as rfe;
|
||||||
|
#[cfg(feature = "reflect")]
|
||||||
|
use crate::macros::Reflect;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
#[cfg(feature = "serde")]
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use super::{TlmSetId, TlmSetItem};
|
use super::{TlmSetId, TlmSetItem};
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Encode, Decode)]
|
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub struct ToTlmSet {
|
pub struct ToTlmSet {
|
||||||
pub items: Vec<TlmSetItem>,
|
pub items: Vec<TlmSetItem>,
|
||||||
pub id: TlmSetId,
|
pub id: TlmSetId,
|
||||||
@@ -16,20 +17,20 @@ pub struct ToTlmSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub struct ToHk {
|
pub struct ToHk {
|
||||||
pub perf: PerfData,
|
pub perf: PerfData,
|
||||||
pub counter: u32,
|
pub counter: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub struct ToOutData {
|
pub struct ToOutData {
|
||||||
pub counter: u32,
|
pub counter: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
pub enum ToCmd {
|
pub enum ToCmd {
|
||||||
#[default]
|
#[default]
|
||||||
Noop,
|
Noop,
|
||||||
|
|||||||
+25
-116
@@ -96,6 +96,8 @@ impl ReflectValue {
|
|||||||
ReflectValue::Bool(b) => *b,
|
ReflectValue::Bool(b) => *b,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn vec(self) -> Vec<ReflectValue> {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Reflect: std::fmt::Debug {
|
pub trait Reflect: std::fmt::Debug {
|
||||||
@@ -444,125 +446,32 @@ impl Reflect for bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl ToCsv for bool {
|
impl<T: Reflect> Reflect for Vec<T> {
|
||||||
// fn to_csv(&self) -> Vec<String> {
|
fn reflect_type(&self) -> ReflectType {
|
||||||
// vec![format!(" = {}", self)]
|
ReflectType::Value
|
||||||
// }
|
}
|
||||||
// fn enumerate(&self) -> Vec<String> {
|
|
||||||
// vec![format!(" = bool")]
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl<T: ToCsv + Default> ToCsv for Vec<T> {
|
fn type_name(&self) -> &str {
|
||||||
// fn to_csv(&self) -> Vec<String> {
|
"vec[]"
|
||||||
// self.iter()
|
}
|
||||||
// .enumerate()
|
|
||||||
// .map(|(i, x)| {
|
|
||||||
// x.to_csv()
|
|
||||||
// .iter()
|
|
||||||
// .map(|a| format!("[{}].{}", i, a))
|
|
||||||
// .collect::<Vec<String>>()
|
|
||||||
// })
|
|
||||||
// .flatten()
|
|
||||||
// .collect()
|
|
||||||
// }
|
|
||||||
// fn enumerate(&self) -> Vec<String> {
|
|
||||||
// T::default()
|
|
||||||
// .enumerate()
|
|
||||||
// .iter()
|
|
||||||
// .map(|x| format!("[{}].{}", std::any::type_name::<T>(), x))
|
|
||||||
// .collect::<Vec<String>>()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl<T: ToCsv + Default, const N: usize> ToCsv for [T; N] {
|
fn fields(&mut self) -> Vec<(&str, &mut dyn Reflect)> {
|
||||||
// fn to_csv(&self) -> Vec<String> {
|
Vec::new()
|
||||||
// self.iter()
|
}
|
||||||
// .enumerate()
|
|
||||||
// .map(|(i, x)| {
|
|
||||||
// x.to_csv()
|
|
||||||
// .iter()
|
|
||||||
// .map(|a| format!("[{}].{}", i, a))
|
|
||||||
// .collect::<Vec<String>>()
|
|
||||||
// })
|
|
||||||
// .flatten()
|
|
||||||
// .collect()
|
|
||||||
// }
|
|
||||||
// fn enumerate(&self) -> Vec<String> {
|
|
||||||
// T::default()
|
|
||||||
// .enumerate()
|
|
||||||
// .iter()
|
|
||||||
// .map(|x| format!("[{}].{}", std::any::type_name::<T>(), x))
|
|
||||||
// .collect::<Vec<String>>()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl<T1: ToCsv, T2: ToCsv> ToCsv for (T1, T2) {
|
fn set_value(&mut self, value: ReflectValue) {
|
||||||
// fn to_csv(&self) -> Vec<String> {
|
*self = value.vec();
|
||||||
// let mut csvs = Vec::new();
|
}
|
||||||
// csvs.extend(self.0.to_csv().iter().map(|x| format!("[0].{}", x)));
|
|
||||||
// csvs.extend(self.1.to_csv().iter().map(|x| format!("[1].{}", x)));
|
|
||||||
// csvs
|
|
||||||
// }
|
|
||||||
// fn enumerate(&self) -> Vec<String> {
|
|
||||||
// vec![format!(
|
|
||||||
// " = ({}, {})",
|
|
||||||
// std::any::type_name::<T1>(),
|
|
||||||
// std::any::type_name::<T2>()
|
|
||||||
// )]
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl<T1: ToCsv, T2: ToCsv, T3: ToCsv> ToCsv for (T1, T2, T3) {
|
fn get_value(&self) -> ReflectValue {
|
||||||
// fn to_csv(&self) -> Vec<String> {
|
ReflectValue::Bool(*self)
|
||||||
// let mut csvs = Vec::new();
|
}
|
||||||
// csvs.extend(self.0.to_csv().iter().map(|x| format!("[0].{}", x)));
|
|
||||||
// csvs.extend(self.1.to_csv().iter().map(|x| format!("[1].{}", x)));
|
|
||||||
// csvs.extend(self.2.to_csv().iter().map(|x| format!("[2].{}", x)));
|
|
||||||
// csvs
|
|
||||||
// }
|
|
||||||
// fn enumerate(&self) -> Vec<String> {
|
|
||||||
// vec![format!(
|
|
||||||
// " = ({}, {}, {})",
|
|
||||||
// std::any::type_name::<T1>(),
|
|
||||||
// std::any::type_name::<T2>(),
|
|
||||||
// std::any::type_name::<T2>()
|
|
||||||
// )]
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl<T1: ToCsv, T2: ToCsv, T3: ToCsv, T4: ToCsv> ToCsv for (T1, T2, T3, T4) {
|
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> {
|
||||||
// fn to_csv(&self) -> Vec<String> {
|
Vec::new()
|
||||||
// let mut csvs = Vec::new();
|
}
|
||||||
// csvs.extend(self.0.to_csv().iter().map(|x| format!("[0].{}", x)));
|
|
||||||
// csvs.extend(self.1.to_csv().iter().map(|x| format!("[1].{}", x)));
|
|
||||||
// csvs.extend(self.2.to_csv().iter().map(|x| format!("[2].{}", x)));
|
|
||||||
// csvs.extend(self.3.to_csv().iter().map(|x| format!("[3].{}", x)));
|
|
||||||
// csvs
|
|
||||||
// }
|
|
||||||
// fn enumerate(&self) -> Vec<String> {
|
|
||||||
// vec![format!(
|
|
||||||
// " = ({}, {}, {}, {})",
|
|
||||||
// std::any::type_name::<T1>(),
|
|
||||||
// std::any::type_name::<T2>(),
|
|
||||||
// std::any::type_name::<T2>(),
|
|
||||||
// std::any::type_name::<T3>()
|
|
||||||
// )]
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl<T: ToCsv> ToCsvClean for T {
|
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> {
|
||||||
// fn to_csv_clean(&self) -> Vec<String> {
|
None
|
||||||
// self.to_csv().iter().map(|x| to_csv_clean(x)).collect()
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fn enumerate_clean(&self) -> Vec<String> {
|
|
||||||
// self.enumerate().iter().map(|x| to_csv_clean(x)).collect()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn to_csv_clean(s: &String) -> String {
|
|
||||||
// let s = s.replace(".[", "[");
|
|
||||||
// let s = s.replace(". =", " =");
|
|
||||||
// s
|
|
||||||
// }
|
|
||||||
|
|||||||
+4
-3
@@ -4,11 +4,12 @@ use bincode::{Decode, Encode};
|
|||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
use crate as rfe;
|
||||||
use serde::{Deserialize, Serialize};
|
#[cfg(feature = "reflect")]
|
||||||
|
use crate::macros::Reflect;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Encode, Decode)]
|
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Encode, Decode)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||||
|
|
||||||
pub struct PerfData {
|
pub struct PerfData {
|
||||||
enter_time: Timestamp,
|
enter_time: Timestamp,
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ path = "src/decom.rs"
|
|||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
simple_logger.workspace = true
|
simple_logger.workspace = true
|
||||||
rfe = { path = "../../rfe", features = [] }
|
rfe = { path = "../../rfe", features = ["reflect"] }
|
||||||
bincode = { workspace = true, features = ["std"] }
|
bincode = { workspace = true, features = ["std"] }
|
||||||
|
|||||||
Reference in New Issue
Block a user