Skip to content

Commit

Permalink
updating code
Browse files Browse the repository at this point in the history
  • Loading branch information
tanneberger committed May 15, 2024
1 parent a4f6183 commit 5e7f9ab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
19 changes: 11 additions & 8 deletions include/config.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef CONFIG_H
#define CONFIG_H

#include <map>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -43,9 +46,7 @@ template <typename T> class Range {

/// Check that the given Range is inside the bounds (inclusive) of this Range.
[[nodiscard]] auto contains(const Range<T>& other) const noexcept -> bool {
if (other.min_ < min_ || other.max_ > max_)
return false;
return true;
return !static_cast<bool>(other.min_ < min_ || other.max_ > max_);
};
};

Expand All @@ -66,15 +67,15 @@ template <typename T> class SpectrumSlice {
, frequency_range_(center_frequency - sample_rate / 2, center_frequency + sample_rate / 2)
, sample_rate_(sample_rate){};

friend bool operator==(const SpectrumSlice<T>&, const SpectrumSlice<T>&);
friend bool operator!=(const SpectrumSlice<T>&, const SpectrumSlice<T>&);
friend auto operator==(const SpectrumSlice<T>&, const SpectrumSlice<T>&) -> bool;
friend auto operator!=(const SpectrumSlice<T>&, const SpectrumSlice<T>&) -> bool;
};

template <typename T> bool operator==(const SpectrumSlice<T>& lhs, const SpectrumSlice<T>& rhs) {
template <typename T> auto operator==(const SpectrumSlice<T>& lhs, const SpectrumSlice<T>& rhs) -> bool {
return lhs.center_frequency_ == rhs.center_frequency_ && lhs.sample_rate_ == rhs.sample_rate_;
};

template <typename T> bool operator!=(const SpectrumSlice<T>& lhs, const SpectrumSlice<T>& rhs) {
template <typename T> auto operator!=(const SpectrumSlice<T>& lhs, const SpectrumSlice<T>& rhs) -> bool {
return !operator==<T>(lhs, rhs);
};

Expand Down Expand Up @@ -180,7 +181,7 @@ static config::decimate_or_stream get_decimate_or_stream(const config::SpectrumS
}

template <> struct from<config::TopLevel> {
static config::TopLevel from_toml(const value& v) {
static auto from_toml(const value& v) -> config::TopLevel {
const unsigned int center_frequency = find<unsigned int>(v, "CenterFrequency");
const std::string device_string = find<std::string>(v, "DeviceString");
const unsigned int sample_rate = find<unsigned int>(v, "SampleRate");
Expand Down Expand Up @@ -247,3 +248,5 @@ template <> struct from<config::TopLevel> {
}; // namespace toml

#endif

#endif
8 changes: 4 additions & 4 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Stream::Stream(const SpectrumSlice<unsigned int>& input_spectrum, const Spectrum
const auto& input_sample_rate = input_spectrum.sample_rate_;
const auto& sample_rate = spectrum.sample_rate_;
decimation_ = input_sample_rate / sample_rate;
auto rem = input_sample_rate % sample_rate;
if (rem != 0) {
auto remainder = input_sample_rate % sample_rate;
if (remainder != 0) {
throw std::invalid_argument("Input sample rate is not divisible by Stream block sample rate.");
}
}
Expand All @@ -34,9 +34,9 @@ Decimate::Decimate(const SpectrumSlice<unsigned int>& input_spectrum, const Spec
const auto& input_sample_rate = input_spectrum.sample_rate_;
const auto& sample_rate = spectrum.sample_rate_;
decimation_ = input_sample_rate / sample_rate;
auto rem = input_sample_rate % sample_rate;
auto remainder = input_sample_rate % sample_rate;

if (rem != 0) {
if (remainder != 0) {
throw std::invalid_argument("Input sample rate is not divisible by Decimate block sample rate.");
}

Expand Down
6 changes: 3 additions & 3 deletions src/tetra-receiver.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <fstream>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <cstdlib>
#include <string>

#include <cxxopts.hpp>
Expand Down Expand Up @@ -140,7 +140,7 @@ class GnuradioTopBlock {
}
};

int main(int argc, char** argv) {
auto main(int argc, char** argv) -> int {
try {
cxxopts::Options options("tetra-receiver", "Receive multiple TETRA streams at once and send the bits out via UDP");

Expand All @@ -166,7 +166,7 @@ int main(int argc, char** argv) {
return EXIT_SUCCESS;
}

gr::top_block_sptr tb;
gr::top_block_sptr tb = 0;

// Read from config file instead
if (result.count("config-file")) {
Expand Down

0 comments on commit 5e7f9ab

Please sign in to comment.