14#include "ns3/simulator.h"
30 static TypeId tid =
TypeId(
"ns3::SimpleEndDeviceLoraPhy")
32 .SetGroupName(
"lorawan")
54 NS_LOG_FUNCTION(
this << packet << txParams << frequencyHz << txPowerDbm);
61 NS_LOG_INFO(
"Cannot send because device is currently not in STANDBY or SLEEP mode");
73 packet->RemovePacketTag(tag);
75 packet->AddPacketTag(tag);
79 m_channel->Send(
this, packet, txPowerDbm, txParams, duration, frequencyHz);
102 NS_LOG_FUNCTION(
this << packet << rxPowerDbm <<
unsigned(sf) << duration << frequencyHz);
122 NS_LOG_INFO(
"Dropping packet because device is in SLEEP state");
126 NS_LOG_INFO(
"Dropping packet because device is in TX state");
130 NS_LOG_INFO(
"Dropping packet because device is already in RX state");
143 bool canLockOnPacket =
true;
152 NS_LOG_INFO(
"Packet lost because it's on frequency "
153 << frequencyHz <<
" Hz and we are listening at " <<
m_frequencyHz <<
" Hz");
165 canLockOnPacket =
false;
173 <<
unsigned(sf) <<
", while we are listening for SF" <<
unsigned(
m_sf));
185 canLockOnPacket =
false;
192 NS_LOG_INFO(
"Dropping packet reception of packet with sf = "
193 <<
unsigned(sf) <<
" because under the sensitivity of " <<
sensitivity
206 canLockOnPacket =
false;
282 packet->RemovePacketTag(tag);
285 packet->AddPacketTag(tag);
bool IsNull() const
Check for null implementation.
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.
Class representing a LoRa transceiver.
static const double sensitivity[6]
The sensitivity vector of this device to different SFs.
uint8_t m_sf
The Spreading Factor this device is listening for.
bool IsOnFrequency(uint32_t frequencyHz) override
Whether this device is listening on the specified frequency or not.
void SwitchToRx()
Switch to the RX state.
void SwitchToStandby()
Switch to the STANDBY state.
uint32_t m_frequencyHz
The frequency [Hz] this device is listening on.
TracedValue< State > m_state
The state this PHY is currently in.
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 SwitchToTx(double txPowerDbm)
Switch to the TX state.
@ RX
The PHY layer is receiving a packet.
@ TX
The PHY layer is sending a packet.
@ SLEEP
The PHY layer is sleeping.
@ STANDBY
The PHY layer is in STANDBY.
void TxFinished(Ptr< const Packet > packet) override
Signals the end of a transmission by the EndDeviceLoraPhy.
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...
Ptr< LoraInterferenceHelper::Event > Add(Time duration, double rxPower, uint8_t spreadingFactor, Ptr< Packet > packet, uint32_t frequencyHz)
Add an event to the InterferenceHelper.
uint8_t IsDestroyedByInterference(Ptr< LoraInterferenceHelper::Event > event)
Determine whether the event was destroyed by interference or not.
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet reception ends.
LoraInterferenceHelper m_interference
The LoraInterferenceHelper associated to this PHY.
static Time GetOnAirTime(Ptr< Packet > packet, LoraTxParameters txParams)
Compute the time that a packet with certain characteristics will take to be transmitted.
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.
virtual void EndReceive(Ptr< Packet > packet, Ptr< LoraInterferenceHelper::Event > event)=0
Finish reception of a packet.
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 Send(Ptr< Packet > packet, LoraTxParameters txParams, uint32_t frequencyHz, double txPowerDbm) override
Instruct the PHY to send a packet according to some parameters.
~SimpleEndDeviceLoraPhy() override
Destructor.
SimpleEndDeviceLoraPhy()
Default constructor.
static TypeId GetTypeId()
Register this type.
void StartReceive(Ptr< Packet > packet, double rxPowerDbm, uint8_t sf, Time duration, uint32_t frequencyHz) override
Start receiving a packet.
void EndReceive(Ptr< Packet > packet, Ptr< LoraInterferenceHelper::Event > event) override
Finish reception of a packet.
#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.
#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...
uint8_t sf
Spreading Factor.