fcu_custom_type.cpp
Go to the documentation of this file.
1 #include <FlightController.hpp>
2 #include <iostream>
3 
4 struct MyIdent : public msp::Message {
6 
7  virtual msp::ID id() const override { return msp::ID::MSP_IDENT; }
8 
10 
11  virtual bool decode(const msp::ByteVector &data) override {
12  raw_data = data;
13  return true;
14  }
15 };
16 
17 struct Callbacks {
18  void onIdent(const MyIdent &ident) {
19  std::cout << "Raw Ident data: ";
20  for(auto d : ident.raw_data) {
21  std::cout << int(d) << " ";
22  }
23  std::cout << std::endl;
24  }
25 };
26 
27 int main(int argc, char *argv[]) {
28  const std::string device =
29  (argc > 1) ? std::string(argv[1]) : "/dev/ttyUSB0";
30  const size_t baudrate = (argc > 2) ? std::stoul(argv[2]) : 115200;
31 
32  Callbacks cbs;
34  fcu.connect(device, baudrate);
35 
36  // subscribe with costum type
37  fcu.subscribe(&Callbacks::onIdent, &cbs, 1);
38 
39  // Ctrl+C to quit
40  std::cin.get();
41 }
Message(FirmwareVariant v)
Message constructor accepting a FirmwareVariant.
Definition: Message.hpp:28
int main(int argc, char *argv[])
ID
Definition: msp_msg.hpp:30
FirmwareVariant
Enum of firmware variants.
msp::ByteVector raw_data
virtual msp::ID id() const override
get the ID of the message
virtual bool decode(const msp::ByteVector &data) override
Decode message contents from a ByteVector.
MyIdent(msp::FirmwareVariant v)
bool connect(const std::string &device, const size_t baudrate=115200, const double &timeout=0.0, const bool print_info=false)
Connects to a physical flight controller, which includes connecting the internal Client object and qu...
void onIdent(const MyIdent &ident)
std::shared_ptr< msp::client::SubscriptionBase > subscribe(void(C::*callback)(const T &), C *context, const double tp=0.0)
Register callback function that is called when type is received.


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