…
This commit is contained in:
parent
198c541e58
commit
c7f329b89b
5 changed files with 226 additions and 892 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
target/
|
1027
Cargo.lock
generated
1027
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -5,7 +5,5 @@ edition = "2021"
|
||||||
author = "Martin Brodbeck <info@rustysoft.de>"
|
author = "Martin Brodbeck <info@rustysoft.de>"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4"
|
config = { version = "0.13.4", features = ["yaml"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
|
||||||
serde_json = "1.0"
|
|
||||||
reqwest = { version = "0.11", features = ["blocking", "json"] }
|
|
||||||
|
|
0
src/lib.rs
Normal file
0
src/lib.rs
Normal file
84
src/main.rs
84
src/main.rs
|
@ -1,89 +1,7 @@
|
||||||
use chrono::Local;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::io::prelude::*;
|
|
||||||
use std::net::TcpStream;
|
|
||||||
use std::str;
|
|
||||||
|
|
||||||
pub struct RigCtl {
|
|
||||||
pub stream: TcpStream,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RigCtl {
|
|
||||||
pub fn new() -> Result<Self, std::io::Error> {
|
|
||||||
let stream = TcpStream::connect("127.0.0.1:4532")?;
|
|
||||||
Ok(RigCtl { stream })
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_frequency(&mut self) -> String {
|
|
||||||
self.stream.write(b"f").unwrap();
|
|
||||||
let mut buffer = [0; 64];
|
|
||||||
self.stream.read(&mut buffer[..]).unwrap();
|
|
||||||
let freq = str::from_utf8(&buffer)
|
|
||||||
.unwrap()
|
|
||||||
.lines()
|
|
||||||
.next()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
freq
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_mode(&mut self) -> (String, String) {
|
|
||||||
self.stream.write(b"m").unwrap();
|
|
||||||
let mut buffer = [0; 64];
|
|
||||||
self.stream.read(&mut buffer[..]).unwrap();
|
|
||||||
let mut retvals = str::from_utf8(&buffer).unwrap().lines();
|
|
||||||
let mode = retvals.next().unwrap().to_string();
|
|
||||||
let passband = retvals.next().unwrap().to_string();
|
|
||||||
(mode, passband)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
struct RadioData {
|
|
||||||
key: String,
|
|
||||||
radio: String,
|
|
||||||
frequency: String,
|
|
||||||
mode: String,
|
|
||||||
timestamp: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match RigCtl::new() {
|
|
||||||
Ok(mut rigctl) => {
|
|
||||||
let key = "".to_string();
|
|
||||||
|
|
||||||
let radio = "clrigctl".to_string();
|
|
||||||
|
|
||||||
let frequency = rigctl.get_frequency();
|
|
||||||
//println!("Frequenz: {} Hz", frequency);
|
|
||||||
|
|
||||||
let (mode, _) = rigctl.get_mode();
|
|
||||||
//println!("Mode: {}", mode);
|
|
||||||
|
|
||||||
let timestamp = Local::now().format("%Y/%m/%d %H:%M").to_string();
|
|
||||||
//println!("Timestamp: {}", timestamp);
|
|
||||||
|
|
||||||
let radiodata = RadioData {
|
|
||||||
key,
|
|
||||||
radio,
|
|
||||||
frequency,
|
|
||||||
mode,
|
|
||||||
timestamp,
|
|
||||||
};
|
|
||||||
let radiodata_json = serde_json::to_string(&radiodata).unwrap();
|
|
||||||
|
|
||||||
let client = reqwest::blocking::Client::new();
|
|
||||||
let resp = client
|
|
||||||
.post("https://cloudlog.rustysoft.de/index.php/api/radio")
|
|
||||||
.body(radiodata_json)
|
|
||||||
.send();
|
|
||||||
|
|
||||||
println!("{:?}", resp);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
println!("{}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue