From 990725273307d51437de79f796089ba87ee982c1 Mon Sep 17 00:00:00 2001 From: strawmanbobi Date: Sun, 21 Oct 2018 20:16:02 +0800 Subject: [PATCH] updated decode algorithms from CC26XX example --- .../Application/Irext/include/ir_ac_control.h | 2 +- .../Application/Irext/include/ir_defs.h | 12 +++++--- .../Application/Irext/include/ir_tv_control.h | 4 +-- .../Irext/src/ir_ac_binary_parse.c | 30 +++++++++++++++---- .../Application/Irext/src/ir_ac_build_frame.c | 2 -- .../Application/Irext/src/ir_ac_control.c | 8 +++++ .../Irext/src/ir_ac_parse_parameter.c | 1 - .../Source/Application/Irext/src/ir_decode.c | 20 ++++++++++--- 8 files changed, 60 insertions(+), 19 deletions(-) diff --git a/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/include/ir_ac_control.h b/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/include/ir_ac_control.h index 6eeee04..1ce4882 100644 --- a/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/include/ir_ac_control.h +++ b/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/include/ir_ac_control.h @@ -357,7 +357,7 @@ typedef struct tag_head { UINT16 tag; UINT16 len; - unsigned short offset; + UINT16 offset; UINT8 *p_data; } t_tag_head; diff --git a/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/include/ir_defs.h b/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/include/ir_defs.h index 7b60e53..b16e660 100644 --- a/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/include/ir_defs.h +++ b/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/include/ir_defs.h @@ -29,6 +29,10 @@ extern "C" #define TRUE 1 #define FALSE 0 +#define FORMAT_HEX 16 +#define FORMAT_DECIMAL 10 + + typedef unsigned char UINT8; typedef signed char INT8; typedef unsigned short UINT16; @@ -39,12 +43,12 @@ typedef int BOOL; void noprint(const char *fmt, ...); -#if !defined BOARD_CC26XX -#define ir_malloc(A) malloc(A) -#define ir_free(A) free(A) -#else +#if defined BOARD_CC26XX #define ir_malloc(A) ICall_malloc(A) #define ir_free(A) ICall_free(A) +#else +#define ir_malloc(A) malloc(A) +#define ir_free(A) free(A) #endif #define ir_memcpy(A, B, C) memcpy(A, B, C) diff --git a/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/include/ir_tv_control.h b/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/include/ir_tv_control.h index 9e86741..50dfaf4 100644 --- a/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/include/ir_tv_control.h +++ b/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/include/ir_tv_control.h @@ -73,7 +73,7 @@ typedef struct ir_data UINT8 index; } t_ir_data; -#if !defined BOARD_51 +#if !defined BOARD_51 && !defined BOARD_STM8 #pragma pack(1) #endif typedef struct ir_cycles @@ -83,7 +83,7 @@ typedef struct ir_cycles UINT16 space; } t_ir_cycles; -#if !defined BOARD_51 +#if !defined BOARD_51 && !defined BOARD_STM8 #pragma pack() #endif diff --git a/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_ac_binary_parse.c b/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_ac_binary_parse.c index 747a8b8..d154f54 100644 --- a/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_ac_binary_parse.c +++ b/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_ac_binary_parse.c @@ -9,15 +9,18 @@ Revision log: * 2017-01-03: created by strawmanbobi **************************************************************************************/ -#include - #include "../include/ir_ac_binary_parse.h" #include "../include/ir_decode.h" UINT16 tag_head_offset = 0; extern struct ir_bin_buffer *p_ir_buffer; -extern struct tag_head *tags; + +#if defined USE_DYNAMIC_TAG +extern struct tag_head* tags; +#else +extern struct tag_head tags[]; +#endif UINT8 tag_count = 0; const UINT16 tag_index[TAG_COUNT_FOR_PROTOCOL] = @@ -30,7 +33,11 @@ const UINT16 tag_index[TAG_COUNT_FOR_PROTOCOL] = INT8 binary_parse_offset() { int i = 0; - UINT16 *phead = (UINT16 *) &p_ir_buffer->data[1]; +#if defined BOARD_ESP8266 + UINT8 *phead = (UINT8 *)&p_ir_buffer->data[1]; +#else + UINT16 *phead = (UINT16 *)&p_ir_buffer->data[1]; +#endif // BOARD_ESP8266 tag_count = p_ir_buffer->data[0]; if (TAG_COUNT_FOR_PROTOCOL != tag_count) @@ -40,16 +47,29 @@ INT8 binary_parse_offset() tag_head_offset = (UINT16) ((tag_count << 1) + 1); +#if defined USE_DYNAMIC_TAG tags = (t_tag_head *) ir_malloc(tag_count * sizeof(t_tag_head)); + if (NULL == tags) { return IR_DECODE_FAILED; } +#endif for (i = 0; i < tag_count; i++) { tags[i].tag = tag_index[i]; + +#if defined BOARD_STM8 && defined COMPILER_IAR + UINT16 offset = *(phead + i); + tags[i].offset = (offset >> 8) | (offset << 8); +#elif defined BOARD_ESP8266 + UINT16 tmp_a = *(phead + i * 2); + UINT16 tmp_b = *(phead + i * 2 + 1); + tags[i].offset = tmp_b << 8 | tmp_a; +#else tags[i].offset = *(phead + i); +#endif if (tags[i].offset == TAG_INVALID) { @@ -96,7 +116,7 @@ INT8 binary_parse_len() void binary_tags_info() { -#if defined BOARD_PC +#if defined BOARD_PC && defined DEBUG UINT16 i = 0; for (i = 0; i < tag_count; i++) { diff --git a/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_ac_build_frame.c b/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_ac_build_frame.c index f3f767d..456d86a 100644 --- a/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_ac_build_frame.c +++ b/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_ac_build_frame.c @@ -141,5 +141,3 @@ UINT16 create_ir_frame() return context->code_cnt; } - - diff --git a/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_ac_control.c b/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_ac_control.c index 2bd8219..3d07dc0 100644 --- a/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_ac_control.c +++ b/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_ac_control.c @@ -22,7 +22,12 @@ Revision log: #include "../include/ir_utils.h" +#if defined USE_DYNAMIC_TAG extern struct tag_head *tags; +#else +extern struct tag_head tags[]; +#endif + extern UINT8 tag_count; static INT8 ir_context_init(); @@ -88,6 +93,7 @@ INT8 ir_ac_lib_parse() context->si.mode_count = 2; } context->si.dir_index = 0; + break; } } @@ -359,11 +365,13 @@ INT8 ir_ac_lib_parse() } } +#if defined USE_DYNAMIC_TAG if (NULL != tags) { ir_free(tags); tags = NULL; } +#endif ir_hex_code = (UINT8 *) ir_malloc(context->default_code.len); if (NULL == ir_hex_code) diff --git a/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_ac_parse_parameter.c b/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_ac_parse_parameter.c index 6dc072a..e5c8cea 100644 --- a/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_ac_parse_parameter.c +++ b/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_ac_parse_parameter.c @@ -96,7 +96,6 @@ INT8 parse_common_ac_parameter(t_tag_head *tag, t_tag_comp *comp_data, UINT8 wit string_to_hex_common(tag->p_data, hex_data, hex_len); // parse hex data to AC data structure - //*comp_len = hex_len; if (AC_PARAMETER_TYPE_1 == type) { diff --git a/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_decode.c b/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_decode.c index f2b8cdd..052c044 100644 --- a/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_decode.c +++ b/cc26xx-example/ti/BLE-CC264x/ble_cc26xx/Projects/ble/SimpleBLEPeripheral-IREXT/CC26xx/Source/Application/Irext/src/ir_decode.c @@ -21,8 +21,12 @@ Revision log: struct ir_bin_buffer binary_file; struct ir_bin_buffer *p_ir_buffer = &binary_file; -struct tag_head *tags; +#if defined USE_DYNAMIC_TAG +struct tag_head *tags; +#else +struct tag_head tags[TAG_COUNT_FOR_PROTOCOL]; +#endif UINT8 *ir_hex_code = NULL; UINT8 ir_hex_len = 0; @@ -67,7 +71,7 @@ void noprint(const char *fmt, ...) } // pubic function definitions - +#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; @@ -111,7 +115,12 @@ INT8 ir_file_open(const UINT8 category, const UINT8 sub_category, const char* fi } } } - +#else +INT8 ir_file_open(const UINT8 category, const UINT8 sub_category, const char* file_name) +{ + return IR_DECODE_SUCCESS; +} +#endif INT8 ir_binary_open(const UINT8 category, const UINT8 sub_category, UINT8* binary, UINT16 binary_length) { @@ -263,7 +272,7 @@ static UINT16 ir_ac_lib_control(t_remote_ac_status ac_status, UINT16 *user_data, UINT16 time_length = 0; #if defined BOARD_PC - UINT8 i = 0; + UINT16 i = 0; #endif if (0 == context->default_code.len) @@ -375,12 +384,15 @@ static UINT16 ir_ac_lib_control(t_remote_ac_status ac_status, UINT16 *user_data, static INT8 ir_ac_lib_close() { +#if defined USE_DYNAMIC_TAG // free context if (NULL != tags) { ir_free(tags); tags = NULL; } +#endif + free_ac_context(); return IR_DECODE_SUCCEEDED;