Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wavelog-hamlib"
version = "1.2.0"
version = "1.3.0"
authors = ["Luca Cireddu <sardylan@gmail.com>"]
description = "Simple tool to connect Hamlib rigctld instance with Wavelog"
repository = "https://github.com/sardylan/wavelog-hamlib.git"
Expand All @@ -9,15 +9,15 @@ keywords = ["wavelog", "hamlib", "adif", "tokio", "reqwest"]
edition = "2021"

[dependencies]
chrono = { version = "0.4.38", features = ["serde"] }
clap = { version = "4.5.17", features = ["cargo", "color", "derive", "env", "unicode"] }
hamlib-client = "1.0.0"
chrono = { version = "0.4.42", features = ["serde"] }
clap = { version = "4.5.53", features = ["cargo", "color", "derive", "env", "unicode"] }
hamlib-client = "1.1.0"
lazy_static = "1.5.0"
log = "0.4.22"
log4rs = "1.3.0"
regex = "1.10.6"
reqwest = { version = "0.12.7", features = ["json"] }
serde = { version = "1.0.210", features = ["derive"] }
serde_json = { version = "1.0.128", features = ["std"] }
thiserror = "1.0.63"
tokio = { version = "1.40.0", features = ["full"] }
regex = "1.12.2"
reqwest = { version = "0.12.28", features = ["json"] }
serde = { version = "1.0.228", features = ["derive"] }
serde_json = { version = "1.0.147", features = ["std"] }
tokio = { version = "1.48.0", features = ["full"] }
tracing = "0.1.44"
tracing-log = "0.2.0"
tracing-subscriber = { version = "0.3.22", features = ["ansi", "serde", "chrono", "env-filter"] }
12 changes: 11 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use clap::crate_name;
use clap::value_parser;
use clap::{ArgAction, Parser};
use log::Level;
use tracing::Level;

#[derive(Parser, Debug)]
#[command(version, author, about, long_about = None)]
Expand Down Expand Up @@ -110,4 +110,14 @@ pub struct Config {
long_help = "Set the name of Satellite (empty values disable Sat Mode)"
)]
pub sat: String,

#[arg(
short = 'm',
long,
action = ArgAction::Set,
default_value = "",
help = "Force mode",
long_help = "Forces the mode reported (empty values is the same of not setting this option)"
)]
pub force_mode: String,
}
6 changes: 3 additions & 3 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

use hamlib_client::error::RigCtlError;
use std::fmt;
use std::fmt::{Display, Formatter};

#[derive(Debug)]
pub enum WavelogHamlibError {
Expand All @@ -35,8 +35,8 @@ impl From<reqwest::Error> for WavelogHamlibError {
}
}

impl fmt::Display for WavelogHamlibError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl Display for WavelogHamlibError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match &self {
WavelogHamlibError::Hamlib(e) => write!(f, "Hamlib error: {}", &e),
WavelogHamlibError::Wavelog(e) => write!(f, "Wavelog error: {}", &e),
Expand Down
42 changes: 42 additions & 0 deletions src/log.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2024 Luca Cireddu <sardylan@gmail.com>
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

use tracing::Level;
use tracing_subscriber::{prelude::*, EnvFilter};

pub fn configure(level: &Level) {
tracing_log::LogTracer::init().expect("Failed to set logger");

let crate_name = clap::crate_name!().replace('-', "_");

let filter = EnvFilter::try_new(format!("{}={},warn", crate_name, level))
.unwrap_or_else(|_| EnvFilter::new(format!("{}={},warn", crate_name, Level::INFO)));
Comment thread
sardylan marked this conversation as resolved.

let fmt_layer = tracing_subscriber::fmt::layer()
.with_writer(std::io::stderr)
.with_ansi(true)
.with_level(true)
.with_file(true)
.with_line_number(true)
.with_thread_ids(true)
.with_target(true);

tracing_subscriber::registry()
.with(filter)
.with(fmt_layer)
.try_init()
.ok();
}
44 changes: 0 additions & 44 deletions src/logging.rs

This file was deleted.

98 changes: 57 additions & 41 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*
*/

mod errors;
mod config;
mod logging;
mod errors;
mod log;
mod wavelog;

use crate::config::Config;
Expand All @@ -28,100 +28,116 @@ use hamlib_client::RigCtlClient;
use std::string::String;
use std::time::Duration;
use tokio::time::sleep;
use tracing::{debug, error, info, trace, warn};

#[tokio::main]
async fn main() {
let configuration = Config::parse();

logging::configure(&configuration.log_level);
log::configure(&configuration.log_level);

match program(&configuration).await {
Ok(_) => {}
Err(e) => {
log::error!("{}", e)
error!("{}", e)
}
}
}

async fn program(configuration: &Config) -> Result<(), WavelogHamlibError> {
log::trace!("Creating Wavelog client for {} with radio name \"{}\"", &configuration.wavelog_url, configuration.wavelog_radio);
let wavelog_client = wavelog::Client::new(&configuration.wavelog_url, &configuration.wavelog_key);

log::trace!("Creating client for {}:{}", &configuration.rigctl_host, configuration.rigctl_port);
trace!(
"Creating Wavelog client for {} with radio name \"{}\"",
&configuration.wavelog_url,
configuration.wavelog_radio
);
let wavelog_client =
wavelog::Client::new(&configuration.wavelog_url, &configuration.wavelog_key);

trace!(
"Creating client for {}:{}",
&configuration.rigctl_host,
configuration.rigctl_port
);
let mut rigctl = RigCtlClient::new(&configuration.rigctl_host, configuration.rigctl_port, None);
rigctl.set_communication_timeout(configuration.rigctl_timeout);

rigctl.connect().await?;
log::info!("Connected");
info!("Connected");

loop {
log::debug!("Getting info from Hamlib");
debug!("Getting info from Hamlib");

let vfo = rigctl.get_vfo().await?;
log::trace!("Rig vfo: {}", &vfo);
trace!("Rig vfo: {}", &vfo);
let rx_vfo = vfo.vfo;
log::debug!("RX vfo: {}", &rx_vfo);
debug!("RX vfo: {}", &rx_vfo);

let split_vfo = rigctl.get_split_vfo().await?;
log::trace!("Rig split_vfo: {}", &split_vfo);
trace!("Rig split_vfo: {}", &split_vfo);
let tx_vfo = split_vfo.tx_vfo;
log::debug!("TX vfo: {}", &tx_vfo);
debug!("TX vfo: {}", &tx_vfo);

let rx_mode = rigctl.get_mode(rx_vfo).await?;
log::trace!("{}: {}", &rx_vfo, &rx_mode);
let rx_freq = rigctl.get_freq(rx_vfo).await?;
log::trace!("{}: {}", &rx_vfo, &rx_freq);
let force_mode = Mode::from(&configuration.force_mode.as_str());
debug!("Force mode: {}", &force_mode);

let tx_mode = rigctl.get_split_mode(rx_vfo).await?;
log::trace!("{}: {}", &tx_vfo, &tx_mode);
let tx_freq = rigctl.get_split_freq(rx_vfo).await?;
log::trace!("{}: {}", &tx_vfo, &tx_freq);
let (rx_mode, tx_mode) = if force_mode == Mode::None {
let rx_mode = rigctl.get_mode(rx_vfo).await?;
let tx_mode = rigctl.get_mode(tx_vfo).await?;
(Mode::from(rx_mode.mode), Mode::from(tx_mode.mode))
} else {
(force_mode, force_mode)
};
trace!("{} Mode: {}", &rx_vfo, &rx_mode);
trace!("{} Mode: {}", &tx_vfo, &tx_mode);

let update_prop_mode =
if !&configuration.sat.is_empty() {
log::debug!("Enabling SAT propagation mode");
Some(PropagationMode::SAT)
} else {
None
};
let rx_freq = rigctl.get_freq(rx_vfo).await?;
trace!("{}: {}", &rx_vfo, &rx_freq);
let tx_freq = rigctl.get_freq(tx_vfo).await?;
Comment thread
sardylan marked this conversation as resolved.
trace!("{}: {}", &tx_vfo, &tx_freq);

let update_prop_mode = if !&configuration.sat.is_empty() {
debug!("Enabling SAT propagation mode");
Some(PropagationMode::SAT)
} else {
None
};

let update_tx_freq =
if &configuration.sat == "QO-100"
&& tx_freq.frequency == rx_freq.frequency {
log::debug!("Manually setting TX Frequency for QO-100 satellite activity");
if &configuration.sat == "QO-100" && tx_freq.frequency == rx_freq.frequency {
debug!("Manually setting TX Frequency for QO-100 satellite activity");
tx_freq.frequency - 8089500000
} else {
tx_freq.frequency
};

log::debug!("Preparing update");
debug!("Preparing update");
let update = Update {
radio: String::from(&configuration.wavelog_radio),
frequency: update_tx_freq,
mode: Mode::from(tx_mode.mode),
mode: tx_mode,
frequency_rx: Some(rx_freq.frequency),
mode_rx: Some(Mode::from(rx_mode.mode)),
mode_rx: Some(rx_mode),
prop_mode: update_prop_mode,
power: None,
sat_name: Some(String::from(&configuration.sat)).filter(String::is_empty),
};
log::trace!("Update: {}", &update);
trace!("Update: {}", &update);

log::debug!("Sending update to Wavelog");
debug!("Sending update to Wavelog");
let result = wavelog_client.send_update(update).await;
log::trace!("Result: {:?}", &result);
trace!("Result: {:?}", &result);
match result {
Ok(response) => {
if !response {
log::warn!("Error sending update to Wavelog");
warn!("Error sending update to Wavelog");
}
}
Err(e) => {
log::error!("{}", e);
error!("{}", e);
}
}

log::debug!("Sleeping");
debug!("Sleeping");
sleep(Duration::from_millis(configuration.interval)).await;
}
}
Loading