Move code to radio module

This commit is contained in:
Greg Shuflin 2021-02-28 01:31:29 -08:00
parent 48faf189c8
commit 4183e0afc5
2 changed files with 48 additions and 32 deletions

View File

@ -8,11 +8,7 @@ const COPYRIGHT: &'static str = "Copyright (C) 2018 Serge Vakulenko KK6ABQ";
const VERSION: Option<&'static str> = option_env!("VERSION"); const VERSION: Option<&'static str> = option_env!("VERSION");
extern { extern {
fn radio_connect();
fn radio_upload(cont_flag: c_int); fn radio_upload(cont_flag: c_int);
fn radio_disconnect();
fn radio_verify_config();
fn radio_download();
} }
fn print_usage() { 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(); print_usage();
} }
unsafe { unsafe {
radio_connect(); radio::connect();
radio::read_image(&matches.free[0]); radio::read_image(&matches.free[0]);
radio::print_version(); radio::print_version();
radio_upload(0); radio_upload(0);
radio_disconnect(); radio::disconnect();
} }
} else if config_flag { } else if config_flag {
let conf_args = matches.free.len(); 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 { if let Some(img) = image_filename {
// Apply text config to image file. // Apply text config to image file.
unsafe { radio::read_image(&img);
radio::read_image(&img); radio::print_version();
radio::print_version(); radio::parse_config(&config_filename);
radio::parse_config(&config_filename); radio::verify_config();
radio_verify_config(); radio::save_image("device.img");
radio::save_image("device.img");
}
} else { } else {
// Update device from text config file. // Update device from text config file.
unsafe { unsafe {
radio_connect(); radio::connect();
radio_download(); radio::download();
radio::print_version(); radio::print_version();
radio::save_image("device.img"); radio::save_image("device.img");
radio::parse_config(&config_filename); radio::parse_config(&config_filename);
radio_verify_config(); radio::verify_config();
radio_upload(1); radio_upload(1);
radio_disconnect(); radio::disconnect();
} }
} }
} else if verify_flag { } 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(); print_usage();
} }
// Verify text config file. // Verify text config file.
unsafe { radio::connect();
radio_connect(); radio::parse_config(&matches.free[0]);
radio::parse_config(&matches.free[0]); radio::verify_config();
radio_verify_config(); radio::disconnect();
radio_disconnect();
}
} else if read_flag { } else if read_flag {
if matches.free.len() != 0 { if matches.free.len() != 0 {
print_usage(); print_usage();
} }
// Dump device to image file. // Dump device to image file.
unsafe { radio::connect();
radio_connect(); radio::download();
radio_download();
radio::print_version(); radio::print_version();
radio_disconnect(); radio::disconnect();
radio::save_image("device.img"); radio::save_image("device.img");
}
// Print configuration to file. // Print configuration to file.
let filename = "device.conf"; 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(); print_usage();
} }
unsafe { radio::connect();
radio_connect();
radio::write_csv(&matches.free[0]); radio::write_csv(&matches.free[0]);
radio_disconnect(); radio::disconnect();
}
} else { } else {
if matches.free.len() != 1 { if matches.free.len() != 1 {
print_usage(); print_usage();

View File

@ -3,7 +3,11 @@ use libc::{c_char, c_int};
use std::os::unix::io::AsRawFd; use std::os::unix::io::AsRawFd;
extern { extern {
fn radio_connect();
fn radio_disconnect();
fn radio_download();
fn radio_list_c(); fn radio_list_c();
fn radio_verify_config();
fn radio_print_version(stdout: *const libc::FILE); fn radio_print_version(stdout: *const libc::FILE);
fn radio_print_config(file: *const libc::FILE, verbose: c_int); fn radio_print_config(file: *const libc::FILE, verbose: c_int);
fn radio_read_image(filename: *const c_char); fn radio_read_image(filename: *const c_char);
@ -12,12 +16,36 @@ extern {
fn radio_write_csv(filename: *const c_char); 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() { pub fn list() {
unsafe { unsafe {
radio_list_c(); radio_list_c();
} }
} }
pub fn verify_config() {
unsafe {
radio_verify_config();
}
}
pub fn read_image(filename: &str) { pub fn read_image(filename: &str) {
let filename = CString::new(filename.to_string()).unwrap(); let filename = CString::new(filename.to_string()).unwrap();
unsafe { unsafe {