From 73988d50a3982de474d412dd6a083e70e41e2cc2 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Mon, 22 May 2023 17:25:07 -0600 Subject: [PATCH 01/10] Channel buffer as an array --- rust/oxide-rtlsdr/Cargo.toml | 1 + rust/oxide-rtlsdr/src/lib.rs | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/rust/oxide-rtlsdr/Cargo.toml b/rust/oxide-rtlsdr/Cargo.toml index 05edf9a..0dd7f42 100644 --- a/rust/oxide-rtlsdr/Cargo.toml +++ b/rust/oxide-rtlsdr/Cargo.toml @@ -21,3 +21,4 @@ num = "0.4.0" custom_error = "1.9.2" oxide-decoders = { path = "../oxide-decoders" } tokio = { version = "1.28.1", features = ["full", "tracing"] } +array-init = "2.1.0" diff --git a/rust/oxide-rtlsdr/src/lib.rs b/rust/oxide-rtlsdr/src/lib.rs index e3e2526..1caa2e4 100644 --- a/rust/oxide-rtlsdr/src/lib.rs +++ b/rust/oxide-rtlsdr/src/lib.rs @@ -47,7 +47,7 @@ pub struct RtlSdr { bias_tee: bool, rtl_mult: i32, frequencies: Vec, - channel: Vec>, + channel: [Box; 16], decoder_type: ValidDecoderType, } @@ -62,6 +62,17 @@ impl RtlSdr { decoder: ValidDecoderType, ) -> RtlSdr { frequencies.sort_by(|a, b| a.partial_cmp(b).unwrap()); + let mut channels: Vec> = Vec::new(); + + // FIXME: This feels so wasteful to create 16 decoders when we only need 1 or 2 + // But the array needs to be filled. Can we do better? + for _ in 0..16_usize { + channels.push(Box::new(ACARSDecoder::new( + 0, + 0, + [num::complex::Complex::new(0.0, 0.0); 192], + ))); + } Self { ctl: None, @@ -73,7 +84,8 @@ impl RtlSdr { bias_tee, rtl_mult, frequencies, - channel: vec![], + // array_init::array_init(|i: usize| (i * i) as u32); + channel: array_init::from_iter(channels.into_iter()).unwrap(), decoder_type: decoder, } } @@ -252,7 +264,7 @@ impl RtlSdr { ACARSDecoder::new(i as i32, channels[i], window_array); out_channel.set_output_channel(output_channel.clone()); - self.channel.push(Box::new(out_channel)); + self.channel[i] = Box::new(out_channel); } info!( @@ -294,6 +306,7 @@ impl RtlSdr { reader .read_async(4, buffer_len, |bytes: &[u8]| { counter = 0; + for m in 0..rtloutbufz { for vb_item in vb.iter_mut().take(self.rtl_mult as usize) { *vb_item = (bytes[counter] as f32 - 127.37) @@ -302,7 +315,8 @@ impl RtlSdr { counter += 2; } - for channel in &mut self.channel { + for channel in &mut self.channel.iter_mut().take(self.frequencies.len()) + { let mut d: num::Complex = num::complex::Complex::new(0.0, 0.0); for (ind, vb_item) in @@ -314,7 +328,7 @@ impl RtlSdr { channel.set_dm_buffer_at_index(m, d.norm()); } } - for channel in &mut self.channel { + for channel in &mut self.channel.iter_mut().take(self.frequencies.len()) { channel.decode(rtloutbufz as u32); } }) From 232095871952b40bbfbe170befeb60960188d1e3 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Mon, 22 May 2023 18:05:29 -0600 Subject: [PATCH 02/10] Sketchy --- rust/oxide-bin/Cargo.toml | 1 + rust/oxide-bin/src/main.rs | 25 ++++++++++++++++++++++++- rust/oxide-scanner/src/lib.rs | 9 ++++++--- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/rust/oxide-bin/Cargo.toml b/rust/oxide-bin/Cargo.toml index b52814b..3955654 100644 --- a/rust/oxide-bin/Cargo.toml +++ b/rust/oxide-bin/Cargo.toml @@ -19,3 +19,4 @@ oxide-logging = { path = "../oxide-logging" } oxide-scanner = { path = "../oxide-scanner" } oxide-decoders = { path = "../oxide-decoders" } tokio = { version = "1.28.1", features = ["full", "tracing"] } +array-init = "2.1.0" diff --git a/rust/oxide-bin/src/main.rs b/rust/oxide-bin/src/main.rs index f92799c..0c2b182 100644 --- a/rust/oxide-bin/src/main.rs +++ b/rust/oxide-bin/src/main.rs @@ -246,7 +246,30 @@ async fn main() { } } - let scanner = oxide_scanner::OxideScanner::new(rtlsdr, args.output_to_console, false); + // FIXME: Fucked up padding of useless data + // Trying to avoid as much heap allocation....not sure I'm actually doing anything useful here + // pad the end of the vector with empty SDRs + + let sdr_len: usize = rtlsdr.len(); + + while rtlsdr.len() < 8 { + rtlsdr.push(RtlSdr::new( + String::from(""), + 0, + 0, + false, + 160, + vec![], + ValidDecoderType::ACARS, + )); + } + + // create an array of length 8 to hold the SDRs + + let rtlsdr_array: [RtlSdr; 8] = array_init::from_iter(rtlsdr.into_iter()).unwrap(); + + let scanner = + oxide_scanner::OxideScanner::new(rtlsdr_array, sdr_len, args.output_to_console, false); scanner.run().await; trace!("Starting the sleep loop"); diff --git a/rust/oxide-scanner/src/lib.rs b/rust/oxide-scanner/src/lib.rs index 377a0a6..aa3bebc 100644 --- a/rust/oxide-scanner/src/lib.rs +++ b/rust/oxide-scanner/src/lib.rs @@ -22,19 +22,22 @@ use oxide_rtlsdr::RtlSdr; use tokio::sync::mpsc; pub struct OxideScanner { - sdrs: Vec, + sdrs: [RtlSdr; 8], enable_output_command_line: bool, enable_output_zmq: bool, + number_of_sdrs: usize, } impl OxideScanner { pub fn new( - sdrs: Vec, + sdrs: [RtlSdr; 8], + number_of_sdrs: usize, enable_output_command_line: bool, enable_output_zmq: bool, ) -> OxideScanner { OxideScanner { sdrs, + number_of_sdrs, enable_output_command_line, enable_output_zmq, } @@ -50,7 +53,7 @@ impl OxideScanner { output.monitor_receiver_channel().await; }); - for mut sdr in self.sdrs.into_iter() { + for mut sdr in self.sdrs.into_iter().take(self.number_of_sdrs) { info!("[OXIDE SCANNER] Opening SDR {}", sdr.get_serial()); match sdr.open_sdr(tx_channel.clone()) { Ok(_) => { From eee3fe9204304ff20828594872494795e5b9ea44 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Mon, 22 May 2023 19:58:31 -0600 Subject: [PATCH 03/10] Saving some potential release optimization compile options for later --- Cargo.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index dfd1e8e..34338e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,9 @@ repository = "https://github.com/sdr-enthusiasts/acars-oxide" readme = "README.md" license = "MIT" rust-version = "1.69.0" + +# [profile.release] +# debug = true +# lto = "fat" +# codegen-units = 1 +# opt-level = 2 From 3748fb1141645a1784c7adc0031e17cf99acb09d Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Mon, 22 May 2023 20:07:25 -0600 Subject: [PATCH 04/10] move to num_complex crate to see if there is any speed improvements --- rust/oxide-decoders/Cargo.toml | 1 + rust/oxide-decoders/src/decoders/acars.rs | 11 +++++------ rust/oxide-decoders/src/lib.rs | 3 ++- rust/oxide-rtlsdr/Cargo.toml | 1 + rust/oxide-rtlsdr/src/lib.rs | 15 +++++++-------- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/rust/oxide-decoders/Cargo.toml b/rust/oxide-decoders/Cargo.toml index 174d8e5..7bd8b23 100644 --- a/rust/oxide-decoders/Cargo.toml +++ b/rust/oxide-decoders/Cargo.toml @@ -16,3 +16,4 @@ log = "0.4.17" custom_error = "1.9.2" num = "0.4.0" tokio = { version = "1.28.1", features = ["full", "tracing"] } +num-complex = "0.4.3" diff --git a/rust/oxide-decoders/src/decoders/acars.rs b/rust/oxide-decoders/src/decoders/acars.rs index fb52327..740c6b3 100644 --- a/rust/oxide-decoders/src/decoders/acars.rs +++ b/rust/oxide-decoders/src/decoders/acars.rs @@ -16,7 +16,7 @@ use crate::Decoder; use custom_error::custom_error; -use num::Complex; +use num_complex::Complex; use std::fmt::Display; use std::fmt::Formatter; use std::ops::Add; @@ -443,7 +443,7 @@ impl Decoder for ACARSDecoder { } impl ACARSDecoder { - pub fn new(channel_number: i32, freq: i32, wf: [num::Complex; 192]) -> Self { + pub fn new(channel_number: i32, freq: i32, wf: [Complex; 192]) -> Self { let mut h: [f32; FLENO] = [0.0; FLENO]; for (i, h_item) in h.iter_mut().enumerate().take(FLENO) { *h_item = f32::cos( @@ -467,7 +467,7 @@ impl ACARSDecoder { msk_bit_count: 0, msk_s: 0, idx: 0, - inb: [num::Complex::new(0.0, 0.0); FLEN as usize], + inb: [Complex::new(0.0, 0.0); FLEN as usize], outbits: 0, nbits: 8, acars_state: ACARSState::Wsyn, @@ -483,7 +483,7 @@ impl ACARSDecoder { for n in 0..len as usize { let in_: f32 = self.dm_buffer[n]; let s: f32 = 1800.0 / INTRATE as f32 * 2.0 * std::f32::consts::PI + self.msk_df; - let mut v: num::Complex = num::Complex::new(0.0, 0.0); + let mut v: Complex = num::Complex::new(0.0, 0.0); let mut o: f32; /* VCO */ @@ -494,8 +494,7 @@ impl ACARSDecoder { /* mixer */ - self.inb[self.idx as usize] = - in_ * num::Complex::exp(-self.msk_phi * num::Complex::i()); + self.inb[self.idx as usize] = in_ * Complex::exp(-self.msk_phi * num::Complex::i()); self.idx = (self.idx + 1) % (FLEN as u32); /* bit clock */ diff --git a/rust/oxide-decoders/src/lib.rs b/rust/oxide-decoders/src/lib.rs index e2187bf..d5d30d0 100644 --- a/rust/oxide-decoders/src/lib.rs +++ b/rust/oxide-decoders/src/lib.rs @@ -15,6 +15,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA use decoders::acars::AssembledACARSMessage; +use num_complex::Complex; use tokio::sync::mpsc::UnboundedSender; #[macro_use] @@ -32,7 +33,7 @@ pub enum ValidDecoderType { pub trait Decoder: Send + Sync { fn decode(&mut self, length: u32); - fn get_wf_at_index(&self, index: usize) -> num::Complex; + fn get_wf_at_index(&self, index: usize) -> Complex; fn set_dm_buffer_at_index(&mut self, index: usize, value: f32); fn set_output_channel(&mut self, channel: UnboundedSender); } diff --git a/rust/oxide-rtlsdr/Cargo.toml b/rust/oxide-rtlsdr/Cargo.toml index 0dd7f42..1b020e8 100644 --- a/rust/oxide-rtlsdr/Cargo.toml +++ b/rust/oxide-rtlsdr/Cargo.toml @@ -22,3 +22,4 @@ custom_error = "1.9.2" oxide-decoders = { path = "../oxide-decoders" } tokio = { version = "1.28.1", features = ["full", "tracing"] } array-init = "2.1.0" +num-complex = "0.4.3" diff --git a/rust/oxide-rtlsdr/src/lib.rs b/rust/oxide-rtlsdr/src/lib.rs index 1caa2e4..5af9e37 100644 --- a/rust/oxide-rtlsdr/src/lib.rs +++ b/rust/oxide-rtlsdr/src/lib.rs @@ -16,6 +16,7 @@ #[macro_use] extern crate log; +use num_complex::Complex; use oxide_decoders::decoders::acars::ACARSDecoder; use oxide_decoders::decoders::acars::{self, AssembledACARSMessage}; use oxide_decoders::{Decoder, ValidDecoderType}; @@ -70,7 +71,7 @@ impl RtlSdr { channels.push(Box::new(ACARSDecoder::new( 0, 0, - [num::complex::Complex::new(0.0, 0.0); 192], + [Complex::new(0.0, 0.0); 192], ))); } @@ -242,7 +243,7 @@ impl RtlSdr { let am_freq = ((channel - center_freq_actual) as f32) * 2.0 * std::f32::consts::PI / (rtl_in_rate as f32); - let mut window: Vec> = vec![]; + let mut window: Vec> = vec![]; for i in 0..self.rtl_mult { // ch->wf[ind]=cexpf(AMFreq*ind*-I)/rtlMult/127.5; let window_value = (am_freq * i as f32 * -num::complex::Complex::i()).exp() @@ -255,8 +256,7 @@ impl RtlSdr { for i in 0..self.frequencies.len() { // create an array out of the channel_window[i] vector - let mut window_array: [num::Complex; 192] = - [num::complex::Complex::new(0.0, 0.0); 192]; + let mut window_array: [Complex; 192] = [Complex::new(0.0, 0.0); 192]; for (ind, window_value) in channel_windows[i].iter().enumerate() { window_array[ind] = *window_value; } @@ -294,7 +294,7 @@ impl RtlSdr { pub async fn read_samples(mut self) { let rtloutbufz = self.get_rtloutbufsz(); let buffer_len: u32 = rtloutbufz as u32 * self.rtl_mult as u32 * 2; - let mut vb: [num::Complex; 320] = [num::complex::Complex::new(0.0, 0.0); 320]; + let mut vb: [Complex; 320] = [num::complex::Complex::new(0.0, 0.0); 320]; let mut counter: usize = 0; match self.reader { @@ -310,14 +310,13 @@ impl RtlSdr { for m in 0..rtloutbufz { for vb_item in vb.iter_mut().take(self.rtl_mult as usize) { *vb_item = (bytes[counter] as f32 - 127.37) - + (bytes[counter + 1] as f32 - 127.37) - * num::complex::Complex::i(); + + (bytes[counter + 1] as f32 - 127.37) * Complex::i(); counter += 2; } for channel in &mut self.channel.iter_mut().take(self.frequencies.len()) { - let mut d: num::Complex = num::complex::Complex::new(0.0, 0.0); + let mut d: Complex = Complex::new(0.0, 0.0); for (ind, vb_item) in vb.iter().enumerate().take(self.rtl_mult as usize) From 5ea857963695bcc768264723ce06aba2f4cddf57 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Mon, 22 May 2023 23:38:37 -0600 Subject: [PATCH 05/10] Loop iteration improvements in read_async --- .gitignore | 2 ++ rust/oxide-decoders/src/decoders/acars.rs | 4 ++++ rust/oxide-decoders/src/lib.rs | 1 + rust/oxide-rtlsdr/src/lib.rs | 23 +++++++++++++++-------- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index cf91a6c..d2810b2 100644 --- a/.gitignore +++ b/.gitignore @@ -181,3 +181,5 @@ Cargo.lock #/target flamegraph.svg +*.stacks +cargo-flamegraph.stacks diff --git a/rust/oxide-decoders/src/decoders/acars.rs b/rust/oxide-decoders/src/decoders/acars.rs index 740c6b3..843a56e 100644 --- a/rust/oxide-decoders/src/decoders/acars.rs +++ b/rust/oxide-decoders/src/decoders/acars.rs @@ -440,6 +440,10 @@ impl Decoder for ACARSDecoder { fn set_output_channel(&mut self, output_channel: UnboundedSender) { self.output_channel = Some(output_channel); } + + fn get_wf_iter(&self) -> std::slice::Iter<'_, Complex> { + self.wf.iter() + } } impl ACARSDecoder { diff --git a/rust/oxide-decoders/src/lib.rs b/rust/oxide-decoders/src/lib.rs index d5d30d0..31b76ff 100644 --- a/rust/oxide-decoders/src/lib.rs +++ b/rust/oxide-decoders/src/lib.rs @@ -34,6 +34,7 @@ pub enum ValidDecoderType { pub trait Decoder: Send + Sync { fn decode(&mut self, length: u32); fn get_wf_at_index(&self, index: usize) -> Complex; + fn get_wf_iter(&self) -> std::slice::Iter<'_, Complex>; fn set_dm_buffer_at_index(&mut self, index: usize, value: f32); fn set_output_channel(&mut self, channel: UnboundedSender); } diff --git a/rust/oxide-rtlsdr/src/lib.rs b/rust/oxide-rtlsdr/src/lib.rs index 5af9e37..b098448 100644 --- a/rust/oxide-rtlsdr/src/lib.rs +++ b/rust/oxide-rtlsdr/src/lib.rs @@ -295,7 +295,6 @@ impl RtlSdr { let rtloutbufz = self.get_rtloutbufsz(); let buffer_len: u32 = rtloutbufz as u32 * self.rtl_mult as u32 * 2; let mut vb: [Complex; 320] = [num::complex::Complex::new(0.0, 0.0); 320]; - let mut counter: usize = 0; match self.reader { None => { @@ -305,23 +304,31 @@ impl RtlSdr { Some(mut reader) => { reader .read_async(4, buffer_len, |bytes: &[u8]| { - counter = 0; + let mut bytes_iterator = bytes.iter(); for m in 0..rtloutbufz { for vb_item in vb.iter_mut().take(self.rtl_mult as usize) { - *vb_item = (bytes[counter] as f32 - 127.37) - + (bytes[counter + 1] as f32 - 127.37) * Complex::i(); - counter += 2; + *vb_item = (bytes_iterator + .next() + .expect("Ran out of bytes!") + .to_owned() as f32 + - 127.37) + + (bytes_iterator.next().expect("Ran out of bytes!").to_owned() + as f32 + - 127.37) + * Complex::i(); } for channel in &mut self.channel.iter_mut().take(self.frequencies.len()) { let mut d: Complex = Complex::new(0.0, 0.0); - for (ind, vb_item) in - vb.iter().enumerate().take(self.rtl_mult as usize) + for (wf, vb_item) in vb + .iter() + .zip(channel.get_wf_iter()) + .take(self.rtl_mult as usize) { - d += vb_item * channel.get_wf_at_index(ind); + d += vb_item * wf; } channel.set_dm_buffer_at_index(m, d.norm()); From c1369efe405a05ee4443da3f9c62f609aa99d72a Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Tue, 23 May 2023 07:51:37 -0600 Subject: [PATCH 06/10] small acars demod_msk iterating improvement --- rust/oxide-decoders/src/decoders/acars.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rust/oxide-decoders/src/decoders/acars.rs b/rust/oxide-decoders/src/decoders/acars.rs index 843a56e..9144a54 100644 --- a/rust/oxide-decoders/src/decoders/acars.rs +++ b/rust/oxide-decoders/src/decoders/acars.rs @@ -484,8 +484,7 @@ impl ACARSDecoder { pub fn demod_msk(&mut self, len: u32) { /* MSK demod */ - for n in 0..len as usize { - let in_: f32 = self.dm_buffer[n]; + for in_ in &mut self.dm_buffer.into_iter().take(len as usize) { let s: f32 = 1800.0 / INTRATE as f32 * 2.0 * std::f32::consts::PI + self.msk_df; let mut v: Complex = num::Complex::new(0.0, 0.0); let mut o: f32; From dba4df1abee9bac796cc0a798e406093f17a1341 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Tue, 23 May 2023 07:56:57 -0600 Subject: [PATCH 07/10] remove get_wf_at_index method --- rust/oxide-decoders/src/decoders/acars.rs | 4 ---- rust/oxide-decoders/src/lib.rs | 1 - 2 files changed, 5 deletions(-) diff --git a/rust/oxide-decoders/src/decoders/acars.rs b/rust/oxide-decoders/src/decoders/acars.rs index 9144a54..825b769 100644 --- a/rust/oxide-decoders/src/decoders/acars.rs +++ b/rust/oxide-decoders/src/decoders/acars.rs @@ -429,10 +429,6 @@ impl Decoder for ACARSDecoder { self.demod_msk(length); } - fn get_wf_at_index(&self, index: usize) -> Complex { - self.wf[index] - } - fn set_dm_buffer_at_index(&mut self, index: usize, value: f32) { self.dm_buffer[index] = value; } diff --git a/rust/oxide-decoders/src/lib.rs b/rust/oxide-decoders/src/lib.rs index 31b76ff..79a9b89 100644 --- a/rust/oxide-decoders/src/lib.rs +++ b/rust/oxide-decoders/src/lib.rs @@ -33,7 +33,6 @@ pub enum ValidDecoderType { pub trait Decoder: Send + Sync { fn decode(&mut self, length: u32); - fn get_wf_at_index(&self, index: usize) -> Complex; fn get_wf_iter(&self) -> std::slice::Iter<'_, Complex>; fn set_dm_buffer_at_index(&mut self, index: usize, value: f32); fn set_output_channel(&mut self, channel: UnboundedSender); From 897bc7a17fc2d212916f377e30f681bbdbb7a1af Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Tue, 23 May 2023 08:26:34 -0600 Subject: [PATCH 08/10] Remove unnecessary type casting in channel decode call --- rust/oxide-decoders/src/decoders/acars.rs | 6 +++--- rust/oxide-decoders/src/lib.rs | 2 +- rust/oxide-rtlsdr/src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rust/oxide-decoders/src/decoders/acars.rs b/rust/oxide-decoders/src/decoders/acars.rs index 825b769..a09a8ca 100644 --- a/rust/oxide-decoders/src/decoders/acars.rs +++ b/rust/oxide-decoders/src/decoders/acars.rs @@ -425,7 +425,7 @@ pub struct ACARSDecoder { } impl Decoder for ACARSDecoder { - fn decode(&mut self, length: u32) { + fn decode(&mut self, length: usize) { self.demod_msk(length); } @@ -477,10 +477,10 @@ impl ACARSDecoder { } } - pub fn demod_msk(&mut self, len: u32) { + pub fn demod_msk(&mut self, len: usize) { /* MSK demod */ - for in_ in &mut self.dm_buffer.into_iter().take(len as usize) { + for in_ in &mut self.dm_buffer.into_iter().take(len) { let s: f32 = 1800.0 / INTRATE as f32 * 2.0 * std::f32::consts::PI + self.msk_df; let mut v: Complex = num::Complex::new(0.0, 0.0); let mut o: f32; diff --git a/rust/oxide-decoders/src/lib.rs b/rust/oxide-decoders/src/lib.rs index 79a9b89..9d44d53 100644 --- a/rust/oxide-decoders/src/lib.rs +++ b/rust/oxide-decoders/src/lib.rs @@ -32,7 +32,7 @@ pub enum ValidDecoderType { } pub trait Decoder: Send + Sync { - fn decode(&mut self, length: u32); + fn decode(&mut self, length: usize); fn get_wf_iter(&self) -> std::slice::Iter<'_, Complex>; fn set_dm_buffer_at_index(&mut self, index: usize, value: f32); fn set_output_channel(&mut self, channel: UnboundedSender); diff --git a/rust/oxide-rtlsdr/src/lib.rs b/rust/oxide-rtlsdr/src/lib.rs index b098448..500c2df 100644 --- a/rust/oxide-rtlsdr/src/lib.rs +++ b/rust/oxide-rtlsdr/src/lib.rs @@ -335,7 +335,7 @@ impl RtlSdr { } } for channel in &mut self.channel.iter_mut().take(self.frequencies.len()) { - channel.decode(rtloutbufz as u32); + channel.decode(rtloutbufz); } }) .unwrap(); From 1095e2a0a7108b41a4ba63b75c275031df7ca2d2 Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Tue, 23 May 2023 08:32:45 -0600 Subject: [PATCH 09/10] Revert back to num::Complex for testing --- rust/oxide-decoders/Cargo.toml | 2 +- rust/oxide-decoders/src/decoders/acars.rs | 7 ++++--- rust/oxide-decoders/src/lib.rs | 3 ++- rust/oxide-rtlsdr/Cargo.toml | 2 +- rust/oxide-rtlsdr/src/lib.rs | 7 ++++--- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/rust/oxide-decoders/Cargo.toml b/rust/oxide-decoders/Cargo.toml index 7bd8b23..c45ae4b 100644 --- a/rust/oxide-decoders/Cargo.toml +++ b/rust/oxide-decoders/Cargo.toml @@ -16,4 +16,4 @@ log = "0.4.17" custom_error = "1.9.2" num = "0.4.0" tokio = { version = "1.28.1", features = ["full", "tracing"] } -num-complex = "0.4.3" +# num-complex = "0.4.3" diff --git a/rust/oxide-decoders/src/decoders/acars.rs b/rust/oxide-decoders/src/decoders/acars.rs index a09a8ca..bfda72a 100644 --- a/rust/oxide-decoders/src/decoders/acars.rs +++ b/rust/oxide-decoders/src/decoders/acars.rs @@ -16,7 +16,8 @@ use crate::Decoder; use custom_error::custom_error; -use num_complex::Complex; +// use num_complex::Complex; +use num::Complex; use std::fmt::Display; use std::fmt::Formatter; use std::ops::Add; @@ -482,7 +483,7 @@ impl ACARSDecoder { for in_ in &mut self.dm_buffer.into_iter().take(len) { let s: f32 = 1800.0 / INTRATE as f32 * 2.0 * std::f32::consts::PI + self.msk_df; - let mut v: Complex = num::Complex::new(0.0, 0.0); + let mut v: Complex = Complex::new(0.0, 0.0); let mut o: f32; /* VCO */ @@ -493,7 +494,7 @@ impl ACARSDecoder { /* mixer */ - self.inb[self.idx as usize] = in_ * Complex::exp(-self.msk_phi * num::Complex::i()); + self.inb[self.idx as usize] = in_ * Complex::exp(-self.msk_phi * Complex::i()); self.idx = (self.idx + 1) % (FLEN as u32); /* bit clock */ diff --git a/rust/oxide-decoders/src/lib.rs b/rust/oxide-decoders/src/lib.rs index 9d44d53..05ddb88 100644 --- a/rust/oxide-decoders/src/lib.rs +++ b/rust/oxide-decoders/src/lib.rs @@ -15,7 +15,8 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA use decoders::acars::AssembledACARSMessage; -use num_complex::Complex; +//use num_complex::Complex; +use num::Complex; use tokio::sync::mpsc::UnboundedSender; #[macro_use] diff --git a/rust/oxide-rtlsdr/Cargo.toml b/rust/oxide-rtlsdr/Cargo.toml index 1b020e8..5b93267 100644 --- a/rust/oxide-rtlsdr/Cargo.toml +++ b/rust/oxide-rtlsdr/Cargo.toml @@ -22,4 +22,4 @@ custom_error = "1.9.2" oxide-decoders = { path = "../oxide-decoders" } tokio = { version = "1.28.1", features = ["full", "tracing"] } array-init = "2.1.0" -num-complex = "0.4.3" +# num-complex = "0.4.3" diff --git a/rust/oxide-rtlsdr/src/lib.rs b/rust/oxide-rtlsdr/src/lib.rs index 500c2df..cc0d262 100644 --- a/rust/oxide-rtlsdr/src/lib.rs +++ b/rust/oxide-rtlsdr/src/lib.rs @@ -16,7 +16,8 @@ #[macro_use] extern crate log; -use num_complex::Complex; +// use num_complex::Complex; +use num::Complex; use oxide_decoders::decoders::acars::ACARSDecoder; use oxide_decoders::decoders::acars::{self, AssembledACARSMessage}; use oxide_decoders::{Decoder, ValidDecoderType}; @@ -246,7 +247,7 @@ impl RtlSdr { let mut window: Vec> = vec![]; for i in 0..self.rtl_mult { // ch->wf[ind]=cexpf(AMFreq*ind*-I)/rtlMult/127.5; - let window_value = (am_freq * i as f32 * -num::complex::Complex::i()).exp() + let window_value = (am_freq * i as f32 * -Complex::i()).exp() / self.rtl_mult as f32 / 127.5; window.push(window_value); @@ -294,7 +295,7 @@ impl RtlSdr { pub async fn read_samples(mut self) { let rtloutbufz = self.get_rtloutbufsz(); let buffer_len: u32 = rtloutbufz as u32 * self.rtl_mult as u32 * 2; - let mut vb: [Complex; 320] = [num::complex::Complex::new(0.0, 0.0); 320]; + let mut vb: [Complex; 320] = [Complex::new(0.0, 0.0); 320]; match self.reader { None => { From d98dfed50b7956da02c3c957fab3655d5146b3ff Mon Sep 17 00:00:00 2001 From: Fred Clausen <43556888+fredclausen@users.noreply.github.com> Date: Tue, 23 May 2023 08:51:39 -0600 Subject: [PATCH 10/10] bump version for new build --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 34338e7..f6638d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ [workspace.package] edition = "2021" -version = "0.1.0" +version = "0.1.1" authors = ["Fred Clausen"] description = "ACARS Oxide. A utility to receive, via librtlsdr and RTL-SDR dongle(s), ACARS and VDLM2 messages." documentation = "https://github.com/sdr-enthusiasts/acars-oxide"