A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lora-tag.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 University of Padova
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Davide Magrin <magrinda@dei.unipd.it>
7 */
8
9#include "lora-tag.h"
10
11#include "ns3/tag.h"
12#include "ns3/uinteger.h"
13
14namespace ns3
15{
16namespace lorawan
17{
18
20
21TypeId
23{
24 static TypeId tid =
25 TypeId("ns3::LoraTag").SetParent<Tag>().SetGroupName("lorawan").AddConstructor<LoraTag>();
26 return tid;
27}
28
31{
32 return GetTypeId();
33}
34
35LoraTag::LoraTag(uint8_t sf, uint8_t destroyedBy)
36 : m_sf(sf),
37 m_destroyedBy(destroyedBy),
39 m_dataRate(0),
41{
42}
43
47
50{
51 // Each datum about a spreading factor is 1 byte + receivePower (the size of a double) +
52 // frequency (4 bytes)
53 return 3 + sizeof(double) + 4;
54}
55
56void
65
66void
75
76void
77LoraTag::Print(std::ostream& os) const
78{
79 os << m_sf << " " << m_destroyedBy << " " << m_receivePower << " " << m_dataRate;
80}
81
82uint8_t
84{
85 return m_sf;
86}
87
88uint8_t
90{
91 return m_destroyedBy;
92}
93
94double
96{
97 return m_receivePower;
98}
99
100void
102{
103 m_destroyedBy = sf;
104}
105
106void
108{
109 m_sf = sf;
110}
111
112void
113LoraTag::SetReceivePower(double receivePower)
114{
115 m_receivePower = receivePower;
116}
117
118void
120{
121 m_frequencyHz = frequencyHz;
122}
123
126{
127 return m_frequencyHz;
128}
129
130uint8_t
132{
133 return m_dataRate;
134}
135
136void
137LoraTag::SetDataRate(uint8_t dataRate)
138{
139 m_dataRate = dataRate;
140}
141
142} // namespace lorawan
143} // namespace ns3
read and write tag data
Definition tag-buffer.h:41
TAG_BUFFER_INLINE uint32_t ReadU32()
Definition tag-buffer.h:206
void WriteDouble(double v)
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition tag-buffer.h:161
TAG_BUFFER_INLINE uint8_t ReadU8()
Definition tag-buffer.h:185
TAG_BUFFER_INLINE void WriteU32(uint32_t v)
Definition tag-buffer.h:176
double ReadDouble()
tag a set of bytes in a packet
Definition tag.h:28
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Tag used to save various data about a packet, like its Spreading Factor and data about interference.
Definition lora-tag.h:26
static TypeId GetTypeId()
Register this type.
Definition lora-tag.cc:22
uint32_t m_frequencyHz
The frequency [Hz] of this packet.
Definition lora-tag.h:137
uint8_t GetDestroyedBy() const
Read which Spreading Factor this packet was destroyed by.
Definition lora-tag.cc:89
void SetFrequency(uint32_t frequencyHz)
Set the frequency of the packet.
Definition lora-tag.cc:119
uint8_t m_dataRate
The data rate that needs to be used to send this packet.
Definition lora-tag.h:136
void SetDataRate(uint8_t dataRate)
Set the data rate for this packet.
Definition lora-tag.cc:137
void Deserialize(TagBuffer i) override
Definition lora-tag.cc:67
~LoraTag() override
Destructor.
Definition lora-tag.cc:44
void SetSpreadingFactor(uint8_t sf)
Set which Spreading Factor this packet was transmitted with.
Definition lora-tag.cc:107
uint8_t GetDataRate() const
Get the data rate for this packet.
Definition lora-tag.cc:131
void Serialize(TagBuffer i) const override
Definition lora-tag.cc:57
double GetReceivePower() const
Read the power this packet arrived with.
Definition lora-tag.cc:95
uint32_t GetSerializedSize() const override
Definition lora-tag.cc:49
uint32_t GetFrequency() const
Get the frequency of the packet.
Definition lora-tag.cc:125
uint8_t m_destroyedBy
The Spreading Factor that destroyed the packet.
Definition lora-tag.h:134
uint8_t m_sf
The Spreading Factor used by the packet.
Definition lora-tag.h:133
uint8_t GetSpreadingFactor() const
Read which Spreading Factor this packet was transmitted with.
Definition lora-tag.cc:83
LoraTag(uint8_t sf=0, uint8_t destroyedBy=0)
Create a LoraTag with a given spreading factor and collision.
Definition lora-tag.cc:35
void Print(std::ostream &os) const override
Definition lora-tag.cc:77
void SetReceivePower(double receivePower)
Set the power this packet was received with.
Definition lora-tag.cc:113
void SetDestroyedBy(uint8_t sf)
Set which Spreading Factor this packet was destroyed by.
Definition lora-tag.cc:101
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition lora-tag.cc:30
double m_receivePower
The reception power of this packet.
Definition lora-tag.h:135
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.