Skip to content

Commit

Permalink
(wip) Add support for AF Method B (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
windytan committed Jun 12, 2023
1 parent b34fd7c commit 771c3fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
23 changes: 16 additions & 7 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ std::string CarrierFrequency::str() const {

bool operator== (const CarrierFrequency &f1,
const CarrierFrequency &f2) {
return (f1.kHz() == f2.kHz());
return (f1.code_ == f2.code_);
}

bool operator< (const CarrierFrequency &f1,
Expand All @@ -134,31 +134,40 @@ void AltFreqList::insert(uint16_t af_code) {
CarrierFrequency::Band::FM);
lf_mf_follows_ = false;

if (frequency.isValid()) {
alt_freqs_.insert(frequency);
if (frequency.isValid() && num_expected_ > 0) {
// Something has gone wrong; stop receiving this list
if (num_received_ >= num_expected_) {
num_expected_ = 0;
alt_freqs_.clear();
} else {
alt_freqs_.insert(frequency);
num_received_++;
}
} else if (af_code == 205) {
// filler
} else if (af_code == 224) {
// no AF exists
} else if (af_code >= 225 && af_code <= 249) {
num_alt_freqs_ = af_code - 224;
num_expected_ = af_code - 224;
num_received_ = 0;
alt_freqs_.clear();
} else if (af_code == 250) {
// AM/LF freq follows
lf_mf_follows_ = true;
}
}

bool AltFreqList::isComplete() const {
return (alt_freqs_.size() == num_alt_freqs_ &&
num_alt_freqs_ > 0);
return num_expected_ == num_received_ &&
num_received_ > 0;
}

std::set<CarrierFrequency> AltFreqList::get() const {
return alt_freqs_;
}

void AltFreqList::clear() {
alt_freqs_.clear();
num_expected_ = num_received_ = 0;
}

std::vector<std::string> splitLine(const std::string& line, char delimiter) {
Expand Down
7 changes: 4 additions & 3 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CarrierFrequency {
const CarrierFrequency &f2);

private:
uint16_t code_;
uint16_t code_ {};
Band band_ { Band::FM };
};

Expand All @@ -97,8 +97,9 @@ class AltFreqList {

private:
std::set<CarrierFrequency> alt_freqs_;
unsigned num_alt_freqs_ { 0 };
bool lf_mf_follows_ { false };
size_t num_expected_ { 0 };
size_t num_received_ { 0 };
bool lf_mf_follows_ { false };
};

template<typename T, size_t N>
Expand Down

0 comments on commit 771c3fe

Please sign in to comment.