Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor all frequencies from MHz (double) to Hz (uint32_t) #179

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions helper/lora-phy-helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ LoraPhyHelper::Create(Ptr<Node> node, Ptr<NetDevice> device) const

// For now, assume that the PHY will listen to the default EU channels
// with this ReceivePath configuration:
// 3 ReceivePaths on 868.1
// 3 ReceivePaths on 868.3
// 2 ReceivePaths on 868.5
// 3 ReceivePaths on 868.1 MHz
// 3 ReceivePaths on 868.3 MHz
// 2 ReceivePaths on 868.5 MHz

// We expect that MacHelper instances will overwrite this setting if the
// device will operate in a different region
std::vector<double> frequencies;
frequencies.push_back(868.1);
frequencies.push_back(868.3);
frequencies.push_back(868.5);
std::vector<uint32_t> frequenciesHz;
frequenciesHz.push_back(868100000);
frequenciesHz.push_back(868300000);
frequenciesHz.push_back(868500000);

for (auto& f : frequencies)
for (auto& f : frequenciesHz)
{
DynamicCast<SimpleGatewayLoraPhy>(phy)->AddFrequency(f);
}
Expand Down
44 changes: 22 additions & 22 deletions helper/lorawan-mac-helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ LorawanMacHelper::ConfigureForAlohaRegion(Ptr<ClassAEndDeviceLorawanMac> edMac)
// Second receive window parameters //
//////////////////////////////////////
edMac->SetSecondReceiveWindowDataRate(0);
edMac->SetSecondReceiveWindowFrequency(869.525);
edMac->SetSecondReceiveWindowFrequency(869525000);
}

void
Expand Down Expand Up @@ -187,7 +187,7 @@ LorawanMacHelper::ConfigureForAlohaRegion(Ptr<GatewayLorawanMac> gwMac) const
DynamicCast<GatewayLoraPhy>(gwPhy)->AddReceptionPath();
receptionPaths++;
}
gwPhy->AddFrequency(868.1);
gwPhy->AddFrequency(868100000);
}
}

Expand All @@ -201,12 +201,12 @@ LorawanMacHelper::ApplyCommonAlohaConfigurations(Ptr<LorawanMac> lorawanMac) con
//////////////

LogicalLoraChannelHelper channelHelper;
channelHelper.AddSubBand(868, 868.6, 1, 14);
channelHelper.AddSubBand(868000000, 868600000, 1, 14);

//////////////////////
// Default channels //
//////////////////////
Ptr<LogicalLoraChannel> lc1 = CreateObject<LogicalLoraChannel>(868.1, 0, 5);
Ptr<LogicalLoraChannel> lc1 = CreateObject<LogicalLoraChannel>(868100000, 0, 5);
channelHelper.AddChannel(lc1);

lorawanMac->SetLogicalLoraChannelHelper(channelHelper);
Expand Down Expand Up @@ -256,7 +256,7 @@ LorawanMacHelper::ConfigureForEuRegion(Ptr<ClassAEndDeviceLorawanMac> edMac) con
// Second receive window parameters //
//////////////////////////////////////
edMac->SetSecondReceiveWindowDataRate(0);
edMac->SetSecondReceiveWindowFrequency(869.525);
edMac->SetSecondReceiveWindowFrequency(869525000);
}

void
Expand All @@ -277,10 +277,10 @@ LorawanMacHelper::ConfigureForEuRegion(Ptr<GatewayLorawanMac> gwMac) const
NS_LOG_DEBUG("Resetting reception paths");
gwPhy->ResetReceptionPaths();

std::vector<double> frequencies;
frequencies.push_back(868.1);
frequencies.push_back(868.3);
frequencies.push_back(868.5);
std::vector<uint32_t> frequencies;
frequencies.push_back(868100000);
frequencies.push_back(868300000);
frequencies.push_back(868500000);

for (auto& f : frequencies)
{
Expand All @@ -307,16 +307,16 @@ LorawanMacHelper::ApplyCommonEuConfigurations(Ptr<LorawanMac> lorawanMac) const
//////////////

LogicalLoraChannelHelper channelHelper;
channelHelper.AddSubBand(868, 868.6, 0.01, 14);
channelHelper.AddSubBand(868.7, 869.2, 0.001, 14);
channelHelper.AddSubBand(869.4, 869.65, 0.1, 27);
channelHelper.AddSubBand(868000000, 868600000, 0.01, 14);
channelHelper.AddSubBand(868700000, 869200000, 0.001, 14);
channelHelper.AddSubBand(869400000, 869650000, 0.1, 27);

//////////////////////
// Default channels //
//////////////////////
Ptr<LogicalLoraChannel> lc1 = CreateObject<LogicalLoraChannel>(868.1, 0, 5);
Ptr<LogicalLoraChannel> lc2 = CreateObject<LogicalLoraChannel>(868.3, 0, 5);
Ptr<LogicalLoraChannel> lc3 = CreateObject<LogicalLoraChannel>(868.5, 0, 5);
Ptr<LogicalLoraChannel> lc1 = CreateObject<LogicalLoraChannel>(868100000, 0, 5);
Ptr<LogicalLoraChannel> lc2 = CreateObject<LogicalLoraChannel>(868300000, 0, 5);
Ptr<LogicalLoraChannel> lc3 = CreateObject<LogicalLoraChannel>(868500000, 0, 5);
channelHelper.AddChannel(lc1);
channelHelper.AddChannel(lc2);
channelHelper.AddChannel(lc3);
Expand Down Expand Up @@ -370,7 +370,7 @@ LorawanMacHelper::ConfigureForSingleChannelRegion(Ptr<ClassAEndDeviceLorawanMac>
// Second receive window parameters //
//////////////////////////////////////
edMac->SetSecondReceiveWindowDataRate(0);
edMac->SetSecondReceiveWindowFrequency(869.525);
edMac->SetSecondReceiveWindowFrequency(869525000);
}

void
Expand All @@ -391,8 +391,8 @@ LorawanMacHelper::ConfigureForSingleChannelRegion(Ptr<GatewayLorawanMac> gwMac)
NS_LOG_DEBUG("Resetting reception paths");
gwPhy->ResetReceptionPaths();

std::vector<double> frequencies;
frequencies.push_back(868.1);
std::vector<uint32_t> frequencies;
frequencies.push_back(868100000);

for (auto& f : frequencies)
{
Expand All @@ -419,14 +419,14 @@ LorawanMacHelper::ApplyCommonSingleChannelConfigurations(Ptr<LorawanMac> lorawan
//////////////

LogicalLoraChannelHelper channelHelper;
channelHelper.AddSubBand(868, 868.6, 0.01, 14);
channelHelper.AddSubBand(868.7, 869.2, 0.001, 14);
channelHelper.AddSubBand(869.4, 869.65, 0.1, 27);
channelHelper.AddSubBand(868000000, 868600000, 0.01, 14);
channelHelper.AddSubBand(868700000, 869200000, 0.001, 14);
channelHelper.AddSubBand(869400000, 869650000, 0.1, 27);

//////////////////////
// Default channels //
//////////////////////
Ptr<LogicalLoraChannel> lc1 = CreateObject<LogicalLoraChannel>(868.1, 0, 5);
Ptr<LogicalLoraChannel> lc1 = CreateObject<LogicalLoraChannel>(868100000, 0, 5);
channelHelper.AddChannel(lc1);

lorawanMac->SetLogicalLoraChannelHelper(channelHelper);
Expand Down
16 changes: 8 additions & 8 deletions model/class-a-end-device-lorawan-mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,10 @@
DynamicCast<EndDeviceLoraPhy>(m_phy)->SwitchToStandby();

// Switch to appropriate channel and data rate
NS_LOG_INFO("Using parameters: " << m_secondReceiveWindowFrequency << "Hz, DR"
NS_LOG_INFO("Using parameters: " << m_secondReceiveWindowFrequencyHz << " Hz, DR"
<< unsigned(m_secondReceiveWindowDataRate));

DynamicCast<EndDeviceLoraPhy>(m_phy)->SetFrequency(m_secondReceiveWindowFrequency);
DynamicCast<EndDeviceLoraPhy>(m_phy)->SetFrequency(m_secondReceiveWindowFrequencyHz);
DynamicCast<EndDeviceLoraPhy>(m_phy)->SetSpreadingFactor(
GetSfFromDataRate(m_secondReceiveWindowDataRate));

Expand Down Expand Up @@ -506,15 +506,15 @@
}

void
ClassAEndDeviceLorawanMac::SetSecondReceiveWindowFrequency(double frequencyMHz)
ClassAEndDeviceLorawanMac::SetSecondReceiveWindowFrequency(uint32_t frequencyHz)
{
m_secondReceiveWindowFrequency = frequencyMHz;
m_secondReceiveWindowFrequencyHz = frequencyHz;
}

double
uint32_t
ClassAEndDeviceLorawanMac::GetSecondReceiveWindowFrequency() const
{
return m_secondReceiveWindowFrequency;
return m_secondReceiveWindowFrequencyHz;

Check warning on line 517 in model/class-a-end-device-lorawan-mac.cc

View check run for this annotation

Codecov / codecov/patch

model/class-a-end-device-lorawan-mac.cc#L517

Added line #L517 was not covered by tests
}

/////////////////////////
Expand All @@ -531,7 +531,7 @@

uint8_t rx1DrOffset = rxParamSetupReq->GetRx1DrOffset();
uint8_t rx2DataRate = rxParamSetupReq->GetRx2DataRate();
double frequency = rxParamSetupReq->GetFrequency();
uint32_t frequency = rxParamSetupReq->GetFrequency();

Check warning on line 534 in model/class-a-end-device-lorawan-mac.cc

View check run for this annotation

Codecov / codecov/patch

model/class-a-end-device-lorawan-mac.cc#L534

Added line #L534 was not covered by tests

NS_LOG_FUNCTION(this << unsigned(rx1DrOffset) << unsigned(rx2DataRate) << frequency);

Expand All @@ -550,7 +550,7 @@
// For now, don't check for validity of frequency
m_secondReceiveWindowDataRate = rx2DataRate;
m_rx1DrOffset = rx1DrOffset;
m_secondReceiveWindowFrequency = frequency;
m_secondReceiveWindowFrequencyHz = frequency;

Check warning on line 553 in model/class-a-end-device-lorawan-mac.cc

View check run for this annotation

Codecov / codecov/patch

model/class-a-end-device-lorawan-mac.cc#L553

Added line #L553 was not covered by tests

// Craft a RxParamSetupAns as response
NS_LOG_INFO("Adding RxParamSetupAns reply");
Expand Down
12 changes: 6 additions & 6 deletions model/class-a-end-device-lorawan-mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,16 @@ class ClassAEndDeviceLorawanMac : public EndDeviceLorawanMac
/**
* Set the frequency that will be used for the second receive window.
*
* \param frequencyMHz The Frequency.
* \param frequencyHz The Frequency.
*/
void SetSecondReceiveWindowFrequency(double frequencyMHz);
void SetSecondReceiveWindowFrequency(uint32_t frequencyHz);

/**
* Get the frequency that is used for the second receive window.
*
* \return The frequency, in MHz.
* \return The frequency, in Hz.
*/
double GetSecondReceiveWindowFrequency() const;
uint32_t GetSecondReceiveWindowFrequency() const;

/////////////////////////
// MAC command methods //
Expand Down Expand Up @@ -188,9 +188,9 @@ class ClassAEndDeviceLorawanMac : public EndDeviceLorawanMac
EventId m_secondReceiveWindow;

/**
* The frequency to listen on for the second receive window.
* The frequency [Hz] to listen on for the second receive window.
*/
double m_secondReceiveWindowFrequency;
uint32_t m_secondReceiveWindowFrequencyHz;

/**
* The data rate to listen for during the second downlink transmission.
Expand Down
10 changes: 5 additions & 5 deletions model/end-device-lora-phy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ EndDeviceLoraPhy::GetTypeId()
// These will then be changed by helpers.
EndDeviceLoraPhy::EndDeviceLoraPhy()
: m_state(SLEEP),
m_frequency(868.1),
m_frequencyHz(868100000),
m_sf(7)
{
}
Expand Down Expand Up @@ -95,15 +95,15 @@ EndDeviceLoraPhy::IsTransmitting()
}

bool
EndDeviceLoraPhy::IsOnFrequency(double frequencyMHz)
EndDeviceLoraPhy::IsOnFrequency(uint32_t frequencyHz)
{
return m_frequency == frequencyMHz;
return m_frequencyHz == frequencyHz;
}

void
EndDeviceLoraPhy::SetFrequency(double frequencyMHz)
EndDeviceLoraPhy::SetFrequency(uint32_t frequencyHz)
{
m_frequency = frequencyMHz;
m_frequencyHz = frequencyHz;
}

void
Expand Down
12 changes: 6 additions & 6 deletions model/end-device-lora-phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,19 @@ class EndDeviceLoraPhy : public LoraPhy
double rxPowerDbm,
uint8_t sf,
Time duration,
double frequencyMHz) override = 0;
uint32_t frequencyHz) override = 0;

// Implementation of LoraPhy's pure virtual functions
void EndReceive(Ptr<Packet> packet, Ptr<LoraInterferenceHelper::Event> event) override = 0;

// Implementation of LoraPhy's pure virtual functions
void Send(Ptr<Packet> packet,
LoraTxParameters txParams,
double frequencyMHz,
uint32_t frequencyHz,
double txPowerDbm) override = 0;

// Implementation of LoraPhy's pure virtual functions
bool IsOnFrequency(double frequencyMHz) override;
bool IsOnFrequency(uint32_t frequencyHz) override;

// Implementation of LoraPhy's pure virtual functions
bool IsTransmitting() override;
Expand All @@ -169,9 +169,9 @@ class EndDeviceLoraPhy : public LoraPhy
* Should a packet be transmitted on a frequency different than that the
* EndDeviceLoraPhy is listening on, the packet will be discarded.
*
* \param frequencyMHz The frequency [MHz] to listen to.
* \param frequencyHz The frequency [Hz] to listen to.
*/
void SetFrequency(double frequencyMHz);
void SetFrequency(uint32_t frequencyHz);

/**
* Set the Spreading Factor this end device will listen for.
Expand Down Expand Up @@ -263,7 +263,7 @@ class EndDeviceLoraPhy : public LoraPhy
// static const double sensitivity[6]; //!< The sensitivity vector of this device to different
// SFs

double m_frequency; //!< The frequency this device is listening on
uint32_t m_frequencyHz; //!< The frequency [Hz] this device is listening on

uint8_t m_sf; //!< The Spreading Factor this device is listening for

Expand Down
30 changes: 15 additions & 15 deletions model/end-device-lorawan-mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,12 @@
{
// Pointer to the current channel
Ptr<LogicalLoraChannel> logicalChannel = *it;
double frequency = logicalChannel->GetFrequency();
uint32_t frequencyHz = logicalChannel->GetFrequency();

waitingTime = std::min(waitingTime, m_channelHelper.GetWaitingTime(logicalChannel));

NS_LOG_DEBUG("Waiting time before the next transmission in channel with frequency "
<< frequency << " is = " << waitingTime.GetSeconds() << ".");
<< frequencyHz << " Hz is = " << waitingTime.GetSeconds() << ".");
}

waitingTime = GetNextClassTransmissionDelay(waitingTime);
Expand All @@ -554,9 +554,9 @@
{
// Pointer to the current channel
Ptr<LogicalLoraChannel> logicalChannel = *it;
double frequency = logicalChannel->GetFrequency();
uint32_t frequencyHz = logicalChannel->GetFrequency();

NS_LOG_DEBUG("Frequency of the current channel: " << frequency);
NS_LOG_DEBUG("Frequency of the current channel: " << frequencyHz << " Hz");

// Verify that we can send the packet
Time waitingTime = m_channelHelper.GetWaitingTime(logicalChannel);
Expand Down Expand Up @@ -837,7 +837,7 @@

void
EndDeviceLorawanMac::OnNewChannelReq(uint8_t chIndex,
double frequency,
uint32_t frequencyHz,
uint8_t minDataRate,
uint8_t maxDataRate)
{
Expand All @@ -849,18 +849,18 @@
// TODO Return false if one of the checks above failed
// TODO Create new channel in the LogicalLoraChannelHelper

SetLogicalChannel(chIndex, frequency, minDataRate, maxDataRate);
SetLogicalChannel(chIndex, frequencyHz, minDataRate, maxDataRate);

Check warning on line 852 in model/end-device-lorawan-mac.cc

View check run for this annotation

Codecov / codecov/patch

model/end-device-lorawan-mac.cc#L852

Added line #L852 was not covered by tests

NS_LOG_INFO("Adding NewChannelAns reply");
m_macCommandList.emplace_back(CreateObject<NewChannelAns>(dataRateRangeOk, channelFrequencyOk));
}

void
EndDeviceLorawanMac::AddLogicalChannel(double frequency)
EndDeviceLorawanMac::AddLogicalChannel(uint32_t frequencyHz)

Check warning on line 859 in model/end-device-lorawan-mac.cc

View check run for this annotation

Codecov / codecov/patch

model/end-device-lorawan-mac.cc#L859

Added line #L859 was not covered by tests
{
NS_LOG_FUNCTION(this << frequency);
NS_LOG_FUNCTION(this << frequencyHz);

Check warning on line 861 in model/end-device-lorawan-mac.cc

View check run for this annotation

Codecov / codecov/patch

model/end-device-lorawan-mac.cc#L861

Added line #L861 was not covered by tests

m_channelHelper.AddChannel(frequency);
m_channelHelper.AddChannel(frequencyHz);

Check warning on line 863 in model/end-device-lorawan-mac.cc

View check run for this annotation

Codecov / codecov/patch

model/end-device-lorawan-mac.cc#L863

Added line #L863 was not covered by tests
}

void
Expand All @@ -873,27 +873,27 @@

void
EndDeviceLorawanMac::SetLogicalChannel(uint8_t chIndex,
double frequency,
uint32_t frequencyHz,
uint8_t minDataRate,
uint8_t maxDataRate)
{
NS_LOG_FUNCTION(this << unsigned(chIndex) << frequency << unsigned(minDataRate)
NS_LOG_FUNCTION(this << unsigned(chIndex) << frequencyHz << unsigned(minDataRate)

Check warning on line 880 in model/end-device-lorawan-mac.cc

View check run for this annotation

Codecov / codecov/patch

model/end-device-lorawan-mac.cc#L880

Added line #L880 was not covered by tests
<< unsigned(maxDataRate));

m_channelHelper.SetChannel(
chIndex,
CreateObject<LogicalLoraChannel>(frequency, minDataRate, maxDataRate));
CreateObject<LogicalLoraChannel>(frequencyHz, minDataRate, maxDataRate));

Check warning on line 885 in model/end-device-lorawan-mac.cc

View check run for this annotation

Codecov / codecov/patch

model/end-device-lorawan-mac.cc#L885

Added line #L885 was not covered by tests
}

void
EndDeviceLorawanMac::AddSubBand(double startFrequency,
double endFrequency,
EndDeviceLorawanMac::AddSubBand(uint32_t startFrequencyHz,

Check warning on line 889 in model/end-device-lorawan-mac.cc

View check run for this annotation

Codecov / codecov/patch

model/end-device-lorawan-mac.cc#L889

Added line #L889 was not covered by tests
uint32_t endFrequencyHz,
double dutyCycle,
double maxTxPowerDbm)
{
NS_LOG_FUNCTION_NOARGS();

m_channelHelper.AddSubBand(startFrequency, endFrequency, dutyCycle, maxTxPowerDbm);
m_channelHelper.AddSubBand(startFrequencyHz, endFrequencyHz, dutyCycle, maxTxPowerDbm);

Check warning on line 896 in model/end-device-lorawan-mac.cc

View check run for this annotation

Codecov / codecov/patch

model/end-device-lorawan-mac.cc#L896

Added line #L896 was not covered by tests
}

double
Expand Down
Loading