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
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
15 \brief Annotations inline non-template implementation */
17 //#include "Annotations.ih"
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::emu::annotations::Interface
27 prefix_ senf::emu::annotations::Interface::Interface()
31 prefix_ senf::emu::annotations::Interface::Interface(MACAddress const & v)
35 prefix_ bool senf::emu::annotations::Interface::operator<(Interface const & other)
38 return value < other.value;
41 prefix_ bool senf::emu::annotations::Interface::operator==(Interface const & other)
44 return value == other.value;
47 prefix_ std::ostream & senf::emu::annotations::operator<<(std::ostream & os, Interface const & annotation)
49 os << annotation.value;
53 prefix_ std::size_t senf::emu::annotations::hash_value(Interface const & annotation) noexcept
55 return senf::hash_value(annotation.value);
58 //-/////////////////////////////////////////////////////////////////////////////////////////////////
59 // senf::emu::annotations::Quality
61 prefix_ senf::emu::annotations::Quality::Quality()
63 memset(this, 0, sizeof(*this));
66 prefix_ bool senf::emu::annotations::Quality::operator<(Quality const & other)
69 return (snr < other.snr || (snr == other.snr && (rssi < other.rssi)));
72 prefix_ void senf::emu::annotations::Quality::setLoss(unsigned loss)
74 flags.framePredecessorLost = std::min(255u, loss);
77 prefix_ std::ostream & senf::emu::annotations::operator<<(std::ostream & os,
78 Quality const & annotation)
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
92 //-/////////////////////////////////////////////////////////////////////////////////////////////////
93 // senf::emu::annotations::Timestamp
95 prefix_ senf::emu::annotations::Timestamp::Timestamp()
99 prefix_ bool senf::emu::annotations::Timestamp::operator<(Timestamp const & other)
102 return as_clock_type() < other.as_clock_type();
105 prefix_ std::ostream & senf::emu::annotations::operator<<(std::ostream & os,
106 Timestamp const & annotation)
108 os << ClockService::abstime(annotation.as_clock_type());
112 prefix_ senf::emu::annotations::Timestamp & senf::emu::annotations::Timestamp::operator=(Timestamp const & other)
114 ::memcpy(timestamp, other.timestamp, sizeof(timestamp));
118 prefix_ void senf::emu::annotations::Timestamp::fromScheduler()
121 timestamp[0]= ClockService::in_seconds(scheduler::now());
122 timestamp[1]= ClockService::in_nanoseconds(scheduler::now()) % 1000000000ull;
125 prefix_ void senf::emu::annotations::Timestamp::fromSocketProtocol(senf::DatagramSocketProtocol const & protocol)
128 struct timespec spec;
129 protocol.timestamp(&spec);
130 timestamp[0]= spec.tv_sec;
131 timestamp[1]= spec.tv_nsec;
134 prefix_ void senf::emu::annotations::Timestamp::fromQueueBuffer(senf::SocketQueueBuffer const & buffer)
137 ::memcpy(timestamp, buffer.timestampPtr(), sizeof(timestamp));
140 prefix_ void senf::emu::annotations::Timestamp::fromWallClock()
143 struct timespec spec;
144 clock_gettime(CLOCK_REALTIME_COARSE, &spec);
145 timestamp[0]= spec.tv_sec;
146 timestamp[1]= spec.tv_nsec;
149 prefix_ senf::ClockService::clock_type senf::emu::annotations::Timestamp::as_clock_type()
152 return ClockService::from_time_t(timestamp[0]) + ClockService::nanoseconds(timestamp[1]);
155 prefix_ std::uint32_t senf::emu::annotations::Timestamp::as_milli_seconds(std::uint32_t modulo)
158 return ((timestamp[0] * 1000) + (timestamp[1] / 1000000)) % modulo;
162 //-/////////////////////////////////////////////////////////////////////////////////////////////////
163 // senf::emu::annotations::WirelessModulation
165 prefix_ senf::emu::annotations::WirelessModulation::WirelessModulation()
169 prefix_ bool senf::emu::annotations::WirelessModulation::operator<(WirelessModulation const & other)
172 return id < other.id;
175 prefix_ std::ostream & senf::emu::annotations::operator<<(std::ostream & os, WirelessModulation const & annotation)
181 //-/////////////////////////////////////////////////////////////////////////////////////////////////
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"