lora-tag.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2017 University of Padova
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Davide Magrin <magrinda@dei.unipd.it>
19  *
20  * Modified by: Bastien Tauran <bastien.tauran@viveris.fr>
21  */
22 
23 #include "lora-tag.h"
24 
25 #include <ns3/tag.h>
26 #include <ns3/uinteger.h>
27 
28 namespace ns3
29 {
30 
31 NS_OBJECT_ENSURE_REGISTERED(LoraTag);
32 
33 TypeId
35 {
36  static TypeId tid = TypeId("ns3::LoraTag").SetParent<Tag>().AddConstructor<LoraTag>();
37  return tid;
38 }
39 
40 TypeId
42 {
43  return GetTypeId();
44 }
45 
46 LoraTag::LoraTag(uint8_t sf, uint8_t destroyedBy)
47  : m_sf(sf),
48  m_modcod(0),
49  m_destroyedBy(destroyedBy),
50  m_receivePower(0),
51  m_dataRate(0),
52  m_frequency(0)
53 {
54 }
55 
57 {
58 }
59 
60 uint32_t
62 {
63  // Each datum about a SF is 1 byte + receivePower (the size of a double) +
64  // frequency (the size of a double)
65  return 4 + 2 * sizeof(double);
66 }
67 
68 void
69 LoraTag::Serialize(TagBuffer i) const
70 {
71  i.WriteU8(m_sf);
72  i.WriteU8(m_modcod);
73  i.WriteU8(m_destroyedBy);
74  i.WriteDouble(m_receivePower);
75  i.WriteU8(m_dataRate);
76  i.WriteDouble(m_frequency);
77 }
78 
79 void
81 {
82  m_sf = i.ReadU8();
83  m_modcod = i.ReadU8();
84  m_destroyedBy = i.ReadU8();
85  m_receivePower = i.ReadDouble();
86  m_dataRate = i.ReadU8();
87  m_frequency = i.ReadDouble();
88 }
89 
90 void
91 LoraTag::Print(std::ostream& os) const
92 {
93  os << m_sf << " " << m_modcod << " " << m_destroyedBy << " " << m_receivePower << " "
94  << m_dataRate;
95 }
96 
97 uint8_t
99 {
100  return m_sf;
101 }
102 
103 uint8_t
105 {
106  return m_destroyedBy;
107 }
108 
109 double
111 {
112  return m_receivePower;
113 }
114 
115 void
117 {
118  m_destroyedBy = sf;
119 }
120 
121 void
123 {
124  m_sf = sf;
125 }
126 
127 void
128 LoraTag::SetReceivePower(double receivePower)
129 {
130  m_receivePower = receivePower;
131 }
132 
133 void
134 LoraTag::SetFrequency(double frequency)
135 {
136  m_frequency = frequency;
137 }
138 
139 double
141 {
142  return m_frequency;
143 }
144 
145 uint8_t
147 {
148  return m_dataRate;
149 }
150 
151 void
152 LoraTag::SetDataRate(uint8_t dataRate)
153 {
154  m_dataRate = dataRate;
155 }
156 
157 uint8_t
159 {
161 }
162 
163 void
164 LoraTag::SetModcod(uint8_t modcod)
165 {
166  m_modcod = modcod;
167 }
168 
169 } // namespace ns3
uint8_t m_sf
The Spreading Factor used by the packet.
Definition: lora-tag.h:145
double GetFrequency(void)
Get the frequency of the packet.
Definition: lora-tag.cc:140
uint8_t m_modcod
The Modcod ID used by the packet.
Definition: lora-tag.h:146
void SetSpreadingFactor(uint8_t sf)
Set which Spreading Factor this packet was transmitted with.
Definition: lora-tag.cc:122
static TypeId GetTypeId(void)
Definition: lora-tag.cc:34
virtual ~LoraTag()
Definition: lora-tag.cc:56
uint8_t m_dataRate
The Data Rate that needs to be used to send this.
Definition: lora-tag.h:149
uint8_t GetSpreadingFactor() const
Read which Spreading Factor this packet was transmitted with.
Definition: lora-tag.cc:98
double m_receivePower
The reception power of this packet.
Definition: lora-tag.h:148
void SetDestroyedBy(uint8_t sf)
Set which Spreading Factor this packet was destroyed by.
Definition: lora-tag.cc:116
uint8_t GetDataRate(void)
Get the data rate for this packet.
Definition: lora-tag.cc:146
virtual TypeId GetInstanceTypeId(void) const
Definition: lora-tag.cc:41
virtual uint32_t GetSerializedSize() const
Definition: lora-tag.cc:61
void SetDataRate(uint8_t dataRate)
Set the data rate for this packet.
Definition: lora-tag.cc:152
uint8_t GetModcod(void)
Get the modcod for this packet.
Definition: lora-tag.cc:158
virtual void Serialize(TagBuffer i) const
Definition: lora-tag.cc:69
void SetFrequency(double frequency)
Set the frequency of the packet.
Definition: lora-tag.cc:134
double GetReceivePower() const
Read the power this packet arrived with.
Definition: lora-tag.cc:110
virtual void Deserialize(TagBuffer i)
Definition: lora-tag.cc:80
void SetReceivePower(double receivePower)
Set the power this packet was received with.
Definition: lora-tag.cc:128
virtual void Print(std::ostream &os) const
Definition: lora-tag.cc:91
double m_frequency
packet.
Definition: lora-tag.h:151
void SetModcod(uint8_t modcod)
Set the modcod for this packet.
Definition: lora-tag.cc:164
LoraTag(uint8_t sf=0, uint8_t destroyedBy=0)
Create a LoraTag with a given spreading factor and collision.
Definition: lora-tag.cc:46
uint8_t GetDestroyedBy() const
Read which Spreading Factor this packet was destroyed by.
Definition: lora-tag.cc:104
uint8_t m_destroyedBy
The Spreading Factor that destroyed the packet.
Definition: lora-tag.h:147
SatModcod_t
Modulation scheme and coding rate for DVB-S2.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.