OpcUaCanOpen
CANopen OPC-UA server
CanStatistics.h
Go to the documentation of this file.
1 
24 #ifndef CANINTERFACE_SOCKCAN_CANSTATISTICS_H_
25 #define CANINTERFACE_SOCKCAN_CANSTATISTICS_H_
26 
27 
28 #ifdef _WIN32
29 # include <atomic>
30 # include <time.h>
31 # ifndef timeval
32 # include "Winsock2.h"
33 # endif
34 #else
35 # define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
36 # if GCC_VERSION > 40800
37 # include <atomic>
38 # else // GCC_VERSION
39 # include <stdatomic.h>
40 # endif // GCC_VERSION
41 # include <sys/time.h>
42 #endif
43 #include "ExportDefinition.h"
44 
45 #include <chrono>
46 using namespace std;
47 using namespace std::chrono;
48 
49 namespace CanModule
50 {
52  {
53 
54  public:
55 
57 
58  void beginNewRun();
59  void computeDerived(unsigned int baudRate);
60 
62  void onTransmit(unsigned int dataLength);
63 
65  void onReceive(unsigned int dataLength);
66 
67  unsigned int totalTransmitted() { return m_totalTransmitted.load(); }
68  unsigned int totalReceived() { return m_totalReceived.load(); }
69  float txRate() { return m_internals.m_transmittedPerSec; }
70  float rxRate() { return m_internals.m_receivedPerSec; }
71  float busLoad() { return m_internals.m_busLoad; }
72 
73  void operator=(const CanStatistics & other); // not default, because of atomic data
74 
75  private:
76 
77  /* Fields below may be accessed by many threads at once */
78  std::atomic_uint_least32_t m_totalTransmitted;
79  std::atomic_uint_least32_t m_totalReceived;
81  std::atomic_uint_least32_t m_transmitted;
83  std::atomic_uint_least32_t m_received;
84 
85 
86  std::atomic_uint_least32_t m_transmittedOctets;
87  std::atomic_uint_least32_t m_receivedOctets;
88 
90  class Internals
91  {
92  public:
96  float m_busLoad;
97  system_clock::time_point m_observationStart;
98  };
100 
101  };
102 
103 }
104 #endif /* CANINTERFACE_SOCKCAN_CANSTATISTICS_H_ */