packeterrorrateestimator.cpp
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32 
33 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
66 #include "xscontrollerconfig.h"
67 #include <cmath>
68 
69 #define PER_UPDATE_PERIOD_MILLISECONDS (10000)
70 #define INVALID_PACKET_RATE (-1)
71 
83  : m_expectedPacketsPerSecond(INVALID_PACKET_RATE)
84  , m_receivedPacketCount(0)
85  , m_packetErrorRate(0)
86  , m_previousUpdateTime(0)
87 {
88 }
89 
92 {
93 }
94 
99 {
100  xsens::Lock lock(&m_mutex);
101  m_expectedPacketsPerSecond = packetsPerSecond;
102 }
103 
110 {
111  xsens::Lock lock(&m_mutex);
113 }
114 
119 {
120  xsens::Lock lock(&m_mutex);
121  return m_packetErrorRate;
122 }
123 
126 {
127  xsNameThisThread("Packet Error Rate Estimator");
128  m_previousUpdateTime = XsTimeStamp::nowMs();
129 }
130 
133 {
134  xsens::Lock lock(&m_mutex);
135 
136  const int64_t now = XsTimeStamp::nowMs();
137 
139  {
140  const int64_t msSinceLastUpdate = now - m_previousUpdateTime;
141 
142  if (msSinceLastUpdate > 0)
143  {
144  const float expectedPackets = (float)floor(m_expectedPacketsPerSecond * (msSinceLastUpdate / 1000));
145  float packetDeliveryRate = 100.0f * (m_receivedPacketCount / expectedPackets);
146 
147  if (packetDeliveryRate > 100.0f)
148  packetDeliveryRate = 100.0f;
149 
150  m_packetErrorRate = (uint8_t)(100 - (int)floor(packetDeliveryRate));
151  JLDEBUGG("Received " << m_receivedPacketCount << " packets in " << msSinceLastUpdate << " ms. Delivery rate: " << (int)(packetDeliveryRate) << "%. Error rate: " << (int)m_packetErrorRate << "%.");
152  }
153  else
154  {
155  m_packetErrorRate = 0;
156  JLDEBUGG("Received " << m_receivedPacketCount << " packets in " << msSinceLastUpdate << " ms. Delivery rate unknown (100%). Error rate unknown (" << (int)m_packetErrorRate << "%).");
157  }
158  }
159 
161  m_previousUpdateTime = now;
162 
164 }
PacketErrorRateEstimator::m_mutex
xsens::Mutex m_mutex
Definition: packeterrorrateestimator.h:86
PacketErrorRateEstimator::m_packetErrorRate
uint8_t m_packetErrorRate
Definition: packeterrorrateestimator.h:89
PacketErrorRateEstimator::m_receivedPacketCount
uint16_t m_receivedPacketCount
Definition: packeterrorrateestimator.h:88
PER_UPDATE_PERIOD_MILLISECONDS
#define PER_UPDATE_PERIOD_MILLISECONDS
Definition: packeterrorrateestimator.cpp:69
xsNameThisThread
void XSTYPES_DLL_API xsNameThisThread(const char *threadName)
Set the name of the current thread to threadName.
Definition: xsthread.c:140
PacketErrorRateEstimator::m_expectedPacketsPerSecond
int32_t m_expectedPacketsPerSecond
Definition: packeterrorrateestimator.h:87
INVALID_PACKET_RATE
#define INVALID_PACKET_RATE
Definition: packeterrorrateestimator.cpp:70
PacketErrorRateEstimator::innerFunction
virtual int32_t innerFunction(void)
Updates the packet error rate estimate periodically.
Definition: packeterrorrateestimator.cpp:132
PacketErrorRateEstimator::PacketErrorRateEstimator
PacketErrorRateEstimator()
Constructor.
Definition: packeterrorrateestimator.cpp:82
f
f
PacketErrorRateEstimator::setExpectedPacketsPerSecond
void setExpectedPacketsPerSecond(int16_t packetsPerSecond)
Set the expected packet reception rate in packets per second.
Definition: packeterrorrateestimator.cpp:98
PacketErrorRateEstimator::~PacketErrorRateEstimator
virtual ~PacketErrorRateEstimator()
Destructor.
Definition: packeterrorrateestimator.cpp:91
PacketErrorRateEstimator::packetErrorRate
uint8_t packetErrorRate(void) const
Return the currently estimated packet error rate.
Definition: packeterrorrateestimator.cpp:118
JLDEBUGG
#define JLDEBUGG(msg)
Definition: journaller.h:280
xsens::Lock
A base class for a Lock.
Definition: xsens_mutex.h:947
PacketErrorRateEstimator::packetReceived
void packetReceived(void)
Indicate that a packet has been received.
Definition: packeterrorrateestimator.cpp:109
int32_t
signed int int32_t
Definition: pstdint.h:515
PacketErrorRateEstimator::initFunction
virtual void initFunction(void)
Initializes the estimation parameters.
Definition: packeterrorrateestimator.cpp:125
packeterrorrateestimator.h
PacketErrorRateEstimator::m_previousUpdateTime
int64_t m_previousUpdateTime
Definition: packeterrorrateestimator.h:90
xscontrollerconfig.h


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20