loop implemented
This commit is contained in:
parent
4df398a749
commit
bf74c5c678
1 changed files with 25 additions and 7 deletions
32
src/main.rs
32
src/main.rs
|
@ -1,9 +1,11 @@
|
||||||
mod cloudlog;
|
mod cloudlog;
|
||||||
mod settings;
|
|
||||||
mod flrig;
|
mod flrig;
|
||||||
|
mod settings;
|
||||||
|
|
||||||
|
use std::{thread, time::Duration};
|
||||||
|
|
||||||
use settings::Settings;
|
|
||||||
use crate::cloudlog::RadioData;
|
use crate::cloudlog::RadioData;
|
||||||
|
use settings::Settings;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let settings = Settings::new().expect("Could not read settings.");
|
let settings = Settings::new().expect("Could not read settings.");
|
||||||
|
@ -16,11 +18,27 @@ fn main() {
|
||||||
power: String::from("5"),
|
power: String::from("5"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let radio_data_new = flrig::get_radio_data(&settings.flrig.host, &settings.flrig.port).unwrap();
|
let mut changes_detected = false;
|
||||||
|
|
||||||
radio_data_current.frequency = radio_data_new.frequency;
|
loop {
|
||||||
radio_data_current.mode = radio_data_new.mode;
|
let radio_data_new =
|
||||||
radio_data_current.power = radio_data_new.power;
|
flrig::get_radio_data(&settings.flrig.host, &settings.flrig.port).unwrap();
|
||||||
|
|
||||||
cloudlog::upload(&settings.cloudlog.url, &radio_data_current);
|
if radio_data_current.frequency != radio_data_new.frequency
|
||||||
|
|| radio_data_current.mode != radio_data_new.mode
|
||||||
|
|| radio_data_current.power != radio_data_new.power
|
||||||
|
{
|
||||||
|
changes_detected = true;
|
||||||
|
radio_data_current.frequency = radio_data_new.frequency;
|
||||||
|
radio_data_current.mode = radio_data_new.mode;
|
||||||
|
radio_data_current.power = radio_data_new.power;
|
||||||
|
}
|
||||||
|
|
||||||
|
if changes_detected {
|
||||||
|
cloudlog::upload(&settings.cloudlog.url, &radio_data_current);
|
||||||
|
changes_detected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
thread::sleep(Duration::from_secs(1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue