A Discrete-Event Network Simulator
API
snr-tag.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005,2006 INRIA
3  * Copyright (c) 2009 MIRKO BANCHI
4  * Copyright (c) 2013 University of Surrey
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Mirko Banchi <mk.banchi@gmail.com>
21  * Konstantinos Katsaros <dinos.katsaros@gmail.com>
22  */
23 
24 #include "snr-tag.h"
25 
26 #include "ns3/double.h"
27 
28 namespace ns3
29 {
30 
32 
33 TypeId
35 {
36  static TypeId tid = TypeId("ns3::SnrTag")
37  .SetParent<Tag>()
38  .SetGroupName("Wifi")
39  .AddConstructor<SnrTag>()
40  .AddAttribute("Snr",
41  "The SNR of the last packet received",
42  DoubleValue(0.0),
44  MakeDoubleChecker<double>());
45  return tid;
46 }
47 
48 TypeId
50 {
51  return GetTypeId();
52 }
53 
55  : m_snr(0)
56 {
57 }
58 
59 uint32_t
61 {
62  return sizeof(double);
63 }
64 
65 void
67 {
68  i.WriteDouble(m_snr);
69 }
70 
71 void
73 {
74  m_snr = i.ReadDouble();
75 }
76 
77 void
78 SnrTag::Print(std::ostream& os) const
79 {
80  os << "Snr=" << m_snr;
81 }
82 
83 void
84 SnrTag::Set(double snr)
85 {
86  m_snr = snr;
87 }
88 
89 double
90 SnrTag::Get() const
91 {
92  return m_snr;
93 }
94 
95 } // namespace ns3
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
static TypeId GetTypeId()
Get the type ID.
Definition: snr-tag.cc:34
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: snr-tag.cc:49
void Set(double snr)
Set the SNR to the given value.
Definition: snr-tag.cc:84
void Serialize(TagBuffer i) const override
Definition: snr-tag.cc:66
uint32_t GetSerializedSize() const override
Definition: snr-tag.cc:60
void Print(std::ostream &os) const override
Definition: snr-tag.cc:78
double m_snr
SNR value in linear scale.
Definition: snr-tag.h:68
SnrTag()
Create a SnrTag with the default SNR 0.
Definition: snr-tag.cc:54
void Deserialize(TagBuffer i) override
Definition: snr-tag.cc:72
double Get() const
Return the SNR value.
Definition: snr-tag.cc:90
read and write tag data
Definition: tag-buffer.h:52
void WriteDouble(double v)
Definition: tag-buffer.cc:118
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:931
#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.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43