From 9b5fae523a60de1bda267af8ff0ca4b363786d25 Mon Sep 17 00:00:00 2001 From: strawmanbobi Date: Mon, 5 Jan 2026 12:25:53 +0800 Subject: [PATCH] IR decoder 1.5.1 1. fixed potential memory leak issue for ac frame parsing algorithm 2. changed decode API, embedded 'change_wind_direction' into ac_status (not compatible with lower versions) 3. changed CMakeLists.txt --- decoder/CMakeLists.txt | 58 ++++---- decoder/src/include/ir_ac_apply.h | 10 +- decoder/src/include/ir_ac_control.h | 5 +- decoder/src/include/ir_decode.h | 5 +- decoder/src/include/ir_defs.h | 2 +- decoder/src/ir_ac_apply.c | 40 +++--- decoder/src/ir_ac_binary_parse.c | 4 +- decoder/src/ir_ac_build_frame.c | 4 +- decoder/src/ir_ac_control.c | 14 +- decoder/src/ir_ac_parse_forbidden_info.c | 4 +- decoder/src/ir_ac_parse_frame_info.c | 13 +- decoder/src/ir_ac_parse_parameter.c | 124 +++++++++++++++--- decoder/src/ir_decode.c | 56 ++++---- decoder/src/ir_decode_test.c | 86 +++++++----- decoder/src/ir_tv_control.c | 6 +- decoder/src/ir_utils.c | 2 +- decoder/src/jni/CMakeLists.txt | 33 +++++ .../java/net/irext/decode/sdk/IRDecode.java | 14 +- .../net/irext/decode/sdk/bean/ACStatus.java | 0 .../decode/sdk/bean/TemperatureRange.java | 0 .../net/irext/decode/sdk/utils/Constants.java | 0 .../jni/src/include/classfile_constants.h | 0 decoder/{ => src}/jni/src/include/jawt.h | 0 .../{ => src}/jni/src/include/jdwpTransport.h | 0 decoder/{ => src}/jni/src/include/jni.h | 0 decoder/{ => src}/jni/src/include/jvmti.h | 0 decoder/{ => src}/jni/src/include/jvmticmlr.h | 0 .../{ => src}/jni/src/include/linux/jawt_md.h | 0 .../{ => src}/jni/src/include/linux/jni_md.h | 0 .../win32/bridge/AccessBridgeCallbacks.h | 0 .../include/win32/bridge/AccessBridgeCalls.c | 0 .../include/win32/bridge/AccessBridgeCalls.h | 0 .../win32/bridge/AccessBridgePackages.h | 0 .../{ => src}/jni/src/include/win32/jawt_md.h | 0 .../{ => src}/jni/src/include/win32/jni_md.h | 0 decoder/{ => src}/jni/src/ir_decode_jni.c | 12 +- decoder/{ => src}/jni/src/ir_decode_jni.h | 4 +- decoder/toolchain-amd64.cmake | 4 + decoder/toolchain-arm64.cmake | 4 + decoder/toolchain-armv7el.cmake | 4 + 40 files changed, 330 insertions(+), 178 deletions(-) create mode 100644 decoder/src/jni/CMakeLists.txt rename decoder/{ => src}/jni/java/net/irext/decode/sdk/IRDecode.java (93%) rename decoder/{ => src}/jni/java/net/irext/decode/sdk/bean/ACStatus.java (100%) rename decoder/{ => src}/jni/java/net/irext/decode/sdk/bean/TemperatureRange.java (100%) rename decoder/{ => src}/jni/java/net/irext/decode/sdk/utils/Constants.java (100%) rename decoder/{ => src}/jni/src/include/classfile_constants.h (100%) rename decoder/{ => src}/jni/src/include/jawt.h (100%) rename decoder/{ => src}/jni/src/include/jdwpTransport.h (100%) rename decoder/{ => src}/jni/src/include/jni.h (100%) rename decoder/{ => src}/jni/src/include/jvmti.h (100%) rename decoder/{ => src}/jni/src/include/jvmticmlr.h (100%) rename decoder/{ => src}/jni/src/include/linux/jawt_md.h (100%) rename decoder/{ => src}/jni/src/include/linux/jni_md.h (100%) rename decoder/{ => src}/jni/src/include/win32/bridge/AccessBridgeCallbacks.h (100%) rename decoder/{ => src}/jni/src/include/win32/bridge/AccessBridgeCalls.c (100%) rename decoder/{ => src}/jni/src/include/win32/bridge/AccessBridgeCalls.h (100%) rename decoder/{ => src}/jni/src/include/win32/bridge/AccessBridgePackages.h (100%) rename decoder/{ => src}/jni/src/include/win32/jawt_md.h (100%) rename decoder/{ => src}/jni/src/include/win32/jni_md.h (100%) rename decoder/{ => src}/jni/src/ir_decode_jni.c (96%) rename decoder/{ => src}/jni/src/ir_decode_jni.h (97%) create mode 100755 decoder/toolchain-amd64.cmake create mode 100755 decoder/toolchain-arm64.cmake create mode 100755 decoder/toolchain-armv7el.cmake diff --git a/decoder/CMakeLists.txt b/decoder/CMakeLists.txt index b8e1281..9ef0561 100644 --- a/decoder/CMakeLists.txt +++ b/decoder/CMakeLists.txt @@ -3,9 +3,6 @@ cmake_minimum_required(VERSION 3.10) ######################################################## project(irdecode) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") -add_definitions(-DBOARD_PC) -# add_definitions(-DBOARD_PC_JNI) -# add_definitions(-DDEBUG) IF (CMAKE_SYSTEM_NAME MATCHES "Linux") MESSAGE("compile platform : Linux") @@ -18,7 +15,10 @@ ELSE () add_definitions(-DPLATFORM_WIN32) ENDIF () -set(SOURCE_FILES_EXECUTABLE +include_directories( + "src/include") + +set(LIB_IRDECODE_SRC src/ir_utils.c src/ir_tv_control.c src/ir_ac_apply.c @@ -31,29 +31,7 @@ set(SOURCE_FILES_EXECUTABLE src/ir_decode.c src/ir_decode_test.c) -set(SOURCE_FILES_LIB - src/ir_utils.c - src/ir_tv_control.c - src/ir_ac_apply.c - src/ir_ac_build_frame.c - src/ir_ac_parse_parameter.c - src/ir_ac_parse_forbidden_info.c - src/ir_ac_parse_frame_info.c - src/ir_ac_control.c - src/ir_ac_binary_parse.c - src/ir_decode.c) - -set(SOURCE_FILES_JNI_SHARED_LIB - jni/src/ir_decode_jni.c - src/ir_utils.c - src/ir_tv_control.c - src/ir_ac_apply.c - src/ir_ac_build_frame.c - src/ir_ac_parse_parameter.c - src/ir_ac_parse_forbidden_info.c - src/ir_ac_parse_frame_info.c - src/ir_ac_control.c - src/ir_ac_binary_parse.c +set(BIN_TEST_SRC src/ir_decode.c) # SET(CMAKE_SYSTEM_NAME Linux) @@ -73,7 +51,25 @@ set(SOURCE_FILES_JNI_SHARED_LIB # SET(CMAKE_CXX_COMPILER "/usr/bin/aarch64-linux-gnu-g++") # SET(CMAKE_FIND_ROOT_PATH "/usr/bin") -# add_library(irdecode SHARED ${SOURCE_FILES_LIB}) -# add_library(irdecode STATIC ${SOURCE_FILES_LIB}) -add_executable(irdecode ${SOURCE_FILES_EXECUTABLE}) -# add_library(irdecode SHARED ${SOURCE_FILES_JNI_SHARED_LIB}) +add_library(irdecode SHARED + ${LIB_IRDECODE_SRC}) + +target_compile_options(irdecode PRIVATE + -DBOARD_PC) + +add_library(irdecode_s STATIC + ${LIB_IRDECODE_SRC}) + +target_compile_options(irdecode_s PRIVATE + -DBOARD_PC) + +target_compile_options(irdecode_s PRIVATE + -fPIC) + +add_executable(irdecode_test + ${BIN_TEST_SRC}) + +target_link_libraries(irdecode_test PRIVATE + irdecode) + +add_subdirectory("src/jni") diff --git a/decoder/src/include/ir_ac_apply.h b/decoder/src/include/ir_ac_apply.h index af68831..4c149cf 100644 --- a/decoder/src/include/ir_ac_apply.h +++ b/decoder/src/include/ir_ac_apply.h @@ -26,15 +26,15 @@ extern "C" #define MIN_TAG_LENGTH_TYPE_1 4 #define MIN_TAG_LENGTH_TYPE_2 6 -INT8 apply_power(t_remote_ac_status ac_status, UINT8 function_code); +INT8 apply_power(t_remote_ac_status *ac_status, UINT8 function_code); -INT8 apply_mode(t_remote_ac_status ac_status, UINT8 function_code); +INT8 apply_mode(t_remote_ac_status *ac_status, UINT8 function_code); -INT8 apply_wind_speed(t_remote_ac_status ac_status, UINT8 function_code); +INT8 apply_wind_speed(t_remote_ac_status *ac_status, UINT8 function_code); -INT8 apply_swing(t_remote_ac_status ac_status, UINT8 function_code); +INT8 apply_swing(t_remote_ac_status *ac_status, UINT8 function_code); -INT8 apply_temperature(t_remote_ac_status ac_status, UINT8 function_code); +INT8 apply_temperature(t_remote_ac_status *ac_status, UINT8 function_code); INT8 apply_function(struct ac_protocol *protocol, UINT8 function); diff --git a/decoder/src/include/ir_ac_control.h b/decoder/src/include/ir_ac_control.h index 68bf99f..16d8406 100644 --- a/decoder/src/include/ir_ac_control.h +++ b/decoder/src/include/ir_ac_control.h @@ -342,7 +342,7 @@ typedef struct ac_protocol UINT8 swing_status; - BOOL change_wind_direction; + UINT8 change_wind_direction; UINT16 dc_cnt; t_ac_bit_num bit_num[MAX_BITNUM]; @@ -382,10 +382,11 @@ typedef struct REMOTE_AC_STATUS UINT8 ac_display; UINT8 ac_sleep; UINT8 ac_timer; + UINT8 change_wind_direction; } t_remote_ac_status; // function polymorphism -typedef INT8 (*lp_apply_ac_parameter)(t_remote_ac_status ac_status, UINT8 function_code); +typedef INT8 (*lp_apply_ac_parameter)(t_remote_ac_status *ac_status, UINT8 function_code); #define TAG_AC_BOOT_CODE 1 #define TAG_AC_ZERO 2 diff --git a/decoder/src/include/ir_decode.h b/decoder/src/include/ir_decode.h index 6d7ebeb..e237e41 100644 --- a/decoder/src/include/ir_decode.h +++ b/decoder/src/include/ir_decode.h @@ -276,11 +276,10 @@ extern INT8 ir_binary_open(const UINT8 category, const UINT8 sub_category, UINT8 * parameters: key_code (in) - the code of pressed key * user_data (out) - output decoded data in INT16 array format * ac_status(in) - pointer to AC status (optional) - * change_wind_direction (in) - if control changes wind direction for AC (for AC only) * * returns: length of decoded data (0 indicates decode failure) */ -extern UINT16 ir_decode(UINT8 key_code, UINT16* user_data, t_remote_ac_status* ac_status, BOOL change_wind_direction); +extern UINT16 ir_decode(UINT8 key_code, UINT16* user_data, t_remote_ac_status* ac_status); /** * function ir_close @@ -362,7 +361,7 @@ extern void ir_lib_free_inner_buffer(); UINT16 ir_decode_combo(const UINT8 category, const UINT8 sub_category, UINT8* binary, UINT16 bin_length, UINT8 key_code, UINT16* user_data, - t_remote_ac_status* ac_status, BOOL change_wind_direction); + t_remote_ac_status* ac_status); #ifdef __cplusplus } diff --git a/decoder/src/include/ir_defs.h b/decoder/src/include/ir_defs.h index dc471ec..b4cd941 100644 --- a/decoder/src/include/ir_defs.h +++ b/decoder/src/include/ir_defs.h @@ -12,7 +12,7 @@ Revision log: #ifndef _IR_DEFS_H #define _IR_DEFS_H -#define IR_DECODE_LIB_VER "1.5.0" +#define IR_DECODE_LIB_VER "1.5.1" #if defined (BOARD_PC) #pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection" diff --git a/decoder/src/ir_ac_apply.c b/decoder/src/ir_ac_apply.c index 1dc8881..08c2e21 100644 --- a/decoder/src/ir_ac_apply.c +++ b/decoder/src/ir_ac_apply.c @@ -13,8 +13,8 @@ Revision log: #pragma ide diagnostic ignored "hicpp-signed-bitwise" #endif -#include "include/ir_utils.h" -#include "include/ir_ac_apply.h" +#include "ir_utils.h" +#include "ir_ac_apply.h" static INT8 apply_ac_power(struct ac_protocol *protocol, UINT8 power_status); @@ -616,17 +616,17 @@ INT8 apply_checksum(struct ac_protocol *protocol) return IR_DECODE_SUCCEEDED; } -INT8 apply_power(t_remote_ac_status ac_status, UINT8 function_code) +INT8 apply_power(t_remote_ac_status *ac_status, UINT8 function_code) { (void) function_code; - apply_ac_power(context, ac_status.ac_power); + apply_ac_power(context, ac_status->ac_power); return IR_DECODE_SUCCEEDED; } -INT8 apply_mode(t_remote_ac_status ac_status, UINT8 function_code) +INT8 apply_mode(t_remote_ac_status *ac_status, UINT8 function_code) { (void) function_code; - if (IR_DECODE_FAILED == apply_ac_mode(context, ac_status.ac_mode)) + if (IR_DECODE_FAILED == apply_ac_mode(context, ac_status->ac_mode)) { // do not implement this mechanism since mode, temperature, wind // speed would have unspecified function @@ -639,16 +639,16 @@ INT8 apply_mode(t_remote_ac_status ac_status, UINT8 function_code) return IR_DECODE_SUCCEEDED; } -INT8 apply_wind_speed(t_remote_ac_status ac_status, UINT8 function_code) +INT8 apply_wind_speed(t_remote_ac_status *ac_status, UINT8 function_code) { - if (FALSE == context->n_mode[ac_status.ac_mode].all_speed) + if (FALSE == context->n_mode[ac_status->ac_mode].all_speed) { // if this level is not in black list - if (!is_in(context->n_mode[ac_status.ac_mode].speed, - ac_status.ac_wind_speed, - context->n_mode[ac_status.ac_mode].speed_cnt)) + if (!is_in(context->n_mode[ac_status->ac_mode].speed, + ac_status->ac_wind_speed, + context->n_mode[ac_status->ac_mode].speed_cnt)) { - if (IR_DECODE_FAILED == apply_ac_wind_speed(context, ac_status.ac_wind_speed) && + if (IR_DECODE_FAILED == apply_ac_wind_speed(context, ac_status->ac_wind_speed) && function_code == AC_FUNCTION_WIND_SPEED) { // do not implement this mechanism since mode, temperature, wind @@ -689,7 +689,7 @@ INT8 apply_wind_speed(t_remote_ac_status ac_status, UINT8 function_code) return IR_DECODE_SUCCEEDED; } -INT8 apply_swing(t_remote_ac_status ac_status, UINT8 function_code) +INT8 apply_swing(t_remote_ac_status *ac_status, UINT8 function_code) { (void) ac_status; if (function_code == AC_FUNCTION_WIND_FIX) @@ -697,7 +697,7 @@ INT8 apply_swing(t_remote_ac_status ac_status, UINT8 function_code) // adjust fixed wind direction according to current status if (context->si.type == SWING_TYPE_NORMAL && context->si.mode_count > 1) { - if (TRUE == context->change_wind_direction) + if (1 == context->change_wind_direction) { context->si.dir_index++; } @@ -735,15 +735,15 @@ INT8 apply_swing(t_remote_ac_status ac_status, UINT8 function_code) return IR_DECODE_SUCCEEDED; } -INT8 apply_temperature(t_remote_ac_status ac_status, UINT8 function_code) +INT8 apply_temperature(t_remote_ac_status *ac_status, UINT8 function_code) { - if (FALSE == context->n_mode[ac_status.ac_mode].all_temp) + if (FALSE == context->n_mode[ac_status->ac_mode].all_temp) { - if (!is_in(context->n_mode[ac_status.ac_mode].temp, - ac_status.ac_temp, - context->n_mode[ac_status.ac_mode].temp_cnt)) + if (!is_in(context->n_mode[ac_status->ac_mode].temp, + ac_status->ac_temp, + context->n_mode[ac_status->ac_mode].temp_cnt)) { - if (IR_DECODE_FAILED == apply_ac_temperature(context, ac_status.ac_temp)) + if (IR_DECODE_FAILED == apply_ac_temperature(context, ac_status->ac_temp)) { if (function_code == AC_FUNCTION_TEMPERATURE_UP /*&& FALSE == has_function(context, AC_FUNCTION_TEMPERATURE_UP)*/) diff --git a/decoder/src/ir_ac_binary_parse.c b/decoder/src/ir_ac_binary_parse.c index de1f016..4b8ee1e 100644 --- a/decoder/src/ir_ac_binary_parse.c +++ b/decoder/src/ir_ac_binary_parse.c @@ -9,8 +9,8 @@ Revision log: * 2017-01-03: created by strawmanbobi **************************************************************************************/ -#include "include/ir_ac_binary_parse.h" -#include "include/ir_decode.h" +#include "ir_ac_binary_parse.h" +#include "ir_decode.h" UINT16 tag_head_offset = 0; diff --git a/decoder/src/ir_ac_build_frame.c b/decoder/src/ir_ac_build_frame.c index 366e08c..38c4d18 100644 --- a/decoder/src/ir_ac_build_frame.c +++ b/decoder/src/ir_ac_build_frame.c @@ -14,8 +14,8 @@ Revision log: #pragma ide diagnostic ignored "readability-redundant-declaration" #endif -#include "include/ir_ac_build_frame.h" -#include "include/ir_decode.h" +#include "ir_ac_build_frame.h" +#include "ir_decode.h" extern t_ac_protocol* context; diff --git a/decoder/src/ir_ac_control.c b/decoder/src/ir_ac_control.c index e6ee7b7..b012968 100644 --- a/decoder/src/ir_ac_control.c +++ b/decoder/src/ir_ac_control.c @@ -13,13 +13,13 @@ Revision log: #include #include -#include "include/ir_ac_control.h" -#include "include/ir_ac_binary_parse.h" -#include "include/ir_decode.h" -#include "include/ir_ac_parse_parameter.h" -#include "include/ir_ac_parse_forbidden_info.h" -#include "include/ir_ac_parse_frame_info.h" -#include "include/ir_utils.h" +#include "ir_ac_control.h" +#include "ir_ac_binary_parse.h" +#include "ir_decode.h" +#include "ir_ac_parse_parameter.h" +#include "ir_ac_parse_forbidden_info.h" +#include "ir_ac_parse_frame_info.h" +#include "ir_utils.h" #if defined USE_DYNAMIC_TAG diff --git a/decoder/src/ir_ac_parse_forbidden_info.c b/decoder/src/ir_ac_parse_forbidden_info.c index 5121932..64e5991 100644 --- a/decoder/src/ir_ac_parse_forbidden_info.c +++ b/decoder/src/ir_ac_parse_forbidden_info.c @@ -17,8 +17,8 @@ Revision log: #include #include -#include "include/ir_decode.h" -#include "include/ir_ac_parse_forbidden_info.h" +#include "ir_decode.h" +#include "ir_ac_parse_forbidden_info.h" extern t_ac_protocol *context; diff --git a/decoder/src/ir_ac_parse_frame_info.c b/decoder/src/ir_ac_parse_frame_info.c index d103815..b416ce8 100644 --- a/decoder/src/ir_ac_parse_frame_info.c +++ b/decoder/src/ir_ac_parse_frame_info.c @@ -10,11 +10,10 @@ Revision log: **************************************************************************************/ #include -#include #include -#include "include/ir_utils.h" -#include "include/ir_ac_parse_frame_info.h" +#include "ir_utils.h" +#include "ir_ac_parse_frame_info.h" INT8 parse_boot_code(struct tag_head *tag) @@ -341,5 +340,13 @@ INT8 parse_bit_num(struct tag_head *tag) if (context->bit_num[i].pos == -1) context->bit_num[i].pos = (UINT16) (context->default_code.len - 1); //convert -1 to last data pos } + + // Ensure bit_num_cnt does not exceed MAX_BITNUM to prevent buffer overflow + if (context->bit_num_cnt > MAX_BITNUM) + { + ir_printf("Warning: bit_num_cnt (%d) exceeds MAX_BITNUM (%d), limiting to MAX_BITNUM\n", + context->bit_num_cnt, MAX_BITNUM); + context->bit_num_cnt = MAX_BITNUM; + } return IR_DECODE_SUCCEEDED; } diff --git a/decoder/src/ir_ac_parse_parameter.c b/decoder/src/ir_ac_parse_parameter.c index d8d2a03..97aeba6 100644 --- a/decoder/src/ir_ac_parse_parameter.c +++ b/decoder/src/ir_ac_parse_parameter.c @@ -13,8 +13,8 @@ Revision log: #include #include -#include "include/ir_utils.h" -#include "include/ir_ac_parse_parameter.h" +#include "ir_utils.h" +#include "ir_ac_parse_parameter.h" static INT8 parse_checksum_byte_typed(const UINT8 *csdata, t_tag_checksum_data *checksum, UINT16 len); @@ -236,6 +236,13 @@ INT8 parse_temp_1(struct tag_head *tag, t_temp_1 *temp1) temp1->len = (UINT8) hex_len; UINT8 seg_len = hex_data[0]; + // Initialize all segments to NULL to ensure proper cleanup in case of error + for (seg_index = AC_TEMP_16; seg_index < (UINT16) AC_TEMP_MAX; seg_index++) + { + temp1->comp_data[seg_index].seg_len = 0; + temp1->comp_data[seg_index].segment = NULL; + } + for (seg_index = AC_TEMP_16; seg_index < (UINT16) AC_TEMP_MAX; seg_index++) { // 020210 indicates set the 02nd byte to [default] +10, +11, +12, +... @@ -243,6 +250,17 @@ INT8 parse_temp_1(struct tag_head *tag, t_temp_1 *temp1) temp1->comp_data[seg_index].segment = (UINT8 *) ir_malloc(seg_len); if (NULL == temp1->comp_data[seg_index].segment) { + // Clean up previously allocated memory + UINT16 cleanup_idx; + for (cleanup_idx = AC_TEMP_16; cleanup_idx < seg_index; cleanup_idx++) + { + if (temp1->comp_data[cleanup_idx].segment != NULL) + { + ir_free(temp1->comp_data[cleanup_idx].segment); + temp1->comp_data[cleanup_idx].segment = NULL; + temp1->comp_data[cleanup_idx].seg_len = 0; + } + } ir_free(hex_data); return IR_DECODE_FAILED; } @@ -400,10 +418,30 @@ INT8 parse_swing_1(struct tag_head *tag, t_swing_1 *swing1, UINT16 swing_count) return IR_DECODE_FAILED; } + // Initialize the comp_data to ensure proper cleanup in case of error + for (seg_index = 0; seg_index < swing_count; seg_index++) + { + swing1->comp_data[seg_index].seg_len = 0; + swing1->comp_data[seg_index].segment = NULL; + } + for (seg_index = 0; seg_index < swing_count; seg_index++) { if (IR_DECODE_FAILED == parse_comp_data_type_1(hex_data, &trav_offset, &swing1->comp_data[seg_index])) { + // Clean up any allocated memory in previous iterations + UINT16 i; + for (i = 0; i < seg_index; i++) + { + if (swing1->comp_data[i].segment != NULL) + { + ir_free(swing1->comp_data[i].segment); + swing1->comp_data[i].segment = NULL; + swing1->comp_data[i].seg_len = 0; + } + } + ir_free(swing1->comp_data); + swing1->comp_data = NULL; ir_free(hex_data); return IR_DECODE_FAILED; } @@ -518,6 +556,16 @@ INT8 parse_checksum(struct tag_head *tag, t_checksum *checksum) checksum->checksum_data + num, (UINT8) (i - preindex) >> (UINT8) 1)) { + // Clean up allocated memory on error + UINT16 j; + for (j = 0; j < num; j++) { + if (checksum->checksum_data[j].spec_pos != NULL) { + ir_free(checksum->checksum_data[j].spec_pos); + checksum->checksum_data[j].spec_pos = NULL; + } + } + ir_free(checksum->checksum_data); + checksum->checksum_data = NULL; return IR_DECODE_FAILED; } preindex = (UINT16) (i + 1); @@ -529,6 +577,16 @@ INT8 parse_checksum(struct tag_head *tag, t_checksum *checksum) checksum->checksum_data + num, (UINT8) (i - preindex) >> (UINT8) 1)) { + // Clean up allocated memory on error + UINT16 j; + for (j = 0; j <= num; j++) { + if (checksum->checksum_data[j].spec_pos != NULL) { + ir_free(checksum->checksum_data[j].spec_pos); + checksum->checksum_data[j].spec_pos = NULL; + } + } + ir_free(checksum->checksum_data); + checksum->checksum_data = NULL; return IR_DECODE_FAILED; } @@ -635,18 +693,12 @@ INT8 parse_function_1_tag29(struct tag_head *tag, t_function_1 *function1) // seg_index in TAG only refers to functional count for (seg_index = AC_FUNCTION_POWER; seg_index < (UINT16) AC_FUNCTION_MAX; seg_index++) { - /** WARNING: for strict mode only **/ - /** - INT8 fid = parse_function_1(hex_data, &trav_offset, &function1->comp_data[0]); - if (fid > AC_FUNCTION_MAX - 1) + INT8 result = parse_function_1(hex_data, &trav_offset, &function1->comp_data[0]); + if (result == IR_DECODE_FAILED) { - irda_free(hex_data); - hex_data = NULL; + ir_free(hex_data); return IR_DECODE_FAILED; } - **/ - - parse_function_1(hex_data, &trav_offset, &function1->comp_data[0]); if (trav_offset >= hex_len) { break; @@ -694,6 +746,13 @@ INT8 parse_temp_2(struct tag_head *tag, t_temp_2 *temp2) temp2->len = (UINT8) hex_len; UINT8 seg_len = hex_data[0]; + // Initialize all segments to NULL to ensure proper cleanup in case of error + for (seg_index = AC_TEMP_16; seg_index < (UINT16) AC_TEMP_MAX; seg_index++) + { + temp2->comp_data[seg_index].seg_len = 0; + temp2->comp_data[seg_index].segment = NULL; + } + for (seg_index = AC_TEMP_16; seg_index < (UINT16) AC_TEMP_MAX; seg_index++) { // 020210 indicates set the 02nd byte to [default] +10, +11, +12, +... @@ -701,6 +760,17 @@ INT8 parse_temp_2(struct tag_head *tag, t_temp_2 *temp2) temp2->comp_data[seg_index].segment = (UINT8 *) ir_malloc(seg_len); if (NULL == temp2->comp_data[seg_index].segment) { + // Clean up previously allocated memory + UINT16 cleanup_idx; + for (cleanup_idx = AC_TEMP_16; cleanup_idx < seg_index; cleanup_idx++) + { + if (temp2->comp_data[cleanup_idx].segment != NULL) + { + ir_free(temp2->comp_data[cleanup_idx].segment); + temp2->comp_data[cleanup_idx].segment = NULL; + temp2->comp_data[cleanup_idx].seg_len = 0; + } + } ir_free(hex_data); return IR_DECODE_FAILED; } @@ -873,10 +943,30 @@ INT8 parse_swing_2(struct tag_head *tag, t_swing_2 *swing2, UINT16 swing_count) return IR_DECODE_FAILED; } + // Initialize the comp_data to ensure proper cleanup in case of error + for (seg_index = 0; seg_index < swing_count; seg_index++) + { + swing2->comp_data[seg_index].seg_len = 0; + swing2->comp_data[seg_index].segment = NULL; + } + for (seg_index = 0; seg_index < swing_count; seg_index++) { if (IR_DECODE_FAILED == parse_comp_data_type_2(hex_data, &trav_offset, &swing2->comp_data[seg_index])) { + // Clean up any allocated memory in previous iterations + UINT16 i; + for (i = 0; i < seg_index; i++) + { + if (swing2->comp_data[i].segment != NULL) + { + ir_free(swing2->comp_data[i].segment); + swing2->comp_data[i].segment = NULL; + swing2->comp_data[i].seg_len = 0; + } + } + ir_free(swing2->comp_data); + swing2->comp_data = NULL; ir_free(hex_data); return IR_DECODE_FAILED; } @@ -993,18 +1083,12 @@ INT8 parse_function_2_tag34(struct tag_head *tag, t_function_2 *function2) // seg_index in TAG only refers to functional count for (seg_index = AC_FUNCTION_POWER; seg_index < (UINT16) AC_FUNCTION_MAX; seg_index++) { - /** WARNING: for strict mode only **/ - /** - INT8 fid = parse_function_2(hex_data, &trav_offset, &function2->comp_data[0]); - if (fid > AC_FUNCTION_MAX - 1) + INT8 result = parse_function_2(hex_data, &trav_offset, &function2->comp_data[0]); + if (result == IR_DECODE_FAILED) { - irda_free(hex_data); - hex_data = NULL; + ir_free(hex_data); return IR_DECODE_FAILED; } - **/ - - parse_function_2(hex_data, &trav_offset, &function2->comp_data[0]); if (trav_offset >= hex_len) { break; diff --git a/decoder/src/ir_decode.c b/decoder/src/ir_decode.c index 0865f42..2c45d0f 100644 --- a/decoder/src/ir_decode.c +++ b/decoder/src/ir_decode.c @@ -14,10 +14,10 @@ Revision log: #include -#include "include/ir_decode.h" -#include "include/ir_utils.h" -#include "include/ir_ac_build_frame.h" -#include "include/ir_ac_apply.h" +#include "ir_decode.h" +#include "ir_utils.h" +#include "ir_ac_build_frame.h" +#include "ir_ac_apply.h" struct ir_bin_buffer binary_file; struct ir_bin_buffer *p_ir_buffer = &binary_file; @@ -79,18 +79,23 @@ static INT8 ir_ac_file_open(const char *file_name); #endif static INT8 ir_ac_binary_open(UINT8 *binary, UINT16 bin_length); -static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16* user_data, UINT8 key_code, - BOOL change_wind_direction); + +static UINT16 ir_ac_control(t_remote_ac_status *ac_status, UINT16* user_data, UINT8 key_code); + static INT8 ir_ac_binary_close(); -static BOOL validate_ac_status(t_remote_ac_status* ac_status, BOOL change_wind_dir); + +static BOOL validate_ac_status(t_remote_ac_status* ac_status); #if !defined NO_FS static INT8 ir_tv_file_open(const char *file_name); #endif static INT8 ir_tv_binary_open(UINT8 *binary, UINT16 bin_length); + static INT8 ir_tv_binary_parse(UINT8 ir_hex_encode); + static UINT16 ir_tv_control(UINT8 key, UINT16 *l_user_data); + static INT8 ir_tv_binary_close(); @@ -244,8 +249,7 @@ INT8 ir_binary_open(const UINT8 category, const UINT8 sub_category, UINT8* binar } /** the main entry of decode algorithm **/ -UINT16 ir_decode(UINT8 key_code, UINT16* user_data, - t_remote_ac_status* ac_status, BOOL change_wind_direction) +UINT16 ir_decode(UINT8 key_code, UINT16* user_data, t_remote_ac_status* ac_status) { ir_printf("remote_category = %d, KEY_CODE_MAX = %d\n", remote_category, KEY_CODE_MAX[remote_category]); @@ -266,21 +270,21 @@ UINT16 ir_decode(UINT8 key_code, UINT16* user_data, return 0; } ir_printf("ac status is not null in decode core : power = %d, mode = %d, " - "temp = %d, wind_dir = %d, wind_speed = %d, " - "key_code = %d, change_wind_direction = %d\n", + "temp = %d, wind_dir = %d, wind_speed = %d, change_wind_direction = %d, " + "key_code = %d\n", ac_status->ac_power, ac_status->ac_mode, ac_status->ac_temp, ac_status->ac_wind_dir, ac_status->ac_wind_speed, - key_code, change_wind_direction); + ac_status->change_wind_direction, + key_code); // ac status validation - if (FALSE == validate_ac_status(ac_status, change_wind_direction)) { + if (FALSE == validate_ac_status(ac_status)) { return 0; } - return ir_ac_control(*ac_status, user_data, key_code, change_wind_direction); + return ir_ac_control(ac_status, user_data, key_code); } } - INT8 ir_close() { if (IR_TYPE_COMMANDS == ir_binary_type) @@ -359,8 +363,7 @@ static INT8 ir_ac_binary_open(UINT8 *binary, UINT16 bin_length) return IR_DECODE_SUCCEEDED; } -static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16* user_data, UINT8 key_code, - BOOL change_wind_direction) +static UINT16 ir_ac_control(t_remote_ac_status *ac_status, UINT16* user_data, UINT8 key_code) { UINT16 time_length = 0; UINT8 function_code = 0; @@ -402,7 +405,7 @@ static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16* user_data, UIN } // pre-set change wind direction flag here - context->change_wind_direction = change_wind_direction; + context->change_wind_direction = ac_status->change_wind_direction; context->time = user_data; @@ -410,15 +413,16 @@ static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16* user_data, UIN ir_memcpy(ir_hex_code, context->default_code.data, context->default_code.len); #if defined USE_APPLY_TABLE - if(ac_status.ac_power != AC_POWER_OFF) + if(ac_status->ac_power != AC_POWER_OFF) { + UINT8 i; for (i = AC_APPLY_POWER; i < AC_APPLY_MAX; i++) { - apply_table[i](context, parameter_array[i]); + apply_table[i](ac_status, function_code); } } #else - if (ac_status.ac_power == AC_POWER_OFF) + if (ac_status->ac_power == AC_POWER_OFF) { // otherwise, power should always be applied apply_power(ac_status, function_code); @@ -426,7 +430,7 @@ static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16* user_data, UIN else { // check the mode as the first priority, despite any other status - if (TRUE == context->n_mode[ac_status.ac_mode].enable) + if (TRUE == context->n_mode[ac_status->ac_mode].enable) { if (is_solo_function(function_code)) { @@ -506,7 +510,7 @@ static INT8 ir_ac_binary_close() return IR_DECODE_SUCCEEDED; } -static BOOL validate_ac_status(t_remote_ac_status* ac_status, BOOL change_wind_dir) +static BOOL validate_ac_status(t_remote_ac_status* ac_status) { if (AC_POWER_OFF != ac_status->ac_power && AC_POWER_ON != ac_status->ac_power) { @@ -528,7 +532,7 @@ static BOOL validate_ac_status(t_remote_ac_status* ac_status, BOOL change_wind_d { return FALSE; } - if (0 != change_wind_dir && 1 != change_wind_dir) + if (0 != ac_status->change_wind_direction && 1 != ac_status->change_wind_direction) { return FALSE; } @@ -776,7 +780,7 @@ static INT8 ir_tv_binary_close() UINT16 ir_decode_combo(const UINT8 category, const UINT8 sub_category, UINT8* binary, UINT16 bin_length, UINT8 key_code, UINT16* user_data, - t_remote_ac_status* ac_status, BOOL change_wind_direction) + t_remote_ac_status* ac_status) { UINT16 decoded_length = 0; @@ -798,7 +802,7 @@ UINT16 ir_decode_combo(const UINT8 category, const UINT8 sub_category, if (IR_DECODE_SUCCEEDED == ir_binary_open(category, sub_category, binary, bin_length)) { - decoded_length = ir_decode(key_code, user_data, ac_status, change_wind_direction); + decoded_length = ir_decode(key_code, user_data, ac_status); ir_close(); return decoded_length; } diff --git a/decoder/src/ir_decode_test.c b/decoder/src/ir_decode_test.c index da24367..4af2661 100644 --- a/decoder/src/ir_decode_test.c +++ b/decoder/src/ir_decode_test.c @@ -16,13 +16,13 @@ Revision log: #include #include -#include "include/ir_defs.h" -#include "include/ir_decode.h" +#include "ir_defs.h" +#include "ir_decode.h" #define INPUT_MAX 3 // global variable definition -t_remote_ac_status ac_status; +t_remote_ac_status *ac_status = NULL; UINT16 user_data[USER_DATA_SIZE]; void input_number(int *val) @@ -80,15 +80,24 @@ static INT8 decode_as_ac(char *file_name) BOOL need_control = TRUE; + if (ac_status == NULL) { + ac_status = (t_remote_ac_status *)malloc(sizeof(t_remote_ac_status)); + if (ac_status == NULL) { + printf("failed to allocate memory for ac_status\n"); + return IR_DECODE_FAILED; + } + } + // init air conditioner status - ac_status.ac_display = 0; - ac_status.ac_sleep = 0; - ac_status.ac_timer = 0; - ac_status.ac_power = AC_POWER_ON; - ac_status.ac_mode = AC_MODE_COOL; - ac_status.ac_temp = AC_TEMP_20; - ac_status.ac_wind_dir = AC_SWING_ON; - ac_status.ac_wind_speed = AC_WS_AUTO; + ac_status->ac_display = 0; + ac_status->ac_sleep = 0; + ac_status->ac_timer = 0; + ac_status->ac_power = AC_POWER_ON; + ac_status->ac_mode = AC_MODE_COOL; + ac_status->ac_temp = AC_TEMP_20; + ac_status->ac_wind_dir = AC_SWING_ON; + ac_status->ac_wind_speed = AC_WS_AUTO; + ac_status->change_wind_direction = 0; if (IR_DECODE_FAILED == ir_file_open(REMOTE_CATEGORY_AC, 0, file_name)) { @@ -112,7 +121,7 @@ static INT8 decode_as_ac(char *file_name) op_match = TRUE; need_control = FALSE; - change_wind_dir = FALSE; + ac_status->change_wind_direction = 0; if (99 == key_code) { @@ -132,9 +141,9 @@ static INT8 decode_as_ac(char *file_name) } else if (15 == key_code) { - if (IR_DECODE_SUCCEEDED == get_supported_wind_speed(ac_status.ac_mode, &supported_speed)) + if (IR_DECODE_SUCCEEDED == get_supported_wind_speed(ac_status->ac_mode, &supported_speed)) { - printf("supported wind speed in %d = %02X\n", ac_status.ac_mode, supported_speed); + printf("supported wind speed in %d = %02X\n", ac_status->ac_mode, supported_speed); } else { @@ -143,10 +152,10 @@ static INT8 decode_as_ac(char *file_name) } else if (16 == key_code) { - if (IR_DECODE_SUCCEEDED == get_temperature_range(ac_status.ac_mode, &min_temperature, &max_temperature)) + if (IR_DECODE_SUCCEEDED == get_temperature_range(ac_status->ac_mode, &min_temperature, &max_temperature)) { printf("supported temperature range in mode %d = %d, %d\n", - ac_status.ac_mode, min_temperature, max_temperature); + ac_status->ac_mode, min_temperature, max_temperature); } else { @@ -170,42 +179,43 @@ static INT8 decode_as_ac(char *file_name) { // notice: only if ac_power is turned on will user_data change when input a different key_code case 0: - ac_status.ac_power = ((ac_status.ac_power == AC_POWER_ON) ? AC_POWER_OFF : AC_POWER_ON); + ac_status->ac_power = ((ac_status->ac_power == AC_POWER_ON) ? AC_POWER_OFF : AC_POWER_ON); need_control = TRUE; break; case 1: - ++ac_status.ac_mode; - ac_status.ac_mode = ac_status.ac_mode % AC_MODE_MAX; + ++ac_status->ac_mode; + ac_status->ac_mode = ac_status->ac_mode % AC_MODE_MAX; need_control = TRUE; break; case 2: case 7: - ac_status.ac_temp = ((ac_status.ac_temp == AC_TEMP_30) ? AC_TEMP_30 : (ac_status.ac_temp + 1)); + ac_status->ac_temp = ((ac_status->ac_temp == AC_TEMP_30) ? AC_TEMP_30 : (ac_status->ac_temp + 1)); need_control = TRUE; break; case 3: case 8: - ac_status.ac_temp = ((ac_status.ac_temp == AC_TEMP_16) ? AC_TEMP_16 : (ac_status.ac_temp - 1)); + ac_status->ac_temp = ((ac_status->ac_temp == AC_TEMP_16) ? AC_TEMP_16 : (ac_status->ac_temp - 1)); need_control = TRUE; break; case 9: - ++ac_status.ac_wind_speed; - ac_status.ac_wind_speed = ac_status.ac_wind_speed % AC_WS_MAX; + ++ac_status->ac_wind_speed; + ac_status->ac_wind_speed = ac_status->ac_wind_speed % AC_WS_MAX; need_control = TRUE; break; case 10: - ac_status.ac_wind_dir = ((ac_status.ac_wind_dir == AC_SWING_ON) ? AC_SWING_OFF : AC_SWING_ON); + ac_status->ac_wind_dir = ((ac_status->ac_wind_dir == AC_SWING_ON) ? AC_SWING_OFF : AC_SWING_ON); need_control = TRUE; break; case 11: - if (ac_status.ac_wind_dir == AC_SWING_OFF) { - change_wind_dir = TRUE; + if (ac_status->ac_wind_dir == AC_SWING_OFF) { + ac_status->change_wind_direction = 1; + } need_control = TRUE; break; @@ -218,13 +228,13 @@ static INT8 decode_as_ac(char *file_name) if (TRUE == op_match && TRUE == need_control) { printf("switch AC to power = %d, mode = %d, temp = %d, speed = %d, swing = %d with key_code = %d\n", - ac_status.ac_power, - ac_status.ac_mode, - ac_status.ac_temp, - ac_status.ac_wind_speed, - ac_status.ac_wind_dir, + ac_status->ac_power, + ac_status->ac_mode, + ac_status->ac_temp, + ac_status->ac_wind_speed, + ac_status->ac_wind_dir, key_code); - length = ir_decode(key_code, user_data, &ac_status, change_wind_dir); + length = ir_decode(key_code, user_data, ac_status); printf("\n === binary decoded : %d\n", length); for (index = 0; index < length; index++) { @@ -273,7 +283,7 @@ static INT8 decode_as_tv(char *file_name, UINT8 ir_hex_encode) { break; } - length = ir_decode(key_code, user_data, NULL, 0); + length = ir_decode(key_code, user_data, NULL); printf("\n === binary decoded : %d\n", length); for (index = 0; index < length; index++) { @@ -287,6 +297,13 @@ static INT8 decode_as_tv(char *file_name, UINT8 ir_hex_encode) return IR_DECODE_SUCCEEDED; } +void cleanup() { + if (ac_status != NULL) { + free(ac_status); + ac_status = NULL; + } +} + static void print_usage(const char *progn) { printf("usage: %s [function] [file] [subcate]\n" "[function] : 0 - decode for AC; 1 - decode for others\n" @@ -324,4 +341,7 @@ int main(int argc, char *argv[]) printf("decode functionality not supported : %c\n", function); break; } + + cleanup(); + return 0; } \ No newline at end of file diff --git a/decoder/src/ir_tv_control.c b/decoder/src/ir_tv_control.c index 53a3e80..6d3990a 100644 --- a/decoder/src/ir_tv_control.c +++ b/decoder/src/ir_tv_control.c @@ -15,9 +15,9 @@ Revision log: #include -#include "include/ir_defs.h" -#include "include/ir_decode.h" -#include "include/ir_tv_control.h" +#include "ir_defs.h" +#include "ir_decode.h" +#include "ir_tv_control.h" struct buffer diff --git a/decoder/src/ir_utils.c b/decoder/src/ir_utils.c index 9045a52..7d90ea5 100644 --- a/decoder/src/ir_utils.c +++ b/decoder/src/ir_utils.c @@ -9,7 +9,7 @@ Revision log: * 2016-10-01: created by strawmanbobi **************************************************************************************/ -#include "include/ir_utils.h" +#include "ir_utils.h" UINT8 char_to_hex(char chr) { diff --git a/decoder/src/jni/CMakeLists.txt b/decoder/src/jni/CMakeLists.txt new file mode 100644 index 0000000..a876adc --- /dev/null +++ b/decoder/src/jni/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 3.10) + +######################################################## +project(ir_decode_jni) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + +IF (CMAKE_SYSTEM_NAME MATCHES "Linux") + MESSAGE("compile platform : Linux") + add_definitions(-DPLATFORM_LINUX) +ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows") + MESSAGE("compile platform : win32") + add_definitions(-DPLATFORM_WIN32) +ELSE () + MESSAGE("invalid compile platform") + add_definitions(-DPLATFORM_WIN32) +ENDIF () + +include_directories( + "${CMAKE_SOURCE_DIR}/src/include" + "src/include") + +set(LIB_IRDECODE_JNI_SRC + src/ir_decode_jni.c) + +add_library(irdecode_jni SHARED + ${LIB_IRDECODE_JNI_SRC}) + +target_compile_definitions(irdecode_jni PRIVATE + -DBOARD_PC + -DBOARD_PC_JNI) + +target_link_libraries(irdecode_jni PRIVATE + irdecode_s) diff --git a/decoder/jni/java/net/irext/decode/sdk/IRDecode.java b/decoder/src/jni/java/net/irext/decode/sdk/IRDecode.java similarity index 93% rename from decoder/jni/java/net/irext/decode/sdk/IRDecode.java rename to decoder/src/jni/java/net/irext/decode/sdk/IRDecode.java index a8ab461..c125dc6 100644 --- a/decoder/jni/java/net/irext/decode/sdk/IRDecode.java +++ b/decoder/src/jni/java/net/irext/decode/sdk/IRDecode.java @@ -4,7 +4,6 @@ import net.irext.decode.sdk.bean.ACStatus; import net.irext.decode.sdk.bean.TemperatureRange; import net.irext.decode.sdk.utils.Constants; - /** * Filename: IRDecode.java * Revised: Date: 2017-04-22 @@ -25,7 +24,7 @@ public class IRDecode { private native int irOpenBinary(int category, int subCate, byte[] binaries, int binLength); - private native int[] irDecode(int keyCode, ACStatus acStatus, int changeWindDirection); + private native int[] irDecode(int keyCode, ACStatus acStatus); private native void irClose(); @@ -64,17 +63,17 @@ public class IRDecode { return irOpenBinary(category, subCate, binaries, binLength); } - public int[] decodeBinary(int keyCode, ACStatus acStatus, int changeWindDir) { + public int[] decodeBinary(int keyCode, ACStatus acStatus) { int []decoded; synchronized (mSync) { if (null == acStatus) { acStatus = new ACStatus(); } // validate ac status - if (!validateAcStatus(acStatus, keyCode, changeWindDir)) { + if (!validateAcStatus(acStatus, keyCode)) { return new int[0]; } - decoded = irDecode(keyCode, acStatus, changeWindDir); + decoded = irDecode(keyCode, acStatus); } return decoded; } @@ -127,7 +126,7 @@ public class IRDecode { return irACGetSupportedWindDirection(acMode); } - private boolean validateAcStatus(ACStatus acStatus, int keyCode, int changeWindDir) { + private boolean validateAcStatus(ACStatus acStatus, int keyCode) { if (acStatus.getAcPower() != Constants.ACPower.POWER_ON.getValue() && acStatus.getAcPower() != Constants.ACPower.POWER_OFF.getValue()) { return false; @@ -148,9 +147,6 @@ public class IRDecode { acStatus.getAcWindDir() > Constants.ACSwing.SWING_OFF.getValue()) { return false; } - if (changeWindDir != 0 && changeWindDir != 1) { - return false; - } return true; } } diff --git a/decoder/jni/java/net/irext/decode/sdk/bean/ACStatus.java b/decoder/src/jni/java/net/irext/decode/sdk/bean/ACStatus.java similarity index 100% rename from decoder/jni/java/net/irext/decode/sdk/bean/ACStatus.java rename to decoder/src/jni/java/net/irext/decode/sdk/bean/ACStatus.java diff --git a/decoder/jni/java/net/irext/decode/sdk/bean/TemperatureRange.java b/decoder/src/jni/java/net/irext/decode/sdk/bean/TemperatureRange.java similarity index 100% rename from decoder/jni/java/net/irext/decode/sdk/bean/TemperatureRange.java rename to decoder/src/jni/java/net/irext/decode/sdk/bean/TemperatureRange.java diff --git a/decoder/jni/java/net/irext/decode/sdk/utils/Constants.java b/decoder/src/jni/java/net/irext/decode/sdk/utils/Constants.java similarity index 100% rename from decoder/jni/java/net/irext/decode/sdk/utils/Constants.java rename to decoder/src/jni/java/net/irext/decode/sdk/utils/Constants.java diff --git a/decoder/jni/src/include/classfile_constants.h b/decoder/src/jni/src/include/classfile_constants.h similarity index 100% rename from decoder/jni/src/include/classfile_constants.h rename to decoder/src/jni/src/include/classfile_constants.h diff --git a/decoder/jni/src/include/jawt.h b/decoder/src/jni/src/include/jawt.h similarity index 100% rename from decoder/jni/src/include/jawt.h rename to decoder/src/jni/src/include/jawt.h diff --git a/decoder/jni/src/include/jdwpTransport.h b/decoder/src/jni/src/include/jdwpTransport.h similarity index 100% rename from decoder/jni/src/include/jdwpTransport.h rename to decoder/src/jni/src/include/jdwpTransport.h diff --git a/decoder/jni/src/include/jni.h b/decoder/src/jni/src/include/jni.h similarity index 100% rename from decoder/jni/src/include/jni.h rename to decoder/src/jni/src/include/jni.h diff --git a/decoder/jni/src/include/jvmti.h b/decoder/src/jni/src/include/jvmti.h similarity index 100% rename from decoder/jni/src/include/jvmti.h rename to decoder/src/jni/src/include/jvmti.h diff --git a/decoder/jni/src/include/jvmticmlr.h b/decoder/src/jni/src/include/jvmticmlr.h similarity index 100% rename from decoder/jni/src/include/jvmticmlr.h rename to decoder/src/jni/src/include/jvmticmlr.h diff --git a/decoder/jni/src/include/linux/jawt_md.h b/decoder/src/jni/src/include/linux/jawt_md.h similarity index 100% rename from decoder/jni/src/include/linux/jawt_md.h rename to decoder/src/jni/src/include/linux/jawt_md.h diff --git a/decoder/jni/src/include/linux/jni_md.h b/decoder/src/jni/src/include/linux/jni_md.h similarity index 100% rename from decoder/jni/src/include/linux/jni_md.h rename to decoder/src/jni/src/include/linux/jni_md.h diff --git a/decoder/jni/src/include/win32/bridge/AccessBridgeCallbacks.h b/decoder/src/jni/src/include/win32/bridge/AccessBridgeCallbacks.h similarity index 100% rename from decoder/jni/src/include/win32/bridge/AccessBridgeCallbacks.h rename to decoder/src/jni/src/include/win32/bridge/AccessBridgeCallbacks.h diff --git a/decoder/jni/src/include/win32/bridge/AccessBridgeCalls.c b/decoder/src/jni/src/include/win32/bridge/AccessBridgeCalls.c similarity index 100% rename from decoder/jni/src/include/win32/bridge/AccessBridgeCalls.c rename to decoder/src/jni/src/include/win32/bridge/AccessBridgeCalls.c diff --git a/decoder/jni/src/include/win32/bridge/AccessBridgeCalls.h b/decoder/src/jni/src/include/win32/bridge/AccessBridgeCalls.h similarity index 100% rename from decoder/jni/src/include/win32/bridge/AccessBridgeCalls.h rename to decoder/src/jni/src/include/win32/bridge/AccessBridgeCalls.h diff --git a/decoder/jni/src/include/win32/bridge/AccessBridgePackages.h b/decoder/src/jni/src/include/win32/bridge/AccessBridgePackages.h similarity index 100% rename from decoder/jni/src/include/win32/bridge/AccessBridgePackages.h rename to decoder/src/jni/src/include/win32/bridge/AccessBridgePackages.h diff --git a/decoder/jni/src/include/win32/jawt_md.h b/decoder/src/jni/src/include/win32/jawt_md.h similarity index 100% rename from decoder/jni/src/include/win32/jawt_md.h rename to decoder/src/jni/src/include/win32/jawt_md.h diff --git a/decoder/jni/src/include/win32/jni_md.h b/decoder/src/jni/src/include/win32/jni_md.h similarity index 100% rename from decoder/jni/src/include/win32/jni_md.h rename to decoder/src/jni/src/include/win32/jni_md.h diff --git a/decoder/jni/src/ir_decode_jni.c b/decoder/src/jni/src/ir_decode_jni.c similarity index 96% rename from decoder/jni/src/ir_decode_jni.c rename to decoder/src/jni/src/ir_decode_jni.c index 74bacdb..b35b6cd 100644 --- a/decoder/jni/src/ir_decode_jni.c +++ b/decoder/src/jni/src/ir_decode_jni.c @@ -12,8 +12,8 @@ Revision log: #include #include "ir_decode_jni.h" -#include "../../src/include/ir_defs.h" -#include "../../src/include/ir_decode.h" +#include "ir_defs.h" +#include "ir_decode.h" // global variable definition extern size_t binary_length; @@ -59,7 +59,7 @@ JNIEXPORT jint JNICALL Java_net_irext_decode_sdk_IRDecode_irOpenBinary } JNIEXPORT jintArray JNICALL Java_net_irext_decode_sdk_IRDecode_irDecode - (JNIEnv *env, jobject this_obj, jint key_code, jobject jni_ac_status, jint change_wind_direction) + (JNIEnv *env, jobject this_obj, jint key_code, jobject jni_ac_status) { UINT16 user_data[USER_DATA_SIZE] = { 0 }; int i = 0; @@ -105,7 +105,7 @@ JNIEXPORT jintArray JNICALL Java_net_irext_decode_sdk_IRDecode_irDecode ir_printf("ac status is null, error!\n"); } - int wave_code_length = ir_decode(key_code, user_data, &ac_status, change_wind_direction); + int wave_code_length = ir_decode(key_code, user_data, &ac_status); jintArray result = (*env)->NewIntArray(env, wave_code_length); if (result == NULL) @@ -131,7 +131,7 @@ JNIEXPORT void JNICALL Java_net_irext_decode_sdk_IRDecode_irClose JNIEXPORT jintArray JNICALL Java_net_irext_decode_sdk_IRDecode_irDecodeCombo (JNIEnv *env, jobject this_obj, jint category_id, jint sub_cate, jbyteArray binaries, jint bin_length, - jint key_code, jobject jni_ac_status, jint change_wind_direction) { + jint key_code, jobject jni_ac_status) { UINT16 user_data[USER_DATA_SIZE] = { 0 }; int i = 0; jint copy_array[USER_DATA_SIZE] = { 0 }; @@ -177,7 +177,7 @@ JNIEXPORT jintArray JNICALL Java_net_irext_decode_sdk_IRDecode_irDecodeCombo int wave_code_length = ir_decode_combo(category_id, sub_cate, buffer, bin_length, key_code, user_data, - &ac_status, change_wind_direction); + &ac_status); jintArray result = (*env)->NewIntArray(env, wave_code_length); if (result == NULL) { diff --git a/decoder/jni/src/ir_decode_jni.h b/decoder/src/jni/src/ir_decode_jni.h similarity index 97% rename from decoder/jni/src/ir_decode_jni.h rename to decoder/src/jni/src/ir_decode_jni.h index 0ed7280..4c3fa85 100644 --- a/decoder/jni/src/ir_decode_jni.h +++ b/decoder/src/jni/src/ir_decode_jni.h @@ -82,7 +82,7 @@ JNIEXPORT jint JNICALL Java_net_irext_decode_sdk_IRDecode_irOpenBinary * Signature: I(Lnet/irext/decodesdk/bean/ACStatus;I)[I */ JNIEXPORT jintArray JNICALL Java_net_irext_decode_sdk_IRDecode_irDecode - (JNIEnv *, jobject, jint, jobject, jint); + (JNIEnv *, jobject, jint, jobject); /* * Class: net_irext_decode_sdk_IRDecode @@ -136,7 +136,7 @@ JNIEXPORT jint JNICALL Java_net_irext_decode_sdk_IRDecode_irACGetSupportedWindDi JNIEXPORT jintArray JNICALL Java_net_irext_decode_sdk_IRDecode_irDecodeCombo (JNIEnv *env, jobject this_obj, jint category_id, jint sub_cate, jbyteArray binaries, jint bin_length, - jint key_code, jobject jni_ac_status, jint change_wind_direction); + jint key_code, jobject jni_ac_status); #ifdef __cplusplus } diff --git a/decoder/toolchain-amd64.cmake b/decoder/toolchain-amd64.cmake new file mode 100755 index 0000000..d3d2f9a --- /dev/null +++ b/decoder/toolchain-amd64.cmake @@ -0,0 +1,4 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR x86_64) +set(CMAKE_C_COMPILER gcc) +set(CMAKE_CXX_COMPILER g++) \ No newline at end of file diff --git a/decoder/toolchain-arm64.cmake b/decoder/toolchain-arm64.cmake new file mode 100755 index 0000000..70fdefb --- /dev/null +++ b/decoder/toolchain-arm64.cmake @@ -0,0 +1,4 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR arm64) +set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) +set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) \ No newline at end of file diff --git a/decoder/toolchain-armv7el.cmake b/decoder/toolchain-armv7el.cmake new file mode 100755 index 0000000..763e74f --- /dev/null +++ b/decoder/toolchain-armv7el.cmake @@ -0,0 +1,4 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR armv7el) +set(CMAKE_C_COMPILER arm-linux-gnueabi-gcc) +set(CMAKE_CXX_COMPILER arm-linux-gnueabi-g++) \ No newline at end of file