RustyLee: Adds organ ID to brain messages

Includes a unique identifier for the sending organ in `BrainMessage`.
Enables the Brain to differentiate and respond appropriately to messages from various organs.
Refactors `Brain` method for clearer communication flow.
This commit is contained in:
Russell Gilbert 2026-03-14 09:14:45 +00:00
parent 6bf5809ed8
commit 175e01e361
3 changed files with 5 additions and 3 deletions

View file

@ -52,7 +52,7 @@ impl Brain {
} }
while let Ok(message) = self.organ_rx.try_recv() { while let Ok(message) = self.organ_rx.try_recv() {
self.process_organ_message(message); self.process_message_from_organ(message);
} }
self.rest(); self.rest();
@ -153,8 +153,8 @@ impl Brain {
self.state != Buried self.state != Buried
} }
fn process_organ_message(&mut self, message: BrainMessage) { fn process_message_from_organ(&mut self, message: BrainMessage) {
debug!("organ message received: {:?}", message); debug!("organ message received: {:?}.", message);
if let OrganCommand::Waken = message.organ_command.command { if let OrganCommand::Waken = message.organ_command.command {
self.state = LifeState::Awake; self.state = LifeState::Awake;
} }

View file

@ -76,6 +76,7 @@ impl Heart {
let reply = BrainMessage { let reply = BrainMessage {
organ_command: command_envelope, organ_command: command_envelope,
responded_at: Time::time_stamp_millis(), responded_at: Time::time_stamp_millis(),
organ_id: self.id,
response, response,
}; };

View file

@ -33,5 +33,6 @@ pub struct OrganCommandEnvelope {
pub struct BrainMessage { pub struct BrainMessage {
pub organ_command: OrganCommandEnvelope, pub organ_command: OrganCommandEnvelope,
pub responded_at: u64, pub responded_at: u64,
pub organ_id: u32,
pub response: OrganResponse, pub response: OrganResponse,
} }