Crate kubos_app[][src]

A simple API to make standalone Rust applications with high-level hooks for mission life-cycle management

Examples

#[macro_use]
extern crate kubos_app;

use kubos_app::*;
use std::time::Duration;

struct MyApp;

impl AppHandler for MyApp {
  fn on_boot(&self) {
    println!("OnBoot logic");

    let request = r#"mutation {
            power(state: ON) {
                success
            }
        }"#;

    match query(ServiceConfig::new("radio-service"), request, Some(Duration::from_secs(1))) {
        Err(error) => {
            eprintln!("Failed to communicate with radio service: {}", error);
            return;
        }
        Ok(data) => {
            if let Some(success) = data.get("power")
                .and_then(|power| power.get("success"))
            {
                match success.as_bool() {
                    Some(true) => println!("Successfully turned on radio"),
                    Some(false) => eprintln!("Failed to turn on radio"),
                    None => eprintln!("Failed to fetch radio power state")
                }
            } else {
                eprintln!("Failed to fetch radio power state");
                return;
            }
        }
    }
  }
  fn on_command(&self) {
    println!("OnCommand logic");
  }
}

fn main() {
    let app = MyApp { };
    app_main!(&app);
}

Macros

app_main

A helper macro which detects the requested run level and calls the appropriate handler function

Structs

ServiceConfig

KubOS config used by either Apps or Services. KubOS config files use the TOML format, and can may contain multiple named Categories. Typically each category corresponds to an App or Service name. This allows one config file to store configuration for multiple Apps / Services at a time.

Enums

RunLevel

The different ways an application can be started

Traits

AppHandler

Common trait which is used to ensure handlers for all required run levels are defined

Functions

app_start

The entry point for all KubOS applications. The preferred way to use this application is through the app_main! macro

query

Execute a GraphQL query against a running KubOS Service using UDP.