Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
windytan committed Aug 27, 2023
1 parent b32de53 commit 9587d69
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 24 deletions.
4 changes: 3 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
bin_PROGRAMS = redsea
redsea_CPPFLAGS = -std=$(CPP_STD) -Wall -Wextra -Wstrict-overflow -Wshadow -Wdouble-promotion -Wundef -Wpointer-arith -Wcast-align -Wcast-qual -Wuninitialized -pedantic \
redsea_CPPFLAGS = -std=$(CPP_STD) -Wall -Wextra -Wstrict-overflow -Wshadow -Wdouble-promotion \
-Wundef -Wpointer-arith -Wcast-align -Wcast-qual -Wuninitialized -pedantic \
-Wno-deprecated-declarations \
$(MACPORTS_CF) $(RFLAGS) $(WIN_CF)
redsea_LDADD = $(MACPORTS_LD) $(LIBC) $(LIQUID) $(ICONV) $(SNDFILE)
redsea_SOURCES = redsea.cc common.cc input.cc subcarrier.cc block_sync.cc groups.cc \
Expand Down
14 changes: 7 additions & 7 deletions src/subcarrier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,19 @@ constexpr float hertz2step(float Hz) {
BiphaseDecoder::BiphaseDecoder() : clock_history_(128) {
}

// At correct clock phase, return binary symbol in
// At correct clock phase, evaluate symbol in
// constellation {-1,0} => 0, {1,0} => 1
Maybe<std::complex<float>> BiphaseDecoder::push(
Maybe<bool> BiphaseDecoder::push(
std::complex<float> psk_symbol) {

Maybe<std::complex<float>> result;
Maybe<bool> result;

result.data = (psk_symbol - prev_psk_symbol_) * 0.5f;
auto biphase_symbol = (psk_symbol - prev_psk_symbol_) * 0.5f;
result.data = biphase_symbol.real() >= 0.0f;
result.valid = (clock_ % 2 == clock_polarity_);
prev_psk_symbol_ = psk_symbol;

clock_history_[clock_] = std::fabs(result.data.real());
clock_history_[clock_] = std::fabs(biphase_symbol.real());
clock_++;

// Periodically evaluate validity of the chosen biphase clock polarity
Expand Down Expand Up @@ -161,8 +162,7 @@ BitBuffer Subcarrier::processChunk(MPXBuffer<>& chunk) {

// One biphase symbol received for every 2 PSK symbols
if (biphase.valid) {
bitbuffer.bits.push_back(delta_decoder_.decode(
biphase.data.real() >= 0.0f));
bitbuffer.bits.push_back(delta_decoder_.decode(biphase.data));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/subcarrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class BiphaseDecoder {
public:
BiphaseDecoder();
~BiphaseDecoder() = default;
Maybe<std::complex<float>> push(std::complex<float> psk_symbol);
Maybe<bool> push(std::complex<float> psk_symbol);

private:
std::complex<float> prev_psk_symbol_ { 0.0f, 0.0f };
Expand Down
2 changes: 1 addition & 1 deletion src/tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace redsea {

std::string getPTYNameString(uint16_t pty);
std::string getPTYNameStringRBDS(uint16_t pty);
std::string getCountryString(uint16_t pi, uint16_t ecc);
std::string getCountryString(uint16_t cc, uint16_t ecc);
std::string getLanguageString(uint16_t code);
std::string getAppNameString(uint16_t aid);
std::string getRTPlusContentTypeString(uint16_t content_type);
Expand Down
2 changes: 1 addition & 1 deletion src/tmc/tmc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ Event getEvent(uint16_t code) {
TMCService::TMCService(const Options& options) : message_(is_encrypted_),
service_key_table_(loadServiceKeyTable()), ps_(8) {
if (!options.loctable_dirs.empty() && g_location_databases.empty()) {
for (std::string loctable_dir : options.loctable_dirs) {
for (const std::string& loctable_dir : options.loctable_dirs) {
uint16_t ltn = readLTN(loctable_dir);
g_location_databases[ltn] = loadLocationDatabase(loctable_dir);
if (options.feed_thru)
Expand Down
14 changes: 7 additions & 7 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ std::string getHoursMinutesString(int hour, int minute) {
return ss.str();
}

std::string join(std::vector<std::string> strings, const std::string& d) {
std::string join(const std::vector<std::string>& strings, const std::string& d) {
std::string result("");
for (size_t i = 0; i < strings.size(); i++) {
result += strings[i];
Expand All @@ -41,7 +41,7 @@ std::string join(std::vector<std::string> strings, const std::string& d) {
return result;
}

std::string join(std::vector<uint16_t> nums, const std::string& d) {
std::string join(const std::vector<uint16_t>& nums, const std::string& d) {
std::string result("");
for (size_t i = 0; i < nums.size(); i++) {
result += std::to_string(nums[i]);
Expand Down Expand Up @@ -211,7 +211,7 @@ std::vector<std::string> splitLine(const std::string& line, char delimiter) {
return result;
}

std::vector<std::vector<std::string>> readCSV(std::vector<std::string> csvdata,
std::vector<std::vector<std::string>> readCSV(const std::vector<std::string>& csvdata,
char delimiter) {
std::vector<std::vector<std::string>> lines;

Expand All @@ -223,7 +223,7 @@ std::vector<std::vector<std::string>> readCSV(std::vector<std::string> csvdata,
return lines;
}

std::vector<std::vector<std::string>> readCSV(std::string filename,
std::vector<std::vector<std::string>> readCSV(const std::string& filename,
char delimiter) {
std::vector<std::vector<std::string>> lines;

Expand All @@ -247,7 +247,7 @@ std::vector<std::vector<std::string>> readCSV(std::string filename,
return lines;
}

CSVTable readCSVWithTitles(std::vector<std::string> csvdata,
CSVTable readCSVWithTitles(const std::vector<std::string>& csvdata,
char delimiter) {
CSVTable table;

Expand All @@ -257,7 +257,7 @@ CSVTable readCSVWithTitles(std::vector<std::string> csvdata,
line.erase(std::remove(line.begin(), line.end(), '\r'), line.end());
line.erase(std::remove(line.begin(), line.end(), '\n'), line.end());

std::vector<std::string> fields = splitLine(line, delimiter);
const std::vector<std::string> fields = splitLine(line, delimiter);
if (is_title_row) {
for (size_t i = 0; i < fields.size(); i++)
table.titles[fields[i]] = i;
Expand All @@ -271,7 +271,7 @@ CSVTable readCSVWithTitles(std::vector<std::string> csvdata,
return table;
}

CSVTable readCSVWithTitles(std::string filename, char delimiter) {
CSVTable readCSVWithTitles(const std::string& filename, char delimiter) {
std::vector<std::string> lines;

std::ifstream in(filename);
Expand Down
12 changes: 6 additions & 6 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ uint32_t getBits(uint16_t word1, uint16_t word2, size_t starting_at) {

std::string getHoursMinutesString(int hour, int minute);

std::string join(std::vector<std::string> strings, const std::string& d);
std::string join(std::vector<uint16_t> nums, const std::string& d);
std::string join(const std::vector<std::string>& strings, const std::string& d);
std::string join(const std::vector<uint16_t>& nums, const std::string& d);

std::string getHexString(uint32_t value, int num_nybbles);
std::string getPrefixedHexString(uint32_t value, int num_nybbles);
Expand All @@ -59,12 +59,12 @@ class CSVTable {
std::vector<CSVRow> rows;
};

std::vector<std::vector<std::string>> readCSV(std::vector<std::string> csvdata,
std::vector<std::vector<std::string>> readCSV(const std::vector<std::string>& csvdata,
char delimiter);
std::vector<std::vector<std::string>> readCSV(std::string filename,
std::vector<std::vector<std::string>> readCSV(const std::string& filename,
char delimiter);
CSVTable readCSVWithTitles(std::string filename, char delimiter);
CSVTable readCSVWithTitles(std::vector<std::string> csvdata,
CSVTable readCSVWithTitles(const std::string& filename, char delimiter);
CSVTable readCSVWithTitles(const std::vector<std::string>& csvdata,
char delimiter);

class CarrierFrequency {
Expand Down

0 comments on commit 9587d69

Please sign in to comment.