11#include "ns3/simulator.h"
26 TypeId(
"ns3::EndDeviceLoraPhy")
28 .SetGroupName(
"lorawan")
29 .AddTraceSource(
"LostPacketBecauseWrongFrequency",
30 "Trace source indicating a packet "
31 "could not be correctly decoded because"
32 "the end device was listening on a different frequency",
34 "ns3::Packet::TracedCallback")
35 .AddTraceSource(
"LostPacketBecauseWrongPolarity",
36 "Trace source indicating a packet "
37 "could not be correctly decoded because"
38 "the end device was expecting a different I/Q polarity",
40 "ns3::Packet::TracedCallback")
41 .AddTraceSource(
"LostPacketBecauseWrongSpreadingFactor",
42 "Trace source indicating a packet "
43 "could not be correctly decoded because"
44 "the end device was listening for a different Spreading Factor",
46 "ns3::Packet::TracedCallback")
47 .AddTraceSource(
"EndDeviceState",
48 "The current state of the device",
50 "ns3::TracedValueCallback::EndDeviceLoraPhy::State");
58 .bandwidthHz = 125000,
60 .lowDataRateOptimize = false,
63 .implicitHeader = false,
66 .frequencyHz = 915'000'000,
69 .symbNumTimeout = 100,
97 return m_regs.frequencyHz == frequencyHz;
118 uint8_t spreadingFactor,
120 uint8_t symbNumTimeout,
125 m_regs.frequencyHz = frequencyHz;
126 m_regs.bandwidthHz = bandwidthHz;
127 m_regs.iqPolarity = iqPolarity;
128 m_regs.spreadingFactor = spreadingFactor;
129 m_regs.symbNumTimeout = symbNumTimeout;
145 m_listeners.remove_if([&listener](
auto&& weakPtr) {
return weakPtr.lock() == listener; });
215 "Improper switch to STANDBY from m_state=" <<
m_state);
247 "Improper switch to STANDBY from m_state=" <<
m_state);
257 "Cannot switch to TX from m_state=" <<
m_state);
267 "Cannot switch to RX_ENABLED from m_state=" <<
m_state);
277 "Cannot switch to RX_ACTIVE from m_state=" <<
m_state);
290 return (os <<
"SLEEP");
292 return (os <<
"STANDBY");
296 return (os <<
"RX_ENABLED");
298 return (os <<
"RX_ACTIVE");
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.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Class representing a LoRa transceiver hardware state-machine of a SX1272 LoRa chip (see SX1272/73 Dat...
void SwitchToSleep()
Switch to the SLEEP state.
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...
void SwitchToTx()
Switch to the TX state.
bool IsOnFrequency(uint32_t frequencyHz) const override
Whether this device is listening on the specified frequency or not.
void SwitchToStandBy()
Switch to the STANDBY state.
void SwitchToRxActive()
Update the RX state to RX_ACTIVE on preamble lock.
void RequestRxSingleMode()
This function reads RX parameters from the internal registers of the PHY hardware and begins a recept...
void ReceiveSingle(uint32_t frequencyHz, IQPolarity iqPolarity, uint8_t spreadingFactor, uint32_t bandwidthHz, uint8_t symbNumTimeout, RxTimeoutCallback rxTimeoutCallback)
This function starts a reception attempt that will time-out if no transmission preamble is detected.
EventId m_rxTimeoutEvent
Event for timed switch from RX_ENABLED to STANDBY.
void SwitchToRxEnabled()
Switch to the RX_ENABLED state.
static const double SENSITIVITY[6]
The sensitivity vector of this device to different SFs.
void NotifyListeners(FUNC f, Ts &&... args)
Notify all EndDeviceLoraPhyListener objects of the given PHY event.
Listeners m_listeners
PHY state listeners.
static TypeId GetTypeId()
Register this type.
EndDeviceLoraRegisters m_regs
High level model of LoRa chip registers.
bool IsTransmitting() const override
Whether this device is transmitting or not.
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 ...
Callback< void > RxTimeoutCallback
Type definition for a callback for when a packet reception hardware timeout expires.
~EndDeviceLoraPhy() override
Destructor.
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 RequestTxMode()
This function puts the PHY in transmission mode.
void RequestSleepMode()
Request a switch to SLEEP mode.
State
An enumeration of the possible internal states of an EndDeviceLoraPhy.
@ TX
The PHY layer is transmitting a packet.
@ 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 RegisterListener(const std::shared_ptr< EndDeviceLoraPhyListener > &listener)
Add the input listener to the list of objects to be notified of PHY-level events.
void TxFinished(Ptr< const Packet > packet) override
Internal call when transmission of a packet finishes.
RxTimeoutCallback m_rxTimeoutCallback
The callback to perform upon reception timeout.
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...
void RxTimeout()
Callback for scheduling the end of an unsuccessful timed reception attempt.
void UnregisterListener(const std::shared_ptr< EndDeviceLoraPhyListener > &listener)
Remove the input listener from the list of objects to be notified of PHY-level events.
void Sleep()
Set this PHY LoRa chip to sleep from standby after a transmission / reception.
virtual void NotifyTx(double txPowerDbm)=0
Notify listeners that the device entered TX state.
virtual void NotifyRxEnabled()=0
Notify listeners that the device entered RX_ENABLED state.
virtual void NotifyRxActive()=0
Notify listeners that the device entered RX_ACTIVE state.
virtual void NotifyStandby()=0
Notify listeners that the device entered STANDBY state.
virtual void NotifySleep()=0
Notify listeners that the device entered SLEEP state.
TxFinishedCallback m_txFinishedCallback
The callback to perform upon the end of a transmission.
static Time GetTSym(uint8_t spreadingFactor, uint32_t bandwidthHz)
Compute the symbol time from spreading factor and bandwidth.
LoraPhy()
Default constructor.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#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 ",...
CodingRate
Enumeration of the LoRa supported coding rates.
IQPolarity
I/Q Polarity of LoRa transmission symbols.
@ UP
Uplink / Upchirp / Normal polarity.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
std::ostream & operator<<(std::ostream &os, const EndDeviceLoraPhy::State &state)
Overloaded operator to print the value of a EndDeviceLoraPhy::State.
Every class exported by the ns3 library is enclosed in the ns3 namespace.