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"
|
||||
rp2040-hal = "0.10.2"
|
||||
rp2040-pac = "0.6.0"
|
||||
serde = { version = "1.0.216", features = ["derive"] }
|
||||
serde_json = "1.0.133"
|
||||
|
||||
@@ -5,11 +5,9 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
rfe.path = "../../rfe"
|
||||
rfe.features = ["std", "serde"]
|
||||
rfe.features = ["std", "reflect"]
|
||||
anyhow.workspace = true
|
||||
simple_logger = "5.0.0"
|
||||
log.workspace = true
|
||||
serde_json.workspace = true
|
||||
serde.workspace = true
|
||||
egui = "0.30.0"
|
||||
eframe = "0.30.0"
|
||||
|
||||
+1
-2
@@ -7,7 +7,7 @@ edition = "2021"
|
||||
default = []
|
||||
std = ["dep:mio"]
|
||||
rp2040 = ["dep:rp2040-hal", "dep:rp2040-pac"]
|
||||
serde = ["dep:serde"]
|
||||
reflect = []
|
||||
|
||||
[dependencies]
|
||||
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-pac = { workspace = true, optional = true }
|
||||
macros.path = "macros"
|
||||
serde = { workspace = true, optional = true }
|
||||
|
||||
+29
-202
@@ -71,7 +71,7 @@ pub fn kind_derive(input: TokenStream) -> TokenStream {
|
||||
|
||||
let expanded = quote! {
|
||||
#[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 {
|
||||
#[default]
|
||||
#(#kind_enum_arms)*
|
||||
@@ -103,161 +103,6 @@ pub fn kind_derive(input: TokenStream) -> TokenStream {
|
||||
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)]
|
||||
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();
|
||||
|
||||
quote! { {
|
||||
fields.push((#field_name, &mut self.#field_ident as &mut dyn 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);
|
||||
fields.push((#field_name, &mut self.#field_ident as &mut dyn rfe::reflect::Reflect));
|
||||
} }
|
||||
});
|
||||
|
||||
quote! {
|
||||
impl Reflect for #name {
|
||||
fn reflect_type(&self) -> ReflectType {
|
||||
ReflectType::Structure
|
||||
impl rfe::reflect::Reflect for #name {
|
||||
fn reflect_type(&self) -> rfe::reflect::ReflectType {
|
||||
rfe::reflect::ReflectType::Structure
|
||||
}
|
||||
|
||||
fn type_name(&self) -> &str {
|
||||
#name_s
|
||||
}
|
||||
|
||||
fn fields(&mut self) -> Vec<(&str, &mut dyn Reflect)> {
|
||||
let mut fields = Vec::new();
|
||||
fn fields(&mut self) -> alloc::vec::Vec<(&str, &mut dyn rfe::reflect::Reflect)> {
|
||||
let mut fields = alloc::vec::Vec::new();
|
||||
#(#field_arms)*
|
||||
fields
|
||||
}
|
||||
|
||||
fn set_value(&mut self, value: ReflectValue) {
|
||||
fn set_value(&mut self, value: rfe::reflect::ReflectValue) {
|
||||
}
|
||||
|
||||
fn get_value(&self) -> ReflectValue {
|
||||
ReflectValue::None
|
||||
fn get_value(&self) -> rfe::reflect::ReflectValue {
|
||||
rfe::reflect::ReflectValue::None
|
||||
}
|
||||
|
||||
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> {
|
||||
Vec::new()
|
||||
fn variants(&self) -> alloc::vec::Vec<(&str, alloc::boxed::Box<dyn rfe::reflect::Reflect>)> {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -329,13 +160,10 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Data::Enum(data_enum) => {
|
||||
let variants = data_enum.variants;
|
||||
let as_arms = variants.iter().enumerate().map(|(i, variant)| {
|
||||
let variant_name = &variant.ident;
|
||||
let variant_name_s = variant_name.to_string();
|
||||
|
||||
match &variant.fields {
|
||||
Fields::Unit => {
|
||||
@@ -345,7 +173,6 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
|
||||
return Some(self);
|
||||
}
|
||||
}
|
||||
// quote! { Self::#variant_name => {}, }
|
||||
}
|
||||
Fields::Unnamed(_) => {
|
||||
quote! {
|
||||
@@ -358,7 +185,7 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
|
||||
}
|
||||
}
|
||||
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 => {
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -379,46 +206,46 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
|
||||
Fields::Unnamed(_) => {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Fields::Named(_) => {
|
||||
panic!("Named fields not supported by ToCsv");
|
||||
panic!("Named fields not supported by Reflect");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
quote! {
|
||||
impl Reflect for #name {
|
||||
fn reflect_type(&self) -> ReflectType {
|
||||
ReflectType::Enumeration
|
||||
impl rfe::reflect::Reflect for #name {
|
||||
fn reflect_type(&self) -> rfe::reflect::ReflectType {
|
||||
rfe::reflect::ReflectType::Enumeration
|
||||
}
|
||||
|
||||
fn type_name(&self) -> &str {
|
||||
#name_s
|
||||
}
|
||||
|
||||
fn fields(&mut self) -> Vec<(&str, &mut dyn Reflect)> {
|
||||
Vec::new()
|
||||
fn fields(&mut self) -> alloc::vec::Vec<(&str, &mut dyn rfe::reflect::Reflect)> {
|
||||
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 {
|
||||
ReflectValue::None
|
||||
fn get_value(&self) -> rfe::reflect::ReflectValue {
|
||||
rfe::reflect::ReflectValue::None
|
||||
}
|
||||
|
||||
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> {
|
||||
let mut variants = Vec::new();
|
||||
fn variants(&self) -> alloc::vec::Vec<(&str, alloc::boxed::Box<dyn rfe::reflect::Reflect>)> {
|
||||
let mut variants = alloc::vec::Vec::new();
|
||||
#(#variant_arms)*
|
||||
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)*
|
||||
panic!("variant incorrect");
|
||||
}
|
||||
@@ -426,7 +253,7 @@ pub fn reflect_derive(input: TokenStream) -> TokenStream {
|
||||
}
|
||||
}
|
||||
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()
|
||||
.into();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ pub mod msg;
|
||||
mod rfe;
|
||||
pub use rfe::*;
|
||||
|
||||
#[cfg(feature = "reflect")]
|
||||
pub mod reflect;
|
||||
|
||||
pub use macros;
|
||||
|
||||
+7
-6
@@ -5,11 +5,12 @@ use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use super::{TlmSetId, TlmSetItem};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate as rfe;
|
||||
#[cfg(feature = "reflect")]
|
||||
use crate::macros::Reflect;
|
||||
|
||||
#[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 items: Vec<TlmSetItem>,
|
||||
pub id: TlmSetId,
|
||||
@@ -18,14 +19,14 @@ pub struct DsTlmSet {
|
||||
}
|
||||
|
||||
#[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 perf: PerfData,
|
||||
pub counter: u32,
|
||||
}
|
||||
|
||||
#[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 counter: u32,
|
||||
pub bytes_written: u32,
|
||||
@@ -33,7 +34,7 @@ pub struct DsOutData {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||
pub enum DsCmd {
|
||||
#[default]
|
||||
Noop,
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
extern crate alloc;
|
||||
use crate as rfe;
|
||||
#[cfg(feature = "reflect")]
|
||||
use crate::macros::Reflect;
|
||||
use crate::utils::PerfData;
|
||||
use bincode::{Decode, Encode};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[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 perf: PerfData,
|
||||
pub counter: u32,
|
||||
}
|
||||
|
||||
#[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 counter: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||
pub enum ExampleCmd {
|
||||
#[default]
|
||||
Noop,
|
||||
|
||||
+6
-5
@@ -2,12 +2,13 @@ use crate::utils::PerfData;
|
||||
use bincode::{Decode, Encode};
|
||||
|
||||
extern crate alloc;
|
||||
use crate as rfe;
|
||||
#[cfg(feature = "reflect")]
|
||||
use crate::macros::Reflect;
|
||||
use alloc::vec::Vec;
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||
pub struct HsHk {
|
||||
pub perf: PerfData,
|
||||
pub counter: u32,
|
||||
@@ -22,13 +23,13 @@ pub struct HsHk {
|
||||
}
|
||||
|
||||
#[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 counter: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||
pub enum HsCmd {
|
||||
#[default]
|
||||
Noop,
|
||||
|
||||
+10
-9
@@ -14,12 +14,13 @@ pub use to::*;
|
||||
mod ds;
|
||||
pub use ds::*;
|
||||
|
||||
use crate as rfe;
|
||||
#[cfg(feature = "reflect")]
|
||||
use crate::macros::Reflect;
|
||||
use crate::time::Timestamp;
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[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 {
|
||||
// instance is FROM for tlm, is TO for cmds
|
||||
pub instance: Instance,
|
||||
@@ -33,7 +34,7 @@ impl TargetMsg {
|
||||
}
|
||||
|
||||
#[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 {
|
||||
#[default]
|
||||
None,
|
||||
@@ -44,7 +45,7 @@ pub enum Instance {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Kind, Encode, Decode)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||
pub enum Msg {
|
||||
#[default]
|
||||
None,
|
||||
@@ -67,7 +68,7 @@ pub enum Msg {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||
pub struct MsgPacket {
|
||||
pub instance: Instance,
|
||||
pub msg: Msg,
|
||||
@@ -93,13 +94,13 @@ impl MsgPacket {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||
pub struct SubList {
|
||||
pub subs: Vec<TargetMsg>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||
pub struct ReinitAppCmd {
|
||||
app_name: String,
|
||||
}
|
||||
@@ -107,7 +108,7 @@ pub struct ReinitAppCmd {
|
||||
pub type TlmSetId = u16;
|
||||
|
||||
#[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 target: TargetMsg,
|
||||
pub decimation: u16,
|
||||
|
||||
+7
-6
@@ -1,14 +1,15 @@
|
||||
use crate::utils::PerfData;
|
||||
use bincode::{Decode, Encode};
|
||||
extern crate alloc;
|
||||
use crate as rfe;
|
||||
#[cfg(feature = "reflect")]
|
||||
use crate::macros::Reflect;
|
||||
use alloc::vec::Vec;
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{TlmSetId, TlmSetItem};
|
||||
|
||||
#[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 items: Vec<TlmSetItem>,
|
||||
pub id: TlmSetId,
|
||||
@@ -16,20 +17,20 @@ pub struct ToTlmSet {
|
||||
}
|
||||
|
||||
#[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 perf: PerfData,
|
||||
pub counter: u32,
|
||||
}
|
||||
|
||||
#[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 counter: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "reflect", derive(Reflect))]
|
||||
pub enum ToCmd {
|
||||
#[default]
|
||||
Noop,
|
||||
|
||||
+25
-116
@@ -96,6 +96,8 @@ impl ReflectValue {
|
||||
ReflectValue::Bool(b) => *b,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn vec(self) -> Vec<ReflectValue> {}
|
||||
}
|
||||
|
||||
pub trait Reflect: std::fmt::Debug {
|
||||
@@ -444,125 +446,32 @@ impl Reflect for bool {
|
||||
}
|
||||
}
|
||||
|
||||
// impl ToCsv for bool {
|
||||
// fn to_csv(&self) -> Vec<String> {
|
||||
// vec![format!(" = {}", self)]
|
||||
// }
|
||||
// fn enumerate(&self) -> Vec<String> {
|
||||
// vec![format!(" = bool")]
|
||||
// }
|
||||
// }
|
||||
impl<T: Reflect> Reflect for Vec<T> {
|
||||
fn reflect_type(&self) -> ReflectType {
|
||||
ReflectType::Value
|
||||
}
|
||||
|
||||
// impl<T: ToCsv + Default> ToCsv for Vec<T> {
|
||||
// fn to_csv(&self) -> Vec<String> {
|
||||
// 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>>()
|
||||
// }
|
||||
// }
|
||||
fn type_name(&self) -> &str {
|
||||
"vec[]"
|
||||
}
|
||||
|
||||
// impl<T: ToCsv + Default, const N: usize> ToCsv for [T; N] {
|
||||
// fn to_csv(&self) -> Vec<String> {
|
||||
// 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>>()
|
||||
// }
|
||||
// }
|
||||
fn fields(&mut self) -> Vec<(&str, &mut dyn Reflect)> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
// impl<T1: ToCsv, T2: ToCsv> ToCsv for (T1, T2) {
|
||||
// fn to_csv(&self) -> Vec<String> {
|
||||
// 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>()
|
||||
// )]
|
||||
// }
|
||||
// }
|
||||
fn set_value(&mut self, value: ReflectValue) {
|
||||
*self = value.vec();
|
||||
}
|
||||
|
||||
// impl<T1: ToCsv, T2: ToCsv, T3: ToCsv> ToCsv for (T1, T2, T3) {
|
||||
// fn to_csv(&self) -> Vec<String> {
|
||||
// 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>()
|
||||
// )]
|
||||
// }
|
||||
// }
|
||||
fn get_value(&self) -> ReflectValue {
|
||||
ReflectValue::Bool(*self)
|
||||
}
|
||||
|
||||
// impl<T1: ToCsv, T2: ToCsv, T3: ToCsv, T4: ToCsv> ToCsv for (T1, T2, T3, T4) {
|
||||
// fn to_csv(&self) -> Vec<String> {
|
||||
// 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>()
|
||||
// )]
|
||||
// }
|
||||
// }
|
||||
fn variants(&self) -> Vec<(&str, Box<dyn Reflect>)> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
// impl<T: ToCsv> ToCsvClean for T {
|
||||
// fn to_csv_clean(&self) -> Vec<String> {
|
||||
// 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
|
||||
// }
|
||||
fn as_variant(&mut self, _i: usize) -> Option<&mut dyn Reflect> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -4,11 +4,12 @@ use bincode::{Decode, Encode};
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate as rfe;
|
||||
#[cfg(feature = "reflect")]
|
||||
use crate::macros::Reflect;
|
||||
|
||||
#[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 {
|
||||
enter_time: Timestamp,
|
||||
|
||||
@@ -11,5 +11,5 @@ path = "src/decom.rs"
|
||||
anyhow.workspace = true
|
||||
log.workspace = true
|
||||
simple_logger.workspace = true
|
||||
rfe = { path = "../../rfe", features = [] }
|
||||
rfe = { path = "../../rfe", features = ["reflect"] }
|
||||
bincode = { workspace = true, features = ["std"] }
|
||||
|
||||
Reference in New Issue
Block a user