You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

lib.rs 1.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #![warn(unsafe_op_in_unsafe_fn)]
  2. use dora_operator_api::{register_operator, DoraOperator, DoraOutputSender, DoraStatus, Event};
  3. register_operator!(ExampleOperator);
  4. #[derive(Debug, Default)]
  5. struct ExampleOperator {
  6. ticks: usize,
  7. }
  8. impl DoraOperator for ExampleOperator {
  9. fn on_event(
  10. &mut self,
  11. event: &Event,
  12. output_sender: &mut DoraOutputSender,
  13. ) -> Result<DoraStatus, String> {
  14. match event {
  15. Event::Input { id, data } => match *id {
  16. "tick" => {
  17. self.ticks += 1;
  18. }
  19. "random" => {
  20. let parsed = {
  21. let data: [u8; 8] =
  22. (*data).try_into().map_err(|_| "unexpected random data")?;
  23. u64::from_le_bytes(data)
  24. };
  25. let output = format!(
  26. "operator received random value {parsed:#x} after {} ticks",
  27. self.ticks
  28. );
  29. output_sender.send("status".into(), output.into_bytes())?;
  30. }
  31. other => eprintln!("ignoring unexpected input {other}"),
  32. },
  33. Event::Stop => {}
  34. Event::InputClosed { id } => {
  35. println!("input `{id}` was closed");
  36. if *id == "random" {
  37. println!("`random` input was closed -> exiting");
  38. return Ok(DoraStatus::Stop);
  39. }
  40. }
  41. other => {
  42. println!("received unknown event {other:?}");
  43. }
  44. }
  45. Ok(DoraStatus::Continue)
  46. }
  47. }

DORA (Dataflow-Oriented Robotic Architecture) is middleware designed to streamline and simplify the creation of AI-based robotic applications. It offers low latency, composable, and distributed datafl