### Complete Transmitter Example Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt A complete example demonstrating how to initialize UAS data, populate it with information, and build Wi-Fi beacon and NaN frames for transmission. Ensure proper initialization of all relevant data fields before building frames. ```c #include #include #include int main() { ODID_UAS_Data uasData; uint8_t wifi_frame[1024]; char mac[6] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}; uint8_t counter = 0; // Initialize all data structures odid_initUasData(&uasData); // Set Basic ID uasData.BasicID[0].IDType = ODID_IDTYPE_SERIAL_NUMBER; uasData.BasicID[0].UAType = ODID_UATYPE_HELICOPTER_OR_MULTIROTOR; strncpy(uasData.BasicID[0].UASID, "DRONE123456789AB", ODID_ID_SIZE); uasData.BasicIDValid[0] = 1; // Set Location (update this in your main loop) uasData.Location.Status = ODID_STATUS_AIRBORNE; uasData.Location.Latitude = 45.539309; uasData.Location.Longitude = -122.966389; uasData.Location.AltitudeGeo = 110.0f; uasData.Location.AltitudeBaro = 100.0f; uasData.Location.Height = 80.0f; uasData.Location.HeightType = ODID_HEIGHT_REF_OVER_GROUND; uasData.Location.Direction = 45.0f; uasData.Location.SpeedHorizontal = 10.0f; uasData.Location.SpeedVertical = 0.0f; uasData.Location.HorizAccuracy = ODID_HOR_ACC_3_METER; uasData.Location.VertAccuracy = ODID_VER_ACC_3_METER; uasData.Location.TimeStamp = 123.4f; uasData.LocationValid = 1; // Set System (operator location) uasData.System.OperatorLocationType = ODID_OPERATOR_LOCATION_TYPE_TAKEOFF; uasData.System.OperatorLatitude = 45.539200; uasData.System.OperatorLongitude = -122.966200; uasData.System.OperatorAltitudeGeo = 10.0f; uasData.SystemValid = 1; // Set Operator ID uasData.OperatorID.OperatorIdType = ODID_OPERATOR_ID; strncpy(uasData.OperatorID.OperatorId, "OP123456789", ODID_ID_SIZE); uasData.OperatorIDValid = 1; // Build Wi-Fi Beacon frame int frame_len = odid_wifi_build_message_pack_beacon_frame( &uasData, mac, "DroneID", 7, 100, counter++, wifi_frame, sizeof(wifi_frame)); if (frame_len > 0) { printf("Wi-Fi Beacon frame ready: %d bytes\n", frame_len); // Transmit wifi_frame via raw 802.11 interface } // Build Wi-Fi NaN frame (alternative) frame_len = odid_wifi_build_message_pack_nan_action_frame( &uasData, mac, counter++, wifi_frame, sizeof(wifi_frame)); if (frame_len > 0) { printf("Wi-Fi NaN frame ready: %d bytes\n", frame_len); } return 0; } ``` -------------------------------- ### Install Wi-Fi Dependencies Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/README.md Install necessary development libraries for Wi-Fi support on Debian/Ubuntu systems. ```bash sudo apt-get install libgps-dev libnl-genl-3-dev ``` -------------------------------- ### Project and Library Setup Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/test/CMakeLists.txt Defines the project name and includes directories for the OpenDroneID library. This is the initial setup for the CMake build system. ```cmake project(opendroneid-core-test C CXX) include_directories(../libopendroneid) ``` -------------------------------- ### Build and Test OpenDroneID Core C on Linux Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/README.md Instructions for building the library, sample app, and unit tests on Linux. Includes dependency installation and build commands. ```bash sudo apt-get install libgps-dev libnl-genl-3-dev libgtest-dev cmake git submodule update --init mkdir build && cd build cmake ../. make -j ``` ```bash test/odidtest ctest . ``` -------------------------------- ### Google Test Policy and Setup Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/test/CMakeLists.txt Applies a CMake policy fix for Google Test and finds the GTest package. This ensures compatibility with newer CMake versions. ```cmake cmake_policy(SET CMP0054 NEW) # Fix warning in GoogleTest for CMake3.16 include(GoogleTest) find_package(GTest REQUIRED) ``` -------------------------------- ### CMake Build Configuration for OpenDroneID Core C Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/wifi/sender/CMakeLists.txt Configures the build process for the OpenDroneID Core C project. It checks for required libraries like PkgConfig, GPS, and NL (libnl-tiny or libnl-genl-3.0), sets up include directories, and defines compiler flags. Finally, it adds the 'sender' executable target and installs it. ```cmake find_package(PkgConfig) pkg_check_modules(GPS REQUIRED libgps) pkg_check_modules(NL QUIET libnl-tiny) if (NOT NL_FOUND) pkg_check_modules(NL REQUIRED libnl-genl-3.0) endif(NOT NL_FOUND) link_libraries(opendroneid m ${GPS_LIBRARIES} ${NL_LIBRARIES} ${GENL_LIBRARIES}) include_directories(../../libopendroneid ${GPS_INCLUDE_DIRS} ${NL_INCLUDE_DIRS} ${GENL_INCLUDE_DIRS}) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GPS_CFLAGS_OTHER} ${NL_CFLAGS_OTHER} ${GENL_CFLAGS_OTHER}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -Wno-unused-parameter -std=gnu99 -fno-strict-aliasing -MD -MP -D_GNU_SOURCE") if (GPS_VERSION VERSION_LESS 3.20) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLIBGPS_OLD") endif() add_executable(sender main.c) install(TARGETS sender DESTINATION bin) ``` -------------------------------- ### Configure ODID_AUTH_MAX_PAGES for Memory Reduction Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/README.md Example of how to configure the ODID_AUTH_MAX_PAGES compile-time option to reduce memory consumption when authentication messages are not used. This is done by adding -DODID_AUTH_MAX_PAGES=1 when calling cmake. ```bash cmake ../. -DODID_AUTH_MAX_PAGES=1 ``` -------------------------------- ### Google Test Dependency Management Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/test/CMakeLists.txt Finds the Google Test framework. If not found, it configures Conan to install the necessary GTest package and sets up CMake to find it. ```cmake find_package(GTest) if(NOT GTest_FOUND) # If GTest not installed on the system, install it via Conan package manager include(conan.cmake) conan_cmake_configure(REQUIRES # Requires specific package revision to avoid newer ones that need conan 1.43 and above # This one is the lastest one that supports conan 1.40.3 "gtest/1.10.0#36d26e265684c2e38d469fbf37664996" GENERATORS cmake_find_package) conan_cmake_autodetect(settings) conan_cmake_install(PATH_OR_REFERENCE . UPDATE # force conancenter to circumvent gitlab error when requesting a package lib/version (without user/channel) REMOTE conancenter SETTINGS ${settings} BUILD missing) # Tell CMake to use for the FindXXX.cmake generated by Conan instead of the default one set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_MODULE_PATH}) endif() ``` -------------------------------- ### Disable Wi-Fi Build Option Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/README.md To disable the Wi-Fi NaN example implementation, use the -DBUILD_WIFI=off parameter during the CMake build process. ```bash cmake -DBUILD_WIFI=off . ``` -------------------------------- ### MAVLink Integration and Test Executable Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/test/CMakeLists.txt Conditionally includes MAVLink libraries and adds a test executable if MAVLINK is enabled. This setup is for integrating with MAVLink for drone communication. ```cmake if(BUILD_MAVLINK) include_directories(../libmav2odid ../mavlink_c_library_v2) add_executable(odidtest opendroneid_sim.c test_inout.c main.c test_mav2odid.c) target_link_libraries(odidtest opendroneid mav2odid m) endif() ``` -------------------------------- ### Unit Test Executable Linking Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/test/CMakeLists.txt Adds a unit test executable for WiFi beacons and links it against the OpenDroneID library and Google Test. It handles different GTest target configurations. ```cmake if(GTest_FOUND) add_executable(unit_odid_wifi_beacon unit_odid_wifi_beacon.cpp) if (TARGET GTest::gtest AND TARGET GTest::gtest_main) target_link_libraries(unit_odid_wifi_beacon opendroneid GTest::gtest GTest::gtest_main) else() # Use the deprecated imported target target_link_libraries(unit_odid_wifi_beacon opendroneid GTest::GTest) endif() gtest_add_tests(TARGET unit_odid_wifi_beacon) endif() ``` -------------------------------- ### Initialize ODID_UAS_Data Container Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Initializes the primary UAS data structure and populates Basic ID, Location, and System fields with sample data. ```c #include // Initialize complete UAS data structure ODID_UAS_Data uasData; odid_initUasData(&uasData); // Set Basic ID data uasData.BasicID[0].IDType = ODID_IDTYPE_SERIAL_NUMBER; uasData.BasicID[0].UAType = ODID_UATYPE_HELICOPTER_OR_MULTIROTOR; strncpy(uasData.BasicID[0].UASID, "ABCD1234567890", ODID_ID_SIZE); uasData.BasicIDValid[0] = 1; // Set Location data uasData.Location.Status = ODID_STATUS_AIRBORNE; uasData.Location.Latitude = 45.539309; uasData.Location.Longitude = -122.966389; uasData.Location.AltitudeGeo = 110.0f; uasData.Location.Height = 80.0f; uasData.Location.HeightType = ODID_HEIGHT_REF_OVER_GROUND; uasData.Location.Direction = 215.7f; uasData.Location.SpeedHorizontal = 5.4f; uasData.Location.SpeedVertical = 2.5f; uasData.Location.TimeStamp = 360.52f; uasData.LocationValid = 1; // Set System data (operator location) uasData.System.OperatorLocationType = ODID_OPERATOR_LOCATION_TYPE_TAKEOFF; uasData.System.OperatorLatitude = 45.539400; uasData.System.OperatorLongitude = -122.966500; uasData.System.OperatorAltitudeGeo = 20.5f; uasData.SystemValid = 1; ``` -------------------------------- ### Initialize MAVLink to Open Drone ID Converter Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Initializes the MAVLink to Open Drone ID converter. This function sets up message scheduling and encoding buffers, preparing the system for flight controller integration. Call this before using other MAVLink integration functions. ```c #include "mav2odid.h" mav2odid_t m2o; if (m2o_init(&m2o) == ODID_SUCCESS) { printf("MAVLink to ODID converter initialized\n"); // Ready to receive MAVLink messages } ``` -------------------------------- ### Build NaN Synchronization Beacon Frame Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Constructs a NaN synchronization beacon frame. This frame must be transmitted before the NaN action frame to establish the NaN cluster. The MAC address is required for synchronization. ```c #include uint8_t sync_beacon[256]; char mac_address[6] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}; int sync_len = odid_wifi_build_nan_sync_beacon_frame( mac_address, sync_beacon, sizeof(sync_beacon) ); if (sync_len > 0) { printf("NaN sync beacon: %d bytes\n", sync_len); // Transmit sync_beacon before action frame } ``` -------------------------------- ### MAVLink Integration Functions Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Functions for initializing the MAVLink converter, parsing MAVLink streams, and managing message cycles for different transmission methods. ```APIDOC ## m2o_init ### Description Initializes the MAVLink to Open Drone ID converter, setting up message scheduling and encoding buffers. ### Response - **result** (int) - Returns ODID_SUCCESS on success. ## m2o_parseMavlink ### Description Parses incoming MAVLink byte stream, detecting and converting Open Drone ID MAVLink messages. ### Parameters - **m2o** (mav2odid_t*) - Required - Pointer to the converter structure. - **mavlink_byte** (uint8_t) - Required - Single byte from the MAVLink stream. ### Response - **msg_type** (ODID_messagetype_t) - Returns the parsed message type or ODID_MESSAGETYPE_INVALID. ## m2o_cycleMessages ### Description Cycles through stored messages for Bluetooth Legacy Advertising. ### Parameters - **m2o** (mav2odid_t*) - Required - Pointer to the converter structure. - **broadcast_data** (uint8_t*) - Required - Buffer to store the message for transmission. ## m2o_collectMessagePack ### Description Collects all valid encoded messages into a single message pack for Bluetooth Long Range or Wi-Fi transmission. ### Parameters - **m2o** (mav2odid_t*) - Required - Pointer to the converter structure. ``` -------------------------------- ### Configure MAVLINK_COMM_NUM_BUFFERS for Memory Reduction Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/README.md Instructions for reducing memory usage when including MAVLink by defining MAVLINK_COMM_NUM_BUFFERS to be equal to 1, before including mavlink_types.h. This is relevant if MAVLink's virtual channel functionality is not used. ```c #define MAVLINK_COMM_NUM_BUFFERS 1 #include "mavlink_types.h" ``` -------------------------------- ### Build Wi-Fi NaN Action Frame Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Constructs a complete Wi-Fi Neighbor Awareness Networking (NaN) action frame containing all drone ID messages. This frame is ready for raw frame transmission. Ensure the UAS data and MAC address are populated correctly. ```c #include ODID_UAS_Data uasData; uint8_t frame_buffer[1024]; char mac_address[6] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}; static uint8_t send_counter = 0; // Populate uasData with current drone state... // (See ODID_UAS_Data example above) int frame_len = odid_wifi_build_message_pack_nan_action_frame( &uasData, mac_address, send_counter++, frame_buffer, sizeof(frame_buffer) ); if (frame_len > 0) { printf("NaN frame built: %d bytes\n", frame_len); // Transmit frame_buffer via raw Wi-Fi interface } ``` -------------------------------- ### Build Wi-Fi Beacon Frame with Drone ID Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Constructs a Wi-Fi Beacon frame with embedded drone ID messages in a vendor-specific information element. This is suitable for broadcast on standard Wi-Fi channels. The SSID and beacon interval can be configured. ```c #include ODID_UAS_Data uasData; uint8_t frame_buffer[1024]; char mac_address[6] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}; char ssid[] = "DroneID_ABC123"; static uint8_t send_counter = 0; // Populate uasData with current drone state... int frame_len = odid_wifi_build_message_pack_beacon_frame( &uasData, mac_address, ssid, strlen(ssid), 100, // Beacon interval in TUs (102.4ms per TU) send_counter++, frame_buffer, sizeof(frame_buffer) ); if (frame_len > 0) { printf("Beacon frame built: %d bytes, SSID: %s\n", frame_len, ssid); // Transmit frame_buffer via raw Wi-Fi interface } ``` -------------------------------- ### Export UAS Data as JSON Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Exports all UAS data to a JSON-formatted string. Ensure the buffer is large enough to hold the JSON output. ```c #include ODID_UAS_Data uasData; char json_buffer[4096]; // Populate uasData... odid_initUasData(&uasData); // ... set all fields ... drone_export_gps_data(&uasData, json_buffer, sizeof(json_buffer)); printf("%s\n", json_buffer); /* Output format: { "Version": "1.1", "Response": { "BasicID": { "UAType0": 2, "IDType0": 2, "UASID0": "12345678901234567890", }, "Location": { "Status": 2, "Latitude": 45.539309, "Longitude": -122.966389, ... }, ... } } */ ``` -------------------------------- ### Nominal OpenDroneID Data Structures Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/README.md These are the nominal (non-encoded) data structures used by the OpenDroneID SDK. ```c ODID_BasicID_data ODID_Location_data ODID_Auth_data ODID_SelfID_data ODID_System_data ODID_OperatorID_data ODID_MessagePack_data ``` -------------------------------- ### Encoded OpenDroneID Data Structures Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/README.md These are the encoded data structures that the SDK will encode to or decode from. ```c ODID_BasicID_encoded ODID_Location_encoded ODID_Auth_encoded ODID_SelfID_encoded ODID_System_encoded ODID_OperatorID_encoded ODID_MessagePack_encoded ``` -------------------------------- ### Encode System Data Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Encodes system information including operator location, EU classification, and area operation parameters. Set OperatorLocationType, ClassificationType, coordinates, AreaCount, AreaRadius, AreaCeiling, AreaFloor, CategoryEU, ClassEU, OperatorAltitudeGeo, and Timestamp. ```c #include ODID_System_data system_data; ODID_System_encoded system_enc; odid_initSystemData(&system_data); system_data.OperatorLocationType = ODID_OPERATOR_LOCATION_TYPE_TAKEOFF; system_data.ClassificationType = ODID_CLASSIFICATION_TYPE_EU; system_data.OperatorLatitude = 45.539400; system_data.OperatorLongitude = -122.966500; system_data.AreaCount = 35; // Number of drones in group system_data.AreaRadius = 75; // meters system_data.AreaCeiling = 176.9f; // meters system_data.AreaFloor = 41.7f; // meters system_data.CategoryEU = ODID_CATEGORY_EU_SPECIFIC; system_data.ClassEU = ODID_CLASS_EU_CLASS_3; system_data.OperatorAltitudeGeo = 20.5f; system_data.Timestamp = 28000000; int result = encodeSystemMessage(&system_enc, &system_data); if (result == ODID_SUCCESS) { printf("System: Operator at %.7f, %.7f, EU Class %d\n", system_data.OperatorLatitude, system_data.OperatorLongitude, system_data.ClassEU); } ``` -------------------------------- ### encodeSystemMessage - Encode Operator/System Data Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Encodes system information including operator location, EU classification category/class, and area operation parameters for swarm/group operations. ```APIDOC ## encodeSystemMessage - Encode Operator/System Data ### Description Encodes system information including operator location, EU classification category/class, and area operation parameters for swarm/group operations. ### Method (Not specified, likely a C function call) ### Endpoint (Not applicable, C function) ### Parameters (Not specified in detail, but implies `ODID_System_encoded*` and `ODID_System_data*` structs are used) ### Request Example ```c #include ODID_System_data system_data; ODID_System_encoded system_enc; odid_initSystemData(&system_data); system_data.OperatorLocationType = ODID_OPERATOR_LOCATION_TYPE_TAKEOFF; system_data.ClassificationType = ODID_CLASSIFICATION_TYPE_EU; system_data.OperatorLatitude = 45.539400; system_data.OperatorLongitude = -122.966500; system_data.AreaCount = 35; // Number of drones in group system_data.AreaRadius = 75; // meters system_data.AreaCeiling = 176.9f; // meters system_data.AreaFloor = 41.7f; // meters system_data.CategoryEU = ODID_CATEGORY_EU_SPECIFIC; system_data.ClassEU = ODID_CLASS_EU_CLASS_3; system_data.OperatorAltitudeGeo = 20.5f; system_data.Timestamp = 28000000; int result = encodeSystemMessage(&system_enc, &system_data); if (result == ODID_SUCCESS) { printf("System: Operator at %.7f, %.7f, EU Class %d\n", system_data.OperatorLatitude, system_data.OperatorLongitude, system_data.ClassEU); } ``` ### Response (Not specified, but the function returns an integer status code, likely ODID_SUCCESS on success.) #### Success Response (ODID_SUCCESS) (Details not specified) #### Response Example (See Request Example for usage) ``` -------------------------------- ### Encode Authentication Data Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Encodes authentication messages, supporting multi-page signatures. Page 0 contains metadata, and subsequent pages hold signature data. Ensure correct initialization of AuthType, DataPage, LastPageIndex, Length, and Timestamp. ```c #include ODID_Auth_data auth0, auth1; ODID_Auth_encoded auth0_enc, auth1_enc; // Page 0 - contains metadata odid_initAuthData(&auth0); auth0.AuthType = ODID_AUTH_UAS_ID_SIGNATURE; auth0.DataPage = 0; auth0.LastPageIndex = 1; // Total 2 pages (0 and 1) auth0.Length = 40; // Total auth data bytes auth0.Timestamp = 28000000; // Seconds since 00:00:00 01/01/2019 UTC memcpy(auth0.AuthData, "12345678901234567", ODID_AUTH_PAGE_ZERO_DATA_SIZE); // Page 1 - additional signature data odid_initAuthData(&auth1); auth1.AuthType = ODID_AUTH_UAS_ID_SIGNATURE; auth1.DataPage = 1; memcpy(auth1.AuthData, "12345678901234567890123", ODID_AUTH_PAGE_NONZERO_DATA_SIZE); // Encode both pages if (encodeAuthMessage(&auth0_enc, &auth0) == ODID_SUCCESS && encodeAuthMessage(&auth1_enc, &auth1) == ODID_SUCCESS) { printf("Authentication encoded: %d pages, %d total bytes\n", auth0.LastPageIndex + 1, auth0.Length); } ``` -------------------------------- ### Cycle Messages for BT Legacy Advertising Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Cycles through stored Open Drone ID messages according to a schedule, returning one message at a time. This is suitable for Bluetooth Legacy Advertising, which supports only one message per advertisement. Call this function periodically. ```c #include "mav2odid.h" mav2odid_t m2o; uint8_t broadcast_data[ODID_MESSAGE_SIZE]; m2o_init(&m2o); // ... parse MAVLink messages ... // Call periodically (faster than BcMinStaticRefreshRate / DRONEID_SCHEDULER_SIZE) if (m2o_cycleMessages(&m2o, broadcast_data) == ODID_SUCCESS) { // Transmit broadcast_data via Bluetooth Legacy Advertising bluetooth_advertise(broadcast_data, ODID_MESSAGE_SIZE); } ``` -------------------------------- ### OpenDroneID Encoding Functions Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/README.md Functions to encode OpenDroneID data structures into their respective encoded formats. ```c int encodeBasicIDMessage(ODID_BasicID_encoded *outEncoded, const ODID_BasicID_data *inData); int encodeLocationMessage(ODID_Location_encoded *outEncoded, const ODID_Location_data *inData); int encodeAuthMessage(ODID_Auth_encoded *outEncoded, const ODID_Auth_data *inData); int encodeSelfIDMessage(ODID_SelfID_encoded *outEncoded, const ODID_SelfID_data *inData); int encodeSystemMessage(ODID_System_encoded *outEncoded, const ODID_System_data *inData); int encodeOperatorIDMessage(ODID_OperatorID_encoded *outEncoded, const ODID_OperatorID_data *inData); int encodeMessagePack(ODID_MessagePack_encoded *outEncoded, const ODID_MessagePack_data *inData); ``` -------------------------------- ### OpenDroneID Decoding Functions Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/README.md Functions to decode encoded OpenDroneID data structures back into their nominal data formats. ```c int decodeBasicIDMessage(ODID_BasicID_data *outData, const ODID_BasicID_encoded *inEncoded); int decodeLocationMessage(ODID_Location_data *outData, const ODID_Location_encoded *inEncoded); int decodeAuthMessage(ODID_Auth_data *outData, const ODID_Auth_encoded *inEncoded); int decodeSelfIDMessage(ODID_SelfID_data *outData, const ODID_SelfID_encoded *inEncoded); int decodeSystemMessage(ODID_System_data *outData, const ODID_System_encoded *inEncoded); int decodeOperatorIDMessage(ODID_OperatorID_data *outData, const ODID_OperatorID_encoded *inEncoded); int decodeMessagePack(ODID_UAS_Data *uasData, const ODID_MessagePack_encoded *pack); ``` -------------------------------- ### encodeSelfIDMessage - Encode Description Text Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Encodes a free-text description message allowing operators to provide context about their flight operation (up to 23 characters). ```APIDOC ## encodeSelfIDMessage - Encode Description Text ### Description Encodes a free-text description message allowing operators to provide context about their flight operation (up to 23 characters). ### Method (Not specified, likely a C function call) ### Endpoint (Not applicable, C function) ### Parameters (Not specified in detail, but implies `ODID_SelfID_encoded*` and `ODID_SelfID_data*` structs are used) ### Request Example ```c #include ODID_SelfID_data selfId; ODID_SelfID_encoded selfId_enc; odid_initSelfIDData(&selfId); selfId.DescType = ODID_DESC_TYPE_TEXT; strncpy(selfId.Desc, "DronesRUS: Real Estate", ODID_STR_SIZE); int result = encodeSelfIDMessage(&selfId_enc, &selfId); if (result == ODID_SUCCESS) { printf("Self ID: %s\n", selfId.Desc); } ``` ### Response (Not specified, but the function returns an integer status code, likely ODID_SUCCESS on success.) #### Success Response (ODID_SUCCESS) (Details not specified) #### Response Example (See Request Example for usage) ``` -------------------------------- ### Accuracy Helper Functions Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Utility functions to convert between horizontal accuracy in meters and ODID enum values. ```APIDOC ## createEnumHorizontalAccuracy ### Description Converts a horizontal accuracy value in meters to the appropriate ODID enum value. ### Parameters - **gps_accuracy** (float) - Required - Accuracy in meters. ### Response - **accuracy_enum** (ODID_Horizontal_accuracy_t) - The corresponding enum value. ## decodeHorizontalAccuracy ### Description Converts an ODID horizontal accuracy enum back to the maximum accuracy value in meters. ### Parameters - **accuracy_enum** (ODID_Horizontal_accuracy_t) - Required - The enum value to decode. ### Response - **accuracy_meters** (float) - The maximum accuracy in meters. ``` -------------------------------- ### encodeAuthMessage - Encode Authentication Data Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Encodes authentication messages supporting multi-page signatures for cryptographic verification. Page 0 contains metadata, and subsequent pages contain signature data. ```APIDOC ## encodeAuthMessage - Encode Authentication Data ### Description Encodes authentication messages supporting multi-page signatures for cryptographic verification, with page 0 containing metadata (timestamp, length, page count) and subsequent pages containing signature data. ### Method (Not specified, likely a C function call) ### Endpoint (Not applicable, C function) ### Parameters (Not specified in detail, but implies `ODID_Auth_encoded*` and `ODID_Auth_data*` structs are used) ### Request Example ```c #include ODID_Auth_data auth0, auth1; ODID_Auth_encoded auth0_enc, auth1_enc; // Page 0 - contains metadata odid_initAuthData(&auth0); auth0.AuthType = ODID_AUTH_UAS_ID_SIGNATURE; auth0.DataPage = 0; auth0.LastPageIndex = 1; // Total 2 pages (0 and 1) auth0.Length = 40; // Total auth data bytes auth0.Timestamp = 28000000; // Seconds since 00:00:00 01/01/2019 UTC memcpy(auth0.AuthData, "12345678901234567", ODID_AUTH_PAGE_ZERO_DATA_SIZE); // Page 1 - additional signature data odid_initAuthData(&auth1); auth1.AuthType = ODID_AUTH_UAS_ID_SIGNATURE; auth1.DataPage = 1; memcpy(auth1.AuthData, "12345678901234567890123", ODID_AUTH_PAGE_NONZERO_DATA_SIZE); // Encode both pages if (encodeAuthMessage(&auth0_enc, &auth0) == ODID_SUCCESS && encodeAuthMessage(&auth1_enc, &auth1) == ODID_SUCCESS) { printf("Authentication encoded: %d pages, %d total bytes\n", auth0.LastPageIndex + 1, auth0.Length); } ``` ### Response (Not specified, but the function returns an integer status code, likely ODID_SUCCESS on success.) #### Success Response (ODID_SUCCESS) (Details not specified) #### Response Example (See Request Example for usage) ``` -------------------------------- ### odid_wifi_receive_message_pack_nan_action_frame Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Parses and validates a received Wi-Fi NaN action frame, extracting the drone ID messages and the transmitter's MAC address. ```APIDOC ## odid_wifi_receive_message_pack_nan_action_frame ### Description Parses and validates a received Wi-Fi NaN action frame, extracting the drone ID messages and the transmitter's MAC address. ### Parameters - **uasData** (ODID_UAS_Data*) - Required - Pointer to the structure to store parsed drone data. - **sender_mac** (char*) - Required - Buffer to store the transmitter's MAC address. - **received_frame** (uint8_t*) - Required - Buffer containing the received Wi-Fi frame. - **frame_len** (size_t) - Required - Length of the received frame. ### Response - **result** (int) - Returns 0 on success. ``` -------------------------------- ### OpenDroneID Encoding Functions Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/README.md Functions used to encode nominal data structures into encoded formats for transmission. ```APIDOC ## Encoding Functions ### Description These functions convert nominal (non-encoded) data structures into encoded structures ready for broadcast. ### Functions - **encodeBasicIDMessage**(ODID_BasicID_encoded *outEncoded, const ODID_BasicID_data *inData) - **encodeLocationMessage**(ODID_Location_encoded *outEncoded, const ODID_Location_data *inData) - **encodeAuthMessage**(ODID_Auth_encoded *outEncoded, const ODID_Auth_data *inData) - **encodeSelfIDMessage**(ODID_SelfID_encoded *outEncoded, const ODID_SelfID_data *inData) - **encodeSystemMessage**(ODID_System_encoded *outEncoded, const ODID_System_data *inData) - **encodeOperatorIDMessage**(ODID_OperatorID_encoded *outEncoded, const ODID_OperatorID_data *inData) - **encodeMessagePack**(ODID_MessagePack_encoded *outEncoded, const ODID_MessagePack_data *inData) ``` -------------------------------- ### Parse Wi-Fi NaN Action Frame Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Parses and validates a received Wi-Fi NaN action frame. Extracts drone ID messages and the transmitter's MAC address. Ensure `received_frame` and `frame_len` are correctly populated before calling. ```c #include ODID_UAS_Data uasData; uint8_t received_frame[1024]; size_t frame_len; // Set from received data char sender_mac[6]; int result = odid_wifi_receive_message_pack_nan_action_frame( &uasData, sender_mac, received_frame, frame_len ); if (result == 0) { printf("Received from MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", (uint8_t)sender_mac[0], (uint8_t)sender_mac[1], (uint8_t)sender_mac[2], (uint8_t)sender_mac[3], (uint8_t)sender_mac[4], (uint8_t)sender_mac[5]); if (uasData.BasicIDValid[0]) printf("Drone ID: %s\n", uasData.BasicID[0].UASID); if (uasData.LocationValid) printf("Position: %.7f, %.7f\n", uasData.Location.Latitude, uasData.Location.Longitude); } ``` -------------------------------- ### OpenDroneID Decoding Functions Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/README.md Functions used to decode encoded data structures back into nominal formats. ```APIDOC ## Decoding Functions ### Description These functions convert encoded data structures back into nominal (non-encoded) data structures for application use. ### Functions - **decodeBasicIDMessage**(ODID_BasicID_data *outData, const ODID_BasicID_encoded *inEncoded) - **decodeLocationMessage**(ODID_Location_data *outData, const ODID_Location_encoded *inEncoded) - **decodeAuthMessage**(ODID_Auth_data *outData, const ODID_Auth_encoded *inEncoded) - **decodeSelfIDMessage**(ODID_SelfID_data *outData, const ODID_SelfID_encoded *inEncoded) - **decodeSystemMessage**(ODID_System_data *outData, const ODID_System_encoded *inEncoded) - **decodeOperatorIDMessage**(ODID_OperatorID_data *outData, const ODID_OperatorID_encoded *inEncoded) - **decodeMessagePack**(ODID_UAS_Data *uasData, const ODID_MessagePack_encoded *pack) ``` -------------------------------- ### Disable MAVLink Build Option Source: https://github.com/opendroneid/opendroneid-core-c/blob/master/README.md To disable MAVLink support, use the -DBUILD_MAVLINK=off parameter during the CMake build process. ```bash cmake -DBUILD_MAVLINK=off . ``` -------------------------------- ### Parse MAVLink Stream Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Parses an incoming MAVLink byte stream to detect and convert Open Drone ID MAVLink messages. This function should be called for each byte received from the MAVLink source (e.g., UART). Ensure `m2o_init` is called first. ```c #include "mav2odid.h" mav2odid_t m2o; m2o_init(&m2o); // Process incoming MAVLink bytes (e.g., from UART) uint8_t mavlink_byte; while (read_byte(&mavlink_byte)) { // Your UART read function ODID_messagetype_t msg_type = m2o_parseMavlink(&m2o, mavlink_byte); if (msg_type != ODID_MESSAGETYPE_INVALID) { printf("Parsed MAVLink message type: %d\n", msg_type); // Messages are now stored in m2o structure // Ready for broadcast via m2o_cycleMessages or m2o_collectMessagePack } } ``` -------------------------------- ### Encode Self-ID Description Text Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Encodes a free-text description for flight operations, limited to 23 characters. Initialize DescType to ODID_DESC_TYPE_TEXT and use strncpy to copy the description into the Desc field. ```c #include ODID_SelfID_data selfId; ODID_SelfID_encoded selfId_enc; odid_initSelfIDData(&selfId); selfId.DescType = ODID_DESC_TYPE_TEXT; strncpy(selfId.Desc, "DronesRUS: Real Estate", ODID_STR_SIZE); int result = encodeSelfIDMessage(&selfId_enc, &selfId); if (result == ODID_SUCCESS) { printf("Self ID: %s\n", selfId.Desc); } ``` -------------------------------- ### Encode Location Message Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Encodes drone position, velocity, and accuracy data into a compressed format for transmission. ```c #include ODID_Location_data location; ODID_Location_encoded location_enc; // Initialize and populate Location odid_initLocationData(&location); location.Status = ODID_STATUS_AIRBORNE; location.Direction = 215.7f; // degrees (0-360) location.SpeedHorizontal = 5.4f; // m/s location.SpeedVertical = 5.25f; // m/s location.Latitude = 45.539309; // WGS84 degrees location.Longitude = -122.966389; // WGS84 degrees location.AltitudeBaro = 100.0f; // meters, barometric location.AltitudeGeo = 110.0f; // meters, WGS84-HAE location.HeightType = ODID_HEIGHT_REF_OVER_GROUND; location.Height = 80.0f; // meters above ground location.HorizAccuracy = createEnumHorizontalAccuracy(2.5f); // 2.5m accuracy location.VertAccuracy = createEnumVerticalAccuracy(0.5f); // 0.5m accuracy location.BaroAccuracy = createEnumVerticalAccuracy(1.5f); location.SpeedAccuracy = createEnumSpeedAccuracy(0.5f); location.TSAccuracy = createEnumTimestampAccuracy(0.2f); location.TimeStamp = 360.52f; // seconds after the hour // Encode the message int result = encodeLocationMessage(&location_enc, &location); if (result == ODID_SUCCESS) { printf("Location: %.7f, %.7f at %.1fm\n", location.Latitude, location.Longitude, location.AltitudeGeo); } ``` -------------------------------- ### Bundle Multiple Encoded Messages Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Combines multiple encoded OpenDroneID messages into a single message pack for transmission. Supports up to 9 messages per pack. Ensure all individual messages are encoded before packing. ```c #include ODID_MessagePack_data pack; ODID_MessagePack_encoded pack_enc; // Assume all *_enc messages are already encoded odid_initMessagePackData(&pack); pack.MsgPackSize = 7; memcpy(&pack.Messages[0], &basicId_enc, ODID_MESSAGE_SIZE); memcpy(&pack.Messages[1], &location_enc, ODID_MESSAGE_SIZE); memcpy(&pack.Messages[2], &auth0_enc, ODID_MESSAGE_SIZE); memcpy(&pack.Messages[3], &auth1_enc, ODID_MESSAGE_SIZE); memcpy(&pack.Messages[4], &selfId_enc, ODID_MESSAGE_SIZE); memcpy(&pack.Messages[5], &system_enc, ODID_MESSAGE_SIZE); memcpy(&pack.Messages[6], &operatorId_enc, ODID_MESSAGE_SIZE); int result = encodeMessagePack(&pack_enc, &pack); if (result == ODID_SUCCESS) { printf("Message pack encoded: %d messages\n", pack.MsgPackSize); // pack_enc ready for BT5 Long Range or Wi-Fi NaN transmission } ``` -------------------------------- ### Collect All Messages into Pack for BT Long Range/Wi-Fi Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Collects all valid encoded Open Drone ID messages into a single message pack. This pack can then be transmitted via Bluetooth 5 Long Range or Wi-Fi NaN. Ensure MAVLink messages are parsed before calling. ```c #include "mav2odid.h" mav2odid_t m2o; m2o_init(&m2o); // ... parse MAVLink messages ... if (m2o_collectMessagePack(&m2o) == ODID_SUCCESS) { printf("Message pack ready: %d messages\n", m2o.messagePackEnc.MsgPackSize); // Transmit m2o.messagePackEnc via BT5 Long Range or Wi-Fi NaN uint8_t *pack_data = (uint8_t *)&m2o.messagePackEnc; size_t pack_size = 3 + m2o.messagePackEnc.MsgPackSize * ODID_MESSAGE_SIZE; bluetooth_long_range_transmit(pack_data, pack_size); } ``` -------------------------------- ### encodeMessagePack - Bundle Multiple Messages Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Combines multiple encoded messages into a single message pack for transmission via Bluetooth Long Range or Wi-Fi NaN, supporting up to 9 messages per pack. ```APIDOC ## encodeMessagePack - Bundle Multiple Messages ### Description Combines multiple encoded messages into a single message pack for transmission via Bluetooth Long Range or Wi-Fi NaN, supporting up to 9 messages per pack. ### Method (Not specified, likely a C function call) ### Endpoint (Not applicable, C function) ### Parameters (Not specified in detail, but implies `ODID_MessagePack_encoded*` and `ODID_MessagePack_data*` structs are used) ### Request Example ```c #include ODID_MessagePack_data pack; ODID_MessagePack_encoded pack_enc; // Assume all *_enc messages are already encoded odid_initMessagePackData(&pack); pack.MsgPackSize = 7; memcpy(&pack.Messages[0], &basicId_enc, ODID_MESSAGE_SIZE); memcpy(&pack.Messages[1], &location_enc, ODID_MESSAGE_SIZE); memcpy(&pack.Messages[2], &auth0_enc, ODID_MESSAGE_SIZE); memcpy(&pack.Messages[3], &auth1_enc, ODID_MESSAGE_SIZE); memcpy(&pack.Messages[4], &selfId_enc, ODID_MESSAGE_SIZE); memcpy(&pack.Messages[5], &system_enc, ODID_MESSAGE_SIZE); memcpy(&pack.Messages[6], &operatorId_enc, ODID_MESSAGE_SIZE); int result = encodeMessagePack(&pack_enc, &pack); if (result == ODID_SUCCESS) { printf("Message pack encoded: %d messages\n", pack.MsgPackSize); // pack_enc ready for BT5 Long Range or Wi-Fi NaN transmission } ``` ### Response (Not specified, but the function returns an integer status code, likely ODID_SUCCESS on success.) #### Success Response (ODID_SUCCESS) (Details not specified) #### Response Example (See Request Example for usage) ``` -------------------------------- ### Encode Basic ID Message Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Encodes drone identification data into a packed format suitable for broadcast transmission. ```c #include ODID_BasicID_data basicId; ODID_BasicID_encoded basicId_enc; // Initialize and populate Basic ID odid_initBasicIDData(&basicId); basicId.IDType = ODID_IDTYPE_CAA_REGISTRATION_ID; basicId.UAType = ODID_UATYPE_HELICOPTER_OR_MULTIROTOR; strncpy(basicId.UASID, "12345678901234567890", ODID_ID_SIZE); // Encode the message int result = encodeBasicIDMessage(&basicId_enc, &basicId); if (result == ODID_SUCCESS) { printf("Basic ID encoded successfully, %d bytes\n", ODID_MESSAGE_SIZE); // basicId_enc is ready for broadcast via Bluetooth or Wi-Fi } ``` -------------------------------- ### Decode Any OpenDroneID Message Source: https://context7.com/opendroneid/opendroneid-core-c/llms.txt Use this function to parse any encoded OpenDroneID message. It automatically detects the message type and decodes it into the appropriate fields of the UAS data structure. Ensure UAS data structure is initialized before calling. ```c #include ODID_UAS_Data uasData; uint8_t received_message[ODID_MESSAGE_SIZE]; // From Bluetooth/Wi-Fi // Initialize storage odid_initUasData(&uasData); // Decode message - automatically determines type ODID_messagetype_t msgType = decodeOpenDroneID(&uasData, received_message); switch (msgType) { case ODID_MESSAGETYPE_BASIC_ID: printf("Received Basic ID: %s (type %d)\n", uasData.BasicID[0].UASID, uasData.BasicID[0].IDType); break; case ODID_MESSAGETYPE_LOCATION: printf("Received Location: %.7f, %.7f\n", uasData.Location.Latitude, uasData.Location.Longitude); break; case ODID_MESSAGETYPE_AUTH: printf("Received Auth page\n"); break; case ODID_MESSAGETYPE_SELF_ID: printf("Received Self ID: %s\n", uasData.SelfID.Desc); break; case ODID_MESSAGETYPE_SYSTEM: printf("Received System: Operator at %.7f, %.7f\n", uasData.System.OperatorLatitude, uasData.System.OperatorLongitude); break; case ODID_MESSAGETYPE_OPERATOR_ID: printf("Received Operator ID: %s\n", uasData.OperatorID.OperatorId); break; case ODID_MESSAGETYPE_PACKED: printf("Received Message Pack\n"); break; case ODID_MESSAGETYPE_INVALID: printf("Invalid message received\n"); break; } ```