15#include "ns3/simulator.h"
29 static TypeId tid =
TypeId(
"ns3::SimpleEndDeviceLoraPhy")
31 .SetGroupName(
"lorawan")
54 NS_LOG_FUNCTION(
this << packet << frequencyHz << iqPolarity << txParams << txPowerDbm);
59 NS_LOG_ERROR(
"Cannot send because device is currently not in SLEEP or STANDBY mode");
70 m_regs.payloadLenBytes = packet->GetSize();
72 m_regs.iqPolarity = iqPolarity;
73 m_regs.frequencyHz = frequencyHz;
74 m_regs.txPowerDbm = txPowerDbm;
78 packet->RemovePacketTag(tag);
80 packet->AddPacketTag(tag);
90 m_channel->Send(
this, packet, frequencyHz, iqPolarity, txParams, txPowerDbm, duration);
100 uint8_t spreadingFactor,
104 NS_LOG_FUNCTION(
this << packet << frequencyHz << iqPolarity <<
unsigned(spreadingFactor)
105 << rxPowerDbm << duration);
114 auto event =
m_interference.Add(duration, rxPowerDbm, spreadingFactor, packet, frequencyHz);
121 NS_LOG_INFO(
"Device already locked onto another transmission");
125 NS_LOG_INFO(
"Dropping packet because device is in " << state <<
" state");
139 if (frequencyHz !=
m_regs.frequencyHz)
141 NS_LOG_INFO(
"Packet ignored because it's on frequency "
142 << frequencyHz <<
" Hz and we are listening to " <<
m_regs.frequencyHz
149 else if (iqPolarity !=
m_regs.iqPolarity)
151 NS_LOG_INFO(
"Packet ignored because it's " << iqPolarity <<
"LINK and we are listening for "
152 <<
m_regs.iqPolarity <<
"LINK transmissions");
158 else if (spreadingFactor !=
m_regs.spreadingFactor)
160 NS_LOG_INFO(
"Packet lost because it's using SF" <<
unsigned(spreadingFactor)
161 <<
", while we are listening for SF"
162 <<
unsigned(
m_regs.spreadingFactor));
170 NS_LOG_INFO(
"Dropping packet reception of packet with SF"
171 <<
unsigned(spreadingFactor) <<
" because under the sensitivity of " << sens
218 packet->RemovePacketTag(tag);
221 packet->AddPacketTag(tag);
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
State GetState()
Return the internal state this end device is currently in.
TracedCallback< Ptr< const Packet >, uint32_t > m_wrongPolarity
Trace source for when a packet is lost because it was transmitted with a different I/Q polarity (upli...
static const double SENSITIVITY[6]
The sensitivity vector of this device to different SFs.
EndDeviceLoraRegisters m_regs
High level model of LoRa chip registers.
void DoStartReceive()
This function should be called by parent classes to signal that the PHY is starting to demodulate a t...
EndDeviceLoraPhy()
Default constructor.
void DoEndReceive()
This function should be called by parent classes to signal that the PHY is finishing to demodulate a ...
TracedCallback< Ptr< const Packet >, uint32_t > m_wrongSf
Trace source for when a packet is lost because it was using a spreading factor different from the one...
void RequestTxMode()
This function puts the PHY in transmission mode.
@ RX_ACTIVE
The PHY layer is actively receiving a transmission after locking onto a preamble.
@ SLEEP
The PHY layer is in low-power sleep state.
@ RX_ENABLED
The PHY layer is listening to the channel for a valid transmission preamble.
@ STANDBY
The PHY layer is in standby mode.
void TxFinished(Ptr< const Packet > packet) override
Internal call when transmission of a packet finishes.
TracedCallback< Ptr< const Packet >, uint32_t > m_wrongFrequency
Trace source for when a packet is lost because it was transmitted on a frequency different from the o...
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet reception ends.
LoraInterferenceHelper m_interference
The LoraInterferenceHelper associated to this PHY.
TracedCallback< Ptr< const Packet >, uint32_t > m_interferedPacket
The trace source fired when a packet cannot be correctly received because of interference.
RxFailedCallback m_rxFailedCallback
The callback to perform upon failed reception of a packet we were locked on.
static Time GetTimeOnAir(uint32_t phyPayloadLen, const LoraTxParameters &txParams)
Compute the total transmission time for a physical packet based on modulation parameters.
TracedCallback< Ptr< const Packet >, uint32_t > m_successfullyReceivedPacket
The trace source fired when a packet was correctly received.
TracedCallback< Ptr< const Packet >, uint32_t > m_startSending
The trace source fired when a packet is sent.
TracedCallback< Ptr< const Packet >, uint32_t > m_underSensitivity
The trace source fired when a packet cannot be received because its power is below the sensitivity th...
Ptr< NetDevice > m_device
The net device this PHY is attached to.
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium.
Ptr< LoraChannel > m_channel
The channel this PHY transmits on.
RxOkCallback m_rxOkCallback
The callback to perform upon correct reception of a packet.
Tag used to save various data about a packet, like its Spreading Factor and data about interference.
void SetFrequency(uint32_t frequencyHz)
Set the frequency of the packet.
void SetSpreadingFactor(uint8_t sf)
Set which Spreading Factor this packet was transmitted with.
void SetReceivePower(double receivePower)
Set the power this packet was received with.
Class representing a simple LoRa transceiver, with an error model based on receiver sensitivity and a...
void StartReceive(Ptr< Packet > packet, uint32_t frequencyHz, IQPolarity iqPolarity, uint8_t spreadingFactor, double rxPowerDbm, Time duration) override
Start receiving a packet.
~SimpleEndDeviceLoraPhy() override
Destructor.
SimpleEndDeviceLoraPhy()
Default constructor.
static TypeId GetTypeId()
Register this type.
void Send(Ptr< Packet > packet, uint32_t frequencyHz, IQPolarity iqPolarity, const LoraTxParameters &txParams, double txPowerDbm) override
Instruct the PHY to send a packet according to some parameters.
void EndReceive(Ptr< Packet > packet, Ptr< LoraInterferenceHelper::Event > event) override
Finish reception of a packet.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
IQPolarity
I/Q Polarity of LoRa transmission symbols.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Structure to collect all parameters that are used to compute the duration of a packet (excluding payl...
CodingRate codingRate
Transmission coding rate.
uint32_t bandwidthHz
Transmission bandwidth in Hz.
bool implicitHeader
Whether to use implicit header mode.
uint8_t spreadingFactor
Symbol Spreading Factor (SF).
bool crcEnabled
Whether Cyclic Redundancy Check (CRC) is enabled.
bool lowDataRateOptimize
Low Data Rate Optimization (mandated for SF11 and SF12).
uint16_t preambleLenSymb
Number of symbols in the packet preamble.