diff --git a/win32-example/.gitignore b/win32-example/.gitignore index c401da2..1b2e5cb 100644 --- a/win32-example/.gitignore +++ b/win32-example/.gitignore @@ -290,7 +290,7 @@ __pycache__/ *.odx.cs *.xsd.cs -DecodeTestWin/DecodeTestWin.vcxproj.filters -DecodeTestWin/DecodeTestWin.vcxproj +DecodeTestWin.vcxproj.filters +DecodeTestWin.vcxproj -# End of https://www.gitignore.io/api/visualstudio \ No newline at end of file +# End of https://www.gitignore.io/api/visualstudio diff --git a/win32-example/IRextWin32Example/DecodeTestWin.cpp b/win32-example/DecodeTestWin.cpp similarity index 100% rename from win32-example/IRextWin32Example/DecodeTestWin.cpp rename to win32-example/DecodeTestWin.cpp diff --git a/win32-example/IRextWin32Example/IRextWin32Example.sln b/win32-example/IRextWin32Example.sln similarity index 100% rename from win32-example/IRextWin32Example/IRextWin32Example.sln rename to win32-example/IRextWin32Example.sln diff --git a/win32-example/IRextWin32Example/IRextWin32Example.vcxproj b/win32-example/IRextWin32Example.vcxproj similarity index 95% rename from win32-example/IRextWin32Example/IRextWin32Example.vcxproj rename to win32-example/IRextWin32Example.vcxproj index a90c3b1..e25b7f4 100644 --- a/win32-example/IRextWin32Example/IRextWin32Example.vcxproj +++ b/win32-example/IRextWin32Example.vcxproj @@ -1,178 +1,178 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - {F4139B9B-37FF-436C-BE1E-B552940BA753} - Win32Proj - IRextWin32Example - 10.0 - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - - - true - - - false - - - false - - - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;BOARD_PC;DEBUG;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {F4139B9B-37FF-436C-BE1E-B552940BA753} + Win32Proj + IRextWin32Example + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;BOARD_PC;DEBUG;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/win32-example/IRextWin32Example/IRextWin32Example.vcxproj.filters b/win32-example/IRextWin32Example.vcxproj.filters similarity index 100% rename from win32-example/IRextWin32Example/IRextWin32Example.vcxproj.filters rename to win32-example/IRextWin32Example.vcxproj.filters diff --git a/win32-example/IRextWin32Example/ReadMe.txt b/win32-example/ReadMe.txt similarity index 100% rename from win32-example/IRextWin32Example/ReadMe.txt rename to win32-example/ReadMe.txt diff --git a/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_apply.h b/win32-example/ir_decoder/src/include/ir_ac_apply.h similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_apply.h rename to win32-example/ir_decoder/src/include/ir_ac_apply.h diff --git a/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_binary_parse.h b/win32-example/ir_decoder/src/include/ir_ac_binary_parse.h similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_binary_parse.h rename to win32-example/ir_decoder/src/include/ir_ac_binary_parse.h diff --git a/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_build_frame.h b/win32-example/ir_decoder/src/include/ir_ac_build_frame.h similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_build_frame.h rename to win32-example/ir_decoder/src/include/ir_ac_build_frame.h diff --git a/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_control.h b/win32-example/ir_decoder/src/include/ir_ac_control.h similarity index 95% rename from win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_control.h rename to win32-example/ir_decoder/src/include/ir_ac_control.h index 60d8722..68bf99f 100644 --- a/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_control.h +++ b/win32-example/ir_decoder/src/include/ir_ac_control.h @@ -126,30 +126,30 @@ typedef enum AC_APPLY_MAX } t_ac_apply; -typedef struct _ac_hex +typedef struct ac_hex { UINT8 len; UINT8 *data; } t_ac_hex; -typedef struct _ac_level +typedef struct ac_level { UINT16 low; UINT16 high; } t_ac_level; -typedef struct _ac_bootcode +typedef struct ac_bootcode { UINT16 len; UINT16 data[16]; -} t_ac_bootcode; +} t_ac_boot_code; -typedef struct _ac_delaycode +typedef struct ac_delay_code { INT16 pos; UINT16 time[8]; UINT16 time_cnt; -} t_ac_delaycode; +} t_ac_delay_code; /* * the array of tag_100X application data @@ -157,26 +157,26 @@ typedef struct _ac_delaycode * byte_pos : the position of update byte * byte_value : the value to be updated to position */ -typedef struct _tag_comp_type_1 +typedef struct tag_comp_type_1 { UINT8 seg_len; UINT8 *segment; } t_tag_comp; -typedef struct _tag_swing_info +typedef struct tag_swing_info { swing_type type; UINT8 mode_count; UINT8 dir_index; } t_swing_info; -typedef struct _tag_power_1 +typedef struct tag_power_1 { UINT8 len; t_tag_comp comp_data[AC_POWER_MAX]; } t_power_1; -typedef struct _tag_temp_1 +typedef struct tag_temp_1 { UINT8 len; UINT8 type; @@ -236,7 +236,7 @@ typedef struct tag_horiswing_1 } hori_swing_1; #endif -typedef struct _tag_checksum_data +typedef struct tag_checksum_data { UINT8 len; UINT8 type; @@ -273,7 +273,7 @@ typedef struct tag_solo_code UINT8 solo_function_codes[AC_FUNCTION_MAX - 1]; } t_solo_code; -typedef struct _ac_bitnum +typedef struct ac_bitnum { INT16 pos; UINT16 bits; @@ -302,7 +302,7 @@ typedef enum CHECKSUM_TYPE_MAX, } t_checksum_type; -typedef struct _ac_n_mode_info +typedef struct ac_n_mode_info { UINT8 enable; UINT8 all_speed; @@ -320,8 +320,8 @@ typedef struct ac_protocol t_ac_hex default_code; t_ac_level zero; t_ac_level one; - t_ac_bootcode boot_code; - t_ac_delaycode dc[MAX_DELAYCODE_NUM]; + t_ac_boot_code boot_code; + t_ac_delay_code dc[MAX_DELAYCODE_NUM]; t_power_1 power1; t_temp_1 temp1; t_mode_1 mode1; diff --git a/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_parse_forbidden_info.h b/win32-example/ir_decoder/src/include/ir_ac_parse_forbidden_info.h similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_parse_forbidden_info.h rename to win32-example/ir_decoder/src/include/ir_ac_parse_forbidden_info.h diff --git a/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_parse_frame_info.h b/win32-example/ir_decoder/src/include/ir_ac_parse_frame_info.h similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_parse_frame_info.h rename to win32-example/ir_decoder/src/include/ir_ac_parse_frame_info.h diff --git a/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_parse_parameter.h b/win32-example/ir_decoder/src/include/ir_ac_parse_parameter.h similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_parse_parameter.h rename to win32-example/ir_decoder/src/include/ir_ac_parse_parameter.h diff --git a/win32-example/IRextWin32Example/ir_decoder/src/include/ir_decode.h b/win32-example/ir_decoder/src/include/ir_decode.h similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/include/ir_decode.h rename to win32-example/ir_decoder/src/include/ir_decode.h diff --git a/win32-example/IRextWin32Example/ir_decoder/src/include/ir_defs.h b/win32-example/ir_decoder/src/include/ir_defs.h similarity index 92% rename from win32-example/IRextWin32Example/ir_decoder/src/include/ir_defs.h rename to win32-example/ir_decoder/src/include/ir_defs.h index be31f58..9a9d8f6 100644 --- a/win32-example/IRextWin32Example/ir_decoder/src/include/ir_defs.h +++ b/win32-example/ir_decoder/src/include/ir_defs.h @@ -12,6 +12,8 @@ Revision log: #ifndef _IR_DEFS_H #define _IR_DEFS_H +#define IR_DECODE_LIB_VER "1.5.0" + #if defined (BOARD_PC) #pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection" #pragma ide diagnostic ignored "OCUnusedMacroInspection" @@ -65,7 +67,7 @@ void noprint(const char *fmt, ...); #define ir_memset(A, B, C) memset(A, B, C) #define ir_strlen(A) strlen(A) #if ((defined BOARD_PC) || (defined BOARD_PC_JNI)) && (defined DEBUG) -#define ir_printf printf +#define ir_printf(...) do { printf(__VA_ARGS__); fflush(stdout); } while(0) #else #define ir_printf noprint #endif diff --git a/win32-example/IRextWin32Example/ir_decoder/src/include/ir_tv_control.h b/win32-example/ir_decoder/src/include/ir_tv_control.h similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/include/ir_tv_control.h rename to win32-example/ir_decoder/src/include/ir_tv_control.h diff --git a/win32-example/IRextWin32Example/ir_decoder/src/include/ir_utils.h b/win32-example/ir_decoder/src/include/ir_utils.h similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/include/ir_utils.h rename to win32-example/ir_decoder/src/include/ir_utils.h diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_apply.c b/win32-example/ir_decoder/src/ir_ac_apply.c similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/ir_ac_apply.c rename to win32-example/ir_decoder/src/ir_ac_apply.c diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_binary_parse.c b/win32-example/ir_decoder/src/ir_ac_binary_parse.c similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/ir_ac_binary_parse.c rename to win32-example/ir_decoder/src/ir_ac_binary_parse.c diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_build_frame.c b/win32-example/ir_decoder/src/ir_ac_build_frame.c similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/ir_ac_build_frame.c rename to win32-example/ir_decoder/src/ir_ac_build_frame.c diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_control.c b/win32-example/ir_decoder/src/ir_ac_control.c similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/ir_ac_control.c rename to win32-example/ir_decoder/src/ir_ac_control.c diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_forbidden_info.c b/win32-example/ir_decoder/src/ir_ac_parse_forbidden_info.c similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_forbidden_info.c rename to win32-example/ir_decoder/src/ir_ac_parse_forbidden_info.c diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_frame_info.c b/win32-example/ir_decoder/src/ir_ac_parse_frame_info.c similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_frame_info.c rename to win32-example/ir_decoder/src/ir_ac_parse_frame_info.c diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_parameter.c b/win32-example/ir_decoder/src/ir_ac_parse_parameter.c similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_parameter.c rename to win32-example/ir_decoder/src/ir_ac_parse_parameter.c diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_decode.c b/win32-example/ir_decoder/src/ir_decode.c similarity index 91% rename from win32-example/IRextWin32Example/ir_decoder/src/ir_decode.c rename to win32-example/ir_decoder/src/ir_decode.c index 1994d5f..659cf8b 100644 --- a/win32-example/IRextWin32Example/ir_decoder/src/ir_decode.c +++ b/win32-example/ir_decoder/src/ir_decode.c @@ -22,7 +22,7 @@ Revision log: struct ir_bin_buffer binary_file; struct ir_bin_buffer *p_ir_buffer = &binary_file; -static const char* version = "0.2.5"; +static const char* version = IR_DECODE_LIB_VER; #if defined USE_DYNAMIC_TAG struct tag_head *tags; @@ -82,6 +82,7 @@ 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 INT8 ir_ac_binary_close(); +static BOOL validate_ac_status(t_remote_ac_status* ac_status, BOOL change_wind_dir); #if !defined NO_FS static INT8 ir_tv_file_open(const char *file_name); @@ -218,7 +219,19 @@ INT8 ir_binary_open(const UINT8 category, const UINT8 sub_category, UINT8* binar return IR_DECODE_FAILED; } - ret = ir_tv_binary_open(binary, bin_length); +#if (defined(BOARD_PC) || defined (BOARD_PC_DLL) || defined (BOARD_ANDROID)) + binary_content = (UINT8 *) ir_malloc(bin_length); + if (NULL == binary_content) + { + ir_printf("failed to malloc memory for binary\n"); + return IR_DECODE_FAILED; + } + memcpy(binary_content, binary, bin_length); +#else + binary_content = binary; +#endif + + ret = ir_tv_binary_open(binary_content, bin_length); if (IR_DECODE_SUCCEEDED == ret) { return ir_tv_binary_parse(ir_hexadecimal); @@ -259,6 +272,10 @@ UINT16 ir_decode(UINT8 key_code, UINT16* user_data, ac_status->ac_temp, ac_status->ac_wind_dir, ac_status->ac_wind_speed, key_code, change_wind_direction); + // ac status validation + if (FALSE == validate_ac_status(ac_status, change_wind_direction)) { + return 0; + } return ir_ac_control(*ac_status, user_data, key_code, change_wind_direction); } } @@ -489,6 +506,35 @@ 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) +{ + if (AC_POWER_OFF != ac_status->ac_power && AC_POWER_ON != ac_status->ac_power) + { + return FALSE; + } + if (ac_status->ac_mode < AC_MODE_COOL || ac_status->ac_mode >= AC_MODE_MAX) + { + return FALSE; + } + if (ac_status->ac_temp < AC_TEMP_16 || ac_status->ac_temp >= AC_TEMP_MAX) + { + return FALSE; + } + if (ac_status->ac_wind_speed < AC_WS_AUTO || ac_status->ac_wind_speed >= AC_WS_MAX) + { + return FALSE; + } + if (ac_status->ac_wind_dir < AC_SWING_ON || ac_status->ac_wind_dir >= AC_SWING_MAX) + { + return FALSE; + } + if (0 != change_wind_dir && 1 != change_wind_dir) + { + return FALSE; + } + return TRUE; +} + // utils INT8 get_temperature_range(UINT8 ac_mode, INT8 *temp_min, INT8 *temp_max) { @@ -652,7 +698,7 @@ static INT8 ir_tv_file_open(const char *file_name) if (stream == NULL) { - ir_printf("\nfile open failed\n"); + ir_printf("file open failed\n"); return IR_DECODE_FAILED; } @@ -662,7 +708,7 @@ static INT8 ir_tv_file_open(const char *file_name) binary_content = (UINT8 *) ir_malloc(binary_length); if (NULL == binary_content) { - ir_printf("\nfailed to alloc memory for binary\n"); + ir_printf("failed to malloc memory for binary\n"); fclose(stream); return IR_DECODE_FAILED; } @@ -681,6 +727,7 @@ static INT8 ir_tv_file_open(const char *file_name) if (IR_DECODE_FAILED == ir_tv_binary_open(binary_content, (UINT16) binary_length)) { + ir_printf("failed to parse command type binary\n"); ir_free(binary_content); binary_length = 0; return IR_DECODE_FAILED; diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_decode_test.c b/win32-example/ir_decoder/src/ir_decode_test.c similarity index 88% rename from win32-example/IRextWin32Example/ir_decoder/src/ir_decode_test.c rename to win32-example/ir_decoder/src/ir_decode_test.c index f3d3a85..da24367 100644 --- a/win32-example/IRextWin32Example/ir_decoder/src/ir_decode_test.c +++ b/win32-example/ir_decoder/src/ir_decode_test.c @@ -30,15 +30,21 @@ void input_number(int *val) char n[50]={0}; int i = 0; *val = 0; - scanf("%s", n); + if (0 != scanf("%s", n)) + { + return; + } getchar(); while(1) { if(n[i] < '0'||n[i] > '9') { - printf("\nInvalid number format, please re-input : "); - scanf("%s", n); - i=0; + printf("invalid number format, please re-input : "); + if (0 != scanf("%s", n)) + { + break; + } + i = 0; } else { @@ -94,13 +100,13 @@ static INT8 decode_as_ac(char *file_name) { if (1 == first_time) { - printf("Please input valid key code " - "(Key code could be referenced from https://irext.net/doc#keymap) : \n"); + printf("please input valid key code " + "(key code could be referenced from https://irext.net/doc#keymap) : \n"); first_time = 0; } else { - printf("Please input valid key code : \n"); + printf("please input valid key code : \n"); } input_number(&key_code); @@ -219,7 +225,7 @@ static INT8 decode_as_ac(char *file_name) ac_status.ac_wind_dir, key_code); length = ir_decode(key_code, user_data, &ac_status, change_wind_dir); - printf("\n === Binary decoded : %d\n", length); + printf("\n === binary decoded : %d\n", length); for (index = 0; index < length; index++) { printf("%d, ", user_data[index]); @@ -245,6 +251,7 @@ static INT8 decode_as_tv(char *file_name, UINT8 ir_hex_encode) // here remote category TV represents for command typed IR code if (IR_DECODE_FAILED == ir_file_open(REMOTE_CATEGORY_TV, ir_hex_encode, file_name)) { + printf("failed to open file : %s\n", file_name); ir_close(); return IR_DECODE_FAILED; } @@ -253,13 +260,13 @@ static INT8 decode_as_tv(char *file_name, UINT8 ir_hex_encode) { if (1 == first_time) { - printf("Please input valid key code " + printf("please input valid key code " "(Key code could be referenced from https://irext.net/doc#keymap) : \n"); first_time = 0; } else { - printf("Please input valid key code : \n"); + printf("please input valid key code : \n"); } input_number(&key_code); if (99 == key_code) @@ -267,7 +274,7 @@ static INT8 decode_as_tv(char *file_name, UINT8 ir_hex_encode) break; } length = ir_decode(key_code, user_data, NULL, 0); - printf("\n === Binary decoded : %d\n", length); + printf("\n === binary decoded : %d\n", length); for (index = 0; index < length; index++) { printf("%d, ", user_data[index]); @@ -281,10 +288,10 @@ static INT8 decode_as_tv(char *file_name, UINT8 ir_hex_encode) } static void print_usage(const char *progn) { - printf("Usage: %s [function] [file] [subcate]\n" - "[function] : 0 - decode for AC; 1 - decode for TV\n" + printf("usage: %s [function] [file] [subcate]\n" + "[function] : 0 - decode for AC; 1 - decode for others\n" "[file] : the remote control binary file\n" - "[subcate] : the sub_cate value from remote_index", progn); + "[sub_cate] : the sub_cate value from remote_index", progn); } int main(int argc, char *argv[]) @@ -304,17 +311,17 @@ int main(int argc, char *argv[]) switch (function) { case '0': - printf("Decode %s as status-typed binary\n", argv[2]); + printf("decode %s as status-typed binary\n", argv[2]); decode_as_ac(argv[2]); break; case '1': - printf("Decode %s as command-typed binary in sub_cate %d\n", argv[2], ir_hex_encode); + printf("decode %s as command-typed binary in sub_cate %d\n", argv[2], ir_hex_encode); decode_as_tv(argv[2], ir_hex_encode); break; default: - printf("Decode functionality not supported : %c\n", function); + printf("decode functionality not supported : %c\n", function); break; } } \ No newline at end of file diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_tv_control.c b/win32-example/ir_decoder/src/ir_tv_control.c similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/ir_tv_control.c rename to win32-example/ir_decoder/src/ir_tv_control.c diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_utils.c b/win32-example/ir_decoder/src/ir_utils.c similarity index 100% rename from win32-example/IRextWin32Example/ir_decoder/src/ir_utils.c rename to win32-example/ir_decoder/src/ir_utils.c