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
#[macro_use] extern crate log;
extern crate env_logger;
mod command;
mod constants;
mod gamepad;
mod heartbeat;
mod keyboard;
mod video;
use gamepad::Gamepad;
use heartbeat::Heartbeat;
use video::Video;
use std::error::Error;
use std::net::TcpStream;
use std::io::Write;
pub fn connect() {
env_logger::init().unwrap();
let mut handshake_stream = match TcpStream::connect(format!("{}:{}", constants::DRONE_HOST, constants::DRONE_TCP_PORT)) {
Ok(stream) => stream,
Err(e) => panic!("Error connecting to handshake socket: {}", e.description()),
};
let functions = [constants::get_handshake, constants::get_video_1_1, constants::get_video_1_2];
for index in 0..functions.len() {
match handshake_stream.write(functions[index]().as_slice()) {
Ok(_) => debug!("Sent {}", index),
Err(e) => panic!("Error writing {}: {}", index, e.description()),
}
}
Heartbeat::new().start();
Video::new().start();
Gamepad::new().start();
}