Compare commits
2 commits
d5ad70666e
...
09f75f97eb
| Author | SHA1 | Date | |
|---|---|---|---|
| 09f75f97eb | |||
| ef10ab5998 |
6 changed files with 39 additions and 16 deletions
14
src/rustylee/src/child_identity.rs
Normal file
14
src/rustylee/src/child_identity.rs
Normal file
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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)*
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
|
|||
|
|
@ -1,15 +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,
|
||||
last_beat: u128,
|
||||
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
|
||||
}
|
||||
|
||||
|
|
@ -19,10 +26,10 @@ impl_identifiable!(LedPump, {
|
|||
});
|
||||
|
||||
impl LedPump {
|
||||
pub fn new(id: u32) -> Self {
|
||||
pub fn new(id: u32, parent_organ_id: u32) -> Self {
|
||||
Self {
|
||||
id,
|
||||
last_beat: 0
|
||||
identity: ChildIdentity::new(id, parent_organ_id),
|
||||
last_beat: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,10 +56,9 @@ impl OrganFactory {
|
|||
brain_command_to_organ_rx,
|
||||
feedback_to_brain_tx
|
||||
);
|
||||
|
||||
|
||||
|
||||
let last_parenchyma_id = organ_id;
|
||||
let led_pump = LedPump::new(OrganFactory::next_parenchyma_id(last_parenchyma_id));
|
||||
let led_pump = LedPump::new(OrganFactory::next_parenchyma_id(last_parenchyma_id), organ_id);
|
||||
heart.add_parenchyma(Box::new(led_pump));
|
||||
heart.start();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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<OrganCommand>;
|
||||
}
|
||||
Loading…
Reference in a new issue