diff --git a/src/rustylee/src/child_identity.rs b/src/rustylee/src/child_identity.rs new file mode 100644 index 0000000..3dadd56 --- /dev/null +++ b/src/rustylee/src/child_identity.rs @@ -0,0 +1,14 @@ +#[derive(Debug, Clone, Copy)] +pub struct ChildIdentity { + id: u32, + parent_id: u32, +} + +impl ChildIdentity { + pub fn new(id: u32, parent_id: u32) -> Self { + Self { + id, + parent_id + } + } +} \ No newline at end of file diff --git a/src/rustylee/src/macros/identifiable.rs b/src/rustylee/src/macros/identifiable.rs index 61ded7f..87b815e 100644 --- a/src/rustylee/src/macros/identifiable.rs +++ b/src/rustylee/src/macros/identifiable.rs @@ -2,8 +2,8 @@ macro_rules! impl_identifiable { ($target:ident, { $($body:tt)* }) => { impl Parenchyma for $target { - fn id(&self) -> u32 { - self.id + fn identity(&self) -> child_identity::ChildIdentity { + self.identity } $($body)* diff --git a/src/rustylee/src/main.rs b/src/rustylee/src/main.rs index 6d9821f..6480059 100644 --- a/src/rustylee/src/main.rs +++ b/src/rustylee/src/main.rs @@ -5,6 +5,7 @@ pub mod coordinates; pub mod protocols; pub mod system; pub mod macros; +pub mod child_identity; use std::fmt::Alignment::Left; use tracing::{debug, info}; diff --git a/src/rustylee/src/organs/led_pump.rs b/src/rustylee/src/organs/led_pump.rs index e72b696..cdb53b0 100644 --- a/src/rustylee/src/organs/led_pump.rs +++ b/src/rustylee/src/organs/led_pump.rs @@ -1,16 +1,22 @@ -use crate::impl_identifiable; +use crate::child_identity::ChildIdentity; use crate::organs::parenchyma::Parenchyma; use crate::protocols::{OrganCommand, OrganCommandEnvelope, OrganResponse}; - +use crate::system::time::Time; +use crate::{child_identity, impl_identifiable}; +use tracing::{info}; pub struct LedPump { - id: u32, - parent_organ_id: u32, + identity: child_identity::ChildIdentity, last_beat: u64, } impl_identifiable!(LedPump, { fn do_work(&mut self, _envelope: OrganCommandEnvelope) -> OrganResponse { // Your logic here + let now = Time::time_stamp_millis(); + if now > self.last_beat + 500 { + info!("LED Pump heart beat at {} {:?}", now, self.identity); + self.last_beat = now; + } OrganResponse::Ok } @@ -22,9 +28,8 @@ impl_identifiable!(LedPump, { impl LedPump { pub fn new(id: u32, parent_organ_id: u32) -> Self { Self { - id, - parent_organ_id, - last_beat: 0 + identity: ChildIdentity::new(id, parent_organ_id), + last_beat: 0, } } -} \ No newline at end of file +} diff --git a/src/rustylee/src/organs/parenchyma.rs b/src/rustylee/src/organs/parenchyma.rs index b223568..bfa26a7 100644 --- a/src/rustylee/src/organs/parenchyma.rs +++ b/src/rustylee/src/organs/parenchyma.rs @@ -1,13 +1,15 @@ +use crate::child_identity::ChildIdentity; +use crate::protocols::{OrganCommand, OrganCommandEnvelope, OrganResponse}; /* Parenchyma: The essential and distinctive functional tissue of an organ, as distinguished from its connective tissue, blood vessels, and nerves (the stroma) */ -use crate::protocols::{OrganCommand, OrganCommandEnvelope, OrganResponse}; - pub trait Parenchyma: Send { - fn id(&self) -> u32; + fn identity(&self) -> ChildIdentity; + fn do_work (&mut self, command_envelope: OrganCommandEnvelope) -> OrganResponse; + fn get_supported_commands(&self) -> Vec; } \ No newline at end of file