• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mavlink / MAVSDK / 11602202969

30 Oct 2024 09:50PM UTC coverage: 38.614% (+0.7%) from 37.918%
11602202969

Pull #2394

github

web-flow
Merge e66473b14 into cebb708a4
Pull Request #2394: Consolidate CI

12032 of 31160 relevant lines covered (38.61%)

246.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

34.09
/src/mavsdk/core/mavsdk_time.cpp
1
#include "mavsdk_time.h"
2
#include <cstdint>
3
#include <limits>
4
#include <cmath>
5
#include <chrono>
6
#include <thread>
7

8
namespace mavsdk {
9

10
using std::chrono::steady_clock;
11
using std::chrono::system_clock;
12

13
SteadyTimePoint Time::steady_time()
24,829✔
14
{
15
    return steady_clock::now();
24,829✔
16
}
17

18
SystemTimePoint Time::system_time()
×
19
{
20
    return system_clock::now();
×
21
}
22

23
double Time::elapsed_s()
2✔
24
{
25
    auto now = steady_time().time_since_epoch();
2✔
26

27
    return static_cast<double>((now.count()) * steady_clock::period::num) /
2✔
28
           static_cast<double>(steady_clock::period::den);
2✔
29
}
30

31
uint64_t Time::elapsed_ms() const
1✔
32
{
33
    return static_cast<uint64_t>(
34
        steady_clock::now().time_since_epoch() / std::chrono::milliseconds(1));
1✔
35
}
36

37
uint64_t Time::elapsed_us() const
×
38
{
39
    return static_cast<uint64_t>(
40
        steady_clock::now().time_since_epoch() / std::chrono::microseconds(1));
×
41
}
42

43
double Time::elapsed_since_s(const SteadyTimePoint& since)
11,018✔
44
{
45
    auto now = steady_time();
11,018✔
46

47
    return static_cast<double>(((now - since).count()) * steady_clock::period::num) /
11,005✔
48
           static_cast<double>(steady_clock::period::den);
22,003✔
49
}
50

51
SteadyTimePoint Time::steady_time_in_future(double duration_s)
2,006✔
52
{
53
    auto now = steady_time();
2,006✔
54
    return now + std::chrono::milliseconds(int64_t(duration_s * 1e3));
2,006✔
55
}
56

57
void Time::shift_steady_time_by(SteadyTimePoint& time, double offset_s)
330✔
58
{
59
    time += std::chrono::milliseconds(int64_t(offset_s * 1e3));
330✔
60
}
330✔
61

62
void Time::sleep_for(std::chrono::hours h)
×
63
{
64
    std::this_thread::sleep_for(h);
×
65
}
×
66

67
void Time::sleep_for(std::chrono::minutes m)
×
68
{
69
    std::this_thread::sleep_for(m);
×
70
}
×
71

72
void Time::sleep_for(std::chrono::seconds s)
×
73
{
74
    std::this_thread::sleep_for(s);
×
75
}
×
76

77
void Time::sleep_for(std::chrono::milliseconds ms)
×
78
{
79
    std::this_thread::sleep_for(ms);
×
80
}
×
81

82
void Time::sleep_for(std::chrono::microseconds us)
×
83
{
84
    std::this_thread::sleep_for(us);
×
85
}
×
86

87
void Time::sleep_for(std::chrono::nanoseconds ns)
×
88
{
89
    std::this_thread::sleep_for(ns);
×
90
}
×
91

92
FakeTime::FakeTime() : Time()
75✔
93
{
94
    // Start with current time so we don't start from 0.
95
    _current = steady_clock::now();
75✔
96
}
75✔
97

98
SteadyTimePoint FakeTime::steady_time()
366✔
99
{
100
    return _current;
366✔
101
}
102

103
void FakeTime::sleep_for(std::chrono::hours h)
×
104
{
105
    _current += h;
×
106
    add_overhead();
×
107
}
×
108

109
void FakeTime::sleep_for(std::chrono::minutes m)
×
110
{
111
    _current += m;
×
112
    add_overhead();
×
113
}
×
114

115
void FakeTime::sleep_for(std::chrono::seconds s)
×
116
{
117
    _current += s;
×
118
    add_overhead();
×
119
}
×
120

121
void FakeTime::sleep_for(std::chrono::milliseconds ms)
164✔
122
{
123
    _current += ms;
164✔
124
    add_overhead();
164✔
125
}
164✔
126

127
void FakeTime::sleep_for(std::chrono::microseconds us)
×
128
{
129
    _current += us;
×
130
    add_overhead();
×
131
}
×
132

133
void FakeTime::sleep_for(std::chrono::nanoseconds ns)
×
134
{
135
    _current += ns;
×
136
    add_overhead();
×
137
}
×
138

139
void FakeTime::add_overhead()
164✔
140
{
141
    _current += std::chrono::microseconds(50);
164✔
142
}
164✔
143

144
SystemTimePoint AutopilotTime::system_time()
×
145
{
146
    return system_clock::now();
×
147
}
148

149
AutopilotTimePoint AutopilotTime::now()
×
150
{
151
    std::lock_guard<std::mutex> lock(_autopilot_system_time_offset_mutex);
×
152
    return AutopilotTimePoint(std::chrono::duration_cast<std::chrono::microseconds>(
×
153
        system_time().time_since_epoch() + _autopilot_time_offset));
×
154
}
×
155

156
void AutopilotTime::shift_time_by(std::chrono::nanoseconds offset)
×
157
{
158
    std::lock_guard<std::mutex> lock(_autopilot_system_time_offset_mutex);
×
159
    _autopilot_time_offset += offset;
×
160
};
×
161

162
AutopilotTimePoint AutopilotTime::time_in(SystemTimePoint local_system_time_point)
×
163
{
164
    std::lock_guard<std::mutex> lock(_autopilot_system_time_offset_mutex);
×
165
    return AutopilotTimePoint(std::chrono::duration_cast<std::chrono::microseconds>(
×
166
        local_system_time_point.time_since_epoch() + _autopilot_time_offset));
×
167
};
×
168

169
} // namespace mavsdk
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc