client_read_test.cpp
Go to the documentation of this file.
00001 #include <Client.hpp>
00002 #include <msp_msg.hpp>
00003 #include <msg_print.hpp>
00004 
00005 #include <iostream>
00006 
00007 typedef unsigned int uint;
00008 
00009 int main(int argc, char *argv[]) {
00010     const std::string device = (argc>1) ? std::string(argv[1]) : "/dev/ttyUSB0";
00011     const uint baudrate = (argc>2) ? std::stoul(argv[2]) : 115200;
00012 
00013     msp::client::Client client;
00014     client.setPrintWarnings(true);
00015     client.connect(device, baudrate);
00016     client.start();
00017 
00018     msp::msg::Ident ident;
00019     if(client.request(ident)==1)
00020         std::cout<<ident;
00021     else
00022         std::cerr<<"unsupported: "<<uint(ident.id())<<std::endl;
00023 
00024     msp::msg::Status status;
00025     if(client.request(status)==1)
00026         std::cout<<status;
00027     else
00028         std::cerr<<"unsupported: "<<uint(status.id())<<std::endl;
00029 
00030     msp::msg::ImuRaw imu_raw;
00031     if(client.request(imu_raw)==1) {
00032         std::cout<<msp::msg::ImuSI(imu_raw, 512.0, 1.0/4.096, 0.92f/10.0f, 9.80665f);
00033     }
00034     else
00035         std::cerr<<"unsupported: "<<uint(imu_raw.id())<<std::endl;
00036 
00037     msp::msg::Servo servo;
00038     if(client.request(servo)==1)
00039         std::cout<<servo;
00040     else
00041         std::cerr<<"unsupported: "<<uint(servo.id())<<std::endl;
00042 
00043     msp::msg::Motor motor;
00044     if(client.request(motor)==1)
00045         std::cout<<motor;
00046     else
00047         std::cerr<<"unsupported: "<<uint(motor.id())<<std::endl;
00048 
00049     msp::msg::Rc rc;
00050     if(client.request(rc)==1)
00051         std::cout<<rc;
00052     else
00053         std::cerr<<"unsupported: "<<uint(rc.id())<<std::endl;
00054 
00055     msp::msg::Attitude attitude;
00056     if(client.request(attitude)==1)
00057         std::cout<<attitude;
00058     else
00059         std::cerr<<"unsupported: "<<uint(attitude.id())<<std::endl;
00060 
00061     msp::msg::Altitude altitude;
00062     if(client.request(altitude)==1)
00063         std::cout<<altitude;
00064     else
00065         std::cerr<<"unsupported: "<<uint(altitude.id())<<std::endl;
00066 
00067     msp::msg::Analog analog;
00068     if(client.request(analog)==1)
00069         std::cout<<analog;
00070     else
00071         std::cerr<<"unsupported: "<<uint(analog.id())<<std::endl;
00072 
00073     msp::msg::RcTuning rc_tuning;
00074     if(client.request(rc_tuning)==1)
00075         std::cout<<rc_tuning;
00076     else
00077         std::cerr<<"unsupported: "<<uint(rc_tuning.id())<<std::endl;
00078 
00079     msp::msg::Pid pid;
00080     if(client.request(pid)==1)
00081         std::cout<<pid;
00082     else
00083         std::cerr<<"unsupported: "<<uint(pid.id())<<std::endl;
00084 
00085     msp::msg::Box box;
00086     if(client.request(box)==1)
00087         std::cout<<box;
00088     else
00089         std::cerr<<"unsupported: "<<uint(box.id())<<std::endl;
00090 
00091     msp::msg::Misc misc;
00092     if(client.request(misc)==1)
00093         std::cout<<misc;
00094     else
00095         std::cerr<<"unsupported: "<<uint(misc.id())<<std::endl;
00096 
00097     msp::msg::MotorPins pins;
00098     if(client.request(pins)==1)
00099         std::cout<<pins;
00100     else
00101         std::cerr<<"unsupported: "<<uint(pins.id())<<std::endl;
00102 
00103     msp::msg::BoxNames box_names;
00104     if(client.request(box_names)==1)
00105         std::cout<<box_names;
00106     else
00107         std::cerr<<"unsupported: "<<uint(box_names.id())<<std::endl;
00108 
00109     msp::msg::PidNames pid_names;
00110     if(client.request(pid_names)==1)
00111         std::cout<<pid_names;
00112     else
00113         std::cerr<<"unsupported: "<<uint(pid_names.id())<<std::endl;
00114 
00115     msp::msg::BoxIds box_ids;
00116     if(client.request(box_ids)==1)
00117         std::cout<<box_ids;
00118     else
00119         std::cerr<<"unsupported: "<<uint(box_ids.id())<<std::endl;
00120 
00121     msp::msg::ServoConf servo_conf;
00122     if(client.request(servo_conf)==1)
00123         std::cout<<servo_conf;
00124     else
00125         std::cerr<<"unsupported: "<<uint(servo_conf.id())<<std::endl;
00126 
00127     // needs "#define DEBUGMSG" in MultiWii firmware
00128     msp::msg::DebugMessage debug_msg;
00129     if(client.request(debug_msg)==1) {
00130             std::cout<<"#Debug message:"<<std::endl;
00131             std::cout<<debug_msg.msg<<std::endl;
00132     }
00133     else
00134         std::cerr<<"unsupported: "<<uint(debug_msg.id())<<std::endl;
00135 
00136     msp::msg::Debug debug;
00137     if(client.request(debug)==1)
00138         std::cout<<debug;
00139     else
00140         std::cerr<<"unsupported: "<<uint(debug.id())<<std::endl;
00141 
00142     client.stop();
00143 }


msp
Author(s): Christian Rauch
autogenerated on Mon Oct 9 2017 03:02:13