proof of concept works

This commit is contained in:
Martin Brodbeck 2021-12-17 10:09:50 +01:00
parent 9e80ef36ed
commit 41b33f5cba
3 changed files with 1067 additions and 15 deletions

1009
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -2,3 +2,10 @@
name = "clrigctl" name = "clrigctl"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
author = "Martin Brodbeck <info@rustysoft.de>"
[dependencies]
chrono = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = { version = "0.11", features = ["blocking", "json"] }

View file

@ -1,25 +1,29 @@
use std::io::prelude::*; use std::io::prelude::*;
use std::net::TcpStream; use std::net::TcpStream;
use std::str; use std::str;
use chrono::{Local};
use serde::{Deserialize, Serialize};
pub struct RigCtl pub struct RigCtl {
{
pub stream: TcpStream, pub stream: TcpStream,
} }
impl RigCtl { impl RigCtl {
pub fn new() -> Self { pub fn new() -> Result<Self, std::io::Error> {
let stream = TcpStream::connect("127.0.0.1:4532").unwrap(); let stream = TcpStream::connect("127.0.0.1:4532")?;
RigCtl { Ok(RigCtl { stream })
stream: stream,
}
} }
pub fn get_frequency(&mut self) -> String { pub fn get_frequency(&mut self) -> String {
self.stream.write(b"f").unwrap(); self.stream.write(b"f").unwrap();
let mut buffer = [0; 64]; let mut buffer = [0; 64];
self.stream.read(&mut buffer[..]).unwrap(); self.stream.read(&mut buffer[..]).unwrap();
let freq = str::from_utf8(&buffer).unwrap().lines().next().unwrap().to_string(); let freq = str::from_utf8(&buffer)
.unwrap()
.lines()
.next()
.unwrap()
.to_string();
freq freq
} }
@ -34,11 +38,43 @@ impl RigCtl {
} }
} }
fn main() { #[derive(Serialize, Deserialize)]
let mut rigctl = RigCtl::new(); struct RadioData {
let freq = rigctl.get_frequency(); key: String,
println!("Frequenz: {} Hz", freq); radio: String,
frequency: String,
let (mode, passband) = rigctl.get_mode(); mode: String,
println!("Mode: {} Passband: {}", mode, passband); timestamp: String,
} }
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);
}
}
}