fcu_custom_type.cpp
Go to the documentation of this file.
00001 #include <FlightController.hpp>
00002 #include <iostream>
00003 
00004 struct MyIdent : public msp::Message {
00005     MyIdent(msp::FirmwareVariant v) : Message(v) {}
00006 
00007     virtual msp::ID id() const override { return msp::ID::MSP_IDENT; }
00008 
00009     msp::ByteVector raw_data;
00010 
00011     virtual bool decode(const msp::ByteVector &data) override {
00012         raw_data = data;
00013         return true;
00014     }
00015 };
00016 
00017 struct Callbacks {
00018     void onIdent(const MyIdent &ident) {
00019         std::cout << "Raw Ident data: ";
00020         for(auto d : ident.raw_data) {
00021             std::cout << int(d) << " ";
00022         }
00023         std::cout << std::endl;
00024     }
00025 };
00026 
00027 int main(int argc, char *argv[]) {
00028     const std::string device =
00029         (argc > 1) ? std::string(argv[1]) : "/dev/ttyUSB0";
00030     const size_t baudrate = (argc > 2) ? std::stoul(argv[2]) : 115200;
00031 
00032     Callbacks cbs;
00033     fcu::FlightController fcu;
00034     fcu.connect(device, baudrate);
00035 
00036     // subscribe with costum type
00037     fcu.subscribe(&Callbacks::onIdent, &cbs, 1);
00038 
00039     // Ctrl+C to quit
00040     std::cin.get();
00041 }


msp
Author(s): Christian Rauch
autogenerated on Thu Jun 20 2019 19:40:38