icub-test
All Data Structures Modules Pages
PortsFrequency.h
1 /*
2  * iCub Robot Unit Tests (Robot Testing Framework)
3  *
4  * Copyright (C) 2015-2019 Istituto Italiano di Tecnologia (IIT)
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef _PORTSFREQUENCY_H_
22 #define _PORTSFREQUENCY_H_
23 
24 #include <yarp/robottestingframework/TestCase.h>
25 #include <yarp/os/BufferedPort.h>
26 #include <yarp/os/Bottle.h>
27 #include <vector>
28 
29 class MyPortInfo {
30 public:
31  std::string name;
32  unsigned int frequency;
33  unsigned int tolerance;
34 };
35 
36 
37 class DataPort : public yarp::os::BufferedPort<yarp::os::Bottle> {
38 public:
39  void reset() {
40  max = smax = sum = ssum = dmax = dsum = 0.0;
41  min = smin = dmin = -1.0;
42  tprev = stprev = 0.0;
43  count = 0;
44  prevPacketCount = 0;
45  packetLostCount = 0;
46  }
47 
48  double getMax() { return max; }
49  double getMin() { return min; }
50  double getAvg() { return sum/count; }
51  double getSMax() { return smax; }
52  double getSMin() { return smin; }
53  double getSAvg() { return ssum/count; }
54  double getDMax() { return dmax; }
55  double getDMin() { return dmin; }
56  double getDAvg() { return dsum/count; }
57  unsigned long getPacketLostCount() { return packetLostCount; }
58  unsigned long getCount() { return count; }
59 
60  virtual void onRead(yarp::os::Bottle& bot);
61 
62 private:
63  unsigned long count, packetLostCount;
64  unsigned long prevPacketCount;
65  double tprev, stprev;
66  double max, min, sum; // receiver time
67  double smax, smin, ssum; // sender time
68  double dmax, dmin, dsum; // time delay
69 };
70 
71 class PortsFrequency : public yarp::robottestingframework::TestCase {
72 public:
73  PortsFrequency();
74  virtual ~PortsFrequency();
75 
76  virtual bool setup(yarp::os::Property& property);
77 
78  virtual void tearDown();
79 
80  virtual void run();
81 
82 private:
83  DataPort port;
84  std::vector<MyPortInfo> ports;
85  double testTime;
86 };
87 
88 #endif //_PORTSFREQUENCY_H