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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Davide Magrin <magrinda@dei.unipd.it>
18 */
19
20#include "lora-tag.h"
21
22#include "ns3/tag.h"
23#include "ns3/uinteger.h"
24
25namespace ns3
26{
27namespace lorawan
28{
29
31
32TypeId
34{
35 static TypeId tid =
36 TypeId("ns3::LoraTag").SetParent<Tag>().SetGroupName("lorawan").AddConstructor<LoraTag>();
37 return tid;
38}
39
42{
43 return GetTypeId();
44}
45
46LoraTag::LoraTag(uint8_t sf, uint8_t destroyedBy)
47 : m_sf(sf),
48 m_destroyedBy(destroyedBy),
49 m_receivePower(0),
50 m_dataRate(0),
51 m_frequency(0)
52{
53}
54
56{
57}
58
61{
62 // Each datum about a spreading factor is 1 byte + receivePower (the size of a double) +
63 // frequency (the size of a double)
64 return 3 + 2 * sizeof(double);
65}
66
67void
69{
70 i.WriteU8(m_sf);
75}
76
77void
79{
80 m_sf = i.ReadU8();
83 m_dataRate = i.ReadU8();
85}
86
87void
88LoraTag::Print(std::ostream& os) const
89{
90 os << m_sf << " " << m_destroyedBy << " " << m_receivePower << " " << m_dataRate;
91}
92
93uint8_t
95{
96 return m_sf;
97}
98
99uint8_t
101{
102 return m_destroyedBy;
103}
104
105double
107{
108 return m_receivePower;
109}
110
111void
113{
114 m_destroyedBy = sf;
115}
116
117void
119{
120 m_sf = sf;
121}
122
123void
124LoraTag::SetReceivePower(double receivePower)
125{
126 m_receivePower = receivePower;
127}
128
129void
130LoraTag::SetFrequency(double frequency)
131{
132 m_frequency = frequency;
133}
134
135double
137{
138 return m_frequency;
139}
140
141uint8_t
143{
144 return m_dataRate;
145}
146
147void
148LoraTag::SetDataRate(uint8_t dataRate)
149{
150 m_dataRate = dataRate;
151}
152
153} // namespace lorawan
154} // namespace ns3
read and write tag data
Definition: tag-buffer.h:52
void WriteDouble(double v)
Definition: tag-buffer.cc:118
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition: tag-buffer.h:172
TAG_BUFFER_INLINE uint8_t ReadU8()
Definition: tag-buffer.h:196
double ReadDouble()
Definition: tag-buffer.cc:170
tag a set of bytes in a packet
Definition: tag.h:39
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Tag used to save various data about a packet, like its Spreading Factor and data about interference.
Definition: lora-tag.h:37
static TypeId GetTypeId()
Register this type.
Definition: lora-tag.cc:33
double m_frequency
The frequency of this packet.
Definition: lora-tag.h:148
uint8_t GetDestroyedBy() const
Read which Spreading Factor this packet was destroyed by.
Definition: lora-tag.cc:100
uint8_t m_dataRate
The data rate that needs to be used to send this packet.
Definition: lora-tag.h:147
void SetDataRate(uint8_t dataRate)
Set the data rate for this packet.
Definition: lora-tag.cc:148
void Deserialize(TagBuffer i) override
Definition: lora-tag.cc:78
~LoraTag() override
Destructor.
Definition: lora-tag.cc:55
void SetSpreadingFactor(uint8_t sf)
Set which Spreading Factor this packet was transmitted with.
Definition: lora-tag.cc:118
uint8_t GetDataRate() const
Get the data rate for this packet.
Definition: lora-tag.cc:142
void Serialize(TagBuffer i) const override
Definition: lora-tag.cc:68
double GetReceivePower() const
Read the power this packet arrived with.
Definition: lora-tag.cc:106
uint32_t GetSerializedSize() const override
Definition: lora-tag.cc:60
void SetFrequency(double frequency)
Set the frequency of the packet.
Definition: lora-tag.cc:130
uint8_t m_destroyedBy
The Spreading Factor that destroyed the packet.
Definition: lora-tag.h:145
uint8_t m_sf
The Spreading Factor used by the packet.
Definition: lora-tag.h:144
uint8_t GetSpreadingFactor() const
Read which Spreading Factor this packet was transmitted with.
Definition: lora-tag.cc:94
LoraTag(uint8_t sf=0, uint8_t destroyedBy=0)
Create a LoraTag with a given spreading factor and collision.
Definition: lora-tag.cc:46
void Print(std::ostream &os) const override
Definition: lora-tag.cc:88
void SetReceivePower(double receivePower)
Set the power this packet was received with.
Definition: lora-tag.cc:124
double GetFrequency() const
Get the frequency of the packet.
Definition: lora-tag.cc:136
void SetDestroyedBy(uint8_t sf)
Set which Spreading Factor this packet was destroyed by.
Definition: lora-tag.cc:112
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: lora-tag.cc:41
double m_receivePower
The reception power of this packet.
Definition: lora-tag.h:146
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.