diff --git a/.gitmodules b/.gitmodules index c4c957e..8696ec6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ -[submodule "interface_lib/Fusion"] - path = interface_lib/Fusion +[submodule "interface_lib/modules/Fusion"] + path = interface_lib/modules/Fusion url = https://github.com/xioTechnologies/Fusion.git -[submodule "interface_lib/hidapi"] - path = interface_lib/hidapi +[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 20ad1c4..9692475 100644 --- a/interface_lib/CMakeLists.txt +++ b/interface_lib/CMakeLists.txt @@ -3,12 +3,10 @@ project(nrealAirLibrary C) set(CMAKE_C_STANDARD 17) -add_subdirectory(hidapi) find_package(json-c REQUIRED CONFIG) -add_subdirectory(Fusion/Fusion) -set(FUSION_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/interface_lib/Fusion) -set(FUSION_LIBRARY Fusion) +add_subdirectory(modules/hidapi) +add_subdirectory(modules/Fusion/Fusion) add_library( nrealAirLibrary @@ -24,11 +22,13 @@ target_include_directories(nrealAirLibrary ) target_include_directories(nrealAirLibrary - BEFORE PRIVATE ${FUSION_INCLUDE_DIR} + SYSTEM BEFORE PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/modules/hidapi + ${CMAKE_CURRENT_SOURCE_DIR}/modules/Fusion ) target_link_libraries(nrealAirLibrary - PRIVATE hidapi::hidapi json-c::json-c ${FUSION_LIBRARY} + PRIVATE hidapi::hidapi json-c::json-c Fusion m ) set(NREAL_AIR_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE) diff --git a/interface_lib/hidapi b/interface_lib/hidapi deleted file mode 160000 index 09ab35f..0000000 --- a/interface_lib/hidapi +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 09ab35ffa9dce60a993f4e55cdeaf0952645f9b7 diff --git a/interface_lib/Fusion b/interface_lib/modules/Fusion similarity index 100% rename from interface_lib/Fusion rename to interface_lib/modules/Fusion 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 4d7af6e..2d80a8b 100644 --- a/interface_lib/src/device3.c +++ b/interface_lib/src/device3.c @@ -32,7 +32,7 @@ #include #include -#include <../hidapi/hidapi/hidapi.h> +#include #include "crc32.h" @@ -235,7 +235,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) { @@ -253,6 +253,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 286c308..878b090 100644 --- a/interface_lib/src/device4.c +++ b/interface_lib/src/device4.c @@ -31,7 +31,7 @@ #include #include -#include <../hidapi/hidapi/hidapi.h> +#include #include "crc32.h" @@ -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)) { fprintf(stderr, "Failed sending firmware upload!\n"); goto jump_to_app; } + + offset += len; } printf("Finish upload!\n");