forked from n6cta/mwtchahrd
Compare commits
2 Commits
ab4f190138
...
c9f6a4a6c5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9f6a4a6c5 | ||
|
|
369de6f873 |
@@ -8,6 +8,7 @@ authors = ["Chris, N6CTA <mail@n6cta.com>"]
|
||||
anyhow = "1.0"
|
||||
chrono = "0.4"
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
reqwest = { version = "0.12.24", features = ["json", "blocking"] }
|
||||
serde_json = "1.0.145"
|
||||
socket2 = "0.5"
|
||||
|
||||
|
||||
38
src/main.rs
38
src/main.rs
@@ -11,6 +11,7 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
use std::net::UdpSocket;
|
||||
use std::net::Ipv4Addr;
|
||||
use serde_json::json;
|
||||
use reqwest;
|
||||
|
||||
/// Validate that the provided port string can be parsed into a u16 and is nonzero.
|
||||
fn validate_port(port: &str) -> Result<u16, String> {
|
||||
@@ -62,6 +63,15 @@ struct Cli {
|
||||
/// Spotter callsign (e.g. W1CDN)
|
||||
#[arg(short = 's', long)]
|
||||
spotter: Option<String>,
|
||||
|
||||
/// Spot UI frames to Spothole
|
||||
#[arg(short = 'o', long, default_value_t = false)]
|
||||
spothole: bool,
|
||||
|
||||
/// Spotting frequency
|
||||
#[arg(short = 'f', long, default_value_t = 14105000)]
|
||||
freq: u32,
|
||||
|
||||
}
|
||||
|
||||
/// Convert a byte slice into a hex-dump string for debugging purposes.
|
||||
@@ -363,6 +373,7 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) {
|
||||
let basic_destination = hdr.callto_str();
|
||||
let timestamp = Local::now().format("%H:%M:%S").to_string();
|
||||
let spotter = &cli.spotter;
|
||||
let freq = &cli.freq;
|
||||
|
||||
// Filter and compute the text from the payload only once.
|
||||
let text = filter_text(&frame.payload);
|
||||
@@ -399,6 +410,32 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) {
|
||||
if cli.ui_only && summary != "UI" {
|
||||
return;
|
||||
}
|
||||
|
||||
// If Spothole is enabled
|
||||
if summary == "UI" && cli.spothole {
|
||||
// curl --request POST --header "Content-Type: application/json"
|
||||
// --data '{"dx_call":"M0TRT","time":1760019539, "freq":14200000,
|
||||
// "comment":"Test spot please ignore", "de_call":"M0TRT"}' https://spothole.app/api/v1/spot
|
||||
|
||||
// POST JSON
|
||||
let packet = json!({
|
||||
"dx_call": &source,
|
||||
"de_call": &spotter,
|
||||
"freq": &freq,
|
||||
"comment": &text,
|
||||
"mode": "PKT",
|
||||
"mode_type": "DATA",
|
||||
"mode_source": "SPOT",
|
||||
"time": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(),
|
||||
});
|
||||
let client = reqwest::blocking::Client::new();
|
||||
let res = client.post("https://spothole.app/api/v1/spot")
|
||||
.json(&packet)
|
||||
.send();
|
||||
println!("res = {res:?}");
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Send UDP
|
||||
if cli.uport != 55555 {
|
||||
@@ -411,6 +448,7 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) {
|
||||
"spotter": &spotter,
|
||||
"summary": &summary,
|
||||
"text": &text,
|
||||
"freq": &freq,
|
||||
"timestamp": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(),
|
||||
"type": "data"
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user