client_read_test.cpp
Go to the documentation of this file.
1 #include <Client.hpp>
2 #include <iostream>
3 #include <msp_msg.hpp>
4 
5 int main(int argc, char *argv[]) {
6  const std::string device =
7  (argc > 1) ? std::string(argv[1]) : "/dev/ttyUSB0";
8  const size_t baudrate = (argc > 2) ? std::stoul(argv[2]) : 115200;
9 
10  msp::client::Client client;
13  client.start(device, baudrate);
14 
16 
17  msp::msg::Ident ident(fw_variant);
18  if(client.sendMessage(ident) == 1) {
19  std::cout << ident;
20  }
21  else
22  std::cerr << "unsupported: " << size_t(ident.id()) << std::endl;
23 
24  msp::msg::Status status(fw_variant);
25  if(client.sendMessage(status) == 1)
26  std::cout << status;
27  else
28  std::cerr << "unsupported: " << size_t(status.id()) << std::endl;
29 
30  msp::msg::RawImu imu_raw(fw_variant);
31  if(client.sendMessage(imu_raw) == 1) {
32  std::cout << imu_raw;
33  std::cout << msp::msg::ImuSI(
34  imu_raw, 512.0, 1.0 / 4.096, 0.92f / 10.0f, 9.80665f);
35  }
36  else
37  std::cerr << "unsupported: " << size_t(imu_raw.id()) << std::endl;
38 
39  msp::msg::Servo servo(fw_variant);
40  if(client.sendMessage(servo) == 1)
41  std::cout << servo;
42  else
43  std::cerr << "unsupported: " << size_t(servo.id()) << std::endl;
44 
45  msp::msg::Motor motor(fw_variant);
46  if(client.sendMessage(motor) == 1)
47  std::cout << motor;
48  else
49  std::cerr << "unsupported: " << size_t(motor.id()) << std::endl;
50 
51  msp::msg::Rc rc(fw_variant);
52  if(client.sendMessage(rc) == 1)
53  std::cout << rc;
54  else
55  std::cerr << "unsupported: " << size_t(rc.id()) << std::endl;
56 
57  msp::msg::Attitude attitude(fw_variant);
58  if(client.sendMessage(attitude) == 1)
59  std::cout << attitude;
60  else
61  std::cerr << "unsupported: " << size_t(attitude.id()) << std::endl;
62 
63  msp::msg::Altitude altitude(fw_variant);
64  if(client.sendMessage(altitude) == 1)
65  std::cout << altitude;
66  else
67  std::cerr << "unsupported: " << size_t(altitude.id()) << std::endl;
68 
69  msp::msg::Analog analog(fw_variant);
70  if(client.sendMessage(analog) == 1)
71  std::cout << analog;
72  else
73  std::cerr << "unsupported: " << size_t(analog.id()) << std::endl;
74 
75  msp::msg::RcTuning rc_tuning(fw_variant);
76  if(client.sendMessage(rc_tuning) == 1)
77  std::cout << rc_tuning;
78  else
79  std::cerr << "unsupported: " << size_t(rc_tuning.id()) << std::endl;
80 
81  msp::msg::Pid pid(fw_variant);
82  if(client.sendMessage(pid) == 1)
83  std::cout << pid;
84  else
85  std::cerr << "unsupported: " << size_t(pid.id()) << std::endl;
86 
87  msp::msg::ActiveBoxes box(fw_variant);
88  if(client.sendMessage(box) == 1)
89  std::cout << box;
90  else
91  std::cerr << "unsupported: " << size_t(box.id()) << std::endl;
92 
93  msp::msg::Misc misc(fw_variant);
94  if(client.sendMessage(misc) == 1)
95  std::cout << misc;
96  else
97  std::cerr << "unsupported: " << size_t(misc.id()) << std::endl;
98 
99  msp::msg::MotorPins pins(fw_variant);
100  if(client.sendMessage(pins) == 1)
101  std::cout << pins;
102  else
103  std::cerr << "unsupported: " << size_t(pins.id()) << std::endl;
104 
105  msp::msg::BoxNames box_names(fw_variant);
106  if(client.sendMessage(box_names) == 1)
107  std::cout << box_names;
108  else
109  std::cerr << "unsupported: " << size_t(box_names.id()) << std::endl;
110 
111  msp::msg::PidNames pid_names(fw_variant);
112  if(client.sendMessage(pid_names) == 1)
113  std::cout << pid_names;
114  else
115  std::cerr << "unsupported: " << size_t(pid_names.id()) << std::endl;
116 
117  msp::msg::BoxIds box_ids(fw_variant);
118  if(client.sendMessage(box_ids) == 1)
119  std::cout << box_ids;
120  else
121  std::cerr << "unsupported: " << size_t(box_ids.id()) << std::endl;
122 
123  msp::msg::ServoConf servo_conf(fw_variant);
124  if(client.sendMessage(servo_conf) == 1)
125  std::cout << servo_conf;
126  else
127  std::cerr << "unsupported: " << size_t(servo_conf.id()) << std::endl;
128 
129  // needs "#define DEBUGMSG" in MultiWii firmware
130 
131  msp::msg::DebugMessage debug_msg(fw_variant);
132  if(client.sendMessage(debug_msg) == 1) {
133  std::cout << "#Debug message:" << std::endl;
134  std::cout << debug_msg.debug_msg << std::endl;
135  }
136  else
137  std::cerr << "unsupported: " << size_t(debug_msg.id()) << std::endl;
138 
139  msp::msg::Debug debug(fw_variant);
140  if(client.sendMessage(debug) == 1)
141  std::cout << debug;
142  else
143  std::cerr << "unsupported: " << size_t(debug.id()) << std::endl;
144 
145  client.stop();
146  std::cout << "PROGRAM COMPLETE" << std::endl;
147 }
bool start(const std::string &device, const size_t baudrate=115200)
Start communications with a flight controller.
Definition: Client.cpp:34
virtual ID id() const override
get the ID of the message
Definition: msp_msg.hpp:2593
void setLoggingLevel(const LoggingLevel &level)
Set the verbosity of the output.
Definition: Client.cpp:18
bool stop()
Stop communications with a flight controller.
Definition: Client.cpp:39
FirmwareVariant
Enum of firmware variants.
void setVariant(const FirmwareVariant &v)
Change the device path on the next connect.
Definition: Client.cpp:30
int main(int argc, char *argv[])
bool sendMessage(msp::Message &message, const double &timeout=0)
Send a message to the connected flight controller. If the message sends data to the flight controller...
Definition: Client.cpp:123
Requests (1xx)
Definition: msp_msg.hpp:2590


msp
Author(s): Christian Rauch
autogenerated on Tue Oct 6 2020 03:38:57