Annotations.cci
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief Annotations inline non-template implementation */
16 
17 //#include "Annotations.ih"
18 
19 // Custom includes
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::emu::annotations::Interface
26 
27 prefix_ senf::emu::annotations::Interface::Interface()
28  : value ()
29 {}
30 
31 prefix_ senf::emu::annotations::Interface::Interface(MACAddress const & v)
32  : value (v)
33 {}
34 
35 prefix_ bool senf::emu::annotations::Interface::operator<(Interface const & other)
36  const
37 {
38  return value < other.value;
39 }
40 
41 prefix_ bool senf::emu::annotations::Interface::operator==(Interface const & other)
42  const
43 {
44  return value == other.value;
45 }
46 
47 prefix_ std::ostream & senf::emu::annotations::operator<<(std::ostream & os, Interface const & annotation)
48 {
49  os << annotation.value;
50  return os;
51 }
52 
53 prefix_ std::size_t senf::emu::annotations::hash_value(Interface const & annotation) noexcept
54 {
55  return senf::hash_value(annotation.value);
56 }
57 
58 //-/////////////////////////////////////////////////////////////////////////////////////////////////
59 // senf::emu::annotations::Quality
60 
61 prefix_ senf::emu::annotations::Quality::Quality()
62 {
63  memset(this, 0, sizeof(*this));
64 }
65 /*
66 prefix_ bool senf::emu::annotations::Quality::operator<(Quality const & other)
67  const
68 {
69  return (snr < other.snr || (snr == other.snr && (rssi < other.rssi)));
70 }
71 */
72 prefix_ void senf::emu::annotations::Quality::setLoss(unsigned loss)
73 {
74  flags.framePredecessorLost = std::min(255u, loss);
75 }
76 
77 prefix_ std::ostream & senf::emu::annotations::operator<<(std::ostream & os,
78  Quality const & annotation)
79 {
80  os << "(snr:" << annotation.snr
81  << " rssi:" << annotation.rssi
82  << " noise:" << annotation.noise
83  << " airTime:" << annotation.airTime
84  << " flags:" << annotation.flags.frameCorrupt << "," << annotation.flags.frameRetransmitted
85  << "," << annotation.flags.frameDuplicate << "," << annotation.flags.frameReordered
86  << "," << annotation.flags.frameAggregated
87  << "," << annotation.flags.framePredecessorLost << "," << annotation.flags.frameLength
88  << ")";
89  return os;
90 }
91 
92 //-/////////////////////////////////////////////////////////////////////////////////////////////////
93 // senf::emu::annotations::Timestamp
94 
95 prefix_ senf::emu::annotations::Timestamp::Timestamp()
96 {
97 }
98 
99 prefix_ bool senf::emu::annotations::Timestamp::operator<(Timestamp const & other)
100  const
101 {
102  return as_clock_type() < other.as_clock_type();
103 }
104 
105 prefix_ std::ostream & senf::emu::annotations::operator<<(std::ostream & os,
106  Timestamp const & annotation)
107 {
108  os << ClockService::abstime(annotation.as_clock_type());
109  return os;
110 }
111 
112 prefix_ senf::emu::annotations::Timestamp & senf::emu::annotations::Timestamp::operator=(Timestamp const & other)
113 {
114  ::memcpy(timestamp, other.timestamp, sizeof(timestamp));
115  return *this;
116 }
117 
118 prefix_ void senf::emu::annotations::Timestamp::fromScheduler()
119  const
120 {
121  timestamp[0]= ClockService::in_seconds(scheduler::now());
122  timestamp[1]= ClockService::in_nanoseconds(scheduler::now()) % 1000000000ull;
123 }
124 
125 prefix_ void senf::emu::annotations::Timestamp::fromSocketProtocol(senf::DatagramSocketProtocol const & protocol)
126  const
127 {
128  struct timespec spec;
129  protocol.timestamp(&spec);
130  timestamp[0]= spec.tv_sec;
131  timestamp[1]= spec.tv_nsec;
132 }
133 
134 prefix_ void senf::emu::annotations::Timestamp::fromQueueBuffer(senf::SocketQueueBuffer const & buffer)
135  const
136 {
137  ::memcpy(timestamp, buffer.timestampPtr(), sizeof(timestamp));
138 }
139 
140 prefix_ void senf::emu::annotations::Timestamp::fromWallClock()
141  const
142 {
143  struct timespec spec;
144  clock_gettime(CLOCK_REALTIME_COARSE, &spec);
145  timestamp[0]= spec.tv_sec;
146  timestamp[1]= spec.tv_nsec;
147 }
148 
149 prefix_ senf::ClockService::clock_type senf::emu::annotations::Timestamp::as_clock_type()
150  const
151 {
152  return ClockService::from_time_t(timestamp[0]) + ClockService::nanoseconds(timestamp[1]);
153 }
154 
155 prefix_ std::uint32_t senf::emu::annotations::Timestamp::as_milli_seconds(std::uint32_t modulo)
156  const
157 {
158  return ((timestamp[0] * 1000) + (timestamp[1] / 1000000)) % modulo;
159 }
160 
161 
162 //-/////////////////////////////////////////////////////////////////////////////////////////////////
163 // senf::emu::annotations::WirelessModulation
164 
165 prefix_ senf::emu::annotations::WirelessModulation::WirelessModulation()
166  : id(0)
167 {}
168 
169 prefix_ bool senf::emu::annotations::WirelessModulation::operator<(WirelessModulation const & other)
170  const
171 {
172  return id < other.id;
173 }
174 
175 prefix_ std::ostream & senf::emu::annotations::operator<<(std::ostream & os, WirelessModulation const & annotation)
176 {
177  os << annotation.id;
178  return os;
179 }
180 
181 //-/////////////////////////////////////////////////////////////////////////////////////////////////
182 #undef prefix_
183 
184 
185 // Local Variables:
186 // mode: c++
187 // fill-column: 100
188 // comment-column: 40
189 // c-file-style: "senf"
190 // indent-tabs-mode: nil
191 // ispell-local-dictionary: "american"
192 // compile-command: "scons -u test"
193 // End: