Skip to content

Commit

Permalink
Add dosimeter commands to Event enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Guggi committed Jun 9, 2024
1 parent abab5aa commit 440a5ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/command/execution_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ pub struct ResultId {
pub enum Event {
Status(ProgramStatus),
Result(ResultId),
EnableDosimeter,
DisableDosimeter,
}

impl Event {
pub fn to_bytes(self) -> Vec<u8> {
impl From<Event> for Vec<u8> {
fn from(value: Event) -> Self {
let mut v = Vec::new();
match self {
match value {
Event::Status(s) => {
v.push(1);
v.extend(s.program_id.to_le_bytes());
Expand All @@ -135,6 +137,12 @@ impl Event {
v.extend(r.program_id.to_le_bytes());
v.extend(r.timestamp.to_le_bytes());
}
Event::EnableDosimeter => {
v.push(3);
}
Event::DisableDosimeter => {
v.push(4);
}
}
v
}
Expand Down
4 changes: 2 additions & 2 deletions src/command/get_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ pub fn get_status(
l_exec.event_vec.as_ref().iter().position(|x| matches!(x, Event::Status(_)))
{
let event = l_exec.event_vec[index];
com.send_packet(&CEPPacket::Data(event.to_bytes()))?;
com.send_packet(&CEPPacket::Data(event.into()))?;
l_exec.event_vec.remove(index)?;
} else {
let event = *l_exec.event_vec.as_ref().last().unwrap(); // Safe, because we know it is not empty
com.send_packet(&CEPPacket::Data(event.to_bytes()))?;
com.send_packet(&CEPPacket::Data(event.into()))?;

if !matches!(event, Event::Result(_)) {
// Results are removed when deleted
Expand Down

0 comments on commit 440a5ec

Please sign in to comment.