diff --git a/helper/lora-phy-helper.cc b/helper/lora-phy-helper.cc index 51ff87bd3d..eb8c37be58 100644 --- a/helper/lora-phy-helper.cc +++ b/helper/lora-phy-helper.cc @@ -77,18 +77,18 @@ LoraPhyHelper::Create(Ptr node, Ptr 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 frequencies; - frequencies.push_back(868.1); - frequencies.push_back(868.3); - frequencies.push_back(868.5); + std::vector frequenciesHz; + frequenciesHz.push_back(868100000); + frequenciesHz.push_back(868300000); + frequenciesHz.push_back(868500000); - for (auto& f : frequencies) + for (auto& f : frequenciesHz) { DynamicCast(phy)->AddFrequency(f); } diff --git a/helper/lorawan-mac-helper.cc b/helper/lorawan-mac-helper.cc index 4e18b7dedb..ca7d5ad1fc 100644 --- a/helper/lorawan-mac-helper.cc +++ b/helper/lorawan-mac-helper.cc @@ -159,7 +159,7 @@ LorawanMacHelper::ConfigureForAlohaRegion(Ptr edMac) // Second receive window parameters // ////////////////////////////////////// edMac->SetSecondReceiveWindowDataRate(0); - edMac->SetSecondReceiveWindowFrequency(869.525); + edMac->SetSecondReceiveWindowFrequency(869525000); } void @@ -187,7 +187,7 @@ LorawanMacHelper::ConfigureForAlohaRegion(Ptr gwMac) const DynamicCast(gwPhy)->AddReceptionPath(); receptionPaths++; } - gwPhy->AddFrequency(868.1); + gwPhy->AddFrequency(868100000); } } @@ -201,12 +201,12 @@ LorawanMacHelper::ApplyCommonAlohaConfigurations(Ptr lorawanMac) con ////////////// LogicalLoraChannelHelper channelHelper; - channelHelper.AddSubBand(868, 868.6, 1, 14); + channelHelper.AddSubBand(868000000, 868600000, 1, 14); ////////////////////// // Default channels // ////////////////////// - Ptr lc1 = CreateObject(868.1, 0, 5); + Ptr lc1 = CreateObject(868100000, 0, 5); channelHelper.AddChannel(lc1); lorawanMac->SetLogicalLoraChannelHelper(channelHelper); @@ -256,7 +256,7 @@ LorawanMacHelper::ConfigureForEuRegion(Ptr edMac) con // Second receive window parameters // ////////////////////////////////////// edMac->SetSecondReceiveWindowDataRate(0); - edMac->SetSecondReceiveWindowFrequency(869.525); + edMac->SetSecondReceiveWindowFrequency(869525000); } void @@ -277,10 +277,10 @@ LorawanMacHelper::ConfigureForEuRegion(Ptr gwMac) const NS_LOG_DEBUG("Resetting reception paths"); gwPhy->ResetReceptionPaths(); - std::vector frequencies; - frequencies.push_back(868.1); - frequencies.push_back(868.3); - frequencies.push_back(868.5); + std::vector frequencies; + frequencies.push_back(868100000); + frequencies.push_back(868300000); + frequencies.push_back(868500000); for (auto& f : frequencies) { @@ -307,16 +307,16 @@ LorawanMacHelper::ApplyCommonEuConfigurations(Ptr 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 lc1 = CreateObject(868.1, 0, 5); - Ptr lc2 = CreateObject(868.3, 0, 5); - Ptr lc3 = CreateObject(868.5, 0, 5); + Ptr lc1 = CreateObject(868100000, 0, 5); + Ptr lc2 = CreateObject(868300000, 0, 5); + Ptr lc3 = CreateObject(868500000, 0, 5); channelHelper.AddChannel(lc1); channelHelper.AddChannel(lc2); channelHelper.AddChannel(lc3); @@ -370,7 +370,7 @@ LorawanMacHelper::ConfigureForSingleChannelRegion(Ptr // Second receive window parameters // ////////////////////////////////////// edMac->SetSecondReceiveWindowDataRate(0); - edMac->SetSecondReceiveWindowFrequency(869.525); + edMac->SetSecondReceiveWindowFrequency(869525000); } void @@ -391,8 +391,8 @@ LorawanMacHelper::ConfigureForSingleChannelRegion(Ptr gwMac) NS_LOG_DEBUG("Resetting reception paths"); gwPhy->ResetReceptionPaths(); - std::vector frequencies; - frequencies.push_back(868.1); + std::vector frequencies; + frequencies.push_back(868100000); for (auto& f : frequencies) { @@ -419,14 +419,14 @@ LorawanMacHelper::ApplyCommonSingleChannelConfigurations(Ptr 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 lc1 = CreateObject(868.1, 0, 5); + Ptr lc1 = CreateObject(868100000, 0, 5); channelHelper.AddChannel(lc1); lorawanMac->SetLogicalLoraChannelHelper(channelHelper); diff --git a/model/class-a-end-device-lorawan-mac.cc b/model/class-a-end-device-lorawan-mac.cc index f59832151b..5bb8d1a482 100644 --- a/model/class-a-end-device-lorawan-mac.cc +++ b/model/class-a-end-device-lorawan-mac.cc @@ -352,10 +352,10 @@ ClassAEndDeviceLorawanMac::OpenSecondReceiveWindow() DynamicCast(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(m_phy)->SetFrequency(m_secondReceiveWindowFrequency); + DynamicCast(m_phy)->SetFrequency(m_secondReceiveWindowFrequencyHz); DynamicCast(m_phy)->SetSpreadingFactor( GetSfFromDataRate(m_secondReceiveWindowDataRate)); @@ -506,15 +506,15 @@ ClassAEndDeviceLorawanMac::GetSecondReceiveWindowDataRate() const } 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; } ///////////////////////// @@ -531,7 +531,7 @@ ClassAEndDeviceLorawanMac::OnRxClassParamSetupReq(Ptr rxParamSe uint8_t rx1DrOffset = rxParamSetupReq->GetRx1DrOffset(); uint8_t rx2DataRate = rxParamSetupReq->GetRx2DataRate(); - double frequency = rxParamSetupReq->GetFrequency(); + uint32_t frequency = rxParamSetupReq->GetFrequency(); NS_LOG_FUNCTION(this << unsigned(rx1DrOffset) << unsigned(rx2DataRate) << frequency); @@ -550,7 +550,7 @@ ClassAEndDeviceLorawanMac::OnRxClassParamSetupReq(Ptr rxParamSe // For now, don't check for validity of frequency m_secondReceiveWindowDataRate = rx2DataRate; m_rx1DrOffset = rx1DrOffset; - m_secondReceiveWindowFrequency = frequency; + m_secondReceiveWindowFrequencyHz = frequency; // Craft a RxParamSetupAns as response NS_LOG_INFO("Adding RxParamSetupAns reply"); diff --git a/model/class-a-end-device-lorawan-mac.h b/model/class-a-end-device-lorawan-mac.h index d85c6422e8..786ee1b588 100644 --- a/model/class-a-end-device-lorawan-mac.h +++ b/model/class-a-end-device-lorawan-mac.h @@ -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 // @@ -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. diff --git a/model/end-device-lora-phy.cc b/model/end-device-lora-phy.cc index fcc8c1d868..41f53bf594 100644 --- a/model/end-device-lora-phy.cc +++ b/model/end-device-lora-phy.cc @@ -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) { } @@ -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 diff --git a/model/end-device-lora-phy.h b/model/end-device-lora-phy.h index c55d460e58..61dfbb9a2a 100644 --- a/model/end-device-lora-phy.h +++ b/model/end-device-lora-phy.h @@ -146,7 +146,7 @@ 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, Ptr event) override = 0; @@ -154,11 +154,11 @@ class EndDeviceLoraPhy : public LoraPhy // Implementation of LoraPhy's pure virtual functions void Send(Ptr 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; @@ -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. @@ -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 diff --git a/model/end-device-lorawan-mac.cc b/model/end-device-lorawan-mac.cc index b5eb1cd8d0..d3cc443428 100644 --- a/model/end-device-lorawan-mac.cc +++ b/model/end-device-lorawan-mac.cc @@ -524,12 +524,12 @@ EndDeviceLorawanMac::GetNextTransmissionDelay() { // Pointer to the current channel Ptr 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); @@ -554,9 +554,9 @@ EndDeviceLorawanMac::GetChannelForTx() { // Pointer to the current channel Ptr 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); @@ -837,7 +837,7 @@ EndDeviceLorawanMac::OnDevStatusReq() void EndDeviceLorawanMac::OnNewChannelReq(uint8_t chIndex, - double frequency, + uint32_t frequencyHz, uint8_t minDataRate, uint8_t maxDataRate) { @@ -849,18 +849,18 @@ EndDeviceLorawanMac::OnNewChannelReq(uint8_t chIndex, // 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); NS_LOG_INFO("Adding NewChannelAns reply"); m_macCommandList.emplace_back(CreateObject(dataRateRangeOk, channelFrequencyOk)); } void -EndDeviceLorawanMac::AddLogicalChannel(double frequency) +EndDeviceLorawanMac::AddLogicalChannel(uint32_t frequencyHz) { - NS_LOG_FUNCTION(this << frequency); + NS_LOG_FUNCTION(this << frequencyHz); - m_channelHelper.AddChannel(frequency); + m_channelHelper.AddChannel(frequencyHz); } void @@ -873,27 +873,27 @@ EndDeviceLorawanMac::AddLogicalChannel(Ptr logicalChannel) 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) << unsigned(maxDataRate)); m_channelHelper.SetChannel( chIndex, - CreateObject(frequency, minDataRate, maxDataRate)); + CreateObject(frequencyHz, minDataRate, maxDataRate)); } void -EndDeviceLorawanMac::AddSubBand(double startFrequency, - double endFrequency, +EndDeviceLorawanMac::AddSubBand(uint32_t startFrequencyHz, + 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); } double diff --git a/model/end-device-lorawan-mac.h b/model/end-device-lorawan-mac.h index 5f588f68d9..d8bdae1529 100644 --- a/model/end-device-lorawan-mac.h +++ b/model/end-device-lorawan-mac.h @@ -283,12 +283,12 @@ class EndDeviceLorawanMac : public LorawanMac * Perform the actions that need to be taken when receiving a NewChannelReq command. * * \param chIndex The ChIndex field of the received NewChannelReq command. - * \param frequency The Frequency field of the received NewChannelReq command. + * \param frequencyHz The Frequency field [Hz] of the received NewChannelReq command. * \param minDataRate The MinDR field of the received NewChannelReq command. * \param maxDataRate The MaxDR field of the received NewChannelReq command. */ void OnNewChannelReq(uint8_t chIndex, - double frequency, + uint32_t frequencyHz, uint8_t minDataRate, uint8_t maxDataRate); @@ -299,20 +299,20 @@ class EndDeviceLorawanMac : public LorawanMac /** * Add a logical channel to the helper. * - * \param frequency The channel's center frequency. + * \param frequencyHz The channel's center frequency [Hz]. */ - void AddLogicalChannel(double frequency); + void AddLogicalChannel(uint32_t frequencyHz); /** * Set a new logical channel in the helper. * * \param chIndex The channel's new index. - * \param frequency The channel's center frequency. + * \param frequencyHz The channel's center frequency [Hz]. * \param minDataRate The minimum data rate allowed on the channel. * \param maxDataRate The maximum data rate allowed on the channel. */ void SetLogicalChannel(uint8_t chIndex, - double frequency, + uint32_t frequencyHz, uint8_t minDataRate, uint8_t maxDataRate); @@ -326,13 +326,13 @@ class EndDeviceLorawanMac : public LorawanMac /** * Add a subband to the logical channel helper. * - * \param startFrequency The SubBand's lowest frequency. - * \param endFrequency The SubBand's highest frequency. + * \param startFrequencyHz The SubBand's lowest frequency [Hz]. + * \param endFrequencyHz The SubBand's highest frequency [Hz]. * \param dutyCycle The SubBand's duty cycle, in fraction form. * \param maxTxPowerDbm The maximum transmission power allowed on the SubBand. */ - void AddSubBand(double startFrequency, - double endFrequency, + void AddSubBand(uint32_t startFrequencyHz, + uint32_t endFrequencyHz, double dutyCycle, double maxTxPowerDbm); diff --git a/model/end-device-status.cc b/model/end-device-status.cc index e0a327e838..8891c24d75 100644 --- a/model/end-device-status.cc +++ b/model/end-device-status.cc @@ -74,12 +74,12 @@ EndDeviceStatus::GetFirstReceiveWindowSpreadingFactor() const return m_firstReceiveWindowSpreadingFactor; } -double +uint32_t EndDeviceStatus::GetFirstReceiveWindowFrequency() const { NS_LOG_FUNCTION_NOARGS(); - return m_firstReceiveWindowFrequency; + return m_firstReceiveWindowFrequencyHz; } uint8_t @@ -90,11 +90,11 @@ EndDeviceStatus::GetSecondReceiveWindowSpreadingFactor() const return m_secondReceiveWindowSpreadingFactor; } -double +uint32_t EndDeviceStatus::GetSecondReceiveWindowFrequency() const { NS_LOG_FUNCTION_NOARGS(); - return m_secondReceiveWindowFrequency; + return m_secondReceiveWindowFrequencyHz; } Ptr @@ -184,10 +184,10 @@ EndDeviceStatus::SetFirstReceiveWindowSpreadingFactor(uint8_t sf) } void -EndDeviceStatus::SetFirstReceiveWindowFrequency(double frequency) +EndDeviceStatus::SetFirstReceiveWindowFrequency(uint32_t frequencyHz) { NS_LOG_FUNCTION_NOARGS(); - m_firstReceiveWindowFrequency = frequency; + m_firstReceiveWindowFrequencyHz = frequencyHz; } void @@ -198,10 +198,10 @@ EndDeviceStatus::SetSecondReceiveWindowSpreadingFactor(uint8_t sf) } void -EndDeviceStatus::SetSecondReceiveWindowFrequency(double frequency) +EndDeviceStatus::SetSecondReceiveWindowFrequency(uint32_t frequencyHz) { NS_LOG_FUNCTION_NOARGS(); - m_secondReceiveWindowFrequency = frequency; + m_secondReceiveWindowFrequencyHz = frequencyHz; } void @@ -254,7 +254,7 @@ EndDeviceStatus::InsertReceivedPacket(Ptr receivedPacket, const Ad // Update Information on the received packet ReceivedPacketInfo info; info.sf = tag.GetSpreadingFactor(); - info.frequency = tag.GetFrequency(); + info.frequencyHz = tag.GetFrequency(); info.packet = receivedPacket; double rcvPower = tag.GetReceivePower(); diff --git a/model/end-device-status.h b/model/end-device-status.h index d7b6f93e02..6250180d53 100644 --- a/model/end-device-status.h +++ b/model/end-device-status.h @@ -48,9 +48,9 @@ namespace lorawan * * (End device address) --- Current device parameters: * - First Receive Window Spreading Factor (SF) and Data Rate (DR) - * - First Receive Window frequency + * - First Receive Window frequency [Hz] * - Second Window Spreading Factor (SF) and Data Rate (DR) - * - Second Receive Window frequency + * - Second Receive Window frequency [Hz] * --- Reply * - Need for reply (true/false) * - Updated reply @@ -62,8 +62,8 @@ namespace lorawan * * (Received packets list) - List of gateways that received the packet (see below) * - Spreading Factor (SF) of the received packet - * - Frequency of the received packet - * - Bandwidth of the received packet + * - Frequency [Hz] of the received packet + * - Bandwidth [Hz] of the received packet * * (Gateway list) - Time at which the packet was received * - Reception power @@ -154,7 +154,7 @@ class EndDeviceStatus : public Object Ptr packet = nullptr; //!< The received packet GatewayList gwList; //!< List of gateways that received this packet uint8_t sf; //!< Spreading factor used to send this packet - double frequency; //!< Carrier frequency [MHz] used to send this packet + uint32_t frequencyHz; //!< Carrier frequency [Hz] used to send this packet }; /** @@ -194,9 +194,9 @@ class EndDeviceStatus : public Object /** * Get the first window frequency of this device. * - * \return The frequency [MHz]. + * \return The frequency [Hz]. */ - double GetFirstReceiveWindowFrequency() const; + uint32_t GetFirstReceiveWindowFrequency() const; /** * Get the spreading factor this device is using in the second @@ -209,9 +209,9 @@ class EndDeviceStatus : public Object /** * Return the second window frequency of this device. * - * \return The frequency [MHz]. + * \return The frequency [Hz]. */ - double GetSecondReceiveWindowFrequency() const; + uint32_t GetSecondReceiveWindowFrequency() const; /** * Get the received packet list. @@ -230,9 +230,9 @@ class EndDeviceStatus : public Object /** * Set the first window frequency of this device. * - * \param frequency The frequency [MHz]. + * \param frequencyHz The frequency [Hz]. */ - void SetFirstReceiveWindowFrequency(double frequency); + void SetFirstReceiveWindowFrequency(uint32_t frequencyHz); /** * Set the spreading factor this device is using in the second receive window. @@ -244,9 +244,9 @@ class EndDeviceStatus : public Object /** * Set the second window frequency of this device. * - * \param frequency The frequency [MHz]. + * \param frequencyHz The frequency [Hz]. */ - void SetSecondReceiveWindowFrequency(double frequency); + void SetSecondReceiveWindowFrequency(uint32_t frequencyHz); /** * Set the reply packet mac header. @@ -357,9 +357,9 @@ class EndDeviceStatus : public Object private: // Receive window data uint8_t m_firstReceiveWindowSpreadingFactor = 0; //!< Spreading Factor (SF) for RX1 window - double m_firstReceiveWindowFrequency = 0; //!< Frequency [MHz] for RX1 window + uint32_t m_firstReceiveWindowFrequencyHz = 0; //!< Frequency [Hz] for RX1 window uint8_t m_secondReceiveWindowSpreadingFactor = 0; //!< Spreading Factor (SF) for RX2 window. - double m_secondReceiveWindowFrequency = 869.525; //!< Frequency [MHz] for RX2 window + uint32_t m_secondReceiveWindowFrequencyHz = 869525000; //!< Frequency [Hz] for RX2 window EventId m_receiveWindowEvent; //!< Event storing the next scheduled downlink transmission ReceivedPacketList m_receivedPacketList; //!< List of received packets diff --git a/model/gateway-lora-phy.cc b/model/gateway-lora-phy.cc index e064b541b8..efe7720779 100644 --- a/model/gateway-lora-phy.cc +++ b/model/gateway-lora-phy.cc @@ -159,24 +159,24 @@ GatewayLoraPhy::IsTransmitting() } void -GatewayLoraPhy::AddFrequency(double frequencyMHz) +GatewayLoraPhy::AddFrequency(uint32_t frequencyHz) { - NS_LOG_FUNCTION(this << frequencyMHz); + NS_LOG_FUNCTION(this << frequencyHz); - m_frequencies.push_back(frequencyMHz); + m_frequenciesHz.push_back(frequencyHz); - NS_ASSERT(m_frequencies.size() <= 8); + NS_ASSERT(m_frequenciesHz.size() <= 8); } bool -GatewayLoraPhy::IsOnFrequency(double frequencyMHz) +GatewayLoraPhy::IsOnFrequency(uint32_t frequencyHz) { - NS_LOG_FUNCTION(this << frequencyMHz); + NS_LOG_FUNCTION(this << frequencyHz); // Look into our list of frequencies - for (auto& f : m_frequencies) + for (auto& f : m_frequenciesHz) { - if (f == frequencyMHz) + if (f == frequencyHz) { return true; } diff --git a/model/gateway-lora-phy.h b/model/gateway-lora-phy.h index 3e47733149..71513f36b2 100644 --- a/model/gateway-lora-phy.h +++ b/model/gateway-lora-phy.h @@ -55,13 +55,13 @@ class GatewayLoraPhy : public LoraPhy double rxPowerDbm, uint8_t sf, Time duration, - double frequencyMHz) override = 0; + uint32_t frequencyHz) override = 0; void EndReceive(Ptr packet, Ptr event) override = 0; void Send(Ptr packet, LoraTxParameters txParams, - double frequencyMHz, + uint32_t frequencyHz, double txPowerDbm) override = 0; bool IsTransmitting() override; @@ -69,10 +69,10 @@ class GatewayLoraPhy : public LoraPhy /** * Check whether the GatewayLoraPhy is currently listening to the specified frequency. * - * \param frequencyMHz The value of the frequency [MHz]. + * \param frequencyHz The value of the frequency [Hz]. * \return True if the frequency is among the one being listened to, false otherwise. */ - bool IsOnFrequency(double frequencyMHz) override; + bool IsOnFrequency(uint32_t frequencyHz) override; /** * Add a reception path, locked on a specific frequency. @@ -89,9 +89,9 @@ class GatewayLoraPhy : public LoraPhy /** * Add a frequency to the list of frequencies we are listening to. * - * \param frequencyMHz The value of the frequency [MHz]. + * \param frequencyHz The value of the frequency [Hz]. */ - void AddFrequency(double frequencyMHz); + void AddFrequency(uint32_t frequencyHz); static const double sensitivity[6]; //!< A vector containing the sensitivities required to //!< correctly decode different spreading factors. @@ -202,7 +202,8 @@ class GatewayLoraPhy : public LoraPhy bool m_isTransmitting; //!< Flag indicating whether a transmission is going on - std::list m_frequencies; //!< List of frequencies the GatewayLoraPhy is listening to. + std::list + m_frequenciesHz; //!< List of frequencies [Hz] the GatewayLoraPhy is listening to. }; } // namespace lorawan diff --git a/model/gateway-lorawan-mac.cc b/model/gateway-lorawan-mac.cc index 9754c5afca..0b4c160357 100644 --- a/model/gateway-lorawan-mac.cc +++ b/model/gateway-lorawan-mac.cc @@ -52,11 +52,11 @@ GatewayLorawanMac::Send(Ptr packet) LoraTag tag; packet->RemovePacketTag(tag); uint8_t dataRate = tag.GetDataRate(); - double frequency = tag.GetFrequency(); + uint32_t frequency = tag.GetFrequency(); NS_LOG_DEBUG("DR: " << unsigned(dataRate)); NS_LOG_DEBUG("SF: " << unsigned(GetSfFromDataRate(dataRate))); NS_LOG_DEBUG("BW: " << GetBandwidthFromDataRate(dataRate)); - NS_LOG_DEBUG("Freq: " << frequency << " MHz"); + NS_LOG_DEBUG("Freq: " << frequency << " Hz"); packet->AddPacketTag(tag); // Make sure we can transmit this packet @@ -139,11 +139,11 @@ GatewayLorawanMac::TxFinished(Ptr packet) } Time -GatewayLorawanMac::GetWaitingTime(double frequency) +GatewayLorawanMac::GetWaitingTime(uint32_t frequencyHz) { NS_LOG_FUNCTION_NOARGS(); - return m_channelHelper.GetWaitingTime(CreateObject(frequency)); + return m_channelHelper.GetWaitingTime(CreateObject(frequencyHz)); } } // namespace lorawan } // namespace ns3 diff --git a/model/gateway-lorawan-mac.h b/model/gateway-lorawan-mac.h index 30fcc29d47..e7f38769a6 100644 --- a/model/gateway-lorawan-mac.h +++ b/model/gateway-lorawan-mac.h @@ -56,10 +56,10 @@ class GatewayLorawanMac : public LorawanMac /** * Return the next time at which we will be able to transmit on the specified frequency. * - * \param frequency The frequency value [MHz]. + * \param frequencyHz The frequency value [Hz]. * \return The next transmission time. */ - Time GetWaitingTime(double frequency); + Time GetWaitingTime(uint32_t frequencyHz); private: protected: diff --git a/model/gateway-status.cc b/model/gateway-status.cc index ebbc69dfae..59f6cdd30c 100644 --- a/model/gateway-status.cc +++ b/model/gateway-status.cc @@ -81,7 +81,7 @@ GatewayStatus::GetGatewayMac() } bool -GatewayStatus::IsAvailableForTransmission(double frequency) +GatewayStatus::IsAvailableForTransmission(uint32_t frequencyHz) { // We can't send multiple packets at once, see SX1301 V2.01 page 29 @@ -100,7 +100,7 @@ GatewayStatus::IsAvailableForTransmission(double frequency) } // Check that the gateway is not constrained by the duty cycle - Time waitingTime = m_gatewayMac->GetWaitingTime(frequency); + Time waitingTime = m_gatewayMac->GetWaitingTime(frequencyHz); if (waitingTime > Seconds(0)) { NS_LOG_INFO("Gateway cannot be used because of duty cycle"); diff --git a/model/gateway-status.h b/model/gateway-status.h index fa79d3decb..163066d37e 100644 --- a/model/gateway-status.h +++ b/model/gateway-status.h @@ -97,10 +97,10 @@ class GatewayStatus : public Object * Query whether or not this gateway is available for immediate transmission * on this frequency. * - * \param frequency The frequency at which the gateway's availability should be queried. + * \param frequencyHz The frequency at which the gateway's availability should be queried. * \return True if the gateway's available, false otherwise. */ - bool IsAvailableForTransmission(double frequency); + bool IsAvailableForTransmission(uint32_t frequencyHz); /** * Set the time of the next scheduled transmission for the gateway. diff --git a/model/logical-lora-channel-helper.cc b/model/logical-lora-channel-helper.cc index a43f87be5e..b7b9647795 100644 --- a/model/logical-lora-channel-helper.cc +++ b/model/logical-lora-channel-helper.cc @@ -85,31 +85,31 @@ LogicalLoraChannelHelper::GetSubBandFromChannel(Ptr channel) } Ptr -LogicalLoraChannelHelper::GetSubBandFromFrequency(double frequency) +LogicalLoraChannelHelper::GetSubBandFromFrequency(uint32_t frequencyHz) { // Get the SubBand this frequency belongs to std::list>::iterator it; for (it = m_subBandList.begin(); it != m_subBandList.end(); it++) { - if ((*it)->BelongsToSubBand(frequency)) + if ((*it)->BelongsToSubBand(frequencyHz)) { return *it; } } - NS_LOG_ERROR("Requested frequency: " << frequency); + NS_LOG_ERROR("Requested frequency: " << frequencyHz); NS_ABORT_MSG("Warning: frequency is outside any known SubBand."); return nullptr; // If no SubBand is found, return 0 } void -LogicalLoraChannelHelper::AddChannel(double frequency) +LogicalLoraChannelHelper::AddChannel(uint32_t frequencyHz) { - NS_LOG_FUNCTION(this << frequency); + NS_LOG_FUNCTION(this << frequencyHz); // Create the new channel and increment the counter - Ptr channel = Create(frequency); + Ptr channel = Create(frequencyHz); // Add it to the list m_channelList.push_back(channel); @@ -136,14 +136,15 @@ LogicalLoraChannelHelper::SetChannel(uint8_t chIndex, Ptr lo } void -LogicalLoraChannelHelper::AddSubBand(double firstFrequency, - double lastFrequency, +LogicalLoraChannelHelper::AddSubBand(uint32_t firstFrequencyHz, + uint32_t lastFrequencyHz, double dutyCycle, double maxTxPowerDbm) { - NS_LOG_FUNCTION(this << firstFrequency << lastFrequency); + NS_LOG_FUNCTION(this << firstFrequencyHz << lastFrequencyHz); - Ptr subBand = Create(firstFrequency, lastFrequency, dutyCycle, maxTxPowerDbm); + Ptr subBand = + Create(firstFrequencyHz, lastFrequencyHz, dutyCycle, maxTxPowerDbm); m_subBandList.push_back(subBand); } diff --git a/model/logical-lora-channel-helper.h b/model/logical-lora-channel-helper.h index 25dfbb5444..3970d5de69 100644 --- a/model/logical-lora-channel-helper.h +++ b/model/logical-lora-channel-helper.h @@ -96,9 +96,9 @@ class LogicalLoraChannelHelper : public Object /** * Add a new channel to the list. * - * \param frequency The frequency of the channel to create. + * \param frequencyHz The frequency of the channel to create. */ - void AddChannel(double frequency); + void AddChannel(uint32_t frequencyHz); /** * Add a new channel to the list. @@ -118,14 +118,14 @@ class LogicalLoraChannelHelper : public Object /** * Add a new SubBand to this helper. * - * \param firstFrequency The first frequency of the subband, in MHz. - * \param lastFrequency The last frequency of the subband, in MHz. + * \param firstFrequencyHz The first frequency [Hz] of the subband, in Hz. + * \param lastFrequencyHz The last frequency [Hz] of the subband, in Hz. * \param dutyCycle The duty cycle that needs to be enforced on this subband. * \param maxTxPowerDbm The maximum transmission power [dBm] that can be used. * on this SubBand. */ - void AddSubBand(double firstFrequency, - double lastFrequency, + void AddSubBand(uint32_t firstFrequencyHz, + uint32_t lastFrequencyHz, double dutyCycle, double maxTxPowerDbm); @@ -163,10 +163,10 @@ class LogicalLoraChannelHelper : public Object /** * Get the SubBand a frequency belongs to. * - * \param frequency The frequency we want to check. + * \param frequencyHz The frequency we want to check. * \return The SubBand the frequency belongs to. */ - Ptr GetSubBandFromFrequency(double frequency); + Ptr GetSubBandFromFrequency(uint32_t frequencyHz); /** * Disable the channel at a specified index. diff --git a/model/logical-lora-channel.cc b/model/logical-lora-channel.cc index f0ee4ada46..2ccbb07b9b 100644 --- a/model/logical-lora-channel.cc +++ b/model/logical-lora-channel.cc @@ -28,7 +28,7 @@ LogicalLoraChannel::GetTypeId() } LogicalLoraChannel::LogicalLoraChannel() - : m_frequency(0), + : m_frequencyHz(0), m_minDataRate(0), m_maxDataRate(5), m_enabledForUplink(true) @@ -41,15 +41,17 @@ LogicalLoraChannel::~LogicalLoraChannel() NS_LOG_FUNCTION(this); } -LogicalLoraChannel::LogicalLoraChannel(double frequency) - : m_frequency(frequency), +LogicalLoraChannel::LogicalLoraChannel(uint32_t frequencyHz) + : m_frequencyHz(frequencyHz), m_enabledForUplink(true) { NS_LOG_FUNCTION(this); } -LogicalLoraChannel::LogicalLoraChannel(double frequency, uint8_t minDataRate, uint8_t maxDataRate) - : m_frequency(frequency), +LogicalLoraChannel::LogicalLoraChannel(uint32_t frequencyHz, + uint8_t minDataRate, + uint8_t maxDataRate) + : m_frequencyHz(frequencyHz), m_minDataRate(minDataRate), m_maxDataRate(maxDataRate), m_enabledForUplink(true) @@ -57,10 +59,10 @@ LogicalLoraChannel::LogicalLoraChannel(double frequency, uint8_t minDataRate, ui NS_LOG_FUNCTION(this); } -double +uint32_t LogicalLoraChannel::GetFrequency() const { - return m_frequency; + return m_frequencyHz; } void @@ -108,8 +110,8 @@ LogicalLoraChannel::IsEnabledForUplink() const bool operator==(const Ptr& first, const Ptr& second) { - double thisFreq = first->GetFrequency(); - double otherFreq = second->GetFrequency(); + uint32_t thisFreq = first->GetFrequency(); + uint32_t otherFreq = second->GetFrequency(); NS_LOG_DEBUG("Checking equality between logical lora channels: " << thisFreq << " " << otherFreq); diff --git a/model/logical-lora-channel.h b/model/logical-lora-channel.h index 6f75e8629d..766c3acac4 100644 --- a/model/logical-lora-channel.h +++ b/model/logical-lora-channel.h @@ -46,27 +46,27 @@ class LogicalLoraChannel : public Object /** * Construct a new LogicalLoraChannel object initializing the carrier frequency. * - * \param frequency The carrier frequency [MHz]. + * \param frequencyHz The carrier Hz [Hz]. */ - LogicalLoraChannel(double frequency); + LogicalLoraChannel(uint32_t frequencyHz); /** * Constructor providing initialization of frequency and data rate limits. * - * \param frequency This channel's frequency [MHz]. + * \param frequencyHz This channel's frequency [Hz]. * \param minDataRate This channel's minimum data rate. * \param maxDataRate This channel's maximum data rate. */ - LogicalLoraChannel(double frequency, uint8_t minDataRate, uint8_t maxDataRate); + LogicalLoraChannel(uint32_t frequencyHz, uint8_t minDataRate, uint8_t maxDataRate); /** - * Get the frequency (MHz). + * Get the frequency (Hz). * * \return The center frequency of this channel. */ - double GetFrequency() const; + uint32_t GetFrequency() const; - // void SetFrequency (double frequencyMHz); + // void SetFrequency (uint32_t frequencyHz); /** * Set the minimum data rate that is allowed on this channel. @@ -114,7 +114,7 @@ class LogicalLoraChannel : public Object bool IsEnabledForUplink() const; private: - double m_frequency; //!< The central frequency of this channel, in MHz. + uint32_t m_frequencyHz; //!< The central frequency of this channel, in Hz. uint8_t m_minDataRate; //!< The minimum data rate that is allowed on this channel. uint8_t m_maxDataRate; //!< The maximum data rate that is allowed on this channel. bool m_enabledForUplink; //!< Whether this channel can be used for uplink or not. diff --git a/model/lora-channel.cc b/model/lora-channel.cc index debb11819b..6e57a5321e 100644 --- a/model/lora-channel.cc +++ b/model/lora-channel.cc @@ -104,9 +104,9 @@ LoraChannel::Send(Ptr sender, double txPowerDbm, LoraTxParameters txParams, Time duration, - double frequencyMHz) const + uint32_t frequencyHz) const { - NS_LOG_FUNCTION(this << sender << packet << txPowerDbm << txParams << duration << frequencyMHz); + NS_LOG_FUNCTION(this << sender << packet << txPowerDbm << txParams << duration << frequencyHz); // Get the mobility model of the sender Ptr senderMobility = sender->GetMobility()->GetObject(); @@ -159,7 +159,7 @@ LoraChannel::Send(Ptr sender, parameters.rxPowerDbm = rxPowerDbm; parameters.sf = txParams.sf; parameters.duration = duration; - parameters.frequencyMHz = frequencyMHz; + parameters.frequencyHz = frequencyHz; // Schedule the receive event NS_LOG_INFO("Scheduling reception of the packet"); @@ -187,7 +187,7 @@ LoraChannel::Receive(uint32_t i, Ptr packet, LoraChannelParameters param parameters.rxPowerDbm, parameters.sf, parameters.duration, - parameters.frequencyMHz); + parameters.frequencyHz); } double @@ -203,7 +203,7 @@ operator<<(std::ostream& os, const LoraChannelParameters& params) { os << "(rxPowerDbm: " << params.rxPowerDbm << ", SF: " << unsigned(params.sf) << ", durationSec: " << params.duration.GetSeconds() - << ", frequencyMHz: " << params.frequencyMHz << ")"; + << ", frequencyHz: " << params.frequencyHz << ")"; return os; } } // namespace lorawan diff --git a/model/lora-channel.h b/model/lora-channel.h index c3dace7315..dde3d7789d 100644 --- a/model/lora-channel.h +++ b/model/lora-channel.h @@ -45,10 +45,10 @@ struct LoraTxParameters; */ struct LoraChannelParameters { - double rxPowerDbm; //!< The reception power. - uint8_t sf; //!< The Spreading Factor of this transmission. - Time duration; //!< The duration of the transmission. - double frequencyMHz; //!< The frequency [MHz] of this transmission. + double rxPowerDbm; //!< The reception power. + uint8_t sf; //!< The Spreading Factor of this transmission. + Time duration; //!< The duration of the transmission. + uint32_t frequencyHz; //!< The frequency [Hz] of this transmission. }; /** @@ -125,7 +125,7 @@ class LoraChannel : public Channel * \param txPowerDbm The power of the transmission. * \param txParams The set of parameters that are used by the transmitter. * \param duration The on-air duration of this packet. - * \param frequencyMHz The frequency this transmission will happen at. + * \param frequencyHz The frequency this transmission will happen at. * * \internal * @@ -137,7 +137,7 @@ class LoraChannel : public Channel double txPowerDbm, LoraTxParameters txParams, Time duration, - double frequencyMHz) const; + uint32_t frequencyHz) const; /** * Compute the received power when transmitting from a point to another one. diff --git a/model/lora-frame-header.cc b/model/lora-frame-header.cc index f6d8c4a3ce..558698a00a 100644 --- a/model/lora-frame-header.cc +++ b/model/lora-frame-header.cc @@ -517,14 +517,14 @@ LoraFrameHeader::AddDutyCycleAns() } void -LoraFrameHeader::AddRxParamSetupReq(uint8_t rx1DrOffset, uint8_t rx2DataRate, double frequency) +LoraFrameHeader::AddRxParamSetupReq(uint8_t rx1DrOffset, uint8_t rx2DataRate, uint32_t frequencyHz) { - NS_LOG_FUNCTION(this << unsigned(rx1DrOffset) << unsigned(rx2DataRate) << frequency); + NS_LOG_FUNCTION(this << unsigned(rx1DrOffset) << unsigned(rx2DataRate) << frequencyHz); // Evaluate whether to eliminate this assert in case new offsets can be defined. NS_ASSERT(0 <= rx1DrOffset && rx1DrOffset <= 5); - Ptr command = Create(rx1DrOffset, rx2DataRate, frequency); + Ptr command = Create(rx1DrOffset, rx2DataRate, frequencyHz); m_macCommands.emplace_back(command); @@ -557,14 +557,14 @@ LoraFrameHeader::AddDevStatusReq() void LoraFrameHeader::AddNewChannelReq(uint8_t chIndex, - double frequency, + uint32_t frequencyHz, uint8_t minDataRate, uint8_t maxDataRate) { NS_LOG_FUNCTION(this); Ptr command = - Create(chIndex, frequency, minDataRate, maxDataRate); + Create(chIndex, frequencyHz, minDataRate, maxDataRate); m_macCommands.emplace_back(command); diff --git a/model/lora-frame-header.h b/model/lora-frame-header.h index 8d32f1de1c..92a4dc383f 100644 --- a/model/lora-frame-header.h +++ b/model/lora-frame-header.h @@ -270,9 +270,9 @@ class LoraFrameHeader : public Header * * \param rx1DrOffset The requested data rate offset for the first receive window. * \param rx2DataRate The requested data rate for the second receive window. - * \param frequency The frequency at which to listen for the second receive window. + * \param frequencyHz The frequency [Hz] at which to listen for the second receive window. */ - void AddRxParamSetupReq(uint8_t rx1DrOffset, uint8_t rx2DataRate, double frequency); + void AddRxParamSetupReq(uint8_t rx1DrOffset, uint8_t rx2DataRate, uint32_t frequencyHz); /** * Add a RxParamSetupAns command. @@ -288,12 +288,12 @@ class LoraFrameHeader : public Header * Add a NewChannelReq command with provided fields. * * \param chIndex The ChIndex field. - * \param frequency The Frequency field. + * \param frequencyHz The Frequency field in Hz. * \param minDataRate The MinDR field. * \param maxDataRate The MaxDR field. */ void AddNewChannelReq(uint8_t chIndex, - double frequency, + uint32_t frequencyHz, uint8_t minDataRate, uint8_t maxDataRate); diff --git a/model/lora-interference-helper.cc b/model/lora-interference-helper.cc index 647ade1b1a..5b486cd1f9 100644 --- a/model/lora-interference-helper.cc +++ b/model/lora-interference-helper.cc @@ -29,13 +29,13 @@ LoraInterferenceHelper::Event::Event(Time duration, double rxPowerdBm, uint8_t spreadingFactor, Ptr packet, - double frequencyMHz) + uint32_t frequencyHz) : m_startTime(Simulator::Now()), m_endTime(m_startTime + duration), m_sf(spreadingFactor), m_rxPowerdBm(rxPowerdBm), m_packet(packet), - m_frequencyMHz(frequencyMHz) + m_frequencyHz(frequencyHz) { // NS_LOG_FUNCTION_NOARGS (); } @@ -83,17 +83,17 @@ LoraInterferenceHelper::Event::GetPacket() const return m_packet; } -double +uint32_t LoraInterferenceHelper::Event::GetFrequency() const { - return m_frequencyMHz; + return m_frequencyHz; } void LoraInterferenceHelper::Event::Print(std::ostream& stream) const { stream << "(" << m_startTime.GetSeconds() << " s - " << m_endTime.GetSeconds() << " s), SF" - << unsigned(m_sf) << ", " << m_rxPowerdBm << " dBm, " << m_frequencyMHz << " MHz"; + << unsigned(m_sf) << ", " << m_rxPowerdBm << " dBm, " << m_frequencyHz << " Hz"; } std::ostream& @@ -185,10 +185,10 @@ LoraInterferenceHelper::Add(Time duration, double rxPower, uint8_t spreadingFactor, Ptr packet, - double frequencyMHz) + uint32_t frequencyHz) { NS_LOG_FUNCTION(this << duration.GetSeconds() << rxPower << unsigned(spreadingFactor) << packet - << frequencyMHz); + << frequencyHz); // Create an event based on the parameters Ptr event = @@ -196,7 +196,7 @@ LoraInterferenceHelper::Add(Time duration, rxPower, spreadingFactor, packet, - frequencyMHz); + frequencyHz); // Add the event to the list m_events.push_back(event); @@ -263,7 +263,7 @@ LoraInterferenceHelper::IsDestroyedByInterference(PtrGetRxPowerdBm(); uint8_t sf = event->GetSpreadingFactor(); - double frequency = event->GetFrequency(); + uint32_t frequency = event->GetFrequency(); // Handy information about the time frame when the packet was received Time now = Simulator::Now(); diff --git a/model/lora-interference-helper.h b/model/lora-interference-helper.h index 6889a9a765..9965d14f19 100644 --- a/model/lora-interference-helper.h +++ b/model/lora-interference-helper.h @@ -53,13 +53,13 @@ class LoraInterferenceHelper * \param rxPowerdBm The power of the signal. * \param spreadingFactor The modulation spreading factor. * \param packet The packet transmitted. - * \param frequencyMHz The carrier frequency of the signal. + * \param frequencyHz The carrier frequency of the signal. */ Event(Time duration, double rxPowerdBm, uint8_t spreadingFactor, Ptr packet, - double frequencyMHz); + uint32_t frequencyHz); ~Event(); //!< Destructor @@ -108,9 +108,9 @@ class LoraInterferenceHelper /** * Get the frequency this event was on. * - * \return The carrier frequency as a double. + * \return The carrier frequency [Hz] as a uint32_t. */ - double GetFrequency() const; + uint32_t GetFrequency() const; /** * Print the current event in a human readable form. @@ -120,12 +120,12 @@ class LoraInterferenceHelper void Print(std::ostream& stream) const; private: - Time m_startTime; //!< The time this signal begins (at the device). - Time m_endTime; //!< The time this signal ends (at the device). - uint8_t m_sf; //!< The spreading factor of this signal. - double m_rxPowerdBm; //!< The power of this event in dBm (at the device). - Ptr m_packet; //!< The packet this event was generated for. - double m_frequencyMHz; //!< The frequency this event was on. + Time m_startTime; //!< The time this signal begins (at the device). + Time m_endTime; //!< The time this signal ends (at the device). + uint8_t m_sf; //!< The spreading factor of this signal. + double m_rxPowerdBm; //!< The power of this event in dBm (at the device). + Ptr m_packet; //!< The packet this event was generated for. + uint32_t m_frequencyHz; //!< The carrier frequency [Hz] this event was on. }; /** @@ -153,7 +153,7 @@ class LoraInterferenceHelper * \param rxPower The received power in dBm. * \param spreadingFactor The spreading factor used by the transmission. * \param packet The packet carried by this transmission. - * \param frequencyMHz The frequency this event was sent at. + * \param frequencyHz The frequency [Hz] this event was sent at. * * \return The newly created event. */ @@ -161,7 +161,7 @@ class LoraInterferenceHelper double rxPower, uint8_t spreadingFactor, Ptr packet, - double frequencyMHz); + uint32_t frequencyHz); /** * Get a list of the interferers currently registered at this InterferenceHelper. diff --git a/model/lora-phy.h b/model/lora-phy.h index 952d89db30..714f8f90ec 100644 --- a/model/lora-phy.h +++ b/model/lora-phy.h @@ -36,12 +36,12 @@ class LoraChannel; */ struct LoraTxParameters { - uint8_t sf = 7; //!< Spreading Factor - bool headerDisabled = false; //!< Whether to use implicit header mode - uint8_t codingRate = 1; //!< Code rate (obtained as 4/(codingRate+4)) - double bandwidthHz = 125000; //!< Bandwidth in Hz - uint32_t nPreamble = 8; //!< Number of preamble symbols - bool crcEnabled = true; //!< Whether Cyclic Redundancy Check (CRC) is enabled + uint8_t sf = 7; //!< Spreading Factor + bool headerDisabled = false; //!< Whether to use implicit header mode + uint8_t codingRate = 1; //!< Code rate (obtained as 4/(codingRate+4)) + uint32_t bandwidthHz = 125000; //!< Bandwidth in Hz + uint32_t nPreamble = 8; //!< Number of preamble symbols + bool crcEnabled = true; //!< Whether Cyclic Redundancy Check (CRC) is enabled bool lowDataRateOptimizationEnabled = false; //!< Whether low data rate optimization is enabled }; @@ -107,13 +107,13 @@ class LoraPhy : public Object * reception). * \param sf The Spreading Factor of the arriving packet. * \param duration The on air time of this packet. - * \param frequencyMHz The frequency this packet is being transmitted on. + * \param frequencyHz The frequency this packet is being transmitted on. */ virtual void StartReceive(Ptr packet, double rxPowerDbm, uint8_t sf, Time duration, - double frequencyMHz) = 0; + uint32_t frequencyHz) = 0; /** * Finish reception of a packet. @@ -134,12 +134,12 @@ class LoraPhy : public Object * * \param packet The packet to send. * \param txParams The desired transmission parameters. - * \param frequencyMHz The frequency on which to transmit. + * \param frequencyHz The frequency on which to transmit. * \param txPowerDbm The power in dBm with which to transmit the packet. */ virtual void Send(Ptr packet, LoraTxParameters txParams, - double frequencyMHz, + uint32_t frequencyHz, double txPowerDbm) = 0; /** @@ -153,11 +153,11 @@ class LoraPhy : public Object /** * Whether this device is listening on the specified frequency or not. * - * \param frequency The frequency to query. + * \param frequencyHz The frequency to query. * \return True if the device is listening on that frequency, false * otherwise. */ - virtual bool IsOnFrequency(double frequency) = 0; + virtual bool IsOnFrequency(uint32_t frequencyHz) = 0; /** * Set the callback to call upon successful reception of a packet. diff --git a/model/lora-tag.cc b/model/lora-tag.cc index b676b7a8aa..5972754577 100644 --- a/model/lora-tag.cc +++ b/model/lora-tag.cc @@ -37,7 +37,7 @@ LoraTag::LoraTag(uint8_t sf, uint8_t destroyedBy) m_destroyedBy(destroyedBy), m_receivePower(0), m_dataRate(0), - m_frequency(0) + m_frequencyHz(0) { } @@ -49,8 +49,8 @@ uint32_t LoraTag::GetSerializedSize() const { // Each datum about a spreading factor is 1 byte + receivePower (the size of a double) + - // frequency (the size of a double) - return 3 + 2 * sizeof(double); + // frequency (4 bytes) + return 3 + sizeof(double) + 4; } void @@ -60,7 +60,7 @@ LoraTag::Serialize(TagBuffer i) const i.WriteU8(m_destroyedBy); i.WriteDouble(m_receivePower); i.WriteU8(m_dataRate); - i.WriteDouble(m_frequency); + i.WriteU32(m_frequencyHz); } void @@ -70,7 +70,7 @@ LoraTag::Deserialize(TagBuffer i) m_destroyedBy = i.ReadU8(); m_receivePower = i.ReadDouble(); m_dataRate = i.ReadU8(); - m_frequency = i.ReadDouble(); + m_frequencyHz = i.ReadU32(); } void @@ -116,15 +116,15 @@ LoraTag::SetReceivePower(double receivePower) } void -LoraTag::SetFrequency(double frequency) +LoraTag::SetFrequency(uint32_t frequencyHz) { - m_frequency = frequency; + m_frequencyHz = frequencyHz; } -double +uint32_t LoraTag::GetFrequency() const { - return m_frequency; + return m_frequencyHz; } uint8_t diff --git a/model/lora-tag.h b/model/lora-tag.h index d46b5d1e0d..5b3cec6d62 100644 --- a/model/lora-tag.h +++ b/model/lora-tag.h @@ -98,9 +98,9 @@ class LoraTag : public Tag * - It is used by the network server to signal to the gateway the frequency of a downlink * packet. * - * \param frequency The frequency value [MHz]. + * \param frequencyHz The frequency value [Hz]. */ - void SetFrequency(double frequency); + void SetFrequency(uint32_t frequencyHz); /** * Get the frequency of the packet. @@ -111,9 +111,9 @@ class LoraTag : public Tag * - It is used by the network server to signal to the gateway the frequency of a downlink * packet. * - * \return The frequency value [MHz]. + * \return The frequency value [Hz]. */ - double GetFrequency() const; + uint32_t GetFrequency() const; /** * Get the data rate for this packet. @@ -130,11 +130,11 @@ class LoraTag : public Tag void SetDataRate(uint8_t dataRate); private: - uint8_t m_sf; //!< The Spreading Factor used by the packet. - uint8_t m_destroyedBy; //!< The Spreading Factor that destroyed the packet. - double m_receivePower; //!< The reception power of this packet. - uint8_t m_dataRate; //!< The data rate that needs to be used to send this packet. - double m_frequency; //!< The frequency of this packet + uint8_t m_sf; //!< The Spreading Factor used by the packet. + uint8_t m_destroyedBy; //!< The Spreading Factor that destroyed the packet. + double m_receivePower; //!< The reception power of this packet. + uint8_t m_dataRate; //!< The data rate that needs to be used to send this packet. + uint32_t m_frequencyHz; //!< The frequency [Hz] of this packet }; } // namespace lorawan } // namespace ns3 diff --git a/model/mac-command.cc b/model/mac-command.cc index 7696dd9a22..584c5eaaba 100644 --- a/model/mac-command.cc +++ b/model/mac-command.cc @@ -548,12 +548,12 @@ RxParamSetupReq::RxParamSetupReq() m_serializedSize = 5; } -RxParamSetupReq::RxParamSetupReq(uint8_t rx1DrOffset, uint8_t rx2DataRate, double frequency) +RxParamSetupReq::RxParamSetupReq(uint8_t rx1DrOffset, uint8_t rx2DataRate, uint32_t frequencyHz) : m_rx1DrOffset(rx1DrOffset), m_rx2DataRate(rx2DataRate), - m_frequency(frequency) + m_frequencyHz(frequencyHz) { - NS_LOG_FUNCTION(this << unsigned(rx1DrOffset) << unsigned(rx2DataRate) << frequency); + NS_LOG_FUNCTION(this << unsigned(rx1DrOffset) << unsigned(rx2DataRate) << frequencyHz); if ((rx1DrOffset & 0b11111000) != 0) { @@ -579,7 +579,7 @@ RxParamSetupReq::Serialize(Buffer::Iterator& start) const start.WriteU8(GetCIDFromMacCommand(m_commandType)); // Data serialization start.WriteU8((m_rx1DrOffset & 0b111) << 4 | (m_rx2DataRate & 0b1111)); - uint32_t encodedFrequency = m_frequency / 100; + uint32_t encodedFrequency = m_frequencyHz / 100; NS_LOG_DEBUG(unsigned(encodedFrequency)); NS_LOG_DEBUG(std::bitset<32>(encodedFrequency)); start.WriteU8((encodedFrequency & 0xff0000) >> 16); // Most significant byte @@ -603,7 +603,7 @@ RxParamSetupReq::Deserialize(Buffer::Iterator& start) uint32_t fourthByte = start.ReadU8(); uint32_t encodedFrequency = (secondByte << 16) | (thirdByte << 8) | fourthByte; NS_LOG_DEBUG(std::bitset<32>(encodedFrequency)); - m_frequency = double(encodedFrequency) * 100; + m_frequencyHz = encodedFrequency * 100; return m_serializedSize; } @@ -616,7 +616,7 @@ RxParamSetupReq::Print(std::ostream& os) const os << "RxParamSetupReq" << std::endl; os << "rx1DrOffset: " << unsigned(m_rx1DrOffset) << std::endl; os << "rx2DataRate: " << unsigned(m_rx2DataRate) << std::endl; - os << "frequency: " << m_frequency << std::endl; + os << "frequency: " << m_frequencyHz << std::endl; } uint8_t @@ -635,12 +635,12 @@ RxParamSetupReq::GetRx2DataRate() return m_rx2DataRate; } -double +uint32_t RxParamSetupReq::GetFrequency() { NS_LOG_FUNCTION(this); - return m_frequency; + return m_frequencyHz; } ///////////////////// @@ -831,11 +831,11 @@ NewChannelReq::NewChannelReq() } NewChannelReq::NewChannelReq(uint8_t chIndex, - double frequency, + uint32_t frequencyHz, uint8_t minDataRate, uint8_t maxDataRate) : m_chIndex(chIndex), - m_frequency(frequency), + m_frequencyHz(frequencyHz), m_minDataRate(minDataRate), m_maxDataRate(maxDataRate) { @@ -854,7 +854,7 @@ NewChannelReq::Serialize(Buffer::Iterator& start) const start.WriteU8(GetCIDFromMacCommand(m_commandType)); start.WriteU8(m_chIndex); - uint32_t encodedFrequency = m_frequency / 100; + uint32_t encodedFrequency = m_frequencyHz / 100; start.WriteU8((encodedFrequency & 0xff0000) >> 16); start.WriteU8((encodedFrequency & 0xff00) >> 8); start.WriteU8(encodedFrequency & 0xff); @@ -873,7 +873,7 @@ NewChannelReq::Deserialize(Buffer::Iterator& start) uint32_t encodedFrequency = 0; encodedFrequency |= uint32_t(start.ReadU16()) << 8; encodedFrequency |= uint32_t(start.ReadU8()); - m_frequency = double(encodedFrequency) * 100; + m_frequencyHz = encodedFrequency * 100; uint8_t dataRateByte = start.ReadU8(); m_maxDataRate = dataRateByte >> 4; m_minDataRate = dataRateByte & 0xf; @@ -897,12 +897,12 @@ NewChannelReq::GetChannelIndex() const return m_chIndex; } -double +uint32_t NewChannelReq::GetFrequency() const { NS_LOG_FUNCTION_NOARGS(); - return m_frequency; + return m_frequencyHz; } uint8_t diff --git a/model/mac-command.h b/model/mac-command.h index 08a7359e5f..7391f6da75 100644 --- a/model/mac-command.h +++ b/model/mac-command.h @@ -363,9 +363,6 @@ class DutyCycleAns : public MacCommand * \ingroup lorawan * * Implementation of the RxParamSetupReq LoRaWAN MAC command. - * - * \todo The use of frequencies in Hz here will cause problems for users, as frequencies are in MHz - * in the rest of the module code. IMO it would be better to have freqs in Hz as uint32_t */ class RxParamSetupReq : public MacCommand { @@ -377,9 +374,9 @@ class RxParamSetupReq : public MacCommand * * \param rx1DrOffset The data rate offset to use for the first receive window. * \param rx2DataRate The data rate to use for the second receive window. - * \param frequency The frequency in Hz to use for the second receive window. + * \param frequencyHz The frequency in Hz to use for the second receive window. */ - RxParamSetupReq(uint8_t rx1DrOffset, uint8_t rx2DataRate, double frequency); + RxParamSetupReq(uint8_t rx1DrOffset, uint8_t rx2DataRate, uint32_t frequencyHz); void Serialize(Buffer::Iterator& start) const override; uint8_t Deserialize(Buffer::Iterator& start) override; @@ -404,12 +401,12 @@ class RxParamSetupReq : public MacCommand * * \return The frequency parameter, in Hz. */ - double GetFrequency(); + uint32_t GetFrequency(); private: - uint8_t m_rx1DrOffset; //!< The RX1DROffset field - uint8_t m_rx2DataRate; //!< The RX2DataRate field - double m_frequency; //!< The Frequency field, _in Hz_ + uint8_t m_rx1DrOffset; //!< The RX1DROffset field + uint8_t m_rx2DataRate; //!< The RX2DataRate field + uint32_t m_frequencyHz; //!< The Frequency field, _in Hz_ }; /** @@ -500,9 +497,6 @@ class DevStatusAns : public MacCommand * \ingroup lorawan * * Implementation of the NewChannelReq LoRaWAN MAC command. - * - * \todo The use of frequencies in Hz here will cause problems for users, as frequencies are in - * MHz in the rest of the module code. IMO it would be better to have freqs in Hz as uint32_t */ class NewChannelReq : public MacCommand { @@ -513,11 +507,11 @@ class NewChannelReq : public MacCommand * Constructor providing initialization of all parameters. * * \param chIndex The index of the channel this command wants to operate on. - * \param frequency The new frequency for this channel in Hz. + * \param frequencyHz The new frequency for this channel in Hz. * \param minDataRate The minimum data rate allowed on this channel. * \param maxDataRate The maximum data rate allowed on this channel. */ - NewChannelReq(uint8_t chIndex, double frequency, uint8_t minDataRate, uint8_t maxDataRate); + NewChannelReq(uint8_t chIndex, uint32_t frequencyHz, uint8_t minDataRate, uint8_t maxDataRate); void Serialize(Buffer::Iterator& start) const override; uint8_t Deserialize(Buffer::Iterator& start) override; @@ -534,7 +528,7 @@ class NewChannelReq : public MacCommand * * \return The Frequency field in Hz. */ - double GetFrequency() const; + uint32_t GetFrequency() const; /** * Get the the MinDR field contained in this MAC command. * @@ -549,10 +543,10 @@ class NewChannelReq : public MacCommand uint8_t GetMaxDataRate() const; private: - uint8_t m_chIndex; //!< The ChIndex field - double m_frequency; //!< The Frequency field, in Hz - uint8_t m_minDataRate; //!< The MinDR field - uint8_t m_maxDataRate; //!< The MaxDR field + uint8_t m_chIndex; //!< The ChIndex field + uint32_t m_frequencyHz; //!< The Frequency field, in Hz + uint8_t m_minDataRate; //!< The MinDR field + uint8_t m_maxDataRate; //!< The MaxDR field }; /** diff --git a/model/network-status.cc b/model/network-status.cc index 74d0fc4236..9147f97b2c 100644 --- a/model/network-status.cc +++ b/model/network-status.cc @@ -117,7 +117,7 @@ NetworkStatus::GetBestGatewayForDevice(LoraDeviceAddress deviceAddress, int wind { // Get the endDeviceStatus we are interested in Ptr edStatus = m_endDeviceStatuses.at(deviceAddress); - double replyFrequency; + uint32_t replyFrequency; if (window == 1) { replyFrequency = edStatus->GetFirstReceiveWindowFrequency(); diff --git a/model/simple-end-device-lora-phy.cc b/model/simple-end-device-lora-phy.cc index 8ed3c11f4d..f5d3d28859 100644 --- a/model/simple-end-device-lora-phy.cc +++ b/model/simple-end-device-lora-phy.cc @@ -48,10 +48,10 @@ SimpleEndDeviceLoraPhy::~SimpleEndDeviceLoraPhy() void SimpleEndDeviceLoraPhy::Send(Ptr packet, LoraTxParameters txParams, - double frequencyMHz, + uint32_t frequencyHz, double txPowerDbm) { - NS_LOG_FUNCTION(this << packet << txParams << frequencyMHz << txPowerDbm); + NS_LOG_FUNCTION(this << packet << txParams << frequencyHz << txPowerDbm); NS_LOG_INFO("Current state: " << m_state); @@ -76,7 +76,7 @@ SimpleEndDeviceLoraPhy::Send(Ptr packet, // Send the packet over the channel NS_LOG_INFO("Sending the packet in the channel"); - m_channel->Send(this, packet, txPowerDbm, txParams, duration, frequencyMHz); + m_channel->Send(this, packet, txPowerDbm, txParams, duration, frequencyHz); // Schedule a call to signal the transmission end. Simulator::Schedule(duration, &SimpleEndDeviceLoraPhy::TxFinished, this, packet); @@ -97,9 +97,9 @@ SimpleEndDeviceLoraPhy::StartReceive(Ptr packet, double rxPowerDbm, uint8_t sf, Time duration, - double frequencyMHz) + uint32_t frequencyHz) { - NS_LOG_FUNCTION(this << packet << rxPowerDbm << unsigned(sf) << duration << frequencyMHz); + NS_LOG_FUNCTION(this << packet << rxPowerDbm << unsigned(sf) << duration << frequencyHz); // Notify the LoraInterferenceHelper of the impinging signal, and remember // the event it creates. This will be used then to correctly handle the end @@ -110,7 +110,7 @@ SimpleEndDeviceLoraPhy::StartReceive(Ptr packet, // still incoming. Ptr event; - event = m_interference.Add(duration, rxPowerDbm, sf, packet, frequencyMHz); + event = m_interference.Add(duration, rxPowerDbm, sf, packet, frequencyHz); // Switch on the current PHY state switch (m_state) @@ -147,11 +147,10 @@ SimpleEndDeviceLoraPhy::StartReceive(Ptr packet, // Check frequency ////////////////// - if (!IsOnFrequency(frequencyMHz)) + if (!IsOnFrequency(frequencyHz)) { NS_LOG_INFO("Packet lost because it's on frequency " - << frequencyMHz << " MHz and we are listening at " << m_frequency - << " MHz"); + << frequencyHz << " Hz and we are listening at " << m_frequencyHz << " Hz"); // Fire the trace source for this event. if (m_device) diff --git a/model/simple-end-device-lora-phy.h b/model/simple-end-device-lora-phy.h index b1118c4cba..bde5f3f090 100644 --- a/model/simple-end-device-lora-phy.h +++ b/model/simple-end-device-lora-phy.h @@ -48,7 +48,7 @@ class SimpleEndDeviceLoraPhy : public EndDeviceLoraPhy double rxPowerDbm, uint8_t sf, Time duration, - double frequencyMHz) override; + uint32_t frequencyHz) override; // Implementation of LoraPhy's pure virtual functions void EndReceive(Ptr packet, Ptr event) override; @@ -56,7 +56,7 @@ class SimpleEndDeviceLoraPhy : public EndDeviceLoraPhy // Implementation of LoraPhy's pure virtual functions void Send(Ptr packet, LoraTxParameters txParams, - double frequencyMHz, + uint32_t frequencyHz, double txPowerDbm) override; private: diff --git a/model/simple-gateway-lora-phy.cc b/model/simple-gateway-lora-phy.cc index 82786a33ca..53b1d23c63 100644 --- a/model/simple-gateway-lora-phy.cc +++ b/model/simple-gateway-lora-phy.cc @@ -50,10 +50,10 @@ SimpleGatewayLoraPhy::~SimpleGatewayLoraPhy() void SimpleGatewayLoraPhy::Send(Ptr packet, LoraTxParameters txParams, - double frequencyMHz, + uint32_t frequencyHz, double txPowerDbm) { - NS_LOG_FUNCTION(this << packet << frequencyMHz << txPowerDbm); + NS_LOG_FUNCTION(this << packet << frequencyHz << txPowerDbm); // Get the time a packet with these parameters will take to be transmitted Time duration = GetOnAirTime(packet, txParams); @@ -90,7 +90,7 @@ SimpleGatewayLoraPhy::Send(Ptr packet, } // Send the packet in the channel - m_channel->Send(this, packet, txPowerDbm, txParams, duration, frequencyMHz); + m_channel->Send(this, packet, txPowerDbm, txParams, duration, frequencyHz); Simulator::Schedule(duration, &SimpleGatewayLoraPhy::TxFinished, this, packet); @@ -112,9 +112,9 @@ SimpleGatewayLoraPhy::StartReceive(Ptr packet, double rxPowerDbm, uint8_t sf, Time duration, - double frequencyMHz) + uint32_t frequencyHz) { - NS_LOG_FUNCTION(this << packet << rxPowerDbm << duration << frequencyMHz); + NS_LOG_FUNCTION(this << packet << rxPowerDbm << duration << frequencyHz); // Fire the trace source m_phyRxBeginTrace(packet); @@ -142,7 +142,7 @@ SimpleGatewayLoraPhy::StartReceive(Ptr packet, // Add the event to the LoraInterferenceHelper Ptr event; - event = m_interference.Add(duration, rxPowerDbm, sf, packet, frequencyMHz); + event = m_interference.Add(duration, rxPowerDbm, sf, packet, frequencyHz); // Cycle over the receive paths to check availability to receive the packet std::list>::iterator it; @@ -199,8 +199,8 @@ SimpleGatewayLoraPhy::StartReceive(Ptr packet, } // If we get to this point, there are no demodulators we can use NS_LOG_INFO("Dropping packet reception of packet with sf = " - << unsigned(sf) << " and frequency " << frequencyMHz - << "MHz because no suitable demodulator was found"); + << unsigned(sf) << " and frequency " << frequencyHz + << "Hz because no suitable demodulator was found"); // Fire the trace source if (m_device) diff --git a/model/simple-gateway-lora-phy.h b/model/simple-gateway-lora-phy.h index 8ead713ed6..ba688e501c 100644 --- a/model/simple-gateway-lora-phy.h +++ b/model/simple-gateway-lora-phy.h @@ -48,13 +48,13 @@ class SimpleGatewayLoraPhy : public GatewayLoraPhy double rxPowerDbm, uint8_t sf, Time duration, - double frequencyMHz) override; + uint32_t frequencyHz) override; void EndReceive(Ptr packet, Ptr event) override; void Send(Ptr packet, LoraTxParameters txParams, - double frequencyMHz, + uint32_t frequencyHz, double txPowerDbm) override; private: diff --git a/model/sub-band.cc b/model/sub-band.cc index 7602c4a6ad..c00980f03f 100644 --- a/model/sub-band.cc +++ b/model/sub-band.cc @@ -31,17 +31,17 @@ SubBand::SubBand() NS_LOG_FUNCTION(this); } -SubBand::SubBand(double firstFrequency, - double lastFrequency, +SubBand::SubBand(uint32_t firstFrequencyHz, + uint32_t lastFrequencyHz, double dutyCycle, double maxTxPowerDbm) - : m_firstFrequency(firstFrequency), - m_lastFrequency(lastFrequency), + : m_firstFrequencyHz(firstFrequencyHz), + m_lastFrequencyHz(lastFrequencyHz), m_dutyCycle(dutyCycle), m_nextTransmissionTime(Seconds(0)), m_maxTxPowerDbm(maxTxPowerDbm) { - NS_LOG_FUNCTION(this << firstFrequency << lastFrequency << dutyCycle << maxTxPowerDbm); + NS_LOG_FUNCTION(this << firstFrequencyHz << lastFrequencyHz << dutyCycle << maxTxPowerDbm); } SubBand::~SubBand() @@ -49,10 +49,10 @@ SubBand::~SubBand() NS_LOG_FUNCTION(this); } -double +uint32_t SubBand::GetFirstFrequency() const { - return m_firstFrequency; + return m_firstFrequencyHz; } double @@ -62,15 +62,15 @@ SubBand::GetDutyCycle() const } bool -SubBand::BelongsToSubBand(double frequency) const +SubBand::BelongsToSubBand(uint32_t frequencyHz) const { - return (frequency > m_firstFrequency) && (frequency < m_lastFrequency); + return (frequencyHz > m_firstFrequencyHz) && (frequencyHz < m_lastFrequencyHz); } bool SubBand::BelongsToSubBand(Ptr logicalChannel) const { - double frequency = logicalChannel->GetFrequency(); + uint32_t frequency = logicalChannel->GetFrequency(); return BelongsToSubBand(frequency); } diff --git a/model/sub-band.h b/model/sub-band.h index 02512101ba..2717d5ec9f 100644 --- a/model/sub-band.h +++ b/model/sub-band.h @@ -42,26 +42,29 @@ class SubBand : public Object /** * Create a new SubBand by specifying all of its properties. * - * \param firstFrequency The SubBand's lowest frequency [MHz]. - * \param lastFrequency The SubBand's highest frequency [MHz]. + * \param firstFrequencyHz The SubBand's lowest frequency [Hz]. + * \param lastFrequencyHz The SubBand's highest frequency [Hz]. * \param dutyCycle The duty cycle (as a fraction) allowed on this SubBand. * \param maxTxPowerDbm The maximum transmission power [dBm] allowed on this SubBand. */ - SubBand(double firstFrequency, double lastFrequency, double dutyCycle, double maxTxPowerDbm); + SubBand(uint32_t firstFrequencyHz, + uint32_t lastFrequencyHz, + double dutyCycle, + double maxTxPowerDbm); /** * Get the lowest frequency of the SubBand. * - * \return The lowest frequency [MHz] of the SubBand. + * \return The lowest frequency [Hz] of the SubBand. */ - double GetFirstFrequency() const; + uint32_t GetFirstFrequency() const; ///** // * Get the last frequency of the subband. // * - // * \return The lowest frequency [MHz] of the SubBand. + // * \return The lowest frequency [Hz] of the SubBand. // */ - // double GetLastFrequency (); + // uint32_t GetLastFrequency (); /** * Get the duty cycle of the subband. @@ -94,18 +97,18 @@ class SubBand : public Object /** * Return whether or not a frequency belongs to this SubBand. * - * \param frequency The frequency [MHz] we want to test against the current subband. - * \return True if the frequency is between firstFrequency and lastFrequency, + * \param frequencyHz The frequency [Hz] we want to test against the current subband. + * \return True if the frequency is between firstFrequencyHz and lastFrequencyHz, * false otherwise. */ - bool BelongsToSubBand(double frequency) const; + bool BelongsToSubBand(uint32_t frequencyHz) const; /** * Return whether or not a channel belongs to this SubBand. * * \param channel The channel we want to test against the current subband. - * \return True if the channel's center frequency is between firstFrequency - * and lastFrequency, false otherwise. + * \return True if the channel's center frequency is between firstFrequencyHz + * and lastFrequencyHz, false otherwise. */ bool BelongsToSubBand(Ptr channel) const; @@ -124,8 +127,8 @@ class SubBand : public Object double GetMaxTxPowerDbm() const; private: - double m_firstFrequency; //!< Starting frequency of the subband, in MHz - double m_lastFrequency; //!< Ending frequency of the subband, in MHz + uint32_t m_firstFrequencyHz; //!< Starting frequency of the subband, in Hz + uint32_t m_lastFrequencyHz; //!< Ending frequency of the subband, in Hz double m_dutyCycle; //!< The duty cycle that needs to be enforced on this subband Time m_nextTransmissionTime; //!< The next time a transmission will be allowed in this subband double m_maxTxPowerDbm; //!< The maximum transmission power that is admitted on this subband diff --git a/test/lorawan-test-suite.cc b/test/lorawan-test-suite.cc index c3e3d1d7e5..f03adef8cb 100644 --- a/test/lorawan-test-suite.cc +++ b/test/lorawan-test-suite.cc @@ -59,8 +59,8 @@ InterferenceTest::DoRun() LoraInterferenceHelper interferenceHelper; - double frequency = 868.1; - double differentFrequency = 868.3; + uint32_t frequency = 868100000; + uint32_t differentFrequency = 868300000; Ptr event; Ptr event1; @@ -895,10 +895,10 @@ LogicalLoraChannelTest::DoRun() ///////////////////////////// // Setup - Ptr channel1 = CreateObject(868); - Ptr channel2 = CreateObject(868); - Ptr channel3 = CreateObject(868.1); - Ptr channel4 = CreateObject(868.001); + Ptr channel1 = CreateObject(868000000); + Ptr channel2 = CreateObject(868000000); + Ptr channel3 = CreateObject(868100000); + Ptr channel4 = CreateObject(868001000); // Equality between channels // Test the == and != operators @@ -911,8 +911,8 @@ LogicalLoraChannelTest::DoRun() ////////////////// // Setup - SubBand subBand(868, 868.7, 0.01, 14); - Ptr channel5 = CreateObject(870); + SubBand subBand(868000000, 868700000, 0.01, 14); + Ptr channel5 = CreateObject(870000000); // Test BelongsToSubBand NS_TEST_EXPECT_MSG_EQ(subBand.BelongsToSubBand(channel3), @@ -931,12 +931,12 @@ LogicalLoraChannelTest::DoRun() // Setup Ptr channelHelper = CreateObject(); - SubBand subBand1(869, 869.4, 0.1, 27); - channel1 = CreateObject(868.1); - channel2 = CreateObject(868.3); - channel3 = CreateObject(868.5); - channel4 = CreateObject(869.1); - channel5 = CreateObject(869.3); + SubBand subBand1(869000000, 869400000, 0.1, 27); + channel1 = CreateObject(868100000); + channel2 = CreateObject(868300000); + channel3 = CreateObject(868500000); + channel4 = CreateObject(869100000); + channel5 = CreateObject(869300000); // Channel diagram // @@ -1259,9 +1259,9 @@ PhyConnectivityTest::Reset() edPhy2 = CreateObject(); edPhy3 = CreateObject(); - edPhy1->SetFrequency(868.1); - edPhy2->SetFrequency(868.1); - edPhy3->SetFrequency(868.1); + edPhy1->SetFrequency(868100000); + edPhy2->SetFrequency(868100000); + edPhy3->SetFrequency(868100000); Ptr mob1 = CreateObject(); Ptr mob2 = CreateObject(); @@ -1293,9 +1293,9 @@ PhyConnectivityTest::Reset() edPhy3->SetSpreadingFactor(12); // Listen on a specific frequency - edPhy1->SetFrequency(868.1); - edPhy2->SetFrequency(868.1); - edPhy3->SetFrequency(868.1); + edPhy1->SetFrequency(868100000); + edPhy2->SetFrequency(868100000); + edPhy3->SetFrequency(868100000); edPhy1->TraceConnectWithoutContext("ReceivedPacket", MakeCallback(&PhyConnectivityTest::ReceivedPacket, this)); @@ -1362,7 +1362,7 @@ PhyConnectivityTest::DoRun() edPhy1, packet, txParams, - 868.1, + 868100000, 14); Simulator::Stop(Hours(2)); @@ -1385,7 +1385,7 @@ PhyConnectivityTest::DoRun() edPhy1, packet, txParams, - 868.1, + 868100000, 14); Simulator::Stop(Hours(2)); @@ -1411,7 +1411,7 @@ PhyConnectivityTest::DoRun() edPhy1, packet, txParams, - 868.1, + 868100000, 14); Simulator::Stop(Hours(2)); @@ -1436,7 +1436,7 @@ PhyConnectivityTest::DoRun() edPhy1, packet, txParams, - 868.1, + 868100000, 14); Simulator::Stop(Hours(2)); @@ -1457,14 +1457,14 @@ PhyConnectivityTest::DoRun() edPhy1, packet, txParams, - 868.1, + 868100000, 14); Simulator::Schedule(Seconds(2), &SimpleEndDeviceLoraPhy::Send, edPhy3, packet, txParams, - 868.1, + 868100000, 14); Simulator::Stop(Hours(2)); @@ -1484,7 +1484,7 @@ PhyConnectivityTest::DoRun() edPhy1, packet, txParams, - 868.3, + 868300000, 14); Simulator::Stop(Hours(2)); @@ -1505,7 +1505,7 @@ PhyConnectivityTest::DoRun() edPhy1, packet, txParams, - 868.1, + 868100000, 14); Simulator::Stop(Hours(2)); @@ -1528,7 +1528,7 @@ PhyConnectivityTest::DoRun() edPhy1, packet, txParams, - 868.1, + 868100000, 14); Simulator::Stop(Hours(2)); @@ -1551,7 +1551,7 @@ PhyConnectivityTest::DoRun() edPhy1, packet, txParams, - 868.1, + 868100000, 14); Simulator::Stop(Hours(2));