1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//! DJI Onboard
//! ===========
//!
//! Rust implementation of DJI open protocol and the application of the protocol.
//!
//! Example
//! -------
//!
//! ```rust,no_run
//! extern crate dji_onboard;
//! extern crate serial;
//!
//! use dji_onboard::{Runner, Task, TaskType};
//!
//! fn main() {
//!     const RAW_KEY: &'static str = "ca229c5d7ca44920ba3716e5baabc310\
//!                                    ed94aa40c1fd405296f793a4d7343518";
//!
//!     let task = Task::activate(12345);
//!
//!     // Create runner
//!     let mut runner = Runner::build()
//!         .finish("/tmp/serial-port", serial::Baud9600, RAW_KEY)
//!         .unwrap();
//!
//!     // Add tasks
//!     runner.add_task(TaskType::simple(task));
//!
//!     // Run the event loop
//!     runner.run();
//! }
//! ```
//!
//! Run
//! ---
//!
//! Create a task file in json format like [task-sample.json](task-sample.json).
//!
//! ```bash
//! # Command line usage:
//! $ cargo run -- -h
//!
//! # Run the program:
//! $ cargo run -- -t task.json
//!
//! # Use `-f <file>` to log flight data to file:
//! $ cargo run -- -t task.json -f flight-data
//! ```
//!
//! To start a shell for interacting with the program, add an entry named *tcp-port* to task.json:
//!
//! ```js
//! {
//!   // ...
//!   "tcp_port": 9090,
//!   // ...
//! }
//! ```
//! then run `telnet 127.0.0.1 9090` or `rlwrap telnet 127.0.0.1 9090`.
//!
//! To start a http server, add *api* to task.json:
//!
//! ```js
//! {
//!   // ...
//!   "api": "localhost:9009",
//!   "flight-data-url": "http://testing.lab.eleme.io/flight/drone/push/data",
//!   "waypoint-status-url": "http://testing.lab.eleme.io/flight/drone/push/waypoint",
//!   // ...
//! }
//! ```
//!
//! Test
//! ----
//!
//! ```bash
//! $ cargo test
//! ```
//!
//! Deploy
//! ------
//!
//! Install ansible first.
//!
//! ```bash
//! $ cargo build --release --target=armv7-unknown-linux-gnueabihf
//! $ cd ./deploy
//! # the target after `--limit` should be listed in *hosts* file
//! $ ansible-playbook -i hosts --limit <target raspberry pi>  playbook.yml
//!
//! # deploy to a new raspberry pi
//! $ ansible-playbook -i hosts --limit raw playbook.yml \
//!     --extra-vars="ansible_host=<ip address of pi> ansible_user=pi platform=<m100 or a3>" \
//!     --ask-pass
//! ```
#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate hyper;
#[macro_use]
extern crate log;

extern crate chrono;
extern crate crypto;
extern crate iron;
extern crate libc;
extern crate logger;
extern crate mio;
#[macro_use]
extern crate open_protocol;
#[macro_use]
extern crate serde_derive;
extern crate serde;
#[macro_use]
extern crate serde_json;
extern crate serial;
#[macro_use]
extern crate router;
extern crate bodyparser;
extern crate urlencoded;

#[cfg(target_arch = "arm")]
extern crate laser;

#[macro_export]
macro_rules! die {
    ($($arg:tt)*) => {{
        use std::io::Write;
        (writeln!(&mut ::std::io::stderr(), $($arg)*)).expect("stderr");
        ::std::process::exit(1);
    }}
}

#[macro_export]
macro_rules! assert_result {
    ($res:expr, $($arg:tt)*) => ({
        match $res {
            Ok(r) => r,
            Err(e) => die!($($arg)*, e)
        }
    })
}

mod error;
mod event;
mod mission;
mod shell;
mod task;
mod waypoint;
mod stats;

pub mod http;
pub mod transport;

pub use error::{Error, Result};
pub use event::Runner;
pub use task::{Task, TaskType};