From 1a307252da5df81ff112a6c67c9c4ed2e5e31ca4 Mon Sep 17 00:00:00 2001 From: TheJackiMonster Date: Thu, 7 Sep 2023 22:52:32 +0200 Subject: [PATCH 1/3] Fix handling buffers with text Signed-off-by: TheJackiMonster --- interface_lib/src/device3.c | 4 +++- interface_lib/src/device4.c | 28 +++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/interface_lib/src/device3.c b/interface_lib/src/device3.c index cc31169..8a7334a 100644 --- a/interface_lib/src/device3.c +++ b/interface_lib/src/device3.c @@ -239,7 +239,7 @@ device3_type* device3_open(device3_event_callback callback) { uint32_t calibration_len = 0; if (recv_payload_msg(device, DEVICE3_MSG_GET_CAL_DATA_LENGTH, 4, (uint8_t*) &calibration_len)) { - char* calibration_data = malloc(calibration_len); + char* calibration_data = malloc(calibration_len + 1); uint32_t position = 0; while (position < calibration_len) { @@ -257,6 +257,8 @@ device3_type* device3_open(device3_event_callback callback) { position += next; } + + calibration_data[calibration_len] = '\0'; struct json_tokener* tokener = json_tokener_new(); struct json_object* root = json_tokener_parse_ex(tokener, calibration_data, calibration_len); diff --git a/interface_lib/src/device4.c b/interface_lib/src/device4.c index e0eb90d..fe4a26c 100644 --- a/interface_lib/src/device4.c +++ b/interface_lib/src/device4.c @@ -111,16 +111,19 @@ static bool recv_payload_msg(device4_type* device, uint16_t msgid, uint8_t len, } if (packet.head != PACKET_HEAD) { + perror("ERROR: invalid payload received\n"); return false; } if (packet.msgid != msgid) { + perror("ERROR: unexpected payload received\n"); return false; } - - const uint8_t status = packet.data[0]; + const uint8_t status = packet.data[0]; + if (status != 0) { + perror("ERROR: payload status failed\n"); return false; } @@ -153,6 +156,7 @@ static bool do_payload_action(device4_type* device, uint16_t msgid, uint8_t len, attempts--; } + perror("ERROR: payload status failed\n"); return false; } @@ -483,6 +487,22 @@ bool device4_update_mcu_firmware(device4_type* device, const char* path) { goto cleanup; } + if (!send_payload_action(device, DEVICE4_MSG_R_ACTIVATION_TIME, 0, NULL)) { + perror("Requesting activation time failed!\n"); + return device; + } + + uint8_t activated; + if (!recv_payload_msg(device, DEVICE4_MSG_R_ACTIVATION_TIME, 1, &activated)) { + perror("Receiving activation time failed!\n"); + return device; + } + + if (!activated) { + perror("Device is not activated!\n"); + goto jump_to_app; + } + size_t offset = 0; while (offset < firmware_len) { @@ -500,10 +520,12 @@ bool device4_update_mcu_firmware(device4_type* device, const char* path) { msgid = DEVICE4_MSG_W_UPDATE_MCU_APP_FW_TRANSMIT; } - if (!do_payload_action(device, msgid, len, firmware)) { + if (!do_payload_action(device, msgid, len, firmware + offset)) { perror("Failed sending firmware upload!\n"); goto jump_to_app; } + + offset += len; } printf("Finish upload!\n"); From 5e9d4d036bfee71e377b2e8f1b392bad6689c6b0 Mon Sep 17 00:00:00 2001 From: TheJackiMonster Date: Thu, 7 Sep 2023 23:02:59 +0200 Subject: [PATCH 2/3] Move Fusion submodule Signed-off-by: TheJackiMonster --- .gitmodules | 2 +- CMakeLists.txt | 10 +--------- interface_lib/CMakeLists.txt | 4 ++++ {modules => interface_lib/modules}/Fusion | 0 4 files changed, 6 insertions(+), 10 deletions(-) rename {modules => interface_lib/modules}/Fusion (100%) diff --git a/.gitmodules b/.gitmodules index 5192490..56682d2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "modules/Fusion"] - path = modules/Fusion + path = interface_lib/modules/Fusion url = https://github.com/TheJackiMonster/Fusion.git diff --git a/CMakeLists.txt b/CMakeLists.txt index c072cd7..c47dfa4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,10 +3,6 @@ project(nrealAirLinuxDriver C) set(CMAKE_C_STANDARD 17) -add_subdirectory(modules/Fusion/Fusion) -set(FUSION_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/modules/Fusion) -set(FUSION_LIBRARY Fusion) - add_subdirectory(interface_lib) add_subdirectory(examples) @@ -14,14 +10,10 @@ add_executable(nrealAirLinuxDriver src/driver.c ) -target_include_directories(nrealAirLinuxDriver - SYSTEM BEFORE PRIVATE ${FUSION_INCLUDE_DIR} -) - target_include_directories(nrealAirLinuxDriver BEFORE PUBLIC ${NRA_INCLUDE_DIR} ) target_link_libraries(nrealAirLinuxDriver - ${NRA_LIBRARY} ${FUSION_LIBRARY} + ${NRA_LIBRARY} ) \ No newline at end of file diff --git a/interface_lib/CMakeLists.txt b/interface_lib/CMakeLists.txt index fec5dd4..c787c1f 100644 --- a/interface_lib/CMakeLists.txt +++ b/interface_lib/CMakeLists.txt @@ -6,6 +6,10 @@ set(CMAKE_C_STANDARD 17) find_package(hidapi REQUIRED) find_package(json-c REQUIRED) +add_subdirectory(modules/Fusion/Fusion) +set(FUSION_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/modules/Fusion) +set(FUSION_LIBRARY Fusion) + add_library( nrealAirLibrary src/crc32.c diff --git a/modules/Fusion b/interface_lib/modules/Fusion similarity index 100% rename from modules/Fusion rename to interface_lib/modules/Fusion From 193dd8bf83308716699dff5d2d4ed2415dc90c1e Mon Sep 17 00:00:00 2001 From: TheJackiMonster Date: Thu, 7 Sep 2023 23:30:42 +0200 Subject: [PATCH 3/3] Update submodules usage Signed-off-by: TheJackiMonster --- .gitmodules | 7 +++++-- interface_lib/CMakeLists.txt | 12 ++++++------ interface_lib/modules/Fusion | 2 +- interface_lib/modules/hidapi | 1 + interface_lib/src/device3.c | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) create mode 160000 interface_lib/modules/hidapi diff --git a/.gitmodules b/.gitmodules index 56682d2..8696ec6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ -[submodule "modules/Fusion"] +[submodule "interface_lib/modules/Fusion"] path = interface_lib/modules/Fusion - url = https://github.com/TheJackiMonster/Fusion.git + url = https://github.com/xioTechnologies/Fusion.git +[submodule "interface_lib/modules/hidapi"] + path = interface_lib/modules/hidapi + url = https://github.com/libusb/hidapi.git diff --git a/interface_lib/CMakeLists.txt b/interface_lib/CMakeLists.txt index c787c1f..5acbb29 100644 --- a/interface_lib/CMakeLists.txt +++ b/interface_lib/CMakeLists.txt @@ -3,12 +3,10 @@ project(nrealAirLibrary C) set(CMAKE_C_STANDARD 17) -find_package(hidapi REQUIRED) -find_package(json-c REQUIRED) +find_package(json-c REQUIRED CONFIG) +add_subdirectory(modules/hidapi) add_subdirectory(modules/Fusion/Fusion) -set(FUSION_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/modules/Fusion) -set(FUSION_LIBRARY Fusion) add_library( nrealAirLibrary @@ -22,11 +20,13 @@ target_include_directories(nrealAirLibrary ) target_include_directories(nrealAirLibrary - SYSTEM BEFORE PRIVATE ${FUSION_INCLUDE_DIR} + SYSTEM BEFORE PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/modules/hidapi + ${CMAKE_CURRENT_SOURCE_DIR}/modules/Fusion ) target_link_libraries(nrealAirLibrary - hidapi::hidapi json-c::json-c ${FUSION_LIBRARY} m + hidapi::hidapi json-c::json-c Fusion m ) set(NRA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE) diff --git a/interface_lib/modules/Fusion b/interface_lib/modules/Fusion index f69fd25..0fd6785 160000 --- a/interface_lib/modules/Fusion +++ b/interface_lib/modules/Fusion @@ -1 +1 @@ -Subproject commit f69fd25df008ca11e709579fea4b784537f8911e +Subproject commit 0fd6785d3e3e2f8c358603db47ff5dadc0e338af diff --git a/interface_lib/modules/hidapi b/interface_lib/modules/hidapi new file mode 160000 index 0000000..c19ae12 --- /dev/null +++ b/interface_lib/modules/hidapi @@ -0,0 +1 @@ +Subproject commit c19ae126d8856b55af34d64ee11641920475961c diff --git a/interface_lib/src/device3.c b/interface_lib/src/device3.c index 8a7334a..8f6ee65 100644 --- a/interface_lib/src/device3.c +++ b/interface_lib/src/device3.c @@ -306,7 +306,7 @@ device3_type* device3_open(device3_event_callback callback) { .gain = 0.5f, .accelerationRejection = 10.0f, .magneticRejection = 20.0f, - .rejectionTimeout = 5 * SAMPLE_RATE, /* 5 seconds */ + .recoveryTriggerPeriod = 5 * SAMPLE_RATE, /* 5 seconds */ }; FusionAhrsSetSettings((FusionAhrs*) device->ahrs, &settings);