proof of concept works
This commit is contained in:
parent
9e80ef36ed
commit
41b33f5cba
3 changed files with 1067 additions and 15 deletions
1009
Cargo.lock
generated
1009
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -2,3 +2,10 @@
|
|||
name = "clrigctl"
|
||||
version = "0.1.0"
|
||||
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"] }
|
||||
|
|
66
src/main.rs
66
src/main.rs
|
@ -1,25 +1,29 @@
|
|||
use std::io::prelude::*;
|
||||
use std::net::TcpStream;
|
||||
use std::str;
|
||||
use chrono::{Local};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub struct RigCtl
|
||||
{
|
||||
pub struct RigCtl {
|
||||
pub stream: TcpStream,
|
||||
}
|
||||
|
||||
impl RigCtl {
|
||||
pub fn new() -> Self {
|
||||
let stream = TcpStream::connect("127.0.0.1:4532").unwrap();
|
||||
RigCtl {
|
||||
stream: stream,
|
||||
}
|
||||
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();
|
||||
let freq = str::from_utf8(&buffer)
|
||||
.unwrap()
|
||||
.lines()
|
||||
.next()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
freq
|
||||
}
|
||||
|
||||
|
@ -34,11 +38,43 @@ impl RigCtl {
|
|||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut rigctl = RigCtl::new();
|
||||
let freq = rigctl.get_frequency();
|
||||
println!("Frequenz: {} Hz", freq);
|
||||
|
||||
let (mode, passband) = rigctl.get_mode();
|
||||
println!("Mode: {} – Passband: {}", mode, passband);
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct RadioData {
|
||||
key: String,
|
||||
radio: String,
|
||||
frequency: String,
|
||||
mode: String,
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue