-
Notifications
You must be signed in to change notification settings - Fork 27
/
msp_read_test.cpp
148 lines (122 loc) · 4.12 KB
/
msp_read_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <MSP.hpp>
#include <msp_msg.hpp>
#include <iostream>
#include <msg_print.hpp>
int main(int argc, char *argv[]) {
const std::string device = (argc>1) ? std::string(argv[1]) : "/dev/ttyUSB0";
const size_t baudrate = (argc>2) ? std::stoul(argv[2]) : 115200;
msp::MSP msp(device, baudrate);
msp.setWait(1);
// wait for flight controller to become ready
{
std::cout<<"Connecting FCU..."<<std::endl;
msp::msg::Ident ident;
if(msp.request_wait(ident, 10)) {
std::cout<<"MSP version "<< size_t(ident.version)<<" ready"<<std::endl;
}
}
std::cout<<"ready"<<std::endl;
msp::msg::Ident ident;
if(msp.request_block(ident))
std::cout<<ident;
else
std::cerr<<"unsupported: "<< size_t(ident.id())<<std::endl;
msp::msg::Status status;
if(msp.request_block(status))
std::cout<<status;
else
std::cerr<<"unsupported: "<< size_t(status.id())<<std::endl;
msp::msg::ImuRaw imu_raw;
if(msp.request_block(imu_raw))
std::cout<<msp::msg::ImuSI(imu_raw, 512.0, 1.0/4.096, 0.92f/10.0f, 9.80665f);
else
std::cerr<<"unsupported: "<< size_t(imu_raw.id())<<std::endl;
msp::msg::Servo servo;
if(msp.request_block(servo))
std::cout<<servo;
else
std::cerr<<"unsupported: "<< size_t(servo.id())<<std::endl;
msp::msg::Motor motor;
if(msp.request_block(motor))
std::cout<<motor;
else
std::cerr<<"unsupported: "<< size_t(motor.id())<<std::endl;
msp::msg::Rc rc;
if(msp.request_block(rc))
std::cout<<rc;
else
std::cerr<<"unsupported: "<< size_t(rc.id())<<std::endl;
msp::msg::Attitude attitude;
if(msp.request_block(attitude))
std::cout<<attitude;
else
std::cerr<<"unsupported: "<< size_t(attitude.id())<<std::endl;
msp::msg::Altitude altitude;
if(msp.request_block(altitude))
std::cout<<altitude;
else
std::cerr<<"unsupported: "<< size_t(altitude.id())<<std::endl;
msp::msg::Analog analog;
if(msp.request_block(analog))
std::cout<<analog;
else
std::cerr<<"unsupported: "<< size_t(analog.id())<<std::endl;
msp::msg::RcTuning rc_tuning;
if(msp.request_block(rc_tuning))
std::cout<<rc_tuning;
else
std::cerr<<"unsupported: "<< size_t(rc_tuning.id())<<std::endl;
msp::msg::Pid pid;
if(msp.request_block(pid))
std::cout<<pid;
else
std::cerr<<"unsupported: "<< size_t(pid.id())<<std::endl;
msp::msg::Box box;
if(msp.request_block(box))
std::cout<<box;
else
std::cerr<<"unsupported: "<< size_t(box.id())<<std::endl;
msp::msg::Misc misc;
if(msp.request_block(misc))
std::cout<<misc;
else
std::cerr<<"unsupported: "<< size_t(misc.id())<<std::endl;
msp::msg::MotorPins pins;
if(msp.request_block(pins))
std::cout<<pins;
else
std::cerr<<"unsupported: "<< size_t(pins.id())<<std::endl;
msp::msg::BoxNames box_names;
if(msp.request_block(box_names))
std::cout<<box_names;
else
std::cerr<<"unsupported: "<< size_t(box_names.id())<<std::endl;
msp::msg::PidNames pid_names;
if(msp.request_block(pid_names))
std::cout<<pid_names;
else
std::cerr<<"unsupported: "<< size_t(pid_names.id())<<std::endl;
msp::msg::BoxIds box_ids;
if(msp.request_block(box_ids))
std::cout<<box_ids;
else
std::cerr<<"unsupported: "<< size_t(box_ids.id())<<std::endl;
msp::msg::ServoConf servo_conf;
if(msp.request_block(servo_conf))
std::cout<<servo_conf;
else
std::cerr<<"unsupported: "<< size_t(servo_conf.id())<<std::endl;
// needs "#define DEBUGMSG" in MultiWii firmware
msp::msg::DebugMessage debug_msg;
if(msp.request_block(debug_msg)) {
std::cout<<"#Debug message:"<<std::endl;
std::cout<<debug_msg.msg<<std::endl;
}
else
std::cerr<<"unsupported: "<< size_t(debug_msg.id())<<std::endl;
msp::msg::Debug debug;
if(msp.request_block(debug))
std::cout<<debug;
else
std::cerr<<"unsupported: "<< size_t(debug.id())<<std::endl;
}