Advertisement
Guest User

BH19

a guest
Oct 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include "motor_control/link.hpp"
  3. #include "motor_control/reporter.hpp"
  4.  
  5. namespace mc = bw::motor_control;
  6.  
  7. int main()
  8. {
  9.     auto link = bw::motor_control::create_link();
  10.     if (!link->bind()) {
  11.         std::cerr << "Failed to bind motor link udp socket.\n"
  12.                   << "Multiple instances running?"
  13.                   << std::endl;
  14.         return 1;
  15.     }
  16.  
  17.     auto reporter = bw::motor_control::create_reporter();
  18.     if (!reporter->connect()) {
  19.         std::cerr << "Failed to connect reporter to UI" << std::endl;
  20.         return 1;
  21.     }
  22.  
  23.     while (true) {
  24.         mc::packet packet;
  25.         mc::read_result result = link->read(packet);
  26.         if (result == mc::read_result::ok) {
  27.             // Do something nice with the packet
  28.  
  29.             // Print packet
  30.             for (auto b : packet) {
  31.                 std::cout << std::hex << static_cast<unsigned>(b);
  32.             }
  33.             std::cout << std::endl;
  34.  
  35.             if (!reporter->send(packet)) {
  36.                 std::cerr << "Failed to send" << std::endl;
  37.             }
  38.         }
  39.         else if (result == mc::read_result::error) {
  40.             return 1;
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement