Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/aloha-throughput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ main(int argc, char* argv[])
LoraTxParameters txParams;
txParams.sf = sf;
txParams.headerDisabled = false;
txParams.codingRate = 1;
txParams.codingRate = LoraTxParameters::CODING_RATE_4_5;
txParams.bandwidthHz = 125000;
txParams.nPreamble = 8;
txParams.crcEnabled = true;
Expand Down
5 changes: 4 additions & 1 deletion model/end-device-lora-phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ class EndDeviceLoraPhy : public LoraPhy
double rxPowerDbm,
uint8_t sf,
Time duration,
uint32_t frequencyHz) override = 0;
uint32_t frequencyHz,
uint8_t syncWord) override = 0;

// Implementation of LoraPhy's pure virtual functions
void EndReceive(Ptr<Packet> packet, Ptr<LoraInterferenceHelper::Event> event) override = 0;
Expand Down Expand Up @@ -267,6 +268,8 @@ class EndDeviceLoraPhy : public LoraPhy

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

uint8_t m_syncWord; //!< The sync word this device is using

/**
* typedef for a list of EndDeviceLoraPhyListener.
*/
Expand Down
2 changes: 1 addition & 1 deletion model/end-device-lorawan-mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ EndDeviceLorawanMac::EndDeviceLorawanMac()
m_nbTrans(1),
m_dataRate(0),
m_txPowerDbm(14),
m_codingRate(1),
m_codingRate(LoraTxParameters::CODING_RATE_4_5),
// LoraWAN default
m_headerDisabled(false),
// LoraWAN default
Expand Down
4 changes: 2 additions & 2 deletions model/end-device-lorawan-mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ class EndDeviceLorawanMac : public LorawanMac
uint8_t m_nbTrans; //!< Default number of unacknowledged redundant transmissions of each packet.
TracedValue<uint8_t> m_dataRate; //!< The data rate this device is using to transmit.
TracedValue<double>
m_txPowerDbm; //!< The transmission ERP [dBm] this device is currently using.
uint8_t m_codingRate; //!< The coding rate used by this device.
m_txPowerDbm; //!< The transmission ERP [dBm] this device is currently using.
LoraTxParameters::CodingRate m_codingRate; //!< The coding rate used by this device.
bool m_headerDisabled; //!< Whether or not the LoRa PHY header is disabled for communications by
//!< this device.
LoraDeviceAddress m_address; //!< The address of this device.
Expand Down
3 changes: 2 additions & 1 deletion model/gateway-lora-phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class GatewayLoraPhy : public LoraPhy
double rxPowerDbm,
uint8_t sf,
Time duration,
uint32_t frequencyHz) override = 0;
uint32_t frequencyHz,
uint8_t syncWord) override = 0;

void EndReceive(Ptr<Packet> packet, Ptr<LoraInterferenceHelper::Event> event) override = 0;

Expand Down
2 changes: 1 addition & 1 deletion model/gateway-lorawan-mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ GatewayLorawanMac::Send(Ptr<Packet> packet)
LoraTxParameters params;
params.sf = GetSfFromDataRate(dataRate);
params.headerDisabled = false;
params.codingRate = 1;
params.codingRate = LoraTxParameters::CODING_RATE_4_5;
params.bandwidthHz = GetBandwidthFromDataRate(dataRate);
params.nPreamble = 8;
params.crcEnabled = true;
Expand Down
9 changes: 6 additions & 3 deletions model/lora-channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ LoraChannel::Send(Ptr<LoraPhy> sender,
double txPowerDbm,
LoraTxParameters txParams,
Time duration,
uint32_t frequencyHz) const
uint32_t frequencyHz,
uint8_t syncWord) const
{
NS_LOG_FUNCTION(this << sender << packet << txPowerDbm << txParams << duration << frequencyHz);

Expand Down Expand Up @@ -160,6 +161,7 @@ LoraChannel::Send(Ptr<LoraPhy> sender,
parameters.sf = txParams.sf;
parameters.duration = duration;
parameters.frequencyHz = frequencyHz;
parameters.syncWord = syncWord;

// Schedule the receive event
NS_LOG_INFO("Scheduling reception of the packet");
Expand Down Expand Up @@ -187,7 +189,8 @@ LoraChannel::Receive(uint32_t i, Ptr<Packet> packet, LoraChannelParameters param
parameters.rxPowerDbm,
parameters.sf,
parameters.duration,
parameters.frequencyHz);
parameters.frequencyHz,
parameters.syncWord);
}

double
Expand All @@ -203,7 +206,7 @@ operator<<(std::ostream& os, const LoraChannelParameters& params)
{
os << "(rxPowerDbm: " << params.rxPowerDbm << ", SF: " << unsigned(params.sf)
<< ", duration: " << params.duration.As(Time::MS) << ", frequencyHz: " << params.frequencyHz
<< ")";
<< ", syncWord: " << params.syncWord << ")";
return os;
}
} // namespace lorawan
Expand Down
13 changes: 8 additions & 5 deletions model/lora-channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ 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.
uint32_t frequencyHz; //!< The frequency [Hz] 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.
uint8_t syncWord = 0x34; //!< The sync word of this transmission.
};

/**
Expand Down Expand Up @@ -126,6 +127,7 @@ class LoraChannel : public Channel
* @param txParams The set of parameters that are used by the transmitter.
* @param duration The on-air duration of this packet.
* @param frequencyHz The frequency this transmission will happen at.
* @param syncWord The sync word of the packet
*
* @internal
*
Expand All @@ -137,7 +139,8 @@ class LoraChannel : public Channel
double txPowerDbm,
LoraTxParameters txParams,
Time duration,
uint32_t frequencyHz) const;
uint32_t frequencyHz,
uint8_t syncWord) const;

/**
* Compute the received power when transmitting from a point to another one.
Expand Down
20 changes: 20 additions & 0 deletions model/lora-phy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,19 @@ LoraPhy::GetTypeId()
"could not be correctly received because"
"its received power is below the sensitivity of the receiver",
MakeTraceSourceAccessor(&LoraPhy::m_underSensitivity),
"ns3::Packet::TracedCallback")
.AddTraceSource("LostPacketBecauseSyncWordMismatch",
"Trace source indicating a packet "
"could not be synced to because a mismatch "
"in the sync word configured in the PHY and used "
"in the packet",
MakeTraceSourceAccessor(&LoraPhy::m_wrongSyncWord),
"ns3::Packet::TracedCallback");
return tid;
}

LoraPhy::LoraPhy()
: m_syncWord(0x34)
{
}

Expand All @@ -87,6 +95,18 @@ LoraPhy::SetDevice(Ptr<NetDevice> device)
m_device = device;
}

uint8_t
LoraPhy::GetSyncWord() const
{
return m_syncWord;
}

void
LoraPhy::SetSyncWord(uint8_t syncWord)
{
m_syncWord = syncWord;
}

Ptr<LoraChannel>
LoraPhy::GetChannel() const
{
Expand Down
54 changes: 47 additions & 7 deletions model/lora-phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,23 @@ 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))
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
/**
* Enumeration of the LoRa coding rates supported
*/
enum CodingRate
{
CODING_RATE_4_5 = 1, //!< Coding rate 4/5
CODING_RATE_4_6 = 2, //!< Coding rate 4/6
CODING_RATE_4_7 = 3, //!< Coding rate 4/7
CODING_RATE_4_8 = 4, //!< Coding rate 4/8
};

uint8_t sf = 7; //!< Spreading Factor
bool headerDisabled = false; //!< Whether to use implicit header mode
CodingRate codingRate = CODING_RATE_4_5; //!< 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
};

Expand Down Expand Up @@ -108,12 +119,14 @@ class LoraPhy : public Object
* @param sf The Spreading Factor of the arriving packet.
* @param duration The on air time of this packet.
* @param frequencyHz The frequency this packet is being transmitted on.
* @param syncWord The sync word this packet was transmitted with
*/
virtual void StartReceive(Ptr<Packet> packet,
double rxPowerDbm,
uint8_t sf,
Time duration,
uint32_t frequencyHz) = 0;
uint32_t frequencyHz,
uint8_t syncWord) = 0;

/**
* Finish reception of a packet.
Expand Down Expand Up @@ -234,6 +247,20 @@ class LoraPhy : public Object
*/
void SetDevice(Ptr<NetDevice> device);

/**
* Get the sync word this PHY is configured to use.
*
* @return The configured sync word
*/
uint8_t GetSyncWord() const;

/**
* Configure the PHY to use the given sync word.
*
* @param syncWord The sync word to use.
*/
void SetSyncWord(uint8_t syncWord);

/**
* Compute the symbol time from spreading factor and bandwidth.
*
Expand Down Expand Up @@ -268,6 +295,13 @@ class LoraPhy : public Object

Ptr<MobilityModel> m_mobility; //!< The mobility model associated to this PHY.

/**
* The sync word is used in the preamble. All outgoing packets will use
* this sync word and the PHY will not sync with incoming packets with
* a different sync word.
*/
uint8_t m_syncWord;

protected:
// Member objects

Expand Down Expand Up @@ -312,6 +346,12 @@ class LoraPhy : public Object
*/
TracedCallback<Ptr<const Packet>, uint32_t> m_interferedPacket;

/**
* The trace source fired when a packet cannot be correctly received because
* received packet uses a different sync word than the PHY is configured.
*/
TracedCallback<Ptr<const Packet>, uint32_t> m_wrongSyncWord;

// Callbacks

/**
Expand Down
27 changes: 22 additions & 5 deletions model/lora-tag.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace lorawan

NS_OBJECT_ENSURE_REGISTERED(LoraTag);

const uint8_t LoraTag::SYNC_WORD_LORAWAN = 0x34;

TypeId
LoraTag::GetTypeId()
{
Expand All @@ -34,10 +36,10 @@ LoraTag::GetInstanceTypeId() const

LoraTag::LoraTag(uint8_t sf, uint8_t destroyedBy)
: m_sf(sf),
m_sync(SYNC_WORD_LORAWAN),
m_destroyedBy(destroyedBy),
m_receivePower(0),
m_dataRate(0),
m_frequencyHz(0)
m_dataRate(0)
{
}

Expand All @@ -48,15 +50,17 @@ LoraTag::~LoraTag()
uint32_t
LoraTag::GetSerializedSize() const
{
// Each datum about a spreading factor is 1 byte + receivePower (the size of a double) +
// frequency (4 bytes)
return 3 + sizeof(double) + 4;
// 4 * uint8_t: (m_sf, m_sync, m_destroyedBy, m_dataRate)
// 1 * uint32_t: (m_frequencyHz)
// 1 * double: (m_receivePower)
return 4 * sizeof(uint8_t) + 1 * sizeof(uint32_t) + 1 * sizeof(double);
}

void
LoraTag::Serialize(TagBuffer i) const
{
i.WriteU8(m_sf);
i.WriteU8(m_sync);
i.WriteU8(m_destroyedBy);
i.WriteDouble(m_receivePower);
i.WriteU8(m_dataRate);
Expand All @@ -67,6 +71,7 @@ void
LoraTag::Deserialize(TagBuffer i)
{
m_sf = i.ReadU8();
m_sync = i.ReadU8();
m_destroyedBy = i.ReadU8();
m_receivePower = i.ReadDouble();
m_dataRate = i.ReadU8();
Expand Down Expand Up @@ -127,6 +132,18 @@ LoraTag::GetFrequency() const
return m_frequencyHz;
}

void
LoraTag::SetSyncWord(uint8_t syncWord)
{
m_sync = syncWord;
}

uint8_t
LoraTag::GetSyncWord() const
{
return m_sync;
}

uint8_t
LoraTag::GetDataRate() const
{
Expand Down
17 changes: 17 additions & 0 deletions model/lora-tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace lorawan
class LoraTag : public Tag
{
public:
static const uint8_t SYNC_WORD_LORAWAN; //!< The sync word used in public LoRaWAN

/**
* Register this type.
* @return The object TypeId.
Expand Down Expand Up @@ -129,8 +131,23 @@ class LoraTag : public Tag
*/
void SetDataRate(uint8_t dataRate);

/**
* Set the sync word of this packet.
*
* @param syncWord The sync word to set
*/
void SetSyncWord(uint8_t syncWord);

/**
* Get the sync word of this packet.
*
* @return The sync word of this packet
*/
uint8_t GetSyncWord() const;

private:
uint8_t m_sf; //!< The Spreading Factor used by the packet.
uint8_t m_sync; //!< The sync word of this 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.
Expand Down
Loading