Move code to radio module
This commit is contained in:
parent
48faf189c8
commit
4183e0afc5
42
src/lib.rs
42
src/lib.rs
@ -8,11 +8,7 @@ const COPYRIGHT: &'static str = "Copyright (C) 2018 Serge Vakulenko KK6ABQ";
|
||||
const VERSION: Option<&'static str> = option_env!("VERSION");
|
||||
|
||||
extern {
|
||||
fn radio_connect();
|
||||
fn radio_upload(cont_flag: c_int);
|
||||
fn radio_disconnect();
|
||||
fn radio_verify_config();
|
||||
fn radio_download();
|
||||
}
|
||||
|
||||
fn print_usage() {
|
||||
@ -96,11 +92,11 @@ pub extern "C" fn rust_main(_argc: c_int, _argv: *const *const c_char) -> c_int
|
||||
print_usage();
|
||||
}
|
||||
unsafe {
|
||||
radio_connect();
|
||||
radio::connect();
|
||||
radio::read_image(&matches.free[0]);
|
||||
radio::print_version();
|
||||
radio_upload(0);
|
||||
radio_disconnect();
|
||||
radio::disconnect();
|
||||
}
|
||||
} else if config_flag {
|
||||
let conf_args = matches.free.len();
|
||||
@ -115,24 +111,22 @@ pub extern "C" fn rust_main(_argc: c_int, _argv: *const *const c_char) -> c_int
|
||||
|
||||
if let Some(img) = image_filename {
|
||||
// Apply text config to image file.
|
||||
unsafe {
|
||||
radio::read_image(&img);
|
||||
radio::print_version();
|
||||
radio::parse_config(&config_filename);
|
||||
radio_verify_config();
|
||||
radio::verify_config();
|
||||
radio::save_image("device.img");
|
||||
}
|
||||
} else {
|
||||
// Update device from text config file.
|
||||
unsafe {
|
||||
radio_connect();
|
||||
radio_download();
|
||||
radio::connect();
|
||||
radio::download();
|
||||
radio::print_version();
|
||||
radio::save_image("device.img");
|
||||
radio::parse_config(&config_filename);
|
||||
radio_verify_config();
|
||||
radio::verify_config();
|
||||
radio_upload(1);
|
||||
radio_disconnect();
|
||||
radio::disconnect();
|
||||
}
|
||||
}
|
||||
} else if verify_flag {
|
||||
@ -140,25 +134,21 @@ pub extern "C" fn rust_main(_argc: c_int, _argv: *const *const c_char) -> c_int
|
||||
print_usage();
|
||||
}
|
||||
// Verify text config file.
|
||||
unsafe {
|
||||
radio_connect();
|
||||
radio::connect();
|
||||
radio::parse_config(&matches.free[0]);
|
||||
radio_verify_config();
|
||||
radio_disconnect();
|
||||
}
|
||||
radio::verify_config();
|
||||
radio::disconnect();
|
||||
} else if read_flag {
|
||||
if matches.free.len() != 0 {
|
||||
print_usage();
|
||||
}
|
||||
|
||||
// Dump device to image file.
|
||||
unsafe {
|
||||
radio_connect();
|
||||
radio_download();
|
||||
radio::connect();
|
||||
radio::download();
|
||||
radio::print_version();
|
||||
radio_disconnect();
|
||||
radio::disconnect();
|
||||
radio::save_image("device.img");
|
||||
}
|
||||
|
||||
// Print configuration to file.
|
||||
let filename = "device.conf";
|
||||
@ -171,11 +161,9 @@ pub extern "C" fn rust_main(_argc: c_int, _argv: *const *const c_char) -> c_int
|
||||
print_usage();
|
||||
}
|
||||
|
||||
unsafe {
|
||||
radio_connect();
|
||||
radio::connect();
|
||||
radio::write_csv(&matches.free[0]);
|
||||
radio_disconnect();
|
||||
}
|
||||
radio::disconnect();
|
||||
} else {
|
||||
if matches.free.len() != 1 {
|
||||
print_usage();
|
||||
|
28
src/radio.rs
28
src/radio.rs
@ -3,7 +3,11 @@ use libc::{c_char, c_int};
|
||||
use std::os::unix::io::AsRawFd;
|
||||
|
||||
extern {
|
||||
fn radio_connect();
|
||||
fn radio_disconnect();
|
||||
fn radio_download();
|
||||
fn radio_list_c();
|
||||
fn radio_verify_config();
|
||||
fn radio_print_version(stdout: *const libc::FILE);
|
||||
fn radio_print_config(file: *const libc::FILE, verbose: c_int);
|
||||
fn radio_read_image(filename: *const c_char);
|
||||
@ -12,12 +16,36 @@ extern {
|
||||
fn radio_write_csv(filename: *const c_char);
|
||||
}
|
||||
|
||||
pub fn connect() {
|
||||
unsafe {
|
||||
radio_connect()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disconnect() {
|
||||
unsafe {
|
||||
radio_disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn download() {
|
||||
unsafe {
|
||||
radio_download()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn list() {
|
||||
unsafe {
|
||||
radio_list_c();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn verify_config() {
|
||||
unsafe {
|
||||
radio_verify_config();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_image(filename: &str) {
|
||||
let filename = CString::new(filename.to_string()).unwrap();
|
||||
unsafe {
|
||||
|
Loading…
Reference in New Issue
Block a user