Skip to content

Commit

Permalink
Merge pull request #1 from AndyTWF/no-duplicate-frequencies
Browse files Browse the repository at this point in the history
Fix Multiple Messages
  • Loading branch information
AndyTWF authored Nov 10, 2019
2 parents 6b10a9d + 74a1c79 commit b50438e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
43 changes: 41 additions & 2 deletions AfvBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,21 @@ bool AfvBridge::ConvertBoolean(std::string boolean) const
*/
void AfvBridge::ToggleFrequency(double frequency, bool receive, bool transmit)
{
EuroScopePlugIn::CGrountToAirChannel channel = this->GroundToArChannelSelectFirst();
// If the frequency is our primary frequency, ignore it - ES automatically sets text RCV/XMT when
// primary is selected.
EuroScopePlugIn::CGrountToAirChannel primaryChannel = this->GetPrimaryFrequency();
if (primaryChannel.IsValid() && this->IsFrequencyMatch(frequency, primaryChannel)) {
return;
}

// Otherwise, loop the frequencies and toggle the first one.
EuroScopePlugIn::CGrountToAirChannel channel = this->GroundToArChannelSelectFirst();
while (true) {
if (!channel.IsValid()) {
return;
}

if (std::abs(channel.GetFrequency() - frequency) < this->frequencyDeviation && !this->IsAtisChannel(channel.GetVoiceChannel())) {
if (this->IsFrequencyMatch(frequency, channel) && !this->IsAtisChannel(channel.GetVoiceChannel())) {

if (channel.GetIsTextReceiveOn() != receive) {
channel.ToggleTextReceive();
Expand All @@ -164,12 +171,23 @@ void AfvBridge::ToggleFrequency(double frequency, bool receive, bool transmit)
if (channel.GetIsTextTransmitOn() != transmit) {
channel.ToggleTextTransmit();
}

return;
}

channel = this->GroundToArChannelSelectNext(channel);
}
}

/*
Returns true if the given channel has a frequency within a reasonable deviation
of the target frequency.
*/
bool AfvBridge::IsFrequencyMatch(double targetFrequency, EuroScopePlugIn::CGrountToAirChannel channel)
{
return std::abs(channel.GetFrequency() - targetFrequency) < this->frequencyDeviation;
}

/*
Checks if the channel is an ATIS channel.
*/
Expand All @@ -180,3 +198,24 @@ bool AfvBridge::IsAtisChannel(std::string channel) const

return channel.find("_atis") != std::string::npos;
}

/*
Find the channel which is the primary frequency.
*/
EuroScopePlugIn::CGrountToAirChannel AfvBridge::GetPrimaryFrequency(void)
{
EuroScopePlugIn::CGrountToAirChannel channel = this->GroundToArChannelSelectFirst();
while (true) {
if (!channel.IsValid()) {
break;
}

if (channel.GetIsPrimary()) {
return channel;
}

channel = this->GroundToArChannelSelectNext(channel);
}

return EuroScopePlugIn::CGrountToAirChannel();
}
3 changes: 2 additions & 1 deletion AfvBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ class AfvBridge : public EuroScopePlugIn::CPlugIn

private:

void CheckAtisFrequencies(void);
void ProcessMessage(std::string message);
bool ValidBoolean(std::string boolean) const;
bool ConvertBoolean(std::string boolean) const;
void ToggleFrequency(double frequency, bool receive, bool transmit);
bool IsFrequencyMatch(double targetFrequency, EuroScopePlugIn::CGrountToAirChannel channel);
bool IsAtisChannel(std::string channel) const;
EuroScopePlugIn::CGrountToAirChannel GetPrimaryFrequency(void);

// Lock for the message queue
std::mutex messageLock;
Expand Down
2 changes: 1 addition & 1 deletion constants.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#define PLUGIN_TITLE "Audio for Vatsim EuroScope Bridge"
#define PLUGIN_VERSION "1.2.3"
#define PLUGIN_VERSION "1.3.0"
#define PLUGIN_AUTHOR "Audio for Vatsim Team"
#define PLUGIN_COPYRIGHT "Virtual Air Traffic Simulation Network"

0 comments on commit b50438e

Please sign in to comment.