Skip to content

Commit

Permalink
Address All Rust Build Warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
njfdev committed Aug 31, 2024
1 parent c264760 commit bd9e69e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 47 deletions.
8 changes: 2 additions & 6 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::{
env,
sync::{Arc, Mutex},
};
use tauri::{async_runtime::block_on, ipc::Channel, AppHandle, Manager, State};
use tauri::{async_runtime::block_on, ipc::Channel, AppHandle, State};
use utils::{setup_callbacks, setup_dependencies};

struct AppState {
Expand Down Expand Up @@ -154,11 +154,7 @@ async fn get_sdr_states(state: State<'_, AppState>) -> Result<serde_json::Value,
}

#[tauri::command]
async fn connect_to_sdr(
app: AppHandle,
state: State<'_, AppState>,
args: AvailableSDRArgs,
) -> Result<(), ()> {
async fn connect_to_sdr(app: AppHandle, args: AvailableSDRArgs) -> Result<(), ()> {
info!("Connecting to {}", args.label);

let result = sdr::connect_to_sdr(args, app);
Expand Down
10 changes: 3 additions & 7 deletions src-tauri/src/radio_services/soapysdr_adsb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ use blocks::Rechunker;
use log::error;
use radiorust::{blocks::io::rf, prelude::*};
use soapysdr::Direction;
use tauri::{async_runtime, ipc::Channel, AppHandle, Emitter, Manager};
use tauri::{async_runtime, ipc::Channel, AppHandle, Emitter};
use tokio::{self, time};

use crate::{
modes::types::ModeSState,
radiorust_blocks::adsb_decode::AdsbDecode,
sdr::{enumeration::AvailableSDRArgs, get_sdr_dev, release_sdr_dev},
AppState,
};

pub struct AdsbDecoderState(Arc<Mutex<AdsbDecoderData>>);
Expand Down Expand Up @@ -56,10 +55,7 @@ impl AdsbDecoderState {
.unwrap()
.block_on(async move {
// get SDR
let rtlsdr_dev_result = get_sdr_dev(
app.clone(),
sdr_args
);
let rtlsdr_dev_result = get_sdr_dev(app.clone(), sdr_args);

if rtlsdr_dev_result.is_err() {
// notify frontend of error
Expand Down Expand Up @@ -128,7 +124,7 @@ impl AdsbDecoderState {
}

// release the SDR
release_sdr_dev(app, rtlsdr_dev, sdr_args);
release_sdr_dev(app, rtlsdr_dev, sdr_args).unwrap();
})
}));
}
Expand Down
12 changes: 4 additions & 8 deletions src-tauri/src/radio_services/soapysdr_radio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::{
rbds_decode::{DownMixer, RbdsDecode, RbdsState},
},
sdr::{enumeration::AvailableSDRArgs, get_sdr_dev, release_sdr_dev},
AppState,
};

#[derive(serde::Deserialize, PartialEq)]
Expand Down Expand Up @@ -292,10 +291,8 @@ impl RtlSdrState {

let controls_clone2 = controls_arc.clone();
// add rbds decoder to output FM stream
let rdbs_decoder = RbdsDecode::<f32>::new(
app.clone(),
rbds_channel,
move |radiotext: String| {
let rdbs_decoder =
RbdsDecode::<f32>::new(rbds_channel, move |radiotext: String| {
let _ = controls_clone2.lock().unwrap().set_metadata(
MediaMetadata {
title: Some(&radiotext),
Expand All @@ -304,8 +301,7 @@ impl RtlSdrState {
..Default::default()
},
);
},
);
});
rdbs_decoder.feed_from(&rbds_lowpass_filter);
} else if stream_settings.stream_type == StreamType::AM {
let demodulator = AmDemod::<f32>::new();
Expand Down Expand Up @@ -377,7 +373,7 @@ impl RtlSdrState {
}

// release the SDR
release_sdr_dev(app, rtlsdr_dev, sdr_args);
release_sdr_dev(app, rtlsdr_dev, sdr_args).unwrap();
})
}));
}
Expand Down
16 changes: 3 additions & 13 deletions src-tauri/src/radiorust_blocks/rbds_decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{collections::VecDeque, f64::consts::PI, ops::Range};

use log::{debug, info};
use serde::{Deserialize, Serialize};
use serde_json::json;

#[cfg(debug_assertions)]
use hound::{WavSpec, WavWriter};
Expand All @@ -21,7 +20,7 @@ use radiorust::{
prelude::{ChunkBuf, ChunkBufPool, Complex},
signal::Signal,
};
use tauri::{ipc::Channel, AppHandle, Emitter};
use tauri::ipc::Channel;
use tokio::spawn;
pub struct DownMixer<Flt> {
receiver_connector: ReceiverConnector<Signal<Complex<Flt>>>,
Expand Down Expand Up @@ -215,7 +214,7 @@ impl<Flt> RbdsDecode<Flt>
where
Flt: Float + Into<f64> + Into<f32>,
{
pub fn new<F>(app: AppHandle, rbds_channel: Channel<RbdsState>, radiotext_callback: F) -> Self
pub fn new<F>(rbds_channel: Channel<RbdsState>, radiotext_callback: F) -> Self
where
F: Fn(String) + Send + Sync + 'static,
{
Expand Down Expand Up @@ -580,15 +579,6 @@ fn calculate_syndrome(recieved_data: u32) -> u16 {
syndrome
}

fn send_rbds_data<T: serde::Serialize>(param_name: &str, data: T, app: AppHandle) {
let json_object: String = json!({
param_name: data
})
.to_string();
app.emit("rtlsdr_rbds", json_object.as_str())
.expect("failed to emit event");
}

#[derive(Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RbdsDecoderInfo {
Expand Down Expand Up @@ -871,7 +861,7 @@ fn process_rbds_group<F>(
rbds_state.tp = Some(tp);

// update frontend
rbds_channel.send(rbds_state.clone());
rbds_channel.send(rbds_state.clone()).unwrap();
}

fn rbds_process_bits<F>(
Expand Down
24 changes: 11 additions & 13 deletions src-tauri/src/sdr/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use enumeration::AvailableSDRArgs;
use log::{error, info};
use serde::{Deserialize, Serialize, Serializer};
use serde::{Serialize, Serializer};
use soapysdr::Device;
use tauri::{App, AppHandle, Emitter, Manager, State};
use tauri::{AppHandle, Emitter, Manager, State};

use crate::AppState;

Expand All @@ -16,7 +16,7 @@ where
SDRDeviceState::Available => {
return serializer.serialize_str("Available");
}
SDRDeviceState::Connected { dev } => {
SDRDeviceState::Connected { dev: _ } => {
return serializer.serialize_str("Connected");
}
SDRDeviceState::InUse => {
Expand All @@ -39,9 +39,7 @@ pub struct SDRState {
pub dev: SDRDeviceState,
}

fn connect_to_sdr_with_mut(sdr_state: &mut SDRState, app: AppHandle) -> Result<(), ()> {
let state = app.state::<AppState>();

fn connect_to_sdr_with_mut(sdr_state: &mut SDRState) -> Result<(), ()> {
let dev_result = Device::new(sdr_state.args.clone());

if dev_result.is_err() {
Expand Down Expand Up @@ -108,7 +106,7 @@ pub fn disconnect_sdr(
SDRDeviceState::Available => {
return Err("SDR already disconnected");
}
SDRDeviceState::Connected { dev } => {
SDRDeviceState::Connected { dev: _ } => {
sdr.dev = SDRDeviceState::Available;

app.emit("sdr_states", sdrs.clone()).unwrap();
Expand All @@ -127,8 +125,8 @@ pub fn get_sdr_dev(
let state = app.state::<AppState>();
let mut sdrs = state.sdrs.lock().unwrap();

let mut dev_clone: Option<Device> = None;
let mut args_clone: Option<AvailableSDRArgs> = None;
let dev_clone: Device;
let args_clone: AvailableSDRArgs;

{
let sdr_result = sdrs.iter_mut().find(|sdr_state| sdr_state.args == args);
Expand All @@ -144,22 +142,22 @@ pub fn get_sdr_dev(
}

if let SDRDeviceState::Available = sdr.dev {
connect_to_sdr_with_mut(sdr, app.clone());
connect_to_sdr_with_mut(sdr).unwrap();
}

if let SDRDeviceState::Connected { dev } = sdr.dev.clone() {
sdr.dev = SDRDeviceState::InUse;

dev_clone = Some(dev.clone());
args_clone = Some(sdr.args.clone());
dev_clone = dev.clone();
args_clone = sdr.args.clone();
} else {
return Err(String::from("Could not get SDR device"));
}
}

app.emit("sdr_states", (*sdrs).clone()).unwrap();

return Ok((dev_clone.unwrap(), args_clone.unwrap()));
return Ok((dev_clone, args_clone));
}

pub fn release_sdr_dev(app: AppHandle, dev: Device, args: AvailableSDRArgs) -> Result<(), String> {
Expand Down

0 comments on commit bd9e69e

Please sign in to comment.