From e2d2f8024a5690cf2e648090473c377328021010 Mon Sep 17 00:00:00 2001 From: strawmanbobi Date: Sun, 26 Jul 2020 20:52:04 +0800 Subject: [PATCH] updated examples --- .../Source/ir_decoder/src/ir_decode.c | 33 +- .../Application/ir_decoder/src/ir_decode.c | 33 +- .../IRextWin32Example/DecodeTestWin.cpp | 512 ++++++++++-------- .../IRextWin32Example.vcxproj | 26 +- .../IRextWin32Example.vcxproj.filters | 70 +-- .../{ => src}/include/ir_ac_apply.h | 10 +- .../{ => src}/include/ir_ac_binary_parse.h | 6 +- .../{ => src}/include/ir_ac_build_frame.h | 6 +- .../{ => src}/include/ir_ac_control.h | 10 +- .../include/ir_ac_parse_forbidden_info.h | 6 +- .../include/ir_ac_parse_frame_info.h | 6 +- .../{ => src}/include/ir_ac_parse_parameter.h | 6 +- .../ir_decoder/{ => src}/include/ir_decode.h | 67 ++- .../ir_decoder/{ => src}/include/ir_defs.h | 11 +- .../{ => src}/include/ir_tv_control.h | 12 +- .../ir_decoder/{ => src}/include/ir_utils.h | 10 +- .../ir_decoder/src/ir_ac_apply.c | 20 +- .../ir_decoder/src/ir_ac_binary_parse.c | 6 +- .../ir_decoder/src/ir_ac_build_frame.c | 43 +- .../ir_decoder/src/ir_ac_control.c | 50 +- .../src/ir_ac_parse_forbidden_info.c | 18 +- .../ir_decoder/src/ir_ac_parse_frame_info.c | 54 +- .../ir_decoder/src/ir_ac_parse_parameter.c | 259 ++++----- .../ir_decoder/src/ir_decode.c | 198 ++++--- .../ir_decoder/src/ir_decode_test.c | 324 +++++++++++ .../ir_decoder/src/ir_tv_control.c | 10 +- .../ir_decoder/src/ir_utils.c | 8 +- 27 files changed, 1179 insertions(+), 635 deletions(-) rename win32-example/IRextWin32Example/ir_decoder/{ => src}/include/ir_ac_apply.h (87%) rename win32-example/IRextWin32Example/ir_decoder/{ => src}/include/ir_ac_binary_parse.h (83%) rename win32-example/IRextWin32Example/ir_decoder/{ => src}/include/ir_ac_build_frame.h (87%) rename win32-example/IRextWin32Example/ir_decoder/{ => src}/include/ir_ac_control.h (97%) rename win32-example/IRextWin32Example/ir_decoder/{ => src}/include/ir_ac_parse_forbidden_info.h (86%) rename win32-example/IRextWin32Example/ir_decoder/{ => src}/include/ir_ac_parse_frame_info.h (89%) rename win32-example/IRextWin32Example/ir_decoder/{ => src}/include/ir_ac_parse_parameter.h (94%) rename win32-example/IRextWin32Example/ir_decoder/{ => src}/include/ir_decode.h (88%) rename win32-example/IRextWin32Example/ir_decoder/{ => src}/include/ir_defs.h (87%) rename win32-example/IRextWin32Example/ir_decoder/{ => src}/include/ir_tv_control.h (93%) rename win32-example/IRextWin32Example/ir_decoder/{ => src}/include/ir_utils.h (82%) create mode 100644 win32-example/IRextWin32Example/ir_decoder/src/ir_decode_test.c diff --git a/cc25xx-8051-example/ti/BLE-CC254x/Projects/ble/SimpleBLEPeripheral-IREXT/Source/ir_decoder/src/ir_decode.c b/cc25xx-8051-example/ti/BLE-CC254x/Projects/ble/SimpleBLEPeripheral-IREXT/Source/ir_decoder/src/ir_decode.c index d3d2c09..110bc22 100644 --- a/cc25xx-8051-example/ti/BLE-CC254x/Projects/ble/SimpleBLEPeripheral-IREXT/Source/ir_decoder/src/ir_decode.c +++ b/cc25xx-8051-example/ti/BLE-CC254x/Projects/ble/SimpleBLEPeripheral-IREXT/Source/ir_decoder/src/ir_decode.c @@ -182,7 +182,8 @@ INT8 ir_binary_open(const UINT8 category, const UINT8 sub_category, UINT8* binar } remote_category = (t_remote_category) category; - if (sub_category >= SUB_CATEGORY_NEXT) + if (sub_category < SUB_CATEGORY_QUATERNARY || + sub_category >= SUB_CATEGORY_NEXT) { ir_printf("wrong remote sub category : %d\n", sub_category); return IR_DECODE_FAILED; @@ -235,7 +236,7 @@ UINT16 ir_decode(UINT8 key_code, UINT16* user_data, { ir_printf("remote_category = %d, KEY_CODE_MAX = %d\n", remote_category, KEY_CODE_MAX[remote_category]); - if (key_code >= KEY_CODE_MAX[remote_category]) + if (key_code < 0 || key_code >= KEY_CODE_MAX[remote_category]) { ir_printf("key_code exceeded!\n"); return 0; @@ -469,19 +470,6 @@ static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16* user_data, UIN time_length = create_ir_frame(); -#if (defined BOARD_PC) -#if (defined BOARD_PC_JNI) - ir_printf("code count = %d\n", context->code_cnt); -#else - int i = 0; - for (i = 0; i < context->code_cnt; i++) - { - ir_printf("%d,", context->time[i]); - } -#endif - ir_printf("\n"); -#endif - return time_length; } @@ -635,6 +623,10 @@ INT8 get_supported_wind_direction(UINT8 *supported_wind_direction) if (NULL != context) { *supported_wind_direction = (UINT8) (context->si.mode_count - 1); + if (*supported_wind_direction < 0) + { + *supported_wind_direction = 0; + } return IR_DECODE_SUCCEEDED; } else @@ -721,15 +713,6 @@ static UINT16 ir_tv_control(UINT8 key, UINT16 *l_user_data) memset(l_user_data, 0x00, USER_DATA_SIZE); ir_code_length = tv_binary_decode(key, l_user_data); -#if defined BOARD_PC - // have some debug - ir_printf("length of IR code = %d\n", ir_code_length); - for (print_index = 0; print_index < ir_code_length; print_index++) - { - ir_printf("%d ", l_user_data[print_index]); - } -#endif - return ir_code_length; } @@ -759,7 +742,7 @@ UINT16 ir_decode_combo(const UINT8 category, const UINT8 sub_category, remote_category = (t_remote_category) category; - if (key_code >= KEY_CODE_MAX[remote_category]) + if (key_code < 0 || key_code >= KEY_CODE_MAX[remote_category]) { ir_printf("key_code exceeded!\n"); return 0; diff --git a/cc26xx-ARM-Cortex-M3-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/ir_decoder/src/ir_decode.c b/cc26xx-ARM-Cortex-M3-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/ir_decoder/src/ir_decode.c index d3d2c09..110bc22 100644 --- a/cc26xx-ARM-Cortex-M3-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/ir_decoder/src/ir_decode.c +++ b/cc26xx-ARM-Cortex-M3-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/ir_decoder/src/ir_decode.c @@ -182,7 +182,8 @@ INT8 ir_binary_open(const UINT8 category, const UINT8 sub_category, UINT8* binar } remote_category = (t_remote_category) category; - if (sub_category >= SUB_CATEGORY_NEXT) + if (sub_category < SUB_CATEGORY_QUATERNARY || + sub_category >= SUB_CATEGORY_NEXT) { ir_printf("wrong remote sub category : %d\n", sub_category); return IR_DECODE_FAILED; @@ -235,7 +236,7 @@ UINT16 ir_decode(UINT8 key_code, UINT16* user_data, { ir_printf("remote_category = %d, KEY_CODE_MAX = %d\n", remote_category, KEY_CODE_MAX[remote_category]); - if (key_code >= KEY_CODE_MAX[remote_category]) + if (key_code < 0 || key_code >= KEY_CODE_MAX[remote_category]) { ir_printf("key_code exceeded!\n"); return 0; @@ -469,19 +470,6 @@ static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16* user_data, UIN time_length = create_ir_frame(); -#if (defined BOARD_PC) -#if (defined BOARD_PC_JNI) - ir_printf("code count = %d\n", context->code_cnt); -#else - int i = 0; - for (i = 0; i < context->code_cnt; i++) - { - ir_printf("%d,", context->time[i]); - } -#endif - ir_printf("\n"); -#endif - return time_length; } @@ -635,6 +623,10 @@ INT8 get_supported_wind_direction(UINT8 *supported_wind_direction) if (NULL != context) { *supported_wind_direction = (UINT8) (context->si.mode_count - 1); + if (*supported_wind_direction < 0) + { + *supported_wind_direction = 0; + } return IR_DECODE_SUCCEEDED; } else @@ -721,15 +713,6 @@ static UINT16 ir_tv_control(UINT8 key, UINT16 *l_user_data) memset(l_user_data, 0x00, USER_DATA_SIZE); ir_code_length = tv_binary_decode(key, l_user_data); -#if defined BOARD_PC - // have some debug - ir_printf("length of IR code = %d\n", ir_code_length); - for (print_index = 0; print_index < ir_code_length; print_index++) - { - ir_printf("%d ", l_user_data[print_index]); - } -#endif - return ir_code_length; } @@ -759,7 +742,7 @@ UINT16 ir_decode_combo(const UINT8 category, const UINT8 sub_category, remote_category = (t_remote_category) category; - if (key_code >= KEY_CODE_MAX[remote_category]) + if (key_code < 0 || key_code >= KEY_CODE_MAX[remote_category]) { ir_printf("key_code exceeded!\n"); return 0; diff --git a/win32-example/IRextWin32Example/DecodeTestWin.cpp b/win32-example/IRextWin32Example/DecodeTestWin.cpp index 745a26b..4f07dbe 100644 --- a/win32-example/IRextWin32Example/DecodeTestWin.cpp +++ b/win32-example/IRextWin32Example/DecodeTestWin.cpp @@ -1,237 +1,327 @@ -#include "ir_decoder\include\ir_decode.h" +/************************************************************************************** +Filename: DecodeTestWin.cpp +Revised: Date: 2016-11-05 +Revision: Revision: 1.0 -#include -using namespace std; +Description: This file provides main entry for irda decoder -#ifdef _DEBUG -#define new DEBUG_NEW -#endif +Revision log: +* 2016-11-05: created by strawmanbobi +**************************************************************************************/ + + +#include +#include +#include +#include + +#include "ir_decoder\src\include\ir_defs.h" +#include "ir_decoder\src\include\ir_decode.h" + +#define INPUT_MAX 3 // global variable definition -long binary_length = 0; -UINT8 *binary_content = NULL; - t_remote_ac_status ac_status; -UINT16 user_data[USER_DATA_SIZE] = { 0 }; +UINT16 user_data[USER_DATA_SIZE]; -INT8 decode_as_ac(char* file_name) +void input_number(int *val) { - // keyboard input - int in_char = 0; - int count = 0; - BOOL op_match = TRUE; - UINT8 function_code = AC_FUNCTION_MAX; - - // get status - UINT8 supported_mode = 0x00; - INT8 min_temperature = 0; - INT8 max_temperature = 0; - UINT8 supported_speed = 0x00; - UINT8 supported_swing = 0x00; - - BOOL need_control = TRUE; - - // 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_OFF; - 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; - - if (IR_DECODE_FAILED == ir_file_open(0, 0, file_name)) - { - ir_close(); - return IR_DECODE_FAILED; - } - - do - { - in_char = getchar(); - op_match = TRUE; - need_control = TRUE; - switch (in_char) - { - case 'w': - case 'W': - // temperature plus - ac_status.ac_temp = (t_ac_temperature)((ac_status.ac_temp == AC_TEMP_30) ? AC_TEMP_30 : (ac_status.ac_temp + 1)); - function_code = AC_FUNCTION_TEMPERATURE_UP; - break; - case 's': - case 'S': - ac_status.ac_temp = (t_ac_temperature)((ac_status.ac_temp == AC_TEMP_16) ? AC_TEMP_16 : (ac_status.ac_temp - 1)); - function_code = AC_FUNCTION_TEMPERATURE_DOWN; - // temperature minus - break; - case 'a': - case 'A': - ac_status.ac_wind_speed = (t_ac_wind_speed) (ac_status.ac_wind_speed + 1); - ac_status.ac_wind_speed = (t_ac_wind_speed) (ac_status.ac_wind_speed % AC_WS_MAX); - function_code = AC_FUNCTION_WIND_SPEED; - // wind speed loop - break; - case 'd': - case 'D': - ac_status.ac_wind_dir = (t_ac_swing)((ac_status.ac_wind_dir == 0) ? 1 : 0); - function_code = AC_FUNCTION_WIND_SWING; - // wind swing loop - break; - case 'q': - case 'Q': - ac_status.ac_mode = (t_ac_mode)(ac_status.ac_mode + 1); - ac_status.ac_mode = (t_ac_mode) (ac_status.ac_mode % AC_MODE_MAX); - function_code = AC_FUNCTION_MODE; - break; - case '1': - // turn on - ac_status.ac_power = AC_POWER_ON; - function_code = AC_FUNCTION_POWER; - break; - case '2': - // turn off - ac_status.ac_power = AC_POWER_OFF; - // FUNCTION MAX refers to power off - // function_code = AC_FUNCTION_POWER; - break; - case '3': - if (IR_DECODE_SUCCEEDED == get_supported_mode(&supported_mode)) - { - ir_printf("supported mode = %02X\n", supported_mode); - } - need_control = FALSE; - break; - - case '4': - if (IR_DECODE_SUCCEEDED == get_supported_swing(ac_status.ac_mode, &supported_swing)) - { - ir_printf("supported swing in %d = %02X\n", ac_status.ac_mode, supported_swing); - } - need_control = FALSE; - break; - case '5': - if (IR_DECODE_SUCCEEDED == get_supported_wind_speed(ac_status.ac_mode, &supported_speed)) - { - ir_printf("supported wind speed in %d = %02X\n", ac_status.ac_mode, supported_speed); - } - need_control = FALSE; - break; - - case '6': - if (IR_DECODE_SUCCEEDED == get_temperature_range(ac_status.ac_mode, &min_temperature, &max_temperature)) - { - ir_printf("supported temperature range in mode %d = %d, %d\n", - ac_status.ac_mode, min_temperature, max_temperature); - } - need_control = FALSE; - break; - - default: - op_match = FALSE; - break; - } - - if (TRUE == op_match && TRUE == need_control) - { - ir_printf("switch AC to power = %d, mode = %d, temp = %d, speed = %d, swing = %d\n", - ac_status.ac_power, - ac_status.ac_mode, - ac_status.ac_temp, - ac_status.ac_wind_speed, - ac_status.ac_wind_dir - ); - ir_decode(function_code, user_data, &ac_status, TRUE); - } - } while ('0' != in_char); - - ir_close(); - - // free binary buffer - ir_free(binary_content); - binary_length = 0; - - return IR_DECODE_SUCCEEDED; + char n[50]={0}; + int i = 0; + *val = 0; + scanf_s("%3s", n); + getchar(); + while(1) + { + if(n[i] < '0'||n[i] > '9') + { + printf("\nInvalid number format, please re-input : "); + scanf_s("%3s", n); + i=0; + } + else + { + i++; + } + if(n[i] == '\0') + break; + } + i = 0; + while (n[i] != '\0') + { + *val = (*val * 10 + (int)n[i] - 48); + i++; + } } -INT8 decode_as_tv(char *file_name, UINT8 irda_hex_encode) +static INT8 decode_as_ac(char *file_name) { - // keyboard input - int in_char = 0; - int key_code = -1; - int count = 0; + BOOL op_match = TRUE; + BOOL change_wind_dir = FALSE; + UINT8 function_code = AC_FUNCTION_MAX; + int key_code = 0; + int first_time = 1; + int length = 0; + int index = 0; - if (IR_DECODE_FAILED == ir_file_open(1, 1, file_name)) - { - return IR_DECODE_FAILED; - } + // get status + UINT8 supported_mode = 0x00; + INT8 min_temperature = 0; + INT8 max_temperature = 0; + UINT8 supported_speed = 0x00; + UINT8 supported_swing = 0x00; + UINT8 supported_wind_direction = 0x00; - do - { - in_char = getchar(); - if (in_char >= '0' && in_char <= '9') - { - key_code = in_char - '0'; - ir_decode(key_code, user_data, NULL, FALSE); - } - else if (in_char >= 'a' && in_char <= 'f') - { - key_code = 10 + (in_char - 'a'); - ir_decode(key_code, user_data, NULL, FALSE); - } - else if (in_char == 'q') - { - ir_close(); - } - else - { - // do nothing - } - } while ('Q' != in_char); + BOOL need_control = TRUE; - // free binary buffer - ir_free(binary_content); - binary_length = 0; + // 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; - return IR_DECODE_SUCCEEDED; + if (IR_DECODE_FAILED == ir_file_open(REMOTE_CATEGORY_AC, 0, file_name)) + { + ir_close(); + return IR_DECODE_FAILED; + } + + do + { + if (1 == first_time) + { + 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"); + } + input_number(&key_code); + + op_match = TRUE; + need_control = FALSE; + change_wind_dir = FALSE; + + if (99 == key_code) + { + break; + } + + if (14 == key_code) + { + if (IR_DECODE_SUCCEEDED == get_supported_mode(&supported_mode)) + { + printf("supported mode = %02X\n", supported_mode); + } + else + { + printf("get supported mode failed\n"); + } + } + else if (15 == key_code) + { + 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); + } + else + { + printf("get supported wind speed failed\n"); + } + } + else if (16 == key_code) + { + 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); + } + else + { + printf("get supported temperature range failed\n"); + } + } + else if (17 == key_code) + { + if (IR_DECODE_SUCCEEDED == get_supported_wind_direction(&supported_wind_direction)) + { + printf("supported swing type = %02X\n", supported_wind_direction); + } + else + { + printf("get swing type failed\n"); + } + } + else + { + int temp_mode = 0; + int temp_wind_speed = 0; + + switch (key_code) + { + case 0: + ac_status.ac_power = ((ac_status.ac_wind_dir == AC_POWER_ON) ? AC_POWER_OFF : AC_POWER_ON); + need_control = TRUE; + break; + + case 1: + temp_mode = (int) ac_status.ac_mode; + temp_mode++; + ac_status.ac_mode = (t_ac_mode) (temp_mode % AC_MODE_MAX); + need_control = TRUE; + break; + + case 2: + case 7: + ac_status.ac_temp = (t_ac_temperature) ((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 = (t_ac_temperature) ((ac_status.ac_temp == AC_TEMP_16) ? AC_TEMP_16 : (ac_status.ac_temp - 1)); + need_control = TRUE; + break; + + case 9: + temp_wind_speed = (int)ac_status.ac_wind_speed; + temp_wind_speed++; + ac_status.ac_wind_speed = (t_ac_wind_speed) (temp_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); + need_control = TRUE; + break; + + case 11: + if (ac_status.ac_wind_dir == AC_SWING_OFF) { + change_wind_dir = TRUE; + } + need_control = TRUE; + break; + + default: + op_match = FALSE; + break; + } + + if (TRUE == op_match && TRUE == need_control) + { + printf("switch AC to power = %d, mode = %d, temp = %d, speed = %d, swing = %d with function 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, + function_code); + + length = ir_decode(function_code, user_data, &ac_status, change_wind_dir); + printf("\n === Binary decoded : %d\n", length); + for (index = 0; index < length; index++) + { + printf("%d, ", user_data[index]); + } + printf("===\n"); + } + } + } while (TRUE); + + ir_close(); + + return IR_DECODE_SUCCEEDED; +} + +static INT8 decode_as_tv(char *file_name, UINT8 ir_hex_encode) +{ + // keyboard input + int key_code = 0; + int first_time = 1; + int length = 0; + int index = 0; + + // 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)) + { + ir_close(); + return IR_DECODE_FAILED; + } + + do + { + if (1 == first_time) + { + 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"); + } + input_number(&key_code); + if (99 == key_code) + { + break; + } + length = ir_decode(key_code, user_data, NULL, 0); + printf("\n === Binary decoded : %d\n", length); + for (index = 0; index < length; index++) + { + printf("%d, ", user_data[index]); + } + printf("===\n"); + + } while (TRUE); + + ir_close(); + return IR_DECODE_SUCCEEDED; +} + +static void print_usage(const char *progn) { + printf("Usage: %s [function] [file] [subcate]\n" + "[function] : 0 - decode for AC; 1 - decode for TV\n" + "[file] : the remote control binary file\n" + "[subcate] : the sub_cate value from remote_index", progn); } int main(int argc, char *argv[]) { - int nRetCode = 0; + char function = '0'; + UINT8 ir_hex_encode = 0; - char function = '0'; - UINT8 irda_hex_encode = 0; + if (4 != argc) + { + print_usage(argv[0]); + return -1; + } - if (4 != argc) - { - ir_printf("number of args error !\n"); - return -1; - } + function = argv[1][0]; + ir_hex_encode = (UINT8) (argv[3][0] - '0'); - function = argv[1][0]; - irda_hex_encode = (UINT8)(argv[3][0] - '0'); - ir_printf("decode functionality = %c\n", function); + switch (function) + { + case '0': + printf("Decode %s as status-typed binary\n", argv[2]); + decode_as_ac(argv[2]); + break; - switch (function) - { - case '0': - ir_printf("decode binary file as AC\n"); - 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); + decode_as_tv(argv[2], ir_hex_encode); + break; - case '1': - ir_printf("decode binary file as TV : %d\n", irda_hex_encode); - decode_as_tv(argv[2], irda_hex_encode); - break; + default: + printf("Decode functionality not supported : %c\n", function); + break; + } - default: - ir_printf("decode functionality error !\n"); - break; - } - system("pause"); - - return nRetCode; } \ No newline at end of file diff --git a/win32-example/IRextWin32Example/IRextWin32Example.vcxproj b/win32-example/IRextWin32Example/IRextWin32Example.vcxproj index 65c4895..5628770 100644 --- a/win32-example/IRextWin32Example/IRextWin32Example.vcxproj +++ b/win32-example/IRextWin32Example/IRextWin32Example.vcxproj @@ -146,19 +146,6 @@ true - - - - - - - - - - - - - @@ -172,6 +159,19 @@ + + + + + + + + + + + + + diff --git a/win32-example/IRextWin32Example/IRextWin32Example.vcxproj.filters b/win32-example/IRextWin32Example/IRextWin32Example.vcxproj.filters index d326df2..346eebe 100644 --- a/win32-example/IRextWin32Example/IRextWin32Example.vcxproj.filters +++ b/win32-example/IRextWin32Example/IRextWin32Example.vcxproj.filters @@ -14,41 +14,6 @@ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - 源文件 @@ -84,4 +49,39 @@ 源文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + \ No newline at end of file diff --git a/win32-example/IRextWin32Example/ir_decoder/include/ir_ac_apply.h b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_apply.h similarity index 87% rename from win32-example/IRextWin32Example/ir_decoder/include/ir_ac_apply.h rename to win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_apply.h index a9dc4d2..af68831 100644 --- a/win32-example/IRextWin32Example/ir_decoder/include/ir_ac_apply.h +++ b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_apply.h @@ -9,8 +9,12 @@ Revision log: * 2016-10-12: created by strawmanbobi **************************************************************************************/ -#ifndef _IRDA_APPLY_H_ -#define _IRDA_APPLY_H_ +#ifndef _IR_APPLY_H_ +#define _IR_APPLY_H_ + +#if defined (BOARD_PC) +#pragma ide diagnostic ignored "OCUnusedMacroInspection" +#endif #ifdef __cplusplus extern "C" @@ -40,4 +44,4 @@ INT8 apply_checksum(struct ac_protocol *protocol); } #endif -#endif //_IRDA_APPLY_H_ \ No newline at end of file +#endif // _IR_APPLY_H_ \ No newline at end of file diff --git a/win32-example/IRextWin32Example/ir_decoder/include/ir_ac_binary_parse.h b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_binary_parse.h similarity index 83% rename from win32-example/IRextWin32Example/ir_decoder/include/ir_ac_binary_parse.h rename to win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_binary_parse.h index 921437a..a24ed79 100644 --- a/win32-example/IRextWin32Example/ir_decoder/include/ir_ac_binary_parse.h +++ b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_binary_parse.h @@ -9,8 +9,8 @@ Revision log: * 2017-01-03: created by strawmanbobi **************************************************************************************/ -#ifndef IRDA_DECODER_IR_AC_BINARY_PARSE_H -#define IRDA_DECODER_IR_AC_BINARY_PARSE_H +#ifndef _IR_DECODER_IR_AC_BINARY_PARSE_H +#define _IR_DECODER_IR_AC_BINARY_PARSE_H #ifdef __cplusplus extern "C" @@ -32,4 +32,4 @@ extern INT8 binary_parse_data(); #endif -#endif //IRDA_DECODER_IR_AC_BINARY_PARSE_H +#endif // _IR_DECODER_IR_AC_BINARY_PARSE_H diff --git a/win32-example/IRextWin32Example/ir_decoder/include/ir_ac_build_frame.h b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_build_frame.h similarity index 87% rename from win32-example/IRextWin32Example/ir_decoder/include/ir_ac_build_frame.h rename to win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_build_frame.h index 8def3c8..1b55b11 100644 --- a/win32-example/IRextWin32Example/ir_decoder/include/ir_ac_build_frame.h +++ b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_build_frame.h @@ -9,8 +9,8 @@ Revision log: * 2016-10-01: created by strawmanbobi **************************************************************************************/ -#ifndef _IRDA_IRFRAME_H_ -#define _IRDA_IRFRAME_H_ +#ifndef _IR_IRFRAME_H_ +#define _IR_IRFRAME_H_ #ifdef __cplusplus extern "C" @@ -25,4 +25,4 @@ extern UINT16 create_ir_frame(); } #endif -#endif // _IRDA_IRFRAME_H_ \ No newline at end of file +#endif // _IR_IRFRAME_H_ \ No newline at end of file diff --git a/win32-example/IRextWin32Example/ir_decoder/include/ir_ac_control.h b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_control.h similarity index 97% rename from win32-example/IRextWin32Example/ir_decoder/include/ir_ac_control.h rename to win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_control.h index 1ce4882..60d8722 100644 --- a/win32-example/IRextWin32Example/ir_decoder/include/ir_ac_control.h +++ b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_control.h @@ -8,8 +8,12 @@ Description: This file provides methods for AC IR control Revision log: * 2016-10-12: created by strawmanbobi **************************************************************************************/ -#ifndef IRDA_DECODER_IR_AC_CONTROL_H -#define IRDA_DECODER_IR_AC_CONTROL_H +#ifndef _IR_DECODER_IR_AC_CONTROL_H +#define _IR_DECODER_IR_AC_CONTROL_H + +#if defined (BOARD_PC) +#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection" +#endif #ifdef __cplusplus extern "C" @@ -436,4 +440,4 @@ extern BOOL is_solo_function(UINT8 function_code); } #endif -#endif //IRDA_DECODER_IR_AC_CONTROL_H +#endif // _IR_DECODER_IR_AC_CONTROL_H diff --git a/win32-example/IRextWin32Example/ir_decoder/include/ir_ac_parse_forbidden_info.h b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_parse_forbidden_info.h similarity index 86% rename from win32-example/IRextWin32Example/ir_decoder/include/ir_ac_parse_forbidden_info.h rename to win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_parse_forbidden_info.h index 8f0f5b1..a134ff9 100644 --- a/win32-example/IRextWin32Example/ir_decoder/include/ir_ac_parse_forbidden_info.h +++ b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_parse_forbidden_info.h @@ -9,8 +9,8 @@ Revision log: * 2016-10-05: created by strawmanbobi **************************************************************************************/ -#ifndef _IRDA_PARSE_PARSE_H_ -#define _IRDA_PARSE_PARSE_H_ +#ifndef _IR_PARSE_PARSE_H_ +#define _IR_PARSE_PARSE_H_ #ifdef __cplusplus extern "C" @@ -25,5 +25,5 @@ extern INT8 parse_nmode(struct tag_head *tag, t_ac_n_mode index); } #endif -#endif // _IRDA_PARSE_PARSE_H_ +#endif // _IR_PARSE_PARSE_H_ diff --git a/win32-example/IRextWin32Example/ir_decoder/include/ir_ac_parse_frame_info.h b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_parse_frame_info.h similarity index 89% rename from win32-example/IRextWin32Example/ir_decoder/include/ir_ac_parse_frame_info.h rename to win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_parse_frame_info.h index 899f499..3016ea2 100644 --- a/win32-example/IRextWin32Example/ir_decoder/include/ir_ac_parse_frame_info.h +++ b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_parse_frame_info.h @@ -9,8 +9,8 @@ Revision log: * 2016-10-11: created by strawmanbobi **************************************************************************************/ -#ifndef _IRDA_PARSE_FRAME_PARAMETER_H_ -#define _IRDA_PARSE_FRAME_PARAMETER_H_ +#ifndef _IR_PARSE_FRAME_PARAMETER_H_ +#define _IR_PARSE_FRAME_PARAMETER_H_ #ifdef __cplusplus extern "C" @@ -41,4 +41,4 @@ extern INT8 parse_bit_num(struct tag_head *tag); } #endif -#endif // _IRDA_PARSE_FRAME_PARAMETER_H_ \ No newline at end of file +#endif // _IR_PARSE_FRAME_PARAMETER_H_ \ No newline at end of file diff --git a/win32-example/IRextWin32Example/ir_decoder/include/ir_ac_parse_parameter.h b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_parse_parameter.h similarity index 94% rename from win32-example/IRextWin32Example/ir_decoder/include/ir_ac_parse_parameter.h rename to win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_parse_parameter.h index 6d53e89..c991e46 100644 --- a/win32-example/IRextWin32Example/ir_decoder/include/ir_ac_parse_parameter.h +++ b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_ac_parse_parameter.h @@ -9,8 +9,8 @@ Revision log: * 2016-10-12: created by strawmanbobi **************************************************************************************/ -#ifndef _IRDA_PARSE_AC_PARAMETER_H_ -#define _IRDA_PARSE_AC_PARAMETER_H_ +#ifndef _IR_PARSE_AC_PARAMETER_H_ +#define _IR_PARSE_AC_PARAMETER_H_ #ifdef __cplusplus extern "C" @@ -55,4 +55,4 @@ extern INT8 parse_solo_code(struct tag_head *tag, t_solo_code *sc); } #endif -#endif // _IRDA_PARSE_AC_PARAMETER_H_ \ No newline at end of file +#endif // _IR_PARSE_AC_PARAMETER_H_ \ No newline at end of file diff --git a/win32-example/IRextWin32Example/ir_decoder/include/ir_decode.h b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_decode.h similarity index 88% rename from win32-example/IRextWin32Example/ir_decoder/include/ir_decode.h rename to win32-example/IRextWin32Example/ir_decoder/src/include/ir_decode.h index 75353ae..e0069aa 100644 --- a/win32-example/IRextWin32Example/ir_decoder/include/ir_decode.h +++ b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_decode.h @@ -9,8 +9,13 @@ Revision log: * 2016-10-01: created by strawmanbobi **************************************************************************************/ -#ifndef _IRDA_DECODE_H_ -#define _IRDA_DECODE_H_ +#ifndef _IR_DECODE_H_ +#define _IR_DECODE_H_ + +#if defined (BOARD_PC) +#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection" +#pragma ide diagnostic ignored "OCUnusedMacroInspection" +#endif #ifdef __cplusplus extern "C" @@ -25,15 +30,9 @@ extern "C" #define IR_DECODE_FAILED (-1) #define IR_DECODE_SUCCEEDED (0) -#define IR_CATEGORY_AC 1 -#define IR_CATEGORY_TV 2 - #define IR_TYPE_STATUS 0 #define IR_TYPE_COMMANDS 1 -#define SUB_CATEGORY_QUATERNARY 0 -#define SUB_CATEGORY_HEXADECIMAL 1 - // remote control key definition #define KEY_TV_POWER 0 #define KEY_TV_MUTE 1 @@ -196,8 +195,50 @@ extern "C" #define KEY_DYSON_SLEEP 12 #define KEY_DYSON_COOL 13 +#define STANDARD_KEY_COUNT 14 +#define CHANNEL_KEY_COUNT 10 + +typedef enum +{ + REMOTE_CATEGORY_NONE = 0, + REMOTE_CATEGORY_AC = 1, + REMOTE_CATEGORY_TV = 2, + REMOTE_CATEGORY_STB = 3, + REMOTE_CATEGORY_NETBOX = 4, + REMOTE_CATEGORY_IPTV = 5, + REMOTE_CATEGORY_DVD = 6, + REMOTE_CATEGORY_FAN = 7, + REMOTE_CATEGORY_PROJECTOR = 8, + REMOTE_CATEGORY_STEREO = 9, + REMOTE_CATEGORY_LIGHT = 10, + REMOTE_CATEGORY_BSTB = 11, + REMOTE_CATEGORY_CLEANING_ROBOT = 12, + REMOTE_CATEGORY_AREMOTE_CLEANER = 13, + REMOTE_CATEGORY_DYSON = 14, + REMOTE_CATEGORY_NEXT, + REMOTE_CATEGORY_MAX = 64, +} t_remote_category; + +typedef enum +{ + SUB_CATEGORY_QUATERNARY = 0, + SUB_CATEGORY_HEXADECIMAL = 1, + SUB_CATEGORY_NEXT = 2, + SUB_CATEGORY_MAX = 7, +} t_remote_sub_category; + +/** + * function get_lib_version + * + * description: get version of library + * + * parameters: N/A + * + * returns: the string contains library version + * + */ +extern const char* get_lib_version(); -// exported functions /** * function ir_file_open * @@ -220,11 +261,11 @@ extern INT8 ir_file_open(const UINT8 category, const UINT8 sub_category, const c * parameters: category (in) - category ID get from indexing API * sub_category (in) - subcategory ID get from indexing API * binary (in) - pointer to binary buffer - * binary_length (in) - binary buffer size + * bin_length (in) - binary buffer size * * returns: IR_DECODE_SUCCEEDED / IR_DECODE_FAILED */ -extern INT8 ir_binary_open(const UINT8 category, const UINT8 sub_category, UINT8* binary, UINT16 binary_length); +extern INT8 ir_binary_open(const UINT8 category, const UINT8 sub_category, UINT8* binary, UINT16 bin_length); /** * function ir_decode @@ -318,7 +359,7 @@ extern void ir_lib_free_inner_buffer(); // this function is preferred being called by JNI only UINT16 ir_decode_combo(const UINT8 category, const UINT8 sub_category, - UINT8* binary, UINT16 binary_length, + UINT8* binary, UINT16 bin_length, UINT8 key_code, UINT16* user_data, t_remote_ac_status* ac_status, BOOL change_wind_direction); @@ -326,4 +367,4 @@ UINT16 ir_decode_combo(const UINT8 category, const UINT8 sub_category, } #endif -#endif // _IRDA_DECODE_H_ +#endif // _IR_DECODE_H_ \ No newline at end of file diff --git a/win32-example/IRextWin32Example/ir_decoder/include/ir_defs.h b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_defs.h similarity index 87% rename from win32-example/IRextWin32Example/ir_decoder/include/ir_defs.h rename to win32-example/IRextWin32Example/ir_decoder/src/include/ir_defs.h index 940e6b5..be31f58 100644 --- a/win32-example/IRextWin32Example/ir_decoder/include/ir_defs.h +++ b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_defs.h @@ -9,8 +9,13 @@ Revision log: * 2016-10-01: created by strawmanbobi **************************************************************************************/ -#ifndef PARSE_IR_DEFS_H -#define PARSE_IR_DEFS_H +#ifndef _IR_DEFS_H +#define _IR_DEFS_H + +#if defined (BOARD_PC) +#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection" +#pragma ide diagnostic ignored "OCUnusedMacroInspection" +#endif #ifdef __cplusplus extern "C" @@ -70,4 +75,4 @@ void noprint(const char *fmt, ...); #ifdef __cplusplus } #endif -#endif //PARSE_IR_DEFS_H +#endif //_IR_DEFS_H \ No newline at end of file diff --git a/win32-example/IRextWin32Example/ir_decoder/include/ir_tv_control.h b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_tv_control.h similarity index 93% rename from win32-example/IRextWin32Example/ir_decoder/include/ir_tv_control.h rename to win32-example/IRextWin32Example/ir_decoder/src/include/ir_tv_control.h index eafb9b7..fc948f6 100644 --- a/win32-example/IRextWin32Example/ir_decoder/include/ir_tv_control.h +++ b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_tv_control.h @@ -9,8 +9,13 @@ Revision log: * 2016-10-21: created by strawmanbobi **************************************************************************************/ -#ifndef _IRDA_LIB_H_ -#define _IRDA_LIB_H_ +#ifndef _IR_TV_CONTROL_H_ +#define _IR_TV_CONTROL_H_ + +#if defined (BOARD_PC) +#pragma ide diagnostic ignored "OCUnusedMacroInspection" +#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection" +#endif #ifdef __cplusplus extern "C" @@ -211,5 +216,4 @@ extern UINT8 tv_lib_close(); } #endif -#endif /* _IRDA_LIB_H_ */ - +#endif // _IR_TV_CONTROL_H_ \ No newline at end of file diff --git a/win32-example/IRextWin32Example/ir_decoder/include/ir_utils.h b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_utils.h similarity index 82% rename from win32-example/IRextWin32Example/ir_decoder/include/ir_utils.h rename to win32-example/IRextWin32Example/ir_decoder/src/include/ir_utils.h index 667bdf1..842ac16 100644 --- a/win32-example/IRextWin32Example/ir_decoder/include/ir_utils.h +++ b/win32-example/IRextWin32Example/ir_decoder/src/include/ir_utils.h @@ -9,8 +9,12 @@ Revision log: * 2016-10-01: created by strawmanbobi **************************************************************************************/ -#ifndef _IRDA_UTILS_H_ -#define _IRDA_UTILS_H_ +#ifndef _IR_UTILS_H_ +#define _IR_UTILS_H_ + +#if defined (BOARD_PC) +#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection" +#endif #ifdef __cplusplus extern "C" @@ -33,4 +37,4 @@ extern void hex_byte_to_double_char(char *dest, UINT8 length, UINT8 src); #ifdef __cplusplus } #endif -#endif // _IRDA_UTILS_H_ \ No newline at end of file +#endif // _IR_UTILS_H_ \ No newline at end of file diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_apply.c b/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_apply.c index 267df48..1dc8881 100644 --- a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_apply.c +++ b/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_apply.c @@ -8,10 +8,13 @@ Description: This file provides methods for AC IR applying functionalities Revision log: * 2016-10-12: created by strawmanbobi **************************************************************************************/ +#if defined (BOARD_PC) +#pragma ide diagnostic ignored "bugprone-branch-clone" +#pragma ide diagnostic ignored "hicpp-signed-bitwise" +#endif -#include "../include/ir_utils.h" -#include "../include/ir_ac_apply.h" - +#include "include/ir_utils.h" +#include "include/ir_ac_apply.h" static INT8 apply_ac_power(struct ac_protocol *protocol, UINT8 power_status); @@ -570,7 +573,7 @@ INT8 apply_function(struct ac_protocol *protocol, UINT8 function) INT8 apply_checksum(struct ac_protocol *protocol) { - UINT8 i = 0; + UINT16 i = 0; if (0 == protocol->checksum.len) { @@ -615,12 +618,14 @@ INT8 apply_checksum(struct ac_protocol *protocol) INT8 apply_power(t_remote_ac_status ac_status, UINT8 function_code) { + (void) function_code; apply_ac_power(context, ac_status.ac_power); return IR_DECODE_SUCCEEDED; } 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)) { // do not implement this mechanism since mode, temperature, wind @@ -686,6 +691,7 @@ 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) { + (void) ac_status; if (function_code == AC_FUNCTION_WIND_FIX) { // adjust fixed wind direction according to current status @@ -715,11 +721,13 @@ INT8 apply_swing(t_remote_ac_status ac_status, UINT8 function_code) if (IR_DECODE_FAILED == apply_ac_swing(context, context->swing_status)) { - if (function_code == AC_FUNCTION_WIND_SWING && FALSE == has_function(context, AC_FUNCTION_WIND_SWING)) + if (function_code == AC_FUNCTION_WIND_SWING && + FALSE == has_function(context, AC_FUNCTION_WIND_SWING)) { return IR_DECODE_FAILED; } - else if (function_code == AC_FUNCTION_WIND_FIX && FALSE == has_function(context, AC_FUNCTION_WIND_FIX)) + else if (function_code == AC_FUNCTION_WIND_FIX && + FALSE == has_function(context, AC_FUNCTION_WIND_FIX)) { return IR_DECODE_FAILED; } diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_binary_parse.c b/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_binary_parse.c index d154f54..c2ff2eb 100644 --- a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_binary_parse.c +++ b/win32-example/IRextWin32Example/ir_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 "include/ir_ac_binary_parse.h" +#include "include/ir_decode.h" UINT16 tag_head_offset = 0; @@ -45,7 +45,7 @@ INT8 binary_parse_offset() return IR_DECODE_FAILED; } - tag_head_offset = (UINT16) ((tag_count << 1) + 1); + tag_head_offset = (UINT16) ((tag_count << (UINT16) 1) + 1); #if defined USE_DYNAMIC_TAG tags = (t_tag_head *) ir_malloc(tag_count * sizeof(t_tag_head)); diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_build_frame.c b/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_build_frame.c index 6bef61d..2ba3272 100644 --- a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_build_frame.c +++ b/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_build_frame.c @@ -9,10 +9,15 @@ Revision log: * 2016-10-01: created by strawmanbobi **************************************************************************************/ -#include "../include/ir_ac_build_frame.h" -#include "../include/ir_decode.h" +#if defined (BOARD_PC) +#pragma ide diagnostic ignored "hicpp-signed-bitwise" +#pragma ide diagnostic ignored "readability-redundant-declaration" +#endif -extern t_ac_protocol *context; +#include "include/ir_ac_build_frame.h" +#include "include/ir_decode.h" + +extern t_ac_protocol* context; //return bit number per byte,default value is 8 @@ -41,9 +46,10 @@ UINT8 bits_per_byte(UINT8 index) UINT16 add_delaycode(UINT8 index) { - UINT8 i = 0, j = 0; + UINT16 i = 0; + UINT16 j = 0; UINT8 size = 0; - UINT8 tail_delaycode = 0; + UINT8 tail_delay_code = 0; UINT16 tail_pos = 0; if (context->dc_cnt != 0) @@ -61,7 +67,7 @@ UINT16 add_delaycode(UINT8 index) } else if (context->dc[i].pos == -1) { - tail_delaycode = 1; + tail_delay_code = 1; tail_pos = i; } } @@ -74,7 +80,7 @@ UINT16 add_delaycode(UINT8 index) if (context->dc_cnt != 0) { - if ((index == (ir_hex_len - 1)) && (tail_delaycode == 1)) + if ((index == (ir_hex_len - 1)) && (tail_delay_code == 1)) { for (i = 0; i < context->dc[tail_pos].time_cnt; i++) { @@ -89,10 +95,10 @@ UINT16 add_delaycode(UINT8 index) UINT16 create_ir_frame() { UINT16 i = 0, j = 0; - UINT8 bitnum = 0; - UINT8 *irdata = ir_hex_code; - UINT8 mask = 1; - UINT16 framelen = 0; + UINT8 bit_num = 0; + UINT8 *ir_data = ir_hex_code; + UINT8 mask = 0; + UINT16 frame_length = 0; context->code_cnt = 0; @@ -101,27 +107,24 @@ UINT16 create_ir_frame() { context->time[context->code_cnt++] = context->boot_code.data[i]; } - //code_cnt += context->boot_code.len; for (i = 0; i < ir_hex_len; i++) { - bitnum = bits_per_byte((UINT8) i); - for (j = 0; j < bitnum; j++) + bit_num = bits_per_byte((UINT8) i); + for (j = 0; j < bit_num; j++) { if (context->endian == 0) - mask = (UINT8) ((1 << (bitnum - 1)) >> j); + mask = (UINT8) ((1 << (bit_num - 1)) >> j); else mask = (UINT8) (1 << j); - if (irdata[i] & mask) + if (ir_data[i] & mask) { - //ir_printf("%d,%d,", context->one.low, context->one.high); context->time[context->code_cnt++] = context->one.low; context->time[context->code_cnt++] = context->one.high; } else { - //ir_printf("%d,%d,", context->zero.low, context->zero.high); context->time[context->code_cnt++] = context->zero.low; context->time[context->code_cnt++] = context->zero.high; } @@ -129,11 +132,11 @@ UINT16 create_ir_frame() add_delaycode((UINT8) i); } - framelen = context->code_cnt; + frame_length = context->code_cnt; for (i = 0; i < (context->repeat_times - 1); i++) { - for (j = 0; j < framelen; j++) + for (j = 0; j < frame_length; j++) { context->time[context->code_cnt++] = context->time[j]; } diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_control.c b/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_control.c index 3d07dc0..e6ee7b7 100644 --- a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_control.c +++ b/win32-example/IRextWin32Example/ir_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 "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" #if defined USE_DYNAMIC_TAG @@ -42,7 +42,7 @@ static INT8 ir_context_init() INT8 ir_ac_lib_parse() { - UINT8 i = 0; + UINT i = 0; // suggest not to call init function here for de-couple purpose ir_context_init(); @@ -110,7 +110,7 @@ INT8 ir_ac_lib_parse() if (tags[i].tag == TAG_AC_SWING_1) { context->swing1.count = context->si.mode_count; - context->swing1.len = (UINT8) tags[i].len >> 1; + context->swing1.len = (UINT8) tags[i].len >> (UINT8) 1; swing_space_size = sizeof(t_tag_comp) * context->si.mode_count; context->swing1.comp_data = (t_tag_comp *) ir_malloc(swing_space_size); if (NULL == context->swing1.comp_data) @@ -130,7 +130,7 @@ INT8 ir_ac_lib_parse() else if (tags[i].tag == TAG_AC_SWING_2) { context->swing2.count = context->si.mode_count; - context->swing2.len = (UINT8) tags[i].len >> 1; + context->swing2.len = (UINT8) tags[i].len >> (UINT8) 1; swing_space_size = sizeof(t_tag_comp) * context->si.mode_count; context->swing2.comp_data = (t_tag_comp *) ir_malloc(swing_space_size); if (NULL == context->swing2.comp_data) @@ -150,7 +150,7 @@ INT8 ir_ac_lib_parse() if (tags[i].tag == TAG_AC_DEFAULT_CODE) // default code TAG { - context->default_code.data = (UINT8 *) ir_malloc(((size_t) tags[i].len - 2) >> 1); + context->default_code.data = (UINT8 *) ir_malloc(((size_t) tags[i].len - 2) >> (UINT8) 1); if (NULL == context->default_code.data) { return IR_DECODE_FAILED; @@ -162,7 +162,7 @@ INT8 ir_ac_lib_parse() } else if (tags[i].tag == TAG_AC_POWER_1) // power tag { - context->power1.len = (UINT8) tags[i].len >> 1; + context->power1.len = (UINT8) tags[i].len >> (UINT8) 1; if (IR_DECODE_FAILED == parse_common_ac_parameter(&tags[i], context->power1.comp_data, AC_POWER_MAX, @@ -180,7 +180,7 @@ INT8 ir_ac_lib_parse() } else if (tags[i].tag == TAG_AC_MODE_1) // mode tag { - context->mode1.len = (UINT8) tags[i].len >> 1; + context->mode1.len = (UINT8) tags[i].len >> (UINT8) 1; if (IR_DECODE_FAILED == parse_common_ac_parameter(&tags[i], context->mode1.comp_data, AC_MODE_MAX, @@ -191,7 +191,7 @@ INT8 ir_ac_lib_parse() } else if (tags[i].tag == TAG_AC_SPEED_1) // wind speed tag { - context->speed1.len = (UINT8) tags[i].len >> 1; + context->speed1.len = (UINT8) tags[i].len >> (UINT8) 1; if (IR_DECODE_FAILED == parse_common_ac_parameter(&tags[i], context->speed1.comp_data, AC_WS_MAX, @@ -209,7 +209,7 @@ INT8 ir_ac_lib_parse() } else if (tags[i].tag == TAG_AC_MODE_2) { - context->mode2.len = (UINT8) tags[i].len >> 1; + context->mode2.len = (UINT8) tags[i].len >> (UINT8) 1; if (IR_DECODE_FAILED == parse_common_ac_parameter(&tags[i], context->mode2.comp_data, AC_MODE_MAX, AC_PARAMETER_TYPE_1)) @@ -219,7 +219,7 @@ INT8 ir_ac_lib_parse() } else if (tags[i].tag == TAG_AC_SPEED_2) { - context->speed2.len = (UINT8) tags[i].len >> 1; + context->speed2.len = (UINT8) tags[i].len >> (UINT8) 1; if (IR_DECODE_FAILED == parse_common_ac_parameter(&tags[i], context->speed2.comp_data, AC_WS_MAX, AC_PARAMETER_TYPE_1)) @@ -392,7 +392,7 @@ INT8 ir_ac_lib_parse() { if (is_in(context->sc.solo_function_codes, i, context->sc.solo_func_count)) { - context->solo_function_mark |= (1 << (i - 1)); + context->solo_function_mark |= (UINT8) ((UINT8) 1 << (i - 1)); } } } @@ -428,7 +428,7 @@ INT8 free_ac_context() context->default_code.len = 0; } - for (i = 0; i < AC_POWER_MAX; i++) + for (i = 0; i < (UINT16) AC_POWER_MAX; i++) { if (context->power1.comp_data[i].segment != NULL) { @@ -438,7 +438,7 @@ INT8 free_ac_context() } } - for (i = 0; i < AC_TEMP_MAX; i++) + for (i = 0; i < (UINT16) AC_TEMP_MAX; i++) { if (context->temp1.comp_data[i].segment != NULL) { @@ -454,7 +454,7 @@ INT8 free_ac_context() } } - for (i = 0; i < AC_MODE_MAX; i++) + for (i = 0; i < (UINT16) AC_MODE_MAX; i++) { if (context->mode1.comp_data[i].segment != NULL) { @@ -469,7 +469,7 @@ INT8 free_ac_context() context->mode2.comp_data[i].seg_len = 0; } } - for (i = 0; i < AC_WS_MAX; i++) + for (i = 0; i < (UINT16) AC_WS_MAX; i++) { if (context->speed1.comp_data[i].segment != NULL) { @@ -503,7 +503,7 @@ INT8 free_ac_context() } } - for (i = 0; i < AC_FUNCTION_MAX - 1; i++) + for (i = 0; i < (UINT16) AC_FUNCTION_MAX - 1; i++) { if (context->function1.comp_data[i].segment != NULL) { @@ -550,7 +550,11 @@ INT8 free_ac_context() return IR_DECODE_SUCCEEDED; } +#if defined (BOARD_PC) +#pragma ide diagnostic ignored "hicpp-signed-bitwise" +#endif + BOOL is_solo_function(UINT8 function_code) { return (((context->solo_function_mark >> (function_code - 1)) & 0x01) == 0x01) ? TRUE : FALSE; -} +} \ No newline at end of file diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_forbidden_info.c b/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_forbidden_info.c index 331a243..5121932 100644 --- a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_forbidden_info.c +++ b/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_forbidden_info.c @@ -9,12 +9,16 @@ Revision log: * 2016-10-05: created by strawmanbobi **************************************************************************************/ +#if defined (BOARD_PC) +#pragma ide diagnostic ignored "readability-redundant-declaration" +#endif + #include #include #include -#include "../include/ir_decode.h" -#include "../include/ir_ac_parse_forbidden_info.h" +#include "include/ir_decode.h" +#include "include/ir_ac_parse_forbidden_info.h" extern t_ac_protocol *context; @@ -24,6 +28,7 @@ INT8 parse_nmode_data_speed(char *pdata, t_ac_n_mode seq) { char buf[16] = { 0 }; char *p = pdata; + char *ptr = NULL; UINT16 pos = 0; UINT16 cnt = 0, index = 0; @@ -36,7 +41,7 @@ INT8 parse_nmode_data_speed(char *pdata, t_ac_n_mode seq) ir_memcpy(buf, pdata + pos, index - pos); pos = (UINT16) (index + 1); index = pos; - context->n_mode[seq].speed[cnt++] = (UINT8) atoi(buf); + context->n_mode[seq].speed[cnt++] = (UINT8) strtol(buf, &ptr, 10); context->n_mode[seq].speed_cnt = (UINT8) cnt; ir_memset(buf, 0, 16); } @@ -49,6 +54,7 @@ INT8 parse_nmode_data_temp(char *pdata, t_ac_n_mode seq) char buf[16] = { 0 }; char *p = pdata; + char *ptr = NULL; UINT16 pos = 0; UINT16 cnt = 0, index = 0; @@ -61,7 +67,7 @@ INT8 parse_nmode_data_temp(char *pdata, t_ac_n_mode seq) ir_memcpy(buf, pdata + pos, index - pos); pos = (UINT16) (index + 1); index = pos; - context->n_mode[seq].temp[cnt++] = (UINT8) (atoi(buf) - 16); + context->n_mode[seq].temp[cnt++] = (UINT8) (strtol(buf, &ptr, 10) - 16); context->n_mode[seq].temp_cnt = (UINT8) cnt; ir_memset(buf, 0, 16); } @@ -86,7 +92,7 @@ INT8 parse_nmode_pos(char *buf, t_ac_n_mode index) return IR_DECODE_SUCCEEDED; } - for (i = 0; i < ir_strlen(buf); i++) + for (i = 0; i < (UINT16) ir_strlen(buf); i++) { if (buf[i] == '&') { @@ -140,4 +146,4 @@ INT8 parse_nmode(struct tag_head *tag, t_ac_n_mode index) parse_nmode_pos(buf, index); ir_memset(buf, 0, 64); return IR_DECODE_SUCCEEDED; -} +} \ No newline at end of file diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_frame_info.c b/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_frame_info.c index 0a86f46..336530d 100644 --- a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_frame_info.c +++ b/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_frame_info.c @@ -13,14 +13,15 @@ Revision log: #include #include -#include "../include/ir_utils.h" -#include "../include/ir_ac_parse_frame_info.h" +#include "include/ir_utils.h" +#include "include/ir_ac_parse_frame_info.h" INT8 parse_boot_code(struct tag_head *tag) { UINT8 buf[16] = { 0 }; UINT8 *p = NULL; + char *ptr = NULL; UINT16 pos = 0; UINT16 cnt = 0, index = 0; @@ -44,7 +45,7 @@ INT8 parse_boot_code(struct tag_head *tag) ir_memcpy(buf, tag->p_data + pos, index - pos); pos = (UINT16) (index + 1); index = pos; - context->boot_code.data[cnt++] = (UINT16) (atoi((char *) buf)); + context->boot_code.data[cnt++] = (UINT16) (strtol((char *) buf, &ptr, 10)); ir_memset(buf, 0, 16); } context->boot_code.len = cnt; @@ -57,6 +58,8 @@ INT8 parse_zero(struct tag_head *tag) UINT8 high[16] = { 0 }; UINT16 index = 0; UINT8 *p = NULL; + char *ptr_low = NULL; + char *ptr_high = NULL; if (NULL == tag) { @@ -77,8 +80,8 @@ INT8 parse_zero(struct tag_head *tag) ir_memcpy(low, tag->p_data, index); ir_memcpy(high, tag->p_data + index + 1, (size_t) (tag->len - index - 1)); - context->zero.low = (UINT16) (atoi((char *) low)); - context->zero.high = (UINT16) (atoi((char *) high)); + context->zero.low = (UINT16) (strtol((char *) low, &ptr_low, 10)); + context->zero.high = (UINT16) (strtol((char *) high, &ptr_high, 10)); return IR_DECODE_SUCCEEDED; } @@ -88,6 +91,8 @@ INT8 parse_one(struct tag_head *tag) UINT8 high[16] = { 0 }; UINT16 index = 0; UINT8 *p = NULL; + char *ptr_low = NULL; + char *ptr_high = NULL; if (NULL == tag) { @@ -107,8 +112,8 @@ INT8 parse_one(struct tag_head *tag) ir_memcpy(low, tag->p_data, index); ir_memcpy(high, tag->p_data + index + 1, (size_t) (tag->len - index - 1)); - context->one.low = (UINT16) (atoi((char *) low)); - context->one.high = (UINT16) (atoi((char *) high)); + context->one.low = (UINT16) (strtol((char *) low, &ptr_low, 10)); + context->one.high = (UINT16) (strtol((char *) high, &ptr_high, 10)); return IR_DECODE_SUCCEEDED; } @@ -119,6 +124,7 @@ INT8 parse_delay_code_data(UINT8 *pdata) UINT8 *p = NULL; UINT16 pos = 0; UINT16 cnt = 0, index = 0; + char *ptr = NULL; if (NULL == pdata) { @@ -135,7 +141,7 @@ INT8 parse_delay_code_data(UINT8 *pdata) ir_memcpy(buf, pdata + pos, index - pos); pos = (UINT16) (index + 1); index = pos; - context->dc[context->dc_cnt].time[cnt++] = (UINT16) (atoi((char *) buf)); + context->dc[context->dc_cnt].time[cnt++] = (UINT16) (strtol((char *) buf, &ptr, 10)); context->dc[context->dc_cnt].time_cnt = cnt; ir_memset(buf, 0, 16); } @@ -146,14 +152,16 @@ INT8 parse_delay_code_data(UINT8 *pdata) INT8 parse_delay_code_pos(UINT8 *buf) { UINT16 i = 0; - UINT8 data[64] = { 0 }, start[8] = { 0 }; + UINT8 data[64] = { 0 }; + UINT8 start[8] = { 0 }; + char *ptr = NULL; if (NULL == buf) { return IR_DECODE_FAILED; } - for (i = 0; i < ir_strlen((char *) buf); i++) + for (i = 0; i < (UINT16) ir_strlen((char *) buf); i++) { if (buf[i] == '&') { @@ -163,7 +171,7 @@ INT8 parse_delay_code_pos(UINT8 *buf) } } parse_delay_code_data(data); - context->dc[context->dc_cnt].pos = (UINT16) (atoi((char *) start)); + context->dc[context->dc_cnt].pos = (UINT16) (strtol((char *) start, &ptr, 10)); context->dc_cnt++; return IR_DECODE_SUCCEEDED; @@ -202,6 +210,7 @@ INT8 parse_delay_code(struct tag_head *tag) INT8 parse_frame_len(struct tag_head *tag, UINT16 len) { UINT8 *temp = NULL; + char *ptr = NULL; if (NULL == tag) { @@ -220,7 +229,7 @@ INT8 parse_frame_len(struct tag_head *tag, UINT16 len) ir_memcpy(temp, tag->p_data, len); temp[len] = '\0'; - context->frame_length = (UINT16) (atoi((char *) temp)); + context->frame_length = (UINT16) (strtol((char *) temp, &ptr, 10)); ir_free(temp); return IR_DECODE_SUCCEEDED; @@ -229,32 +238,36 @@ INT8 parse_frame_len(struct tag_head *tag, UINT16 len) INT8 parse_endian(struct tag_head *tag) { UINT8 buf[8] = { 0 }; + char *ptr = NULL; if (NULL == tag) { return IR_DECODE_FAILED; } ir_memcpy(buf, tag->p_data, tag->len); - context->endian = (UINT8) (atoi((char *) buf)); + context->endian = (UINT8) (strtol((char *) buf, &ptr, 10)); return IR_DECODE_SUCCEEDED; } INT8 parse_lastbit(struct tag_head *tag) { UINT8 buf[8] = { 0 }; + char *ptr = NULL; if (NULL == tag) { return IR_DECODE_FAILED; } ir_memcpy(buf, tag->p_data, tag->len); - context->last_bit = (UINT8) (atoi((char *) buf)); + context->last_bit = (UINT8) (strtol((char *) buf, &ptr, 10)); return IR_DECODE_SUCCEEDED; } INT8 parse_repeat_times(struct tag_head *tag) { char asc_code[8] = { 0 }; + char *ptr = NULL; + if (NULL == tag) { return IR_DECODE_FAILED; @@ -262,7 +275,7 @@ INT8 parse_repeat_times(struct tag_head *tag) ir_memcpy(asc_code, tag->p_data, tag->len); - context->repeat_times = (UINT16) (atoi((char *) asc_code)); + context->repeat_times = (UINT16) (strtol((char *) asc_code, &ptr, 10)); return IR_DECODE_SUCCEEDED; } @@ -270,14 +283,17 @@ INT8 parse_repeat_times(struct tag_head *tag) INT8 parse_delay_code_tag48_pos(UINT8 *buf) { UINT16 i = 0; - UINT8 data[64] = { 0 }, start[8] = { 0 }; + UINT8 data[64] = { 0 }; + UINT8 start[8] = { 0 }; + char *ptr_start = NULL; + char *ptr_data = NULL; if (NULL == buf) { return IR_DECODE_FAILED; } - for (i = 0; i < ir_strlen((char *) buf); i++) + for (i = 0; i < (UINT16) ir_strlen((char *) buf); i++) { if (buf[i] == '&') { @@ -287,8 +303,8 @@ INT8 parse_delay_code_tag48_pos(UINT8 *buf) } } - context->bit_num[context->bit_num_cnt].pos = (UINT16) (atoi((char *) start)); - context->bit_num[context->bit_num_cnt].bits = (UINT16) (atoi((char *) data)); + context->bit_num[context->bit_num_cnt].pos = (UINT16) (strtol((char *) start, &ptr_start, 10)); + context->bit_num[context->bit_num_cnt].bits = (UINT16) (strtol((char *) data, &ptr_data, 10)); context->bit_num_cnt++; return IR_DECODE_SUCCEEDED; } diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_parameter.c b/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_parameter.c index 5d20342..ee4e4e9 100644 --- a/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_parameter.c +++ b/win32-example/IRextWin32Example/ir_decoder/src/ir_ac_parse_parameter.c @@ -13,8 +13,16 @@ Revision log: #include #include -#include "../include/ir_utils.h" -#include "../include/ir_ac_parse_parameter.h" +#include "include/ir_utils.h" +#include "include/ir_ac_parse_parameter.h" + +static INT8 parse_checksum_byte_typed(const UINT8 *csdata, t_tag_checksum_data *checksum, UINT16 len); + +static INT8 parse_checksum_half_byte_typed(const UINT8 *csdata, t_tag_checksum_data *checksum, UINT16 len); + +static INT8 parse_checksum_spec_half_byte_typed(const UINT8 *csdata, t_tag_checksum_data *checksum, UINT16 len); + +static INT8 parse_checksum_malloc(struct tag_head *tag, t_checksum *checksum); INT8 parse_comp_data_type_1(UINT8 *data, UINT16 *trav_offset, t_tag_comp *comp) @@ -86,7 +94,7 @@ INT8 parse_common_ac_parameter(t_tag_head *tag, t_tag_comp *comp_data, UINT8 wit return IR_DECODE_FAILED; } - hex_len = tag->len >> 1; + hex_len = tag->len >> (UINT16) 1; hex_data = (UINT8 *) ir_malloc(hex_len); if (NULL == hex_data) { @@ -164,7 +172,7 @@ INT8 parse_power_1(struct tag_head *tag, t_power_1 *power1) return IR_DECODE_FAILED; } - hex_len = tag->len >> 1; + hex_len = tag->len >> (UINT16) 1; hex_data = (UINT8 *) ir_malloc(hex_len); if (NULL == hex_data) @@ -177,7 +185,7 @@ INT8 parse_power_1(struct tag_head *tag, t_power_1 *power1) // parse hex data to power1 data structure power1->len = (UINT8) hex_len; - for (seg_index = AC_POWER_ON; seg_index < AC_POWER_MAX; seg_index++) + for (seg_index = AC_POWER_ON; seg_index < (UINT16) AC_POWER_MAX; seg_index++) { if (IR_DECODE_FAILED == parse_comp_data_type_1(hex_data, &trav_offset, &power1->comp_data[seg_index])) { @@ -210,7 +218,7 @@ INT8 parse_temp_1(struct tag_head *tag, t_temp_1 *temp1) return IR_DECODE_FAILED; } - hex_len = tag->len >> 1; + hex_len = tag->len >> (UINT16) 1; hex_data = (UINT8 *) ir_malloc(hex_len); if (NULL == hex_data) @@ -228,7 +236,7 @@ INT8 parse_temp_1(struct tag_head *tag, t_temp_1 *temp1) temp1->len = (UINT8) hex_len; UINT8 seg_len = hex_data[0]; - for (seg_index = AC_TEMP_16; seg_index < AC_TEMP_MAX; seg_index++) + 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, +... temp1->comp_data[seg_index].seg_len = seg_len; @@ -253,7 +261,7 @@ INT8 parse_temp_1(struct tag_head *tag, t_temp_1 *temp1) // static temperature tag temp1->len = (UINT8) hex_len; temp1->type = TEMP_TYPE_STATIC; - for (seg_index = AC_TEMP_16; seg_index < AC_TEMP_MAX; seg_index++) + for (seg_index = AC_TEMP_16; seg_index < (UINT16) AC_TEMP_MAX; seg_index++) { if (IR_DECODE_FAILED == parse_comp_data_type_1(hex_data, &trav_offset, &temp1->comp_data[seg_index])) { @@ -284,7 +292,7 @@ INT8 parse_mode_1(struct tag_head *tag, t_mode_1 *mode1) return IR_DECODE_FAILED; } - hex_len = tag->len >> 1; + hex_len = tag->len >> (UINT16) 1; hex_data = (UINT8 *) ir_malloc(hex_len); if (NULL == hex_data) @@ -297,7 +305,7 @@ INT8 parse_mode_1(struct tag_head *tag, t_mode_1 *mode1) // parse hex data to mode1 data structure mode1->len = (UINT8) hex_len; - for (seg_index = AC_MODE_COOL; seg_index < AC_MODE_MAX; seg_index++) + for (seg_index = AC_MODE_COOL; seg_index < (UINT16) AC_MODE_MAX; seg_index++) { if (IR_DECODE_FAILED == parse_comp_data_type_1(hex_data, &trav_offset, &mode1->comp_data[seg_index])) { @@ -328,7 +336,7 @@ INT8 parse_speed_1(struct tag_head *tag, t_speed_1 *speed1) return IR_DECODE_FAILED; } - hex_len = tag->len >> 1; + hex_len = tag->len >> (UINT16) 1; hex_data = (UINT8 *) ir_malloc(hex_len); if (NULL == hex_data) @@ -341,7 +349,7 @@ INT8 parse_speed_1(struct tag_head *tag, t_speed_1 *speed1) // parse hex data to speed1 data structure speed1->len = (UINT8) hex_len; - for (seg_index = AC_WS_AUTO; seg_index < AC_WS_MAX; seg_index++) + for (seg_index = AC_WS_AUTO; seg_index < (UINT16) AC_WS_MAX; seg_index++) { if (IR_DECODE_FAILED == parse_comp_data_type_1(hex_data, &trav_offset, &speed1->comp_data[seg_index])) { @@ -372,7 +380,7 @@ INT8 parse_swing_1(struct tag_head *tag, t_swing_1 *swing1, UINT16 swing_count) return IR_DECODE_FAILED; } - hex_len = tag->len >> 1; + hex_len = tag->len >> (UINT16) 1; hex_data = (UINT8 *) ir_malloc(hex_len); if (NULL == hex_data) @@ -411,95 +419,6 @@ INT8 parse_swing_1(struct tag_head *tag, t_swing_1 *swing1, UINT16 swing_count) return IR_DECODE_SUCCEEDED; } -INT8 parse_checksum_byte_typed(UINT8 *csdata, t_tag_checksum_data *checksum, UINT16 len) -{ - checksum->start_byte_pos = csdata[2]; - checksum->end_byte_pos = csdata[3]; - checksum->checksum_byte_pos = csdata[4]; - - if (len > 5) - { - checksum->checksum_plus = csdata[5]; - } - else - { - checksum->checksum_plus = 0; - } - checksum->spec_pos = NULL; - - return IR_DECODE_SUCCEEDED; -} - -INT8 parse_checksum_half_byte_typed(UINT8 *csdata, t_tag_checksum_data *checksum, UINT16 len) -{ - checksum->start_byte_pos = csdata[2]; - checksum->end_byte_pos = csdata[3]; - checksum->checksum_byte_pos = csdata[4]; - - if (len > 5) - { - checksum->checksum_plus = csdata[5]; - } - else - { - checksum->checksum_plus = 0; - } - checksum->spec_pos = NULL; - return IR_DECODE_SUCCEEDED; -} - -INT8 parse_checksum_spec_half_byte_typed(UINT8 *csdata, t_tag_checksum_data *checksum, UINT16 len) -{ - /* - * note: - * for the type of specified half byte checksum algorithm, - * the checksum byte positions are in unit of HALF BYTE, rather than in unit of BYTE - * as well as the specified half byte positions (spec_pos). - * Thus the specified half byte checksum only affects 4 bits of a position - * of half byte specified by check_sum_byte_pos property. - */ - UINT16 spec_pos_size = (UINT16) (len - 4); - - checksum->checksum_byte_pos = csdata[2]; - checksum->checksum_plus = csdata[3]; - checksum->start_byte_pos = 0; - checksum->end_byte_pos = 0; - checksum->spec_pos = (UINT8 *) ir_malloc(spec_pos_size); - if (NULL == checksum->spec_pos) - { - return IR_DECODE_FAILED; - } - ir_memcpy(checksum->spec_pos, &csdata[4], spec_pos_size); - - return IR_DECODE_SUCCEEDED; -} - -INT8 parse_checksum_malloc(struct tag_head *tag, t_checksum *checksum) -{ - UINT8 i = 0; - UINT8 cnt = 0; - - for (i = 0; i < tag->len; i++) - { - if (tag->p_data[i] == '|') - { - cnt++; - } - } - - checksum->len = (UINT8) ((tag->len - cnt) >> 1); - checksum->count = (UINT16) (cnt + 1); - checksum->checksum_data = (t_tag_checksum_data *) ir_malloc(sizeof(t_tag_checksum_data) * checksum->count); - - if (NULL == checksum->checksum_data) - { - return IR_DECODE_FAILED; - } - ir_memset(checksum->checksum_data, 0x00, sizeof(t_tag_checksum_data) * checksum->count); - - return IR_DECODE_SUCCEEDED; -} - INT8 parse_checksum_data(UINT8 *buf, t_tag_checksum_data *checksum, UINT8 length) { UINT8 *hex_data = NULL; @@ -591,13 +510,13 @@ INT8 parse_checksum(struct tag_head *tag, t_checksum *checksum) return IR_DECODE_FAILED; } - for (i = 0; i < tag->len; i++) + for (i = 0; i < (UINT8) tag->len; i++) { if (tag->p_data[i] == '|') { if (IR_DECODE_FAILED == parse_checksum_data(tag->p_data + preindex, checksum->checksum_data + num, - (UINT8) (i - preindex) >> 1)) + (UINT8) (i - preindex) >> (UINT8) 1)) { return IR_DECODE_FAILED; } @@ -608,7 +527,7 @@ INT8 parse_checksum(struct tag_head *tag, t_checksum *checksum) if (IR_DECODE_FAILED == parse_checksum_data(tag->p_data + preindex, checksum->checksum_data + num, - (UINT8) (i - preindex) >> 1)) + (UINT8) (i - preindex) >> (UINT8) 1)) { return IR_DECODE_FAILED; } @@ -700,7 +619,7 @@ INT8 parse_function_1_tag29(struct tag_head *tag, t_function_1 *function1) return IR_DECODE_FAILED; } - hex_len = tag->len >> 1; + hex_len = tag->len >> (UINT16) 1; hex_data = (UINT8 *) ir_malloc(hex_len); if (NULL == hex_data) @@ -714,12 +633,11 @@ INT8 parse_function_1_tag29(struct tag_head *tag, t_function_1 *function1) function1->len = (UINT8) hex_len; // seg_index in TAG only refers to functional count - for (seg_index = AC_FUNCTION_POWER; seg_index < AC_FUNCTION_MAX; seg_index++) + for (seg_index = AC_FUNCTION_POWER; seg_index < (UINT16) AC_FUNCTION_MAX; seg_index++) { - INT8 fid = parse_function_1(hex_data, &trav_offset, &function1->comp_data[0]); - /** WARNING: for strict mode only **/ /** + INT8 fid = parse_function_1(hex_data, &trav_offset, &function1->comp_data[0]); if (fid > AC_FUNCTION_MAX - 1) { irda_free(hex_data); @@ -728,6 +646,7 @@ INT8 parse_function_1_tag29(struct tag_head *tag, t_function_1 *function1) } **/ + parse_function_1(hex_data, &trav_offset, &function1->comp_data[0]); if (trav_offset >= hex_len) { break; @@ -757,7 +676,7 @@ INT8 parse_temp_2(struct tag_head *tag, t_temp_2 *temp2) return IR_DECODE_FAILED; } - hex_len = tag->len >> 1; + hex_len = tag->len >> (UINT16) 1; hex_data = (UINT8 *) ir_malloc(hex_len); if (NULL == hex_data) @@ -775,7 +694,7 @@ INT8 parse_temp_2(struct tag_head *tag, t_temp_2 *temp2) temp2->len = (UINT8) hex_len; UINT8 seg_len = hex_data[0]; - for (seg_index = AC_TEMP_16; seg_index < AC_TEMP_MAX; seg_index++) + 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, +... temp2->comp_data[seg_index].seg_len = seg_len; @@ -800,7 +719,7 @@ INT8 parse_temp_2(struct tag_head *tag, t_temp_2 *temp2) // static temperature tag temp2->len = (UINT8) hex_len; temp2->type = TEMP_TYPE_STATIC; - for (seg_index = AC_TEMP_16; seg_index < AC_TEMP_MAX; seg_index++) + for (seg_index = AC_TEMP_16; seg_index < (UINT16) AC_TEMP_MAX; seg_index++) { if (IR_DECODE_FAILED == parse_comp_data_type_2(hex_data, &trav_offset, &temp2->comp_data[seg_index])) { @@ -836,7 +755,7 @@ INT8 parse_mode_2(struct tag_head *tag, t_mode_2 *mode2) return IR_DECODE_FAILED; } - hex_len = tag->len >> 1; + hex_len = tag->len >> (UINT16) 1; hex_data = (UINT8 *) ir_malloc(hex_len); if (NULL == hex_data) @@ -849,7 +768,7 @@ INT8 parse_mode_2(struct tag_head *tag, t_mode_2 *mode2) // parse hex data to mode1 data structure mode2->len = (UINT8) hex_len; - for (seg_index = AC_MODE_COOL; seg_index < AC_MODE_MAX; seg_index++) + for (seg_index = AC_MODE_COOL; seg_index < (UINT16) AC_MODE_MAX; seg_index++) { if (IR_DECODE_FAILED == parse_comp_data_type_2(hex_data, &trav_offset, &mode2->comp_data[seg_index])) { @@ -885,7 +804,7 @@ INT8 parse_speed_2(struct tag_head *tag, t_speed_2 *speed2) return IR_DECODE_FAILED; } - hex_len = tag->len >> 1; + hex_len = tag->len >> (UINT16) 1; hex_data = (UINT8 *) ir_malloc(hex_len); if (NULL == hex_data) @@ -898,7 +817,7 @@ INT8 parse_speed_2(struct tag_head *tag, t_speed_2 *speed2) // parse hex data to speed1 data structure speed2->len = (UINT8) hex_len; - for (seg_index = AC_WS_AUTO; seg_index < AC_WS_MAX; seg_index++) + for (seg_index = AC_WS_AUTO; seg_index < (UINT16) AC_WS_MAX; seg_index++) { if (IR_DECODE_FAILED == parse_comp_data_type_2(hex_data, &trav_offset, &speed2->comp_data[seg_index])) { @@ -934,7 +853,7 @@ INT8 parse_swing_2(struct tag_head *tag, t_swing_2 *swing2, UINT16 swing_count) return IR_DECODE_FAILED; } - hex_len = tag->len >> 1; + hex_len = tag->len >> (UINT16) 1; hex_data = (UINT8 *) ir_malloc(hex_len); if (NULL == hex_data) @@ -1058,7 +977,7 @@ INT8 parse_function_2_tag34(struct tag_head *tag, t_function_2 *function2) return IR_DECODE_FAILED; } - hex_len = tag->len >> 1; + hex_len = tag->len >> (UINT16) 1; hex_data = (UINT8 *) ir_malloc(hex_len); if (NULL == hex_data) @@ -1072,12 +991,11 @@ INT8 parse_function_2_tag34(struct tag_head *tag, t_function_2 *function2) function2->len = (UINT8) hex_len; // seg_index in TAG only refers to functional count - for (seg_index = AC_FUNCTION_POWER; seg_index < AC_FUNCTION_MAX; seg_index++) + for (seg_index = AC_FUNCTION_POWER; seg_index < (UINT16) AC_FUNCTION_MAX; seg_index++) { - INT8 fid = parse_function_2(hex_data, &trav_offset, &function2->comp_data[0]); - /** WARNING: for strict mode only **/ /** + INT8 fid = parse_function_2(hex_data, &trav_offset, &function2->comp_data[0]); if (fid > AC_FUNCTION_MAX - 1) { irda_free(hex_data); @@ -1086,6 +1004,7 @@ INT8 parse_function_2_tag34(struct tag_head *tag, t_function_2 *function2) } **/ + parse_function_2(hex_data, &trav_offset, &function2->comp_data[0]); if (trav_offset >= hex_len) { break; @@ -1137,8 +1056,7 @@ INT8 parse_swing_info(struct tag_head *tag, t_swing_info *si) // count how many swing types are there si->type = SWING_TYPE_NORMAL; si->mode_count = 1; - int i = 0; - for (i = 0; i < tag->len; i++) + for (int i = 0; i < tag->len; i++) { if (tag->p_data[i] == ',') { @@ -1165,7 +1083,7 @@ INT8 parse_solo_code(struct tag_head *tag, t_solo_code *sc) return IR_DECODE_FAILED; } - hex_len = tag->len >> 1; + hex_len = tag->len >> (UINT16) 1; if (hex_len > AC_FUNCTION_MAX) { @@ -1187,11 +1105,100 @@ INT8 parse_solo_code(struct tag_head *tag, t_solo_code *sc) // per each function takes just 1 byte of length sc->solo_func_count = hex_data[0]; - for (i = 1; i < hex_len; i++) + for (i = 1; i < (UINT8) hex_len; i++) { sc->solo_function_codes[i - 1] = hex_data[i]; } ir_free(hex_data); return IR_DECODE_SUCCEEDED; -} \ No newline at end of file +} + +static INT8 parse_checksum_byte_typed(const UINT8 *csdata, t_tag_checksum_data *checksum, UINT16 len) +{ + checksum->start_byte_pos = csdata[2]; + checksum->end_byte_pos = csdata[3]; + checksum->checksum_byte_pos = csdata[4]; + + if (len > 5) + { + checksum->checksum_plus = csdata[5]; + } + else + { + checksum->checksum_plus = 0; + } + checksum->spec_pos = NULL; + + return IR_DECODE_SUCCEEDED; +} + +static INT8 parse_checksum_half_byte_typed(const UINT8 *csdata, t_tag_checksum_data *checksum, UINT16 len) +{ + checksum->start_byte_pos = csdata[2]; + checksum->end_byte_pos = csdata[3]; + checksum->checksum_byte_pos = csdata[4]; + + if (len > 5) + { + checksum->checksum_plus = csdata[5]; + } + else + { + checksum->checksum_plus = 0; + } + checksum->spec_pos = NULL; + return IR_DECODE_SUCCEEDED; +} + +static INT8 parse_checksum_spec_half_byte_typed(const UINT8 *csdata, t_tag_checksum_data *checksum, UINT16 len) +{ + /* + * note: + * for the type of specified half byte checksum algorithm, + * the checksum byte positions are in unit of HALF BYTE, rather than in unit of BYTE + * as well as the specified half byte positions (spec_pos). + * Thus the specified half byte checksum only affects 4 bits of a position + * of half byte specified by check_sum_byte_pos property. + */ + UINT16 spec_pos_size = (UINT16) (len - 4); + + checksum->checksum_byte_pos = csdata[2]; + checksum->checksum_plus = csdata[3]; + checksum->start_byte_pos = 0; + checksum->end_byte_pos = 0; + checksum->spec_pos = (UINT8 *) ir_malloc(spec_pos_size); + if (NULL == checksum->spec_pos) + { + return IR_DECODE_FAILED; + } + ir_memcpy(checksum->spec_pos, &csdata[4], spec_pos_size); + + return IR_DECODE_SUCCEEDED; +} + +static INT8 parse_checksum_malloc(struct tag_head *tag, t_checksum *checksum) +{ + UINT8 i = 0; + UINT8 cnt = 0; + + for (i = 0; i < (UINT8) tag->len; i++) + { + if (tag->p_data[i] == '|') + { + cnt++; + } + } + + checksum->len = (UINT8) ((UINT8) (tag->len - cnt) >> (UINT8) 1); + checksum->count = (UINT16) (cnt + 1); + checksum->checksum_data = (t_tag_checksum_data *) ir_malloc(sizeof(t_tag_checksum_data) * checksum->count); + + if (NULL == checksum->checksum_data) + { + return IR_DECODE_FAILED; + } + ir_memset(checksum->checksum_data, 0x00, sizeof(t_tag_checksum_data) * checksum->count); + + return IR_DECODE_SUCCEEDED; +} diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_decode.c b/win32-example/IRextWin32Example/ir_decoder/src/ir_decode.c index 5df23ee..008439e 100644 --- a/win32-example/IRextWin32Example/ir_decoder/src/ir_decode.c +++ b/win32-example/IRextWin32Example/ir_decoder/src/ir_decode.c @@ -14,15 +14,15 @@ 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 "include/ir_decode.h" +#include "include/ir_utils.h" +#include "include/ir_ac_build_frame.h" +#include "include/ir_ac_apply.h" struct ir_bin_buffer binary_file; struct ir_bin_buffer *p_ir_buffer = &binary_file; -const char* release = "0.2.2"; +static const char* version = "0.2.5"; #if defined USE_DYNAMIC_TAG struct tag_head *tags; @@ -30,20 +30,39 @@ struct tag_head *tags; struct tag_head tags[TAG_COUNT_FOR_PROTOCOL]; #endif +static UINT8 byte_array[PROTOCOL_SIZE] = { 0 }; +#if !defined NO_FS +static size_t binary_length = 0; +static UINT8 *binary_content = NULL; +#endif + +static t_remote_category remote_category = REMOTE_CATEGORY_NONE; +static UINT8 ir_binary_type = IR_TYPE_STATUS; +static UINT8 ir_hexadecimal = SUB_CATEGORY_QUATERNARY; + +static int KEY_CODE_MAX[] = +{ + 0, + STANDARD_KEY_COUNT, + STANDARD_KEY_COUNT + CHANNEL_KEY_COUNT, + STANDARD_KEY_COUNT + CHANNEL_KEY_COUNT, + STANDARD_KEY_COUNT, + STANDARD_KEY_COUNT + CHANNEL_KEY_COUNT, + STANDARD_KEY_COUNT, + STANDARD_KEY_COUNT, + STANDARD_KEY_COUNT, + STANDARD_KEY_COUNT, + STANDARD_KEY_COUNT, + STANDARD_KEY_COUNT + CHANNEL_KEY_COUNT, + STANDARD_KEY_COUNT, + STANDARD_KEY_COUNT, +}; + UINT8 *ir_hex_code = NULL; UINT8 ir_hex_len = 0; +t_ac_protocol *context = (t_ac_protocol *) byte_array; -UINT8 byteArray[PROTOCOL_SIZE] = { 0 }; - -size_t binary_length = 0; -UINT8 *binary_content = NULL; - -UINT8 ir_binary_type = IR_TYPE_STATUS; -UINT8 ir_hexadecimal = SUB_CATEGORY_QUATERNARY; - -t_ac_protocol *context = (t_ac_protocol *) byteArray; - -lp_apply_ac_parameter apply_table[AC_APPLY_MAX] = +static lp_apply_ac_parameter apply_table[AC_APPLY_MAX] = { apply_power, apply_mode, @@ -59,8 +78,8 @@ lp_apply_ac_parameter apply_table[AC_APPLY_MAX] = static INT8 ir_ac_file_open(const char *file_name); #endif -static INT8 ir_ac_binary_open(UINT8 *binary, UINT16 binary_length); -static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16 *user_data, UINT8 function_code, +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(); @@ -68,7 +87,7 @@ static INT8 ir_ac_binary_close(); static INT8 ir_tv_file_open(const char *file_name); #endif -static INT8 ir_tv_binary_open(UINT8 *binary, UINT16 binary_length); +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(); @@ -76,15 +95,35 @@ static INT8 ir_tv_binary_close(); void noprint(const char *fmt, ...) { - return; + (void) fmt; } // pubic function definitions +const char* get_lib_version() +{ + return version; +} + #if (!defined BOARD_51 && !defined BOARD_CC26XX) INT8 ir_file_open(const UINT8 category, const UINT8 sub_category, const char* file_name) { - INT8 ret = IR_DECODE_SUCCEEDED; - if (category == IR_CATEGORY_AC) + INT8 ret = 0; + if (category < REMOTE_CATEGORY_AC || + category >= REMOTE_CATEGORY_NEXT) + { + ir_printf("wrong remote category : %d\n", category); + return IR_DECODE_FAILED; + } + remote_category = category; + + if (sub_category < SUB_CATEGORY_QUATERNARY || + sub_category >= SUB_CATEGORY_NEXT) + { + ir_printf("wrong remote sub category : %d\n", sub_category); + return IR_DECODE_FAILED; + } + + if (category == REMOTE_CATEGORY_AC) { ir_binary_type = IR_TYPE_STATUS; ret = ir_ac_file_open(file_name); @@ -131,14 +170,29 @@ INT8 ir_file_open(const UINT8 category, const UINT8 sub_category, const char* fi } #endif -INT8 ir_binary_open(const UINT8 category, const UINT8 sub_category, UINT8* binary, UINT16 binary_length) +INT8 ir_binary_open(const UINT8 category, const UINT8 sub_category, UINT8* binary, UINT16 bin_length) { - INT8 ret = IR_DECODE_SUCCEEDED; + INT8 ret = 0; - if (category == IR_CATEGORY_AC) + if (category < REMOTE_CATEGORY_AC || + category >= REMOTE_CATEGORY_NEXT) + { + ir_printf("wrong remote category\n"); + return IR_DECODE_FAILED; + } + remote_category = (t_remote_category) category; + + if (sub_category < SUB_CATEGORY_QUATERNARY || + sub_category >= SUB_CATEGORY_NEXT) + { + ir_printf("wrong remote sub category : %d\n", sub_category); + return IR_DECODE_FAILED; + } + + if (category == REMOTE_CATEGORY_AC) { ir_binary_type = IR_TYPE_STATUS; - ret = ir_ac_binary_open(binary, binary_length); + ret = ir_ac_binary_open(binary, bin_length); if (IR_DECODE_SUCCEEDED == ret) { return ir_ac_lib_parse(); @@ -164,7 +218,7 @@ INT8 ir_binary_open(const UINT8 category, const UINT8 sub_category, UINT8* binar return IR_DECODE_FAILED; } - ret = ir_tv_binary_open(binary, binary_length); + ret = ir_tv_binary_open(binary, bin_length); if (IR_DECODE_SUCCEEDED == ret) { return ir_tv_binary_parse(ir_hexadecimal); @@ -176,10 +230,18 @@ 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) { + ir_printf("remote_category = %d, KEY_CODE_MAX = %d\n", remote_category, KEY_CODE_MAX[remote_category]); + + if (key_code < 0 || key_code >= KEY_CODE_MAX[remote_category]) + { + ir_printf("key_code exceeded!\n"); + return 0; + } + if (IR_TYPE_COMMANDS == ir_binary_type) { return ir_tv_control(key_code, user_data); @@ -192,7 +254,7 @@ UINT16 ir_decode(UINT8 key_code, UINT16* user_data, } ir_printf("ac status is not null in decode core : power = %d, mode = %d, " "temp = %d, wind_dir = %d, wind_speed = %d, " - "keycode = %d, change_wind_direction = %d\n", + "key_code = %d, change_wind_direction = %d\n", ac_status->ac_power, ac_status->ac_mode, ac_status->ac_temp, ac_status->ac_wind_dir, ac_status->ac_wind_speed, @@ -217,11 +279,6 @@ INT8 ir_close() } -#if (defined BOARD_PC || defined BOARD_PC_DLL) -void ir_lib_free_inner_buffer(); -#endif - - // static function definitions //////// AC Begin //////// @@ -275,25 +332,20 @@ static INT8 ir_ac_file_open(const char *file_name) } #endif -static INT8 ir_ac_binary_open(UINT8 *binary, UINT16 binary_length) +static INT8 ir_ac_binary_open(UINT8 *binary, UINT16 bin_length) { // it is recommended that the parameter binary pointing to // a global memory block in embedded platform environment p_ir_buffer->data = binary; - p_ir_buffer->len = binary_length; + p_ir_buffer->len = bin_length; p_ir_buffer->offset = 0; return IR_DECODE_SUCCEEDED; } -static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16 *user_data, UINT8 key_code, +static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16* user_data, UINT8 key_code, BOOL change_wind_direction) { UINT16 time_length = 0; - -#if defined BOARD_PC - UINT16 i = 0; -#endif - UINT8 function_code = 0; switch(key_code) @@ -321,6 +373,9 @@ static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16 *user_data, UIN case 11: function_code = AC_FUNCTION_WIND_FIX; break; + default: + ir_printf("unsupported key_code\n"); + return 0; } if (0 == context->default_code.len) @@ -415,18 +470,6 @@ static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16 *user_data, UIN time_length = create_ir_frame(); -#if (defined BOARD_PC) -#if (defined BOARD_PC_JNI) - ir_printf("code count = %d\n", context->code_cnt); -#else - for (i = 0; i < context->code_cnt; i++) - { - ir_printf("%d,", context->time[i]); - } -#endif - ir_printf("\n"); -#endif - return time_length; } @@ -468,7 +511,7 @@ INT8 get_temperature_range(UINT8 ac_mode, INT8 *temp_min, INT8 *temp_max) *temp_min = -1; *temp_max = -1; - for (i = 0; i < AC_TEMP_MAX; i++) + for (i = 0; i < (UINT8) AC_TEMP_MAX; i++) { if (is_in(context->n_mode[ac_mode].temp, i, context->n_mode[ac_mode].temp_cnt) || (context->temp1.len != 0 && 0 == context->temp1.comp_data[i].seg_len) || @@ -497,13 +540,13 @@ INT8 get_supported_mode(UINT8 *supported_mode) } *supported_mode = 0x1F; - for (i = 0; i < AC_MODE_MAX; i++) + for (i = 0; i < (UINT8) AC_MODE_MAX; i++) { if (0 == context->n_mode[i].enable || (context->mode1.len != 0 && 0 == context->mode1.comp_data[i].seg_len) || (context->mode2.len != 0 && 0 == context->mode2.comp_data[i].seg_len)) { - *supported_mode &= ~(1 << i); + *supported_mode &= (UINT8)(~(UINT8)((UINT8)1 << (UINT8)i)); } } @@ -531,13 +574,13 @@ INT8 get_supported_wind_speed(UINT8 ac_mode, UINT8 *supported_wind_speed) *supported_wind_speed = 0x0F; - for (i = 0; i < AC_WS_MAX; i++) + for (i = 0; i < (UINT8) AC_WS_MAX; i++) { if (is_in(context->n_mode[ac_mode].speed, i, context->n_mode[ac_mode].speed_cnt) || (context->speed1.len != 0 && 0 == context->speed1.comp_data[i].seg_len) || (context->speed2.len != 0 && 0 == context->speed2.comp_data[i].seg_len)) { - *supported_wind_speed &= ~(1 << i); + *supported_wind_speed &= (UINT8)(~(UINT8)((UINT8)1 << (UINT8)i)); } } @@ -580,6 +623,10 @@ INT8 get_supported_wind_direction(UINT8 *supported_wind_direction) if (NULL != context) { *supported_wind_direction = (UINT8) (context->si.mode_count - 1); + if (*supported_wind_direction < 0) + { + *supported_wind_direction = 0; + } return IR_DECODE_SUCCEEDED; } else @@ -642,9 +689,9 @@ static INT8 ir_tv_file_open(const char *file_name) } #endif -static INT8 ir_tv_binary_open(UINT8 *binary, UINT16 binary_length) +static INT8 ir_tv_binary_open(UINT8 *binary, UINT16 bin_length) { - return tv_binary_open(binary, binary_length); + return tv_binary_open(binary, bin_length); } static INT8 ir_tv_binary_parse(UINT8 ir_hex_encode) @@ -666,15 +713,6 @@ static UINT16 ir_tv_control(UINT8 key, UINT16 *l_user_data) memset(l_user_data, 0x00, USER_DATA_SIZE); ir_code_length = tv_binary_decode(key, l_user_data); -#if defined BOARD_PC - // have some debug - ir_printf("length of IR code = %d\n", ir_code_length); - for (print_index = 0; print_index < ir_code_length; print_index++) - { - ir_printf("%d ", l_user_data[print_index]); - } -#endif - return ir_code_length; } @@ -689,13 +727,29 @@ static INT8 ir_tv_binary_close() // combo decode for JNI which means call open, decode and then close in one JNI call UINT16 ir_decode_combo(const UINT8 category, const UINT8 sub_category, - UINT8* binary, UINT16 binary_length, + UINT8* binary, UINT16 bin_length, UINT8 key_code, UINT16* user_data, t_remote_ac_status* ac_status, BOOL change_wind_direction) { UINT16 decoded_length = 0; + + if (category < REMOTE_CATEGORY_AC || + category >= REMOTE_CATEGORY_NEXT) + { + ir_printf("wrong remote category\n"); + return IR_DECODE_FAILED; + } + + remote_category = (t_remote_category) category; + + if (key_code < 0 || key_code >= KEY_CODE_MAX[remote_category]) + { + ir_printf("key_code exceeded!\n"); + return 0; + } + if (IR_DECODE_SUCCEEDED == - ir_binary_open(category, sub_category, binary, binary_length)) + ir_binary_open(category, sub_category, binary, bin_length)) { decoded_length = ir_decode(key_code, user_data, ac_status, change_wind_direction); ir_close(); diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_decode_test.c b/win32-example/IRextWin32Example/ir_decoder/src/ir_decode_test.c new file mode 100644 index 0000000..d14f0f3 --- /dev/null +++ b/win32-example/IRextWin32Example/ir_decoder/src/ir_decode_test.c @@ -0,0 +1,324 @@ +/************************************************************************************** +Filename: ir_main.c +Revised: Date: 2016-11-05 +Revision: Revision: 1.0 + +Description: This file provides main entry for irda decoder + +Revision log: +* 2016-11-05: created by strawmanbobi +**************************************************************************************/ + +#pragma ide diagnostic ignored "OCUnusedMacroInspection" + +#include +#include +#include +#include +#include + +#include "include/ir_defs.h" +#include "include/ir_decode.h" + +#define INPUT_MAX 3 + +// global variable definition +t_remote_ac_status ac_status; +UINT16 user_data[USER_DATA_SIZE]; + +void input_number(int *val) +{ + char n[50]={0}; + int i = 0; + *val = 0; + scanf("%s", n); + getchar(); + while(1) + { + if(n[i] < '0'||n[i] > '9') + { + printf("\nInvalid number format, please re-input : "); + scanf("%s", n); + i=0; + } + else + { + i++; + } + if(n[i] == '\0') + break; + } + i = 0; + while (n[i] != '\0') + { + *val = (*val * 10 + (int)n[i] - 48); + i++; + } +} + +static INT8 decode_as_ac(char *file_name) +{ + BOOL op_match = TRUE; + BOOL change_wind_dir = FALSE; + UINT8 function_code = AC_FUNCTION_MAX; + int key_code = 0; + int first_time = 1; + int length = 0; + int index = 0; + + // get status + UINT8 supported_mode = 0x00; + INT8 min_temperature = 0; + INT8 max_temperature = 0; + UINT8 supported_speed = 0x00; + UINT8 supported_swing = 0x00; + UINT8 supported_wind_direction = 0x00; + + BOOL need_control; + + // 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_OFF; + 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; + + if (IR_DECODE_FAILED == ir_file_open(REMOTE_CATEGORY_AC, 0, file_name)) + { + ir_close(); + return IR_DECODE_FAILED; + } + + do + { + if (1 == first_time) + { + 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"); + } + input_number(&key_code); + + op_match = TRUE; + need_control = FALSE; + change_wind_dir = FALSE; + + if (99 == key_code) + { + break; + } + + if (14 == key_code) + { + if (IR_DECODE_SUCCEEDED == get_supported_mode(&supported_mode)) + { + printf("supported mode = %02X\n", supported_mode); + } + else + { + printf("get supported mode failed\n"); + } + } + else if (15 == key_code) + { + 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); + } + else + { + printf("get supported wind speed failed\n"); + } + } + else if (16 == key_code) + { + 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); + } + else + { + printf("get supported temperature range failed\n"); + } + } + else if (17 == key_code) + { + if (IR_DECODE_SUCCEEDED == get_supported_wind_direction(&supported_wind_direction)) + { + printf("supported swing type = %02X\n", supported_wind_direction); + } + else + { + printf("get swing type failed\n"); + } + } + else + { + switch (key_code) + { + case 0: + ac_status.ac_power = ((ac_status.ac_wind_dir == 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; + 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)); + 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)); + need_control = TRUE; + break; + + case 9: + ++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); + need_control = TRUE; + break; + + case 11: + if (ac_status.ac_wind_dir == AC_SWING_OFF) { + change_wind_dir = TRUE; + } + need_control = TRUE; + break; + + default: + op_match = FALSE; + break; + } + + if (TRUE == op_match && TRUE == need_control) + { + printf("switch AC to power = %d, mode = %d, temp = %d, speed = %d, swing = %d with function 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, + function_code); + + length = ir_decode(function_code, user_data, &ac_status, change_wind_dir); + printf("\n === Binary decoded : %d\n", length); + for (index = 0; index < length; index++) + { + printf("%d, ", user_data[index]); + } + printf("===\n"); + } + } + } while (TRUE); + + ir_close(); + + return IR_DECODE_SUCCEEDED; +} + +static INT8 decode_as_tv(char *file_name, UINT8 ir_hex_encode) +{ + // keyboard input + int key_code = 0; + int first_time = 1; + int length = 0; + int index = 0; + + // 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)) + { + ir_close(); + return IR_DECODE_FAILED; + } + + do + { + if (1 == first_time) + { + 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"); + } + input_number(&key_code); + if (99 == key_code) + { + break; + } + length = ir_decode(key_code, user_data, NULL, 0); + printf("\n === Binary decoded : %d\n", length); + for (index = 0; index < length; index++) + { + printf("%d, ", user_data[index]); + } + printf("===\n"); + + } while (TRUE); + + ir_close(); + return IR_DECODE_SUCCEEDED; +} + +static void print_usage(const char *progn) { + printf("Usage: %s [function] [file] [subcate]\n" + "[function] : 0 - decode for AC; 1 - decode for TV\n" + "[file] : the remote control binary file\n" + "[subcate] : the sub_cate value from remote_index", progn); +} + +int main(int argc, char *argv[]) +{ + char function = '0'; + UINT8 ir_hex_encode = 0; + + if (4 != argc) + { + print_usage(basename(argv[0])); + return -1; + } + + function = argv[1][0]; + ir_hex_encode = (UINT8) (argv[3][0] - '0'); + + switch (function) + { + case '0': + 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); + decode_as_tv(argv[2], ir_hex_encode); + break; + + default: + 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/IRextWin32Example/ir_decoder/src/ir_tv_control.c index dd7869a..9585034 100644 --- a/win32-example/IRextWin32Example/ir_decoder/src/ir_tv_control.c +++ b/win32-example/IRextWin32Example/ir_decoder/src/ir_tv_control.c @@ -9,11 +9,15 @@ Revision log: * 2016-10-21: created by strawmanbobi **************************************************************************************/ +#if defined (BOARD_PC) +#pragma ide diagnostic ignored "hicpp-signed-bitwise" +#endif + #include -#include "../include/ir_defs.h" -#include "../include/ir_decode.h" -#include "../include/ir_tv_control.h" +#include "include/ir_defs.h" +#include "include/ir_decode.h" +#include "include/ir_tv_control.h" struct buffer diff --git a/win32-example/IRextWin32Example/ir_decoder/src/ir_utils.c b/win32-example/IRextWin32Example/ir_decoder/src/ir_utils.c index 6867df7..9045a52 100644 --- a/win32-example/IRextWin32Example/ir_decoder/src/ir_utils.c +++ b/win32-example/IRextWin32Example/ir_decoder/src/ir_utils.c @@ -9,7 +9,7 @@ Revision log: * 2016-10-01: created by strawmanbobi **************************************************************************************/ -#include "../include/ir_utils.h" +#include "include/ir_utils.h" UINT8 char_to_hex(char chr) { @@ -25,7 +25,7 @@ UINT8 char_to_hex(char chr) UINT8 chars_to_hex(const UINT8 *p) { - return (char_to_hex(*p) << 4) + char_to_hex(*(p + 1)); + return ((UINT8) char_to_hex(*p) << (UINT8) 4) + char_to_hex(*(p + 1)); } void string_to_hex_common(UINT8 *p, UINT8 *hex_data, UINT16 len) @@ -77,8 +77,8 @@ void hex_byte_to_double_char(char *dest, UINT8 length, UINT8 src) { return; } - hi_num = (UINT8) ((src >> 4) & 0x0F); - lo_num = (UINT8) (src & 0x0F); + hi_num = (UINT8) ((UINT8) (src >> (UINT8) 4) & (UINT8) 0x0F); + lo_num = (UINT8) (src & (UINT8) 0x0F); dest[0] = hex_half_byte_to_single_char(1, hi_num); dest[1] = hex_half_byte_to_single_char(1, lo_num);