From 364f9c7f31ae61df3481c74dfc8f3d47b8068230 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 29 Nov 2023 15:53:47 +0100 Subject: [PATCH] =?UTF-8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 146 ++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 4 +- src/cloudlog.rs | 20 +++++++ src/lib.rs | 0 src/main.rs | 14 ++++- src/settings.rs | 16 +++--- 6 files changed, 188 insertions(+), 12 deletions(-) create mode 100644 src/cloudlog.rs delete mode 100644 src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index b435c61..eb48481 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,6 +129,8 @@ dependencies = [ "reqwest", "serde", "serde_derive", + "serde_json", + "tokio", ] [[package]] @@ -362,6 +364,12 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +[[package]] +name = "hermit-abi" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" + [[package]] name = "home" version = "0.5.5" @@ -518,6 +526,16 @@ version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.20" @@ -590,6 +608,16 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "object" version = "0.32.1" @@ -659,6 +687,29 @@ dependencies = [ "hashbrown 0.12.3", ] +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.48.5", +] + [[package]] name = "pathdiff" version = "0.2.1" @@ -785,6 +836,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", + "rustls", "serde", "serde_json", "serde_urlencoded", @@ -799,6 +851,20 @@ dependencies = [ "winreg", ] +[[package]] +name = "ring" +version = "0.17.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "684d5e6e18f669ccebf64a92236bb7db9a34f07be010e3627368182027180866" +dependencies = [ + "cc", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.48.0", +] + [[package]] name = "ron" version = "0.7.1" @@ -839,6 +905,28 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "rustls" +version = "0.21.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "629648aced5775d558af50b2b4c7b02983a04b312126d45eeead26e7caa498b9" +dependencies = [ + "log", + "ring", + "rustls-webpki", + "sct", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "ryu" version = "1.0.15" @@ -854,6 +942,22 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "security-framework" version = "2.9.2" @@ -931,6 +1035,15 @@ dependencies = [ "digest", ] +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + [[package]] name = "slab" version = "0.4.9" @@ -940,6 +1053,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "smallvec" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" + [[package]] name = "socket2" version = "0.4.10" @@ -960,6 +1079,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "syn" version = "2.0.39" @@ -1050,11 +1175,26 @@ dependencies = [ "bytes", "libc", "mio", + "num_cpus", + "parking_lot", "pin-project-lite", + "signal-hook-registry", "socket2 0.5.5", + "tokio-macros", "windows-sys 0.48.0", ] +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tokio-native-tls" version = "0.3.1" @@ -1152,6 +1292,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.5.0" diff --git a/Cargo.toml b/Cargo.toml index b7078ab..8d7cfde 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,9 @@ author = "Martin Brodbeck " [dependencies] config = { version = "0.13.4", features = ["yaml"] } home = "0.5.5" -reqwest = "0.11.22" +reqwest = { version = "0.11.22", features = ["json","rustls"] } serde = { version = "1.0.193", features = ["serde_derive"] } serde_derive = "1.0.193" +serde_json = "1.0.108" +tokio = { version = "1.34.0", features = ["full"] } diff --git a/src/cloudlog.rs b/src/cloudlog.rs new file mode 100644 index 0000000..014f63c --- /dev/null +++ b/src/cloudlog.rs @@ -0,0 +1,20 @@ +use serde::Serialize; +use serde_json; +use reqwest::Client; + +#[derive(Serialize)] +pub struct RadioData { + pub key: String, + pub radio: String, + pub frequency : String, + pub mode: String, +} + +#[tokio::main] +pub async fn upload(url: &str, radio_data: &RadioData) { + let radio_data_json = serde_json::to_string(radio_data).unwrap(); + + let res = Client::new().post(url).json(&radio_data_json).send().await.unwrap(); + + println!("{}", radio_data_json); +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/main.rs b/src/main.rs index 0a468f8..a7dbe4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,18 @@ +mod cloudlog; mod settings; use settings::Settings; +use crate::cloudlog::RadioData; fn main() { - let settings = Settings::new() - .expect("Could not read settings."); + let settings = Settings::new().expect("Could not read settings."); - println!("{:?}", settings); + let rd = RadioData { + key: settings.cloudlog.key, + radio: settings.cloudlog.identifier, + frequency: String::from("2400170000"), + mode: String::from("CW"), + }; + + cloudlog::upload(&settings.cloudlog.url, &rd); } diff --git a/src/settings.rs b/src/settings.rs index 8a5d452..5267526 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -4,23 +4,23 @@ use serde_derive::Deserialize; #[derive(Debug, Deserialize)] #[allow(unused)] -struct Cloudlog { - url: String, - key: String, - identifier: String, +pub struct Cloudlog { + pub url: String, + pub key: String, + pub identifier: String, } #[derive(Debug, Deserialize)] #[allow(unused)] -struct Flrig { - host: String, - port: String, +pub struct Flrig { + pub host: String, + pub port: String, } #[derive(Debug, Deserialize)] #[allow(unused)] pub struct Settings { - cloudlog: Cloudlog, + pub cloudlog: Cloudlog, flrig: Flrig, }