firstadd
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "example"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
path = "src/example.rs"
|
||||
|
||||
[dependencies]
|
||||
rfe = { path = "../../rfe" }
|
||||
anyhow.workspace = true
|
||||
log.workspace = true
|
||||
@@ -0,0 +1,69 @@
|
||||
#![no_std]
|
||||
|
||||
use anyhow::Result;
|
||||
use log::info;
|
||||
use msg::{ExampleCmd, ExampleHk, ExampleOutData, Instance, Msg, MsgKind, TargetMsg};
|
||||
use rfe::*;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct ExampleData {
|
||||
hk: ExampleHk,
|
||||
out_data: ExampleOutData,
|
||||
}
|
||||
|
||||
pub struct Example {
|
||||
data: ExampleData,
|
||||
}
|
||||
|
||||
impl Example {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
data: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl App for Example {
|
||||
fn init(&mut self, rfe: &mut rfe::Rfe) -> Result<()> {
|
||||
self.data = Default::default();
|
||||
rfe.subscribe(TargetMsg::new(Instance::Other, MsgKind::ExampleHk));
|
||||
rfe.subscribe(TargetMsg::new(rfe.get_instance(), MsgKind::ExampleCmd));
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
fn run(&mut self, rfe: &mut rfe::Rfe) {
|
||||
self.data.out_data.counter += 1;
|
||||
info!("example running {:?}", self.data);
|
||||
while let Some(msg) = rfe.recv() {
|
||||
match msg.msg {
|
||||
Msg::ExampleCmd(cmd) => match cmd {
|
||||
ExampleCmd::Noop => info!("NOOP command received"),
|
||||
ExampleCmd::Reset => {
|
||||
info!("RESET command received");
|
||||
self.data = Default::default();
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
info!("example got msg {:?}", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.data.out_data.counter > 10 {
|
||||
rfe.send(Msg::ExampleCmd(ExampleCmd::Reset));
|
||||
};
|
||||
}
|
||||
|
||||
fn hk(&mut self, rfe: &mut rfe::Rfe) {
|
||||
self.data.hk.counter = self.data.out_data.counter;
|
||||
rfe.send(Msg::ExampleHk(self.data.hk));
|
||||
}
|
||||
|
||||
fn out_data(&mut self, rfe: &mut rfe::Rfe) {
|
||||
rfe.send(Msg::ExampleOutData(self.data.out_data));
|
||||
}
|
||||
|
||||
fn get_app_rate(&self) -> Rate {
|
||||
Rate::Hz1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user