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

mavlink / MAVSDK / 11767930807

10 Nov 2024 07:33PM UTC coverage: 38.608% (+0.7%) from 37.921%
11767930807

push

github

web-flow
Merge pull request #2394 from mavlink/pr-consolidate-ci

Consolidate CI

12030 of 31159 relevant lines covered (38.61%)

243.33 hits per line

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

87.14
/src/mavsdk/plugins/calibration/calibration_statustext_parser.cpp
1
#include "calibration_statustext_parser.h"
2
#include "calibration_messages.h"
3
#include "log.h"
4

5
namespace mavsdk {
6

7
CalibrationStatustextParser::CalibrationStatustextParser() {}
6✔
8

9
CalibrationStatustextParser::~CalibrationStatustextParser() {}
6✔
10

11
bool CalibrationStatustextParser::parse(const std::string& statustext)
18✔
12
{
13
    // We do a quick check before doing more in-depth parsing.
14
    if (!is_relevant(statustext)) {
18✔
15
        return false;
1✔
16
    }
17

18
    // We start with the most likely messages in order to reduce parsing efforts.
19
    // As soon as one check is successful, the condition is true and we can stop.
20
    if (check_progress(statustext) || check_started(statustext) || check_done(statustext) ||
41✔
21
        check_failed(statustext) || check_cancelled(statustext)) {
41✔
22
        return true;
8✔
23
    }
24

25
    // Whatever doesn't fit into the first checks will end up as a generic
26
    // instruction and caught at the end.
27
    check_instruction(statustext);
9✔
28
    return true;
9✔
29
}
30

31
void CalibrationStatustextParser::reset()
13✔
32
{
33
    _status = Status::None;
13✔
34
    _progress = NAN;
13✔
35
    _failed_message.clear();
13✔
36
    _instruction_message.clear();
13✔
37
}
13✔
38

39
bool CalibrationStatustextParser::is_relevant(const std::string& statustext)
18✔
40
{
41
    // This should be a quick check, so pre-processing without looking at the whole string.
42
    static constexpr char CALIBRATION_PREFIX[] = "[cal] ";
43
    return (statustext.compare(0, 6, CALIBRATION_PREFIX) == 0);
18✔
44
}
45

46
bool CalibrationStatustextParser::check_started(const std::string& statustext)
13✔
47
{
48
    static constexpr char CUSTOM_CAL_QGC_STARTED_MSG[] = "[cal] calibration started: %i %s";
49

50
    int version_stamp;
13✔
51
    const int ret =
52
        sscanf(statustext.c_str(), CUSTOM_CAL_QGC_STARTED_MSG, &version_stamp, _tmp_str);
13✔
53

54
    if (ret == 2) {
13✔
55
        if (version_stamp == 2) {
2✔
56
            _status = Status::Started;
2✔
57
        } else {
58
            _status = Status::Failed;
×
59

60
            std::stringstream error_stream{};
×
61
            error_stream << "Unknown calibration version stamp: " << version_stamp;
×
62
            _failed_message = error_stream.str();
×
63
            LogErr() << _failed_message;
×
64
        }
×
65
        return true;
2✔
66
    }
67

68
    return false;
11✔
69
}
70

71
bool CalibrationStatustextParser::check_done(const std::string& statustext)
11✔
72
{
73
    const int ret = sscanf(statustext.c_str(), CAL_QGC_DONE_MSG, _tmp_str);
11✔
74

75
    if (ret == 1) {
11✔
76
        _status = Status::Done;
×
77
        return true;
×
78
    }
79
    return false;
11✔
80
}
81

82
bool CalibrationStatustextParser::check_failed(const std::string& statustext)
11✔
83
{
84
    static constexpr char CUSTOM_CAL_QGC_FAILED_MSG[] = "[cal] calibration failed: %63[^\n]";
85

86
    const int ret = sscanf(statustext.c_str(), CUSTOM_CAL_QGC_FAILED_MSG, _tmp_str);
11✔
87

88
    if (ret == 1) {
11✔
89
        _status = Status::Failed;
1✔
90
        _failed_message = _tmp_str;
1✔
91
        return true;
1✔
92
    }
93
    return false;
10✔
94
}
95

96
bool CalibrationStatustextParser::check_cancelled(const std::string& statustext)
10✔
97
{
98
    if (statustext.compare(CAL_QGC_CANCELLED_MSG) == 0) {
10✔
99
        _status = Status::Cancelled;
1✔
100
        return true;
1✔
101
    }
102
    return false;
9✔
103
}
104

105
bool CalibrationStatustextParser::check_progress(const std::string& statustext)
17✔
106
{
107
    int progress_int;
17✔
108
    int ret = sscanf(statustext.c_str(), CAL_QGC_PROGRESS_MSG, &progress_int);
17✔
109

110
    if (ret == 1 && progress_int >= 0 && progress_int <= 100) {
17✔
111
        _progress = float(progress_int) / 100;
2✔
112
        _status = Status::Progress;
2✔
113
        return true;
2✔
114
    }
115

116
    static constexpr char SPECIAL_MAG_CAL_QGC_PROGRESS_MSG[] =
117
        "[cal] %s side calibration: progress <%u>";
118

119
    ret = sscanf(statustext.c_str(), SPECIAL_MAG_CAL_QGC_PROGRESS_MSG, _tmp_str, &progress_int);
15✔
120

121
    if (ret == 2 && progress_int >= 0 && progress_int <= 100) {
15✔
122
        _progress = float(progress_int) / 100;
2✔
123
        _status = Status::Progress;
2✔
124
        return true;
2✔
125
    }
126

127
    return false;
13✔
128
}
129

130
bool CalibrationStatustextParser::check_instruction(const std::string& statustext)
9✔
131
{
132
    static constexpr char CATCHALL[] = "[cal] %63[^\n]";
133

134
    const int ret = sscanf(statustext.c_str(), CATCHALL, _tmp_str);
9✔
135

136
    if (ret == 1) {
9✔
137
        _status = Status::Instruction;
9✔
138
        _instruction_message = _tmp_str;
9✔
139
        return true;
9✔
140
    }
141
    return false;
×
142
}
143

144
} // 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

© 2026 Coveralls, Inc