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


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