From 616ec0b56d9e4a8c2a019da073a70fb19de74b91 Mon Sep 17 00:00:00 2001 From: Wolfgang Hoenig Date: Thu, 27 Jul 2023 07:51:25 +0200 Subject: [PATCH 1/2] Add proper broadcast version check to support Crazyradio 2.0 broadcasting Tested with ./example_broadcast --- src/CrazyradioThread.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/CrazyradioThread.cpp b/src/CrazyradioThread.cpp index b6b1036..dbd7212 100644 --- a/src/CrazyradioThread.cpp +++ b/src/CrazyradioThread.cpp @@ -119,7 +119,9 @@ void CrazyradioThread::run() { Crazyradio radio(dev_); const auto version = radio.version(); - bool supports_broadcasts = version.second >= 0x55; + bool supports_broadcasts = + (version.first == 0x99 && version.second >= 0x55) // Crazyradio PA with latest official firmware + || (version.first == 3 && version.second >= 2); // Crazyradio 2.0; const uint8_t enableSafelink[] = {0xFF, 0x05, 1}; const uint8_t ping[] = {0xFF}; From 9b4e72d44c144838128b98c64885ac6af572f70c Mon Sep 17 00:00:00 2001 From: Wolfgang Hoenig Date: Thu, 27 Jul 2023 11:44:45 +0200 Subject: [PATCH 2/2] add example that fails with crazyradio2 --- CMakeLists.txt | 8 ++++ examples/broadcast_and_console.cpp | 63 ++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 examples/broadcast_and_console.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b22aeb7..83b28a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,6 +129,14 @@ if (BUILD_CPP_EXAMPLES) target_link_libraries(example_broadcast crazyflieLinkCpp ) + + # example_broadcast_and_console + add_executable(example_broadcast_and_console + examples/broadcast_and_console.cpp + ) + target_link_libraries(example_broadcast_and_console + crazyflieLinkCpp + ) endif() if (BUILD_PYTHON_BINDINGS) diff --git a/examples/broadcast_and_console.cpp b/examples/broadcast_and_console.cpp new file mode 100644 index 0000000..ea86eda --- /dev/null +++ b/examples/broadcast_and_console.cpp @@ -0,0 +1,63 @@ +#include +#include + +#include "crazyflieLinkCpp/Connection.h" +#include "PacketUtils.hpp" + +using namespace bitcraze::crazyflieLinkCpp; + +void run1() +{ + Connection con("radio://0/80/2M/E7E7E7E7E7"); + + const auto start = std::chrono::high_resolution_clock::now(); + while (true) { + Packet p = con.recv(0); + if (p.port() == 0 && p.channel() == 0) { + std::string str((const char*)p.payload(), (size_t)p.payloadSize()); + std::cout << str; + } + + const auto end = std::chrono::high_resolution_clock::now(); + const std::chrono::duration elapsed = end - start; + if (elapsed.count() > 5000) { + break; + } + } +} + +void run2() +{ + /* Creates a connection that will broadcast to all + * crazyflies on channel 80. Note that this requires + * updating the Crazyradio firmware from its factory version + */ + Connection broadcastConnection("radiobroadcast://*/80/2M"); + + // Requires high level commander enabled (param commander.enHighLevel == 1) + std::cout << "Taking off..." << std::endl; + broadcastConnection.send(PacketUtils::takeoffCommand(0.5f, 0.0f, 3.0f)); + std::this_thread::sleep_for(std::chrono::milliseconds(3250)); + + std::cout << "Landing..." << std::endl; + broadcastConnection.send(PacketUtils::landCommand(0.0f, 0.0f, 3.0f)); + std::this_thread::sleep_for(std::chrono::milliseconds(3250)); + + std::cout << "Stopping..." << std::endl; + broadcastConnection.send(PacketUtils::stopCommand()); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + + broadcastConnection.close(); + std::cout << "Done." << std::endl; +} + +int main() +{ + std::thread t1(run1); + std::thread t2(run2); + + t1.join(); + t2.join(); + + return 0; +} \ No newline at end of file