diff --git a/src/ir_decoder/CMakeLists.txt b/src/ir_decoder/CMakeLists.txt index 58a0b2c..7ddbaf9 100644 --- a/src/ir_decoder/CMakeLists.txt +++ b/src/ir_decoder/CMakeLists.txt @@ -5,44 +5,44 @@ project(irda_decoder) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") add_definitions(-DBOARD_PC) set(SOURCE_FILES_EXECUTABLE - irda_decode.c - include/irda_decode.h - irda_tv_parse_protocol.c - include/irda_tv_parse_protocol.h - irda_ac_apply.c - include/irda_ac_apply.h - include/irda_defs.h - irda_ac_build_frame.c - include/irda_ac_build_frame.h - irda_ac_parse_parameter.c - include/irda_ac_parse_parameter.h - irda_ac_parse_forbidden_info.c - include/irda_ac_parse_forbidden_info.h - irda_ac_parse_frame_info.c - include/irda_ac_parse_frame_info.h - irda_utils.c - include/irda_utils.h - irda_test_main.c - ) + src/ir_decode.c + include/ir_decode.h + src/ir_tv_control.c + include/ir_tv_control.h + src/ir_ac_apply.c + include/ir_ac_apply.h + include/ir_defs.h + src/ir_ac_build_frame.c + include/ir_ac_build_frame.h + src/ir_ac_parse_parameter.c + include/ir_ac_parse_parameter.h + src/ir_ac_parse_forbidden_info.c + include/ir_ac_parse_forbidden_info.h + src/ir_ac_parse_frame_info.c + include/ir_ac_parse_frame_info.h + src/ir_utils.c + include/ir_utils.h + src/ir_test_main.c + src/ir_ac_control.c include/ir_ac_control.h include/ir_ac_binary_parse.h src/ir_ac_binary_parse.c) set(SOURCE_FILES_SHARED_LIB - irda_decode.c - include/irda_decode.h - irda_tv_parse_protocol.c - include/irda_tv_parse_protocol.h - irda_ac_apply.c - include/irda_ac_apply.h - include/irda_defs.h - irda_ac_build_frame.c - include/irda_ac_build_frame.h - irda_ac_parse_parameter.c - include/irda_ac_parse_parameter.h - irda_ac_parse_forbidden_info.c - include/irda_ac_parse_forbidden_info.h - irda_ac_parse_frame_info.c - include/irda_ac_parse_frame_info.h - irda_utils.c - include/irda_utils.h) + src/ir_decode.c + include/ir_decode.h + src/ir_tv_control.c + include/ir_tv_control.h + src/ir_ac_apply.c + include/ir_ac_apply.h + include/ir_defs.h + src/ir_ac_build_frame.c + include/ir_ac_build_frame.h + src/ir_ac_parse_parameter.c + include/ir_ac_parse_parameter.h + src/ir_ac_parse_forbidden_info.c + include/ir_ac_parse_forbidden_info.h + src/ir_ac_parse_frame_info.c + include/ir_ac_parse_frame_info.h + src/ir_utils.c + include/ir_utils.h) add_executable(irda_decoder ${SOURCE_FILES_EXECUTABLE}) # add_library(irda_decoder SHARED ${SOURCE_FILES_SHARED_LIB}) diff --git a/src/ir_decoder/include/ir_ac_apply.h b/src/ir_decoder/include/ir_ac_apply.h new file mode 100644 index 0000000..b353e72 --- /dev/null +++ b/src/ir_decoder/include/ir_ac_apply.h @@ -0,0 +1,43 @@ +/************************************************************************************************** +Filename: irda_ac_apply.h +Revised: Date: 2016-10-12 +Revision: Revision: 1.0 + +Description: This file provides methods for AC IR applying functionalities + +Revision log: +* 2016-10-12: created by strawmanbobi +**************************************************************************************************/ + +#ifndef _IRDA_APPLY_H_ +#define _IRDA_APPLY_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include "ir_decode.h" + +#define MIN_TAG_LENGTH_TYPE_1 4 +#define MIN_TAG_LENGTH_TYPE_2 6 + +INT8 apply_power(remote_ac_status_t ac_status, UINT8 function_code); + +INT8 apply_mode(remote_ac_status_t ac_status, UINT8 function_code); + +INT8 apply_wind_speed(remote_ac_status_t ac_status, UINT8 function_code); + +INT8 apply_swing(remote_ac_status_t ac_status, UINT8 function_code); + +INT8 apply_temperature(remote_ac_status_t ac_status, UINT8 function_code); + +INT8 apply_function(struct ac_protocol *protocol, UINT8 function); + +INT8 apply_checksum(struct ac_protocol *protocol); + +#ifdef __cplusplus +} +#endif + +#endif //_IRDA_APPLY_H_ \ No newline at end of file diff --git a/src/ir_decoder/include/ir_ac_binary_parse.h b/src/ir_decoder/include/ir_ac_binary_parse.h new file mode 100644 index 0000000..7726318 --- /dev/null +++ b/src/ir_decoder/include/ir_ac_binary_parse.h @@ -0,0 +1,35 @@ +/************************************************************************************************** +Filename: irda_ac_binary_parse.h +Revised: Date: 2017-01-03 +Revision: Revision: 1.0 + +Description: This file provides methods for AC binary parse + +Revision log: +* 2017-01-03: created by strawmanbobi +**************************************************************************************************/ + +#ifndef IRDA_DECODER_IR_AC_BINARY_PARSE_H +#define IRDA_DECODER_IR_AC_BINARY_PARSE_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include "ir_defs.h" + +extern INT8 binary_parse_offset(); + +extern INT8 binary_parse_len(); + +extern void binary_tags_info(); + +extern INT8 binary_parse_data(); + +#ifdef __cplusplus +} +#endif + + +#endif //IRDA_DECODER_IR_AC_BINARY_PARSE_H diff --git a/src/ir_decoder/include/irda_ac_build_frame.h b/src/ir_decoder/include/ir_ac_build_frame.h similarity index 92% rename from src/ir_decoder/include/irda_ac_build_frame.h rename to src/ir_decoder/include/ir_ac_build_frame.h index cae208b..1aa9816 100644 --- a/src/ir_decoder/include/irda_ac_build_frame.h +++ b/src/ir_decoder/include/ir_ac_build_frame.h @@ -17,7 +17,7 @@ extern "C" { #endif -#include "irda_defs.h" +#include "ir_defs.h" extern UINT16 create_ir_frame(); diff --git a/src/ir_decoder/include/ir_ac_control.h b/src/ir_decoder/include/ir_ac_control.h new file mode 100644 index 0000000..89f24bb --- /dev/null +++ b/src/ir_decoder/include/ir_ac_control.h @@ -0,0 +1,31 @@ +/************************************************************************************************** +Filename: irda_ac_control.h +Revised: Date: 2016-12-31 +Revision: Revision: 1.0 + +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 + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include "ir_defs.h" + +extern INT8 irda_ac_lib_parse(); + +extern INT8 free_ac_context(); + +extern BOOL is_solo_function(UINT8 function_code); + +#ifdef __cplusplus +} +#endif + +#endif //IRDA_DECODER_IR_AC_CONTROL_H diff --git a/src/ir_decoder/include/irda_ac_parse_forbidden_info.h b/src/ir_decoder/include/ir_ac_parse_forbidden_info.h similarity index 86% rename from src/ir_decoder/include/irda_ac_parse_forbidden_info.h rename to src/ir_decoder/include/ir_ac_parse_forbidden_info.h index 32f3edc..305893e 100644 --- a/src/ir_decoder/include/irda_ac_parse_forbidden_info.h +++ b/src/ir_decoder/include/ir_ac_parse_forbidden_info.h @@ -17,9 +17,9 @@ extern "C" { #endif -#include "irda_decode.h" +#include "ir_decode.h" - extern INT8 parse_nmode(struct tag_head *tag, ac_n_mode index); +extern INT8 parse_nmode(struct tag_head *tag, ac_n_mode index); #ifdef __cplusplus } diff --git a/src/ir_decoder/include/irda_ac_parse_frame_info.h b/src/ir_decoder/include/ir_ac_parse_frame_info.h similarity index 94% rename from src/ir_decoder/include/irda_ac_parse_frame_info.h rename to src/ir_decoder/include/ir_ac_parse_frame_info.h index 832b559..c443546 100644 --- a/src/ir_decoder/include/irda_ac_parse_frame_info.h +++ b/src/ir_decoder/include/ir_ac_parse_frame_info.h @@ -17,7 +17,7 @@ extern "C" { #endif -#include "irda_decode.h" +#include "ir_decode.h" extern INT8 parse_bootcode(struct tag_head *tag); diff --git a/src/ir_decoder/include/irda_ac_parse_parameter.h b/src/ir_decoder/include/ir_ac_parse_parameter.h similarity index 92% rename from src/ir_decoder/include/irda_ac_parse_parameter.h rename to src/ir_decoder/include/ir_ac_parse_parameter.h index 6674ece..88dd8a6 100644 --- a/src/ir_decoder/include/irda_ac_parse_parameter.h +++ b/src/ir_decoder/include/ir_ac_parse_parameter.h @@ -17,11 +17,11 @@ extern "C" { #endif -#include "irda_decode.h" +#include "ir_decode.h" extern INT8 parse_common_ac_parameter(t_tag_head *tag, tag_comp *comp_data, UINT8 with_end, UINT8 type); -extern INT8 parse_defaultcode(struct tag_head *tag, ac_hex *default_code); +extern INT8 parse_default_code(struct tag_head *tag, ac_hex *default_code); extern INT8 parse_power_1(struct tag_head *tag, power_1 *power1); diff --git a/src/ir_decoder/include/irda_decode.h b/src/ir_decoder/include/ir_decode.h similarity index 98% rename from src/ir_decoder/include/irda_decode.h rename to src/ir_decoder/include/ir_decode.h index c8d0322..a4cecb9 100644 --- a/src/ir_decoder/include/irda_decode.h +++ b/src/ir_decoder/include/ir_decode.h @@ -18,7 +18,7 @@ extern "C" #endif #include -#include "irda_defs.h" +#include "ir_defs.h" #define TAG_COUNT_FOR_PROTOCOL 29 @@ -437,15 +437,6 @@ extern UINT16 user_data[]; /* exported functions */ ///////////////////////////////////////////////// AC Begin ///////////////////////////////////////////////// -/* - * function irda_context_init - * - * parameters: - * - * return: IR_DECODE_SUCCEEDED / IR_DECODE_FAILED - */ -extern INT8 irda_context_init(); - /* * function irda_ac_file_open * @@ -596,6 +587,11 @@ extern INT8 get_supported_swing(UINT8 ac_mode, UINT8* supported_swing); */ extern INT8 get_supported_wind_direction(UINT8* supported_wind_direction); +// private extern function +#if (defined BOARD_PC || defined BOARD_PC_DLL) +extern void irda_lib_free_inner_buffer(); +#endif + ///////////////////////////////////////////////// Utils End ///////////////////////////////////////////////// #ifdef __cplusplus diff --git a/src/ir_decoder/include/irda_defs.h b/src/ir_decoder/include/ir_defs.h similarity index 95% rename from src/ir_decoder/include/irda_defs.h rename to src/ir_decoder/include/ir_defs.h index d6cb9b4..ed7a8ca 100644 --- a/src/ir_decoder/include/irda_defs.h +++ b/src/ir_decoder/include/ir_defs.h @@ -29,6 +29,8 @@ typedef unsigned char UINT8; typedef signed char INT8; typedef unsigned short UINT16; typedef signed short INT16; +typedef signed int INT; +typedef unsigned int UINT; typedef int BOOL; #define irda_malloc(A) malloc(A) diff --git a/src/ir_decoder/include/irda_tv_parse_protocol.h b/src/ir_decoder/include/ir_tv_control.h similarity index 99% rename from src/ir_decoder/include/irda_tv_parse_protocol.h rename to src/ir_decoder/include/ir_tv_control.h index 66bb0ef..2660c44 100644 --- a/src/ir_decoder/include/irda_tv_parse_protocol.h +++ b/src/ir_decoder/include/ir_tv_control.h @@ -17,7 +17,7 @@ extern "C" { #endif -#include "irda_defs.h" +#include "ir_defs.h" #define STB_CHANNEL_OFFSET 14 diff --git a/src/ir_decoder/include/irda_utils.h b/src/ir_decoder/include/ir_utils.h similarity index 92% rename from src/ir_decoder/include/irda_utils.h rename to src/ir_decoder/include/ir_utils.h index 25d69c2..4b5a452 100644 --- a/src/ir_decoder/include/irda_utils.h +++ b/src/ir_decoder/include/ir_utils.h @@ -17,8 +17,8 @@ extern "C" { #endif -#include "irda_defs.h" -#include "irda_decode.h" +#include "ir_defs.h" +#include "ir_decode.h" #include diff --git a/src/ir_decoder/include/irda_ac_apply.h b/src/ir_decoder/include/irda_ac_apply.h deleted file mode 100644 index a8ab871..0000000 --- a/src/ir_decoder/include/irda_ac_apply.h +++ /dev/null @@ -1,43 +0,0 @@ -/************************************************************************************************** -Filename: irda_apply.h -Revised: Date: 2016-10-12 -Revision: Revision: 1.0 - -Description: This file provides methods for AC IR applying functionalities - -Revision log: -* 2016-10-12: created by strawmanbobi -**************************************************************************************************/ - -#ifndef _IRDA_APPLY_H_ -#define _IRDA_APPLY_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include "irda_decode.h" - -#define MIN_TAG_LENGTH_TYPE_1 4 -#define MIN_TAG_LENGTH_TYPE_2 6 - -extern INT8 apply_ac_power(struct ac_protocol *protocol, UINT8 power_status); - -extern INT8 apply_ac_mode(struct ac_protocol *protocol, UINT8 mode_status); - -extern INT8 apply_ac_temperature(struct ac_protocol *protocol, UINT8 temperature); - -extern INT8 apply_ac_wind_speed(struct ac_protocol *protocol, UINT8 wind_speed); - -extern INT8 apply_ac_swing(struct ac_protocol *protocol, UINT8 swing_status); - -extern INT8 apply_ac_function(struct ac_protocol *protocol, UINT8 function); - -extern INT8 apply_checksum(struct ac_protocol *protocol); - -#ifdef __cplusplus -} -#endif - -#endif //_IRDA_APPLY_H_ \ No newline at end of file diff --git a/src/ir_decoder/ir_decoder.vcxproj b/src/ir_decoder/ir_decoder.vcxproj index 2d83e44..f9cbb45 100644 --- a/src/ir_decoder/ir_decoder.vcxproj +++ b/src/ir_decoder/ir_decoder.vcxproj @@ -86,7 +86,7 @@ NotUsing Level3 Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;IR_DECODER_EXPORTS;%(PreprocessorDefinitions) + WIN32;_DEBUG;_WINDOWS;_USRDLL;IR_DECODER_EXPORTS;BOARD_PC;%(PreprocessorDefinitions) true @@ -150,7 +150,7 @@ - + @@ -177,7 +177,7 @@ - + diff --git a/src/ir_decoder/irda_decode.c b/src/ir_decoder/irda_decode.c deleted file mode 100644 index c81b9f5..0000000 --- a/src/ir_decoder/irda_decode.c +++ /dev/null @@ -1,1316 +0,0 @@ -/************************************************************************************************** -Filename: irda_decode.c -Revised: Date: 2016-10-01 -Revision: Revision: 1.0 - -Description: This file provides algorithms for IR decode (status type) - -Revision log: -* 2016-10-01: created by strawmanbobi -**************************************************************************************************/ - -#if defined WIN32 -#include "stdafx.h" -#endif - -#include -#include - -#include - -#include "include/irda_decode.h" -#include "include/irda_utils.h" -#include "include/irda_ac_parse_frame_info.h" -#include "include/irda_ac_parse_parameter.h" -#include "include/irda_ac_parse_forbidden_info.h" -#include "include/irda_ac_build_frame.h" -#include "include/irda_ac_apply.h" -#include "include/irda_tv_parse_protocol.h" - -struct ir_bin_buffer binaryfile; -struct ir_bin_buffer *pirda_buffer = &binaryfile; -struct tag_head *tags; - -// IRDA hex code -UINT8* ir_hex_code = NULL; -UINT8 ir_hex_len = 0; - -// tv raw code length -UINT16 tv_bin_length = 0; - -// global output buffer -UINT8 tag_count = 0; -UINT16 tag_head_offset = 0; - -UINT8 byteArray[PROTOCOL_SIZE] = { 0 }; -UINT8 tv_bin[EXPECTED_MEM_SIZE] = { 0 }; - -long binary_length = 0; -UINT8 *binary_content = NULL; - -// 2016-10-09 updated by strawmanbobi, change global data context to array pointer -protocol *context = (protocol *) byteArray; - -// ban function table -// fixed swing should not be counted in case of AC -INT8 apply_power(remote_ac_status_t ac_status, UINT8 function_code); -INT8 apply_mode(remote_ac_status_t ac_status, UINT8 function_code); -INT8 apply_wind_speed(remote_ac_status_t ac_status, UINT8 function_code); -INT8 apply_swing(remote_ac_status_t ac_status, UINT8 function_code); -INT8 apply_temperature(remote_ac_status_t ac_status, UINT8 function_code); - -lp_apply_ac_parameter apply_table[AC_APPLY_MAX] = -{ - apply_power, - apply_mode, - apply_temperature, - apply_temperature, - apply_wind_speed, - apply_swing, - apply_swing -}; - -const UINT16 tag_index[TAG_COUNT_FOR_PROTOCOL] = -{ - 1, 2, 3, 4, 5, 6, 7, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - 41, 42, 43, 44, 45, 46, 47, 48 -}; - -#if (defined BOARD_PC || defined BOARD_PC_DLL) -static void irda_lib_free_inner_buffer(); -#endif - -///////////////////////////////////////////////// AC Begin ///////////////////////////////////////////////// - -INT8 binary_parse_offset() -{ - int i = 0; - UINT16 *phead = (UINT16 *) &pirda_buffer->data[1]; - - tag_count = pirda_buffer->data[0]; - if(TAG_COUNT_FOR_PROTOCOL != tag_count) - { - return IR_DECODE_FAILED; - } - - tag_head_offset = (tag_count << 1) + 1; - - tags = (t_tag_head *) irda_malloc(tag_count * sizeof(t_tag_head)); - if (NULL == tags) - { - return IR_DECODE_FAILED; - } - - for (i = 0; i < tag_count; i++) - { - tags[i].tag = tag_index[i]; - tags[i].offset = *(phead + i); - if (tags[i].offset == TAG_INVALID) - { - tags[i].len = 0; - } - } - return IR_DECODE_SUCCEEDED; -} - -INT8 binary_parse_len() -{ - UINT16 i = 0, j = 0; - for (i = 0; i < (tag_count - 1); i++) - { - if (tags[i].offset == TAG_INVALID) - { - continue; - } - - for (j = (i + 1); j < tag_count; j++) - { - if (tags[j].offset != TAG_INVALID) - { - break; - } - } - if (j < tag_count) - { - tags[i].len = tags[j].offset - tags[i].offset; - } - else - { - tags[i].len = pirda_buffer->len - tags[i].offset - tag_head_offset; - return IR_DECODE_SUCCEEDED; - } - } - if (tags[tag_count - 1].offset != TAG_INVALID) - { - tags[tag_count - 1].len = pirda_buffer->len - tag_head_offset - tags[tag_count - 1].offset; - } - - return IR_DECODE_SUCCEEDED; -} - -void binary_tags_info() -{ -#if defined BOARD_PC - UINT16 i = 0; - for (i = 0; i < tag_count; i++) - { - if (tags[i].len == 0) - { - continue; - } - IR_PRINTF("tag(%d).len = %d\n", tags[i].tag, tags[i].len); - } -#endif -} - -INT8 binary_parse_data() -{ - UINT16 i = 0; - for (i = 0; i < tag_count; i++) - { - tags[i].pdata = pirda_buffer->data + tags[i].offset + tag_head_offset; - } - - return IR_DECODE_SUCCEEDED; -} - -INT8 free_ac_context() -{ - UINT16 i = 0; - - if (ir_hex_code != NULL) - { - irda_free(ir_hex_code); - ir_hex_code = NULL; - } - ir_hex_len = 0; - - if (context->default_code.data != NULL) - { - irda_free(context->default_code.data); - context->default_code.data = NULL; - context->default_code.len = 0; - } - - for (i = 0; i < AC_POWER_MAX; i++) - { - if (context->power1.comp_data[i].segment != NULL) - { - irda_free(context->power1.comp_data[i].segment); - context->power1.comp_data[i].segment = NULL; - context->power1.comp_data[i].seg_len = 0; - } - } - - for (i = 0; i < AC_TEMP_MAX; i++) - { - if (context->temp1.comp_data[i].segment != NULL) - { - irda_free(context->temp1.comp_data[i].segment); - context->temp1.comp_data[i].segment = NULL; - context->temp1.comp_data[i].seg_len = 0; - } - if (context->temp2.comp_data[i].segment != NULL) - { - irda_free(context->temp2.comp_data[i].segment); - context->temp2.comp_data[i].segment = NULL; - context->temp2.comp_data[i].seg_len = 0; - } - } - - for (i = 0; i < AC_MODE_MAX; i++) - { - if (context->mode1.comp_data[i].segment != NULL) - { - irda_free(context->mode1.comp_data[i].segment); - context->mode1.comp_data[i].segment = NULL; - context->mode1.comp_data[i].seg_len = 0; - } - if (context->mode2.comp_data[i].segment != NULL) - { - irda_free(context->mode2.comp_data[i].segment); - context->mode2.comp_data[i].segment = NULL; - context->mode2.comp_data[i].seg_len = 0; - } - } - for (i = 0; i < AC_WS_MAX; i++) - { - if (context->speed1.comp_data[i].segment != NULL) - { - irda_free(context->speed1.comp_data[i].segment); - context->speed1.comp_data[i].segment = NULL; - context->speed1.comp_data[i].seg_len = 0; - } - if (context->speed2.comp_data[i].segment != NULL) - { - irda_free(context->speed2.comp_data[i].segment); - context->speed2.comp_data[i].segment = NULL; - context->speed2.comp_data[i].seg_len = 0; - } - } - - for (i = 0; i < context->si.mode_count; i++) - { - if (context->swing1.comp_data != NULL && - context->swing1.comp_data[i].segment != NULL) - { - irda_free(context->swing1.comp_data[i].segment); - context->swing1.comp_data[i].segment = NULL; - context->swing1.comp_data[i].seg_len = 0; - } - if (context->swing2.comp_data != NULL && - context->swing2.comp_data[i].segment != NULL) - { - irda_free(context->swing2.comp_data[i].segment); - context->swing2.comp_data[i].segment = NULL; - context->swing2.comp_data[i].seg_len = 0; - } - } - - for (i = 0; i < AC_FUNCTION_MAX - 1; i++) - { - if (context->function1.comp_data[i].segment != NULL) - { - irda_free(context->function1.comp_data[i].segment); - context->function1.comp_data[i].segment = NULL; - context->function1.comp_data[i].seg_len = 0; - } - if (context->function2.comp_data[i].segment != NULL) - { - irda_free(context->function2.comp_data[i].segment); - context->function2.comp_data[i].segment = NULL; - context->function2.comp_data[i].seg_len = 0; - } - } - - // free composite data for swing1 and swing 2 - if(context->swing1.comp_data != NULL) - { - irda_free(context->swing1.comp_data); - context->swing1.comp_data = NULL; - } - if(context->swing2.comp_data != NULL) - { - irda_free(context->swing2.comp_data); - context->swing2.comp_data = NULL; - } - - for(i = 0; i < context->checksum.count; i++) - { - if(context->checksum.checksum_data != NULL && - context->checksum.checksum_data[i].spec_pos != NULL) - { - irda_free(context->checksum.checksum_data[i].spec_pos); - context->checksum.checksum_data[i].len = 0; - context->checksum.checksum_data[i].spec_pos = NULL; - } - } - if(context->checksum.checksum_data != NULL) - { - irda_free(context->checksum.checksum_data); - context->checksum.checksum_data = NULL; - } - - return IR_DECODE_SUCCEEDED; -} - -INT8 irda_ac_file_open(const char* file_name) -{ - int ret = 0; -#if !defined WIN32 - FILE *stream = fopen(file_name, "rb"); -#else - FILE *stream; - fopen_s(&stream, file_name, "rb"); -#endif - if (NULL == stream) - { - IR_PRINTF("\nfile open failed\n"); - return IR_DECODE_FAILED; - } - - fseek(stream, 0, SEEK_END); - binary_length = ftell(stream); - binary_content = (UINT8*) irda_malloc(binary_length); - - if (NULL == binary_content) - { - IR_PRINTF("\nfailed to alloc memory for binary\n"); - fclose(stream); - return IR_DECODE_FAILED; - } - - fseek(stream, 0, SEEK_SET); - ret = fread(binary_content, binary_length, 1, stream); - - if (ret <= 0) - { - fclose(stream); - irda_free(binary_content); - binary_length = 0; - return IR_DECODE_FAILED; - } - - fclose(stream); - - if (IR_DECODE_FAILED == irda_ac_lib_open(binary_content, binary_length)) - { - irda_free(binary_content); - binary_length = 0; - return IR_DECODE_FAILED; - } - - return IR_DECODE_SUCCEEDED; -} - -INT8 irda_ac_lib_open(UINT8 *binary, UINT16 binary_length) -{ - // it is recommended that the parameter binary pointing to - // a global memory block in embedded platform environment - pirda_buffer->data = binary; - pirda_buffer->len = binary_length; - pirda_buffer->offset = 0; - return IR_DECODE_SUCCEEDED; -} - -INT8 irda_context_init() -{ - irda_memset(context, 0, sizeof(protocol)); - return IR_DECODE_SUCCEEDED; -} - -INT8 irda_ac_lib_parse() -{ - UINT16 i = 0; - // suggest not to call init function here for de-couple purpose - irda_context_init(); - - if (IR_DECODE_FAILED == binary_parse_offset()) - { - return IR_DECODE_FAILED; - } - - if (IR_DECODE_FAILED == binary_parse_len()) - { - return IR_DECODE_FAILED; - } - - if (IR_DECODE_FAILED == binary_parse_data()) - { - return IR_DECODE_FAILED; - } - - binary_tags_info(); - - context->endian = 0; - context->lastbit = 0; - context->repeat_times = 1; - - for (i = 0; i < N_MODE_MAX; i++) - { - context->n_mode[i].enable = TRUE; - context->n_mode[i].allspeed = FALSE; - context->n_mode[i].alltemp = FALSE; - irda_memset(context->n_mode[i].speed, 0x00, AC_WS_MAX); - context->n_mode[i].speed_cnt = 0; - irda_memset(context->n_mode[i].temp, 0x00, AC_TEMP_MAX); - context->n_mode[i].temp_cnt = 0; - } - - // parse TAG 46 in first priority - for (i = 0; i < tag_count; i++) - { - if (tags[i].tag == TAG_AC_SWING_INFO) - { - if (tags[i].len != 0) - { - parse_swing_info(&tags[i], &(context->si)); - } - else - { - context->si.type = SWING_TYPE_NORMAL; - context->si.mode_count = 2; - } - context->si.dir_index = 0; - } - } - - for (i = 0; i < tag_count; i++) - { - if (tags[i].len == 0) - { - continue; - } - // then parse TAG 26 or 33 - if (context->si.type == SWING_TYPE_NORMAL) - { - UINT16 swing_space_size = 0; - if (tags[i].tag == TAG_AC_SWING_1) - { - context->swing1.count = context->si.mode_count; - context->swing1.len = tags[i].len >> 1; - swing_space_size = sizeof(tag_comp) * context->si.mode_count; - context->swing1.comp_data = (tag_comp*) irda_malloc(swing_space_size); - if (NULL == context->swing1.comp_data) - { - return IR_DECODE_FAILED; - } - - irda_memset(context->swing1.comp_data, 0x00, swing_space_size); - if (IR_DECODE_FAILED == parse_common_ac_parameter(&tags[i], - context->swing1.comp_data, - context->si.mode_count, - AC_PARAMETER_TYPE_1)) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_SWING_2) - { - context->swing2.count = context->si.mode_count; - context->swing2.len = tags[i].len >> 1; - swing_space_size = sizeof(tag_comp) * context->si.mode_count; - context->swing2.comp_data = (tag_comp*) irda_malloc(swing_space_size); - if (NULL == context->swing2.comp_data) - { - return IR_DECODE_FAILED; - } - irda_memset(context->swing2.comp_data, 0x00, swing_space_size); - if (IR_DECODE_FAILED == parse_common_ac_parameter(&tags[i], - context->swing2.comp_data, - context->si.mode_count, - AC_PARAMETER_TYPE_2)) - { - return IR_DECODE_FAILED; - } - } - } - - if (tags[i].tag == TAG_AC_DEFAULT_CODE) // default code TAG - { - context->default_code.data = (UINT8 *) irda_malloc((tags[i].len - 2) >> 1); - if (NULL == context->default_code.data) - { - return IR_DECODE_FAILED; - } - if (IR_DECODE_FAILED == parse_defaultcode(&tags[i], &(context->default_code))) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_POWER_1) // power tag - { - context->power1.len = tags[i].len >> 1; - if (IR_DECODE_FAILED == parse_common_ac_parameter(&tags[i], - context->power1.comp_data, - AC_POWER_MAX, - AC_PARAMETER_TYPE_1)) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_TEMP_1) // temperature tag type 1 - { - if (IR_DECODE_FAILED == parse_temp_1(&tags[i], &(context->temp1))) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_MODE_1) // mode tag - { - context->mode1.len = tags[i].len >> 1; - if (IR_DECODE_FAILED == parse_common_ac_parameter(&tags[i], - context->mode1.comp_data, - AC_MODE_MAX, - AC_PARAMETER_TYPE_1)) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_SPEED_1) // wind speed tag - { - context->speed1.len = tags[i].len >> 1; - if (IR_DECODE_FAILED == parse_common_ac_parameter(&tags[i], - context->speed1.comp_data, - AC_WS_MAX, - AC_PARAMETER_TYPE_1)) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_CHECKSUM_TYPE) - { - if (IR_DECODE_FAILED == parse_checksum(&tags[i], &(context->checksum))) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_MODE_2) - { - context->mode2.len = tags[i].len >> 1; - if (IR_DECODE_FAILED == - parse_common_ac_parameter(&tags[i], - context->mode2.comp_data, AC_MODE_MAX, AC_PARAMETER_TYPE_1)) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_SPEED_2) - { - context->speed2.len = tags[i].len >> 1; - if (IR_DECODE_FAILED == - parse_common_ac_parameter(&tags[i], - context->speed2.comp_data, AC_WS_MAX, AC_PARAMETER_TYPE_1)) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_TEMP_2) - { - if (IR_DECODE_FAILED == parse_temp_2(&tags[i], &(context->temp2))) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_SOLO_FUNCTION) - { - if (IR_DECODE_FAILED == parse_solo_code(&tags[i], &(context->sc))) - { - return IR_DECODE_FAILED; - } - context->solo_function_mark = 1; - } - else if (tags[i].tag == TAG_AC_FUNCTION_1) - { - if (IR_DECODE_FAILED == parse_function_1_tag29(&tags[i], &(context->function1))) - { - IR_PRINTF("\nfunction code parse error\n"); - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_FUNCTION_2) - { - if (IR_DECODE_FAILED == parse_function_2_tag34(&tags[i], &(context->function2))) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_FRAME_LENGTH) - { - if (IR_DECODE_FAILED == parse_framelen(&tags[i], tags[i].len)) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_ZERO) - { - if (IR_DECODE_FAILED == parse_zero(&tags[i])) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_ONE) - { - if (IR_DECODE_FAILED == parse_one(&tags[i])) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_BOOT_CODE) - { - if (IR_DECODE_FAILED == parse_bootcode(&tags[i])) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_REPEAT_TIMES) - { - if (IR_DECODE_FAILED == parse_repeat_times(&tags[i])) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_BITNUM) - { - if (IR_DECODE_FAILED == parse_bitnum(&tags[i])) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_ENDIAN) - { - if (IR_DECODE_FAILED == parse_endian(&tags[i])) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_BAN_FUNCTION_IN_COOL_MODE) - { - if (IR_DECODE_FAILED == parse_nmode(&tags[i], N_COOL)) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_BAN_FUNCTION_IN_HEAT_MODE) - { - if (IR_DECODE_FAILED == parse_nmode(&tags[i], N_HEAT)) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_BAN_FUNCTION_IN_AUTO_MODE) - { - if (IR_DECODE_FAILED == parse_nmode(&tags[i], N_AUTO)) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_BAN_FUNCTION_IN_FAN_MODE) - { - if (IR_DECODE_FAILED == parse_nmode(&tags[i], N_FAN)) - { - return IR_DECODE_FAILED; - } - } - else if (tags[i].tag == TAG_AC_BAN_FUNCTION_IN_DRY_MODE) - { - if (IR_DECODE_FAILED == parse_nmode(&tags[i], N_DRY)) - { - return IR_DECODE_FAILED; - } - } - } - - for(i = 0 ; i < tag_count; i++) - { - if(tags[i].len == 0) - { - continue; - } - if (tags[i].tag == TAG_AC_DELAY_CODE) - { - if (IR_DECODE_FAILED == parse_delaycode(&tags[i])) - { - return IR_DECODE_FAILED; - } - } - if (tags[i].tag == TAG_AC_LASTBIT) - { - if (IR_DECODE_FAILED == parse_lastbit(&tags[i])) - { - return IR_DECODE_FAILED; - } - } - } - - if(NULL != tags) - { - irda_free(tags); - tags = NULL; - } - - ir_hex_code = (UINT8 *) irda_malloc(context->default_code.len); - if(NULL == ir_hex_code) - { - // warning: this AC bin contains no default code - return IR_DECODE_FAILED; - } - - ir_hex_len = context->default_code.len; - irda_memset(ir_hex_code, 0x00, ir_hex_len); - - // pre-calculate solo function status after parse phase - if (1 == context->solo_function_mark) - { - context->solo_function_mark = 0x00; - // bit order from right to left : power, mode, temp+, temp-, wind_speed, swing, fix - for (i = AC_FUNCTION_POWER; i < AC_FUNCTION_MAX; i++) - { - if (isin(context->sc.solo_function_codes, i, context->sc.solo_func_count)) - { - context->solo_function_mark |= (1 << (i - 1)); - } - } - } - - // it is strongly recommended that we free pirda_buffer - // or make global buffer shared in extreme memory case - /* in case of running with test - begin */ -#if (defined BOARD_PC || defined BOARD_PC_DLL) - irda_lib_free_inner_buffer(); -#endif - /* in case of running with test - end */ - - return IR_DECODE_SUCCEEDED; -} - -#if (defined BOARD_PC || defined BOARD_PC_DLL) -static void irda_lib_free_inner_buffer() -{ - if (NULL != binary_content) { - irda_free(binary_content); - binary_content = NULL; - } -} -#endif - -BOOL is_solo_function(UINT8 function_code) -{ - return (((context->solo_function_mark >> (function_code - 1)) & 0x01) == 0x01) ? TRUE : FALSE; -} - -UINT8 has_function(struct ac_protocol *protocol, UINT8 function) -{ - if (0 != protocol->function1.len) - { - if(0 != protocol->function1.comp_data[function - 1].seg_len) - { - return TRUE; - } - } - - if(0 != protocol->function2.len) - { - if(0 != protocol->function2.comp_data[function - 1].seg_len) - { - return TRUE; - } - } - - return FALSE; -} - -INT8 apply_power(remote_ac_status_t ac_status, UINT8 function_code) -{ - apply_ac_power(context, ac_status.acPower); - return IR_DECODE_SUCCEEDED; -} - -INT8 apply_mode(remote_ac_status_t ac_status, UINT8 function_code) -{ - if (IR_DECODE_FAILED == apply_ac_mode(context, ac_status.acMode)) - { - // do not implement this mechanism since mode, temperature, wind - // speed would have unspecified function - //if(FALSE == has_function(context, AC_FUNCTION_MODE)) - { - return IR_DECODE_FAILED; - } - } - - return IR_DECODE_SUCCEEDED; -} - -INT8 apply_wind_speed(remote_ac_status_t ac_status, UINT8 function_code) -{ - if (FALSE == context->n_mode[ac_status.acMode].allspeed) - { - // if this level is not in black list - if(!isin(context->n_mode[ac_status.acMode].speed, - ac_status.acWindSpeed, - context->n_mode[ac_status.acMode].speed_cnt)) - { - if(IR_DECODE_FAILED == apply_ac_wind_speed(context, ac_status.acWindSpeed) && - function_code == AC_FUNCTION_WIND_SPEED) - { - // do not implement this mechanism since mode, temperature, wind - // speed would have unspecified function - //if(FALSE == has_function(context, AC_FUNCTION_WIND_SPEED)) - { - return IR_DECODE_FAILED; - } - } - } - else - { - // if this level is in black list, do not send IR wave if user want to apply this function - if(function_code == AC_FUNCTION_WIND_SPEED) - { - // do not implement this mechanism since mode, temperature, wind - // speed would have unspecified function - //if(FALSE == has_function(context, AC_FUNCTION_WIND_SPEED)) - { - return IR_DECODE_FAILED; - } - } - } - } - else - { - // if this level is in black list, do not send IR wave if user want to apply this function - if(function_code == AC_FUNCTION_WIND_SPEED) - { - // do not implement this mechanism since mode, temperature, wind - // speed would have unspecified function - //if(FALSE == has_function(context, AC_FUNCTION_WIND_SPEED)) - { - return IR_DECODE_FAILED; - } - } - } - return IR_DECODE_SUCCEEDED; -} - -INT8 apply_swing(remote_ac_status_t ac_status, UINT8 function_code) -{ - if(function_code == AC_FUNCTION_WIND_FIX) - { - // adjust fixed wind direction according to current status - if(context->si.type == SWING_TYPE_NORMAL && context->si.mode_count > 1) - { - if (TRUE == context->change_wind_direction) - { - context->si.dir_index++; - } - - if(context->si.dir_index == context->si.mode_count) - { - // reset dir index - context->si.dir_index = 1; - } - context->swing_status = context->si.dir_index; - } - } - else if(function_code == AC_FUNCTION_WIND_SWING) - { - context->swing_status = 0; - } - else - { - // do nothing - } - - 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)) - { - return IR_DECODE_FAILED; - } - else if(function_code == AC_FUNCTION_WIND_FIX && FALSE == has_function(context, AC_FUNCTION_WIND_FIX)) - { - return IR_DECODE_FAILED; - } - } - return IR_DECODE_SUCCEEDED; -} - -INT8 apply_temperature(remote_ac_status_t ac_status, UINT8 function_code) -{ - if (FALSE == context->n_mode[ac_status.acMode].alltemp) - { - if(!isin(context->n_mode[ac_status.acMode].temp, - ac_status.acTemp, - context->n_mode[ac_status.acMode].temp_cnt)) - { - if(IR_DECODE_FAILED == apply_ac_temperature(context, ac_status.acTemp)) - { - if(function_code == AC_FUNCTION_TEMPERATURE_UP - /*&& FALSE == has_function(context, AC_FUNCTION_TEMPERATURE_UP)*/) - { - return IR_DECODE_FAILED; - } - else if(function_code == AC_FUNCTION_TEMPERATURE_DOWN - /*&& FALSE == has_function(context, AC_FUNCTION_TEMPERATURE_DOWN)*/) - { - return IR_DECODE_FAILED; - } - } - } - else - { - // if this level is in black list, do not send IR wave if user want to apply this function - if(function_code == AC_FUNCTION_TEMPERATURE_UP - /*&& FALSE == has_function(context, AC_FUNCTION_TEMPERATURE_UP)*/) - { - return IR_DECODE_FAILED; - } - else if(function_code == AC_FUNCTION_TEMPERATURE_DOWN - /*&& FALSE == has_function(context, AC_FUNCTION_TEMPERATURE_DOWN)*/) - { - return IR_DECODE_FAILED; - } - } - } - else - { - // if this level is in black list, do not send IR wave if user want to apply this function - if(function_code == AC_FUNCTION_TEMPERATURE_UP - /*&& FALSE == has_function(context, AC_FUNCTION_TEMPERATURE_UP)*/) - { - return IR_DECODE_FAILED; - } - else if(function_code == AC_FUNCTION_TEMPERATURE_DOWN - /*&& FALSE == has_function(context, AC_FUNCTION_TEMPERATURE_DOWN)*/) - { - return IR_DECODE_FAILED; - } - } - return IR_DECODE_SUCCEEDED; -} - -UINT16 irda_ac_lib_control(remote_ac_status_t ac_status, UINT16 *user_data, UINT8 function_code, - BOOL change_wind_direction) -{ - UINT16 time_length = 0; - UINT8 i = 0; - - if (0 == context->default_code.len) - { - IR_PRINTF("\ndefault code is empty\n"); - return 0; - } - - // pre-set change wind direction flag here - context->change_wind_direction = change_wind_direction; - - context->time = user_data; - - // generate temp buffer for frame calculation - irda_memcpy(ir_hex_code, context->default_code.data, context->default_code.len); - -#if defined USE_APPLY_TABLE - if(ac_status.acPower != AC_POWER_OFF) - { - for (i = AC_APPLY_POWER; i < AC_APPLY_MAX; i++) - { - apply_table[i](context, parameter_array[i]); - } - } -#else - if(ac_status.acPower == AC_POWER_OFF) - { - // otherwise, power should always be applied - apply_power(ac_status, function_code); - } - else - { - // check the mode as the first priority, despite any other status - if(TRUE == context->n_mode[ac_status.acMode].enable) - { - if (is_solo_function(function_code)) - { - // this key press function needs to send solo code - apply_table[function_code - 1](ac_status, function_code); - } - else - { - if(!is_solo_function(AC_FUNCTION_POWER)) - { - apply_power(ac_status, function_code); - } - - if(!is_solo_function(AC_FUNCTION_MODE)) - { - if (IR_DECODE_FAILED == apply_mode(ac_status, function_code)) - { - return 0; - } - } - - if(!is_solo_function(AC_FUNCTION_WIND_SPEED)) - { - if (IR_DECODE_FAILED == apply_wind_speed(ac_status, function_code)) - { - return 0; - } - } - - if(!is_solo_function(AC_FUNCTION_WIND_SWING) && - !is_solo_function(AC_FUNCTION_WIND_FIX)) - { - if (IR_DECODE_FAILED == apply_swing(ac_status, function_code)) - { - return 0; - } - } - - if(!is_solo_function(AC_FUNCTION_TEMPERATURE_UP) && - !is_solo_function(AC_FUNCTION_TEMPERATURE_DOWN)) - { - if (IR_DECODE_FAILED == apply_temperature(ac_status, function_code)) - { - return 0; - } - } - } - } - else - { - return 0; - } - } -#endif - apply_ac_function(context, function_code); - // checksum should always be applied - apply_checksum(context); - -#if defined BOARD_PC - // have some debug - IR_PRINTF("==============================\n"); - for(i = 0; i < ir_hex_len; i++) - { - IR_PRINTF("[%02X] ", ir_hex_code[i]); - } - IR_PRINTF("\n"); -#endif - - time_length = create_ir_frame(); - - return time_length; -} - -void irda_ac_lib_close() -{ - // free context - if (NULL != tags) - { - irda_free(tags); - tags = NULL; - } - free_ac_context(); - - return; -} - -// utils -INT8 get_temperature_range(UINT8 ac_mode, INT8* temp_min, INT8* temp_max) -{ - UINT8 i = 0; - - if (ac_mode >= AC_MODE_MAX) - { - return IR_DECODE_FAILED; - } - if (NULL == temp_min || NULL == temp_max) - { - return IR_DECODE_FAILED; - } - - if (1 == context->n_mode[ac_mode].alltemp) - { - *temp_min = *temp_max = -1; - return IR_DECODE_SUCCEEDED; - } - - *temp_min = -1; - *temp_max = -1; - for (i = 0; i < AC_TEMP_MAX; i++) - { - if(isin(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) || - (context->temp2.len != 0 && 0 == context->temp2.comp_data[i].seg_len)) - { - continue; - } - if (-1 == *temp_min) - { - *temp_min = i; - } - if (-1 == *temp_max || i > *temp_max) - { - *temp_max = i; - } - } - return IR_DECODE_SUCCEEDED; -} - -INT8 get_supported_mode(UINT8* supported_mode) -{ - UINT8 i = 0; - if (NULL == supported_mode) - { - return IR_DECODE_FAILED; - } - *supported_mode = 0x1F; - - for (i = 0; i < 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); - } - } - - return IR_DECODE_SUCCEEDED; -} - -INT8 get_supported_wind_speed(UINT8 ac_mode, UINT8* supported_wind_speed) -{ - UINT8 i = 0; - if (ac_mode >= AC_MODE_MAX) - { - return IR_DECODE_FAILED; - } - - if (NULL == supported_wind_speed) - { - return IR_DECODE_FAILED; - } - - if (1 == context->n_mode[ac_mode].allspeed) - { - *supported_wind_speed = 0; - return IR_DECODE_SUCCEEDED; - } - - *supported_wind_speed = 0x0F; - - for (i = 0; i < AC_WS_MAX; i++) - { - if (isin(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); - } - } - - return IR_DECODE_SUCCEEDED; -} - -INT8 get_supported_swing(UINT8 ac_mode, UINT8* supported_swing) -{ - if (ac_mode >= AC_MODE_MAX) - { - return IR_DECODE_FAILED; - } - - if (NULL == supported_swing) - { - return IR_DECODE_FAILED; - } - - if (context->si.type == SWING_TYPE_NORMAL) - { - *supported_swing = 0x03; - } - else if (context->si.type == SWING_TYPE_SWING_ONLY) - { - *supported_swing = 0x02; - } - else if (context->si.type == SWING_TYPE_NOT_SPECIFIED) - { - *supported_swing = 0x00; - } - else - { - *supported_swing = 0x01; - } - return IR_DECODE_SUCCEEDED; -} - -INT8 get_supported_wind_direction(UINT8* supported_wind_direction) -{ - if (NULL != context) - { - *supported_wind_direction = context->si.mode_count - 1; - return IR_DECODE_SUCCEEDED; - } - else - { - return IR_DECODE_FAILED; - } -} - -///////////////////////////////////////////////// AC End ////////////////////////////////////////////////// - -///////////////////////////////////////////////// TV Begin ///////////////////////////////////////////////// -INT8 irda_tv_file_open(const char* file_name) -{ - int ret = 0; - -#if !defined WIN32 - FILE *stream = fopen(file_name, "rb"); -#else - FILE *stream; - fopen_s(&stream, file_name, "rb"); -#endif - - if (stream == NULL) - { - IR_PRINTF("\nfile open failed\n"); - return IR_DECODE_FAILED; - } - - fseek(stream, 0, SEEK_END); - binary_length = ftell(stream); - - binary_content = (UINT8*) irda_malloc(binary_length); - if (NULL == binary_content) - { - IR_PRINTF("\nfailed to alloc memory for binary\n"); - fclose(stream); - return IR_DECODE_FAILED; - } - - fseek(stream, 0, SEEK_SET); - ret = fread(binary_content, binary_length, 1, stream); - if (ret <= 0) - { - fclose(stream); - irda_free(binary_content); - binary_length = 0; - return IR_DECODE_FAILED; - } - - fclose(stream); - - if (IR_DECODE_FAILED == irda_tv_lib_open(binary_content, binary_length)) - { - irda_free(binary_content); - binary_length = 0; - return IR_DECODE_FAILED; - } - - return IR_DECODE_SUCCEEDED; -} - -INT8 irda_tv_lib_open(UINT8 *binary, UINT16 binary_length) -{ - return tv_lib_open(binary, binary_length); -} - -INT8 irda_tv_lib_parse(UINT8 irda_hex_encode) -{ - if (FALSE == tv_lib_parse(irda_hex_encode)) - { - IR_PRINTF("parse irda binary failed\n"); - memset(tv_bin, 0x00, EXPECTED_MEM_SIZE); - tv_bin_length = 0; - return IR_DECODE_FAILED; - } - return IR_DECODE_SUCCEEDED; -} - -UINT16 irda_tv_lib_control(UINT8 key, UINT16* l_user_data) -{ - UINT16 print_index = 0; - UINT16 irda_code_length = 0; - memset(l_user_data, 0x00, USER_DATA_SIZE); - irda_code_length = tv_lib_control(key, l_user_data); - -#if defined BOARD_PC - // have some debug - IR_PRINTF("=============================\n"); - IR_PRINTF("length of IRDA code = %d\n", irda_code_length); - for(print_index = 0; print_index < irda_code_length; print_index++) - { - IR_PRINTF("%d ", l_user_data[print_index]); - } - IR_PRINTF("\n=============================\n\n"); -#endif - - return irda_code_length; -} - -INT8 irda_tv_lib_close() -{ -#if (defined BOARD_PC || defined BOARD_PC_DLL) - irda_lib_free_inner_buffer(); -#endif - return IR_DECODE_SUCCEEDED; -} -///////////////////////////////////////////////// TV End ///////////////////////////////////////////////// \ No newline at end of file diff --git a/src/ir_decoder/irda_decode_jni.c b/src/ir_decoder/jni/irda_decode_jni.c similarity index 98% rename from src/ir_decoder/irda_decode_jni.c rename to src/ir_decoder/jni/irda_decode_jni.c index 6e58279..cf2926a 100644 --- a/src/ir_decoder/irda_decode_jni.c +++ b/src/ir_decoder/jni/irda_decode_jni.c @@ -12,9 +12,9 @@ Revision log: #include #include #include -#include "include/irda_decode_jni.h" -#include "include/irda_defs.h" -#include "include/irda_decode.h" +#include "../include/irda_decode_jni.h" +#include "../include/irda_defs.h" +#include "../include/irda_decode.h" // global variable definition UINT16 binary_length = 0; diff --git a/src/ir_decoder/include/irda_decode_jni.h b/src/ir_decoder/jni/irda_decode_jni.h similarity index 100% rename from src/ir_decoder/include/irda_decode_jni.h rename to src/ir_decoder/jni/irda_decode_jni.h diff --git a/src/ir_decoder/irda_ac_apply.c b/src/ir_decoder/src/ir_ac_apply.c similarity index 67% rename from src/ir_decoder/irda_ac_apply.c rename to src/ir_decoder/src/ir_ac_apply.c index d95f903..add9a1e 100644 --- a/src/ir_decoder/irda_ac_apply.c +++ b/src/ir_decoder/src/ir_ac_apply.c @@ -1,5 +1,5 @@ /************************************************************************************************** -Filename: irda_apply.c +Filename: irda_ac_apply.c Revised: Date: 2016-10-12 Revision: Revision: 1.0 @@ -17,8 +17,8 @@ Revision log: #include "stdafx.h" #endif -#include "include/irda_utils.h" -#include "include/irda_ac_apply.h" +#include "../include/ir_utils.h" +#include "../include/ir_ac_apply.h" /* * global vars @@ -31,6 +31,17 @@ Revision log: /* * function declaration */ +static INT8 apply_ac_power(struct ac_protocol *protocol, UINT8 power_status); + +static INT8 apply_ac_mode(struct ac_protocol *protocol, UINT8 mode_status); + +static INT8 apply_ac_temperature(struct ac_protocol *protocol, UINT8 temperature); + +static INT8 apply_ac_wind_speed(struct ac_protocol *protocol, UINT8 wind_speed); + +static INT8 apply_ac_swing(struct ac_protocol *protocol, UINT8 swing_status); + +static UINT8 has_function(struct ac_protocol *protocol, UINT8 function); /* * function definition @@ -141,7 +152,7 @@ INT8 apply_ac_parameter_type_2(UINT8 *dc_data, tag_comp *comp_data, UINT8 curren return IR_DECODE_SUCCEEDED; } -INT8 apply_ac_power(struct ac_protocol *protocol, UINT8 power_status) +static INT8 apply_ac_power(struct ac_protocol *protocol, UINT8 power_status) { UINT16 i = 0; if (0 == protocol->power1.len) @@ -161,7 +172,7 @@ INT8 apply_ac_power(struct ac_protocol *protocol, UINT8 power_status) return IR_DECODE_SUCCEEDED; } -INT8 apply_ac_mode(struct ac_protocol *protocol, UINT8 mode_status) +static INT8 apply_ac_mode(struct ac_protocol *protocol, UINT8 mode_status) { UINT16 i = 0; @@ -203,7 +214,7 @@ INT8 apply_ac_mode(struct ac_protocol *protocol, UINT8 mode_status) return IR_DECODE_SUCCEEDED; } -INT8 apply_ac_wind_speed(struct ac_protocol *protocol, UINT8 wind_speed) +static INT8 apply_ac_wind_speed(struct ac_protocol *protocol, UINT8 wind_speed) { UINT16 i = 0; @@ -245,7 +256,7 @@ INT8 apply_ac_wind_speed(struct ac_protocol *protocol, UINT8 wind_speed) return IR_DECODE_SUCCEEDED; } -INT8 apply_ac_temperature(struct ac_protocol *protocol, UINT8 temp_diff) +static INT8 apply_ac_temperature(struct ac_protocol *protocol, UINT8 temp_diff) { UINT16 i = 0; @@ -302,7 +313,7 @@ INT8 apply_ac_temperature(struct ac_protocol *protocol, UINT8 temp_diff) return IR_DECODE_SUCCEEDED; } -INT8 apply_ac_swing(struct ac_protocol *protocol, UINT8 swing_mode) +static INT8 apply_ac_swing(struct ac_protocol *protocol, UINT8 swing_mode) { UINT16 i = 0; @@ -356,51 +367,7 @@ INT8 apply_ac_swing(struct ac_protocol *protocol, UINT8 swing_mode) return IR_DECODE_SUCCEEDED; } -INT8 apply_ac_function(struct ac_protocol *protocol, UINT8 function) -{ - UINT16 i = 0; - - // function index starts from 1 (AC_FUNCTION_POWER), do -1 operation at first - if (0 == protocol->function1.len) - { - goto try_applying_function2; - } - - if (0 == protocol->function1.comp_data[function - 1].seg_len) - { - // force to apply function in any case - return IR_DECODE_SUCCEEDED; - } - - for (i = 0; i < protocol->function1.comp_data[function - 1].seg_len; i += 2) - { - apply_ac_parameter_type_1(ir_hex_code, &(protocol->function1.comp_data[function - 1]), i, FALSE); - } - - // get return here since function 1 is already applied - return IR_DECODE_SUCCEEDED; - - try_applying_function2: - if (0 == protocol->function2.len) - { - return IR_DECODE_SUCCEEDED; - } - - if (0 == protocol->function2.comp_data[function - 1].seg_len) - { - return IR_DECODE_SUCCEEDED; - } - - for (i = 0; i < protocol->function2.comp_data[function - 1].seg_len; i += 3) - { - apply_ac_parameter_type_2(ir_hex_code, - &(protocol->function2.comp_data[function - 1]), - i, FALSE); - } - return IR_DECODE_SUCCEEDED; -} - -INT8 apply_checksum_byte(UINT8 *ac_code, tag_checksum_data cs, BOOL inverse) +static INT8 apply_checksum_byte(UINT8 *ac_code, tag_checksum_data cs, BOOL inverse) { UINT16 i = 0; UINT8 checksum = 0x00; @@ -432,7 +399,7 @@ INT8 apply_checksum_byte(UINT8 *ac_code, tag_checksum_data cs, BOOL inverse) return IR_DECODE_SUCCEEDED; } -INT8 apply_checksum_halfbyte(UINT8 *ac_code, tag_checksum_data cs, BOOL inverse) +static INT8 apply_checksum_halfbyte(UINT8 *ac_code, tag_checksum_data cs, BOOL inverse) { UINT16 i = 0; UINT8 checksum = 0x00; @@ -464,7 +431,7 @@ INT8 apply_checksum_halfbyte(UINT8 *ac_code, tag_checksum_data cs, BOOL inverse) return IR_DECODE_SUCCEEDED; } -INT8 apply_checksum_spec_byte(UINT8 *ac_code, tag_checksum_data cs, BOOL inverse) +static INT8 apply_checksum_spec_byte(UINT8 *ac_code, tag_checksum_data cs, BOOL inverse) { UINT16 i = 0; UINT8 apply_byte_pos = 0; @@ -518,7 +485,7 @@ INT8 apply_checksum_spec_byte(UINT8 *ac_code, tag_checksum_data cs, BOOL inverse return IR_DECODE_SUCCEEDED; } -INT8 apply_checksum_spec_byte_onebyte(UINT8 *ac_code, tag_checksum_data cs, BOOL inverse) +static INT8 apply_checksum_spec_byte_onebyte(UINT8 *ac_code, tag_checksum_data cs, BOOL inverse) { UINT16 i = 0; UINT8 apply_byte_pos = 0; @@ -563,6 +530,71 @@ INT8 apply_checksum_spec_byte_onebyte(UINT8 *ac_code, tag_checksum_data cs, BOOL return IR_DECODE_SUCCEEDED; } +static UINT8 has_function(struct ac_protocol *protocol, UINT8 function) +{ + if (0 != protocol->function1.len) + { + if(0 != protocol->function1.comp_data[function - 1].seg_len) + { + return TRUE; + } + } + + if(0 != protocol->function2.len) + { + if(0 != protocol->function2.comp_data[function - 1].seg_len) + { + return TRUE; + } + } + + return FALSE; +} + +INT8 apply_function(struct ac_protocol *protocol, UINT8 function) +{ + UINT16 i = 0; + + // function index starts from 1 (AC_FUNCTION_POWER), do -1 operation at first + if (0 == protocol->function1.len) + { + goto try_applying_function2; + } + + if (0 == protocol->function1.comp_data[function - 1].seg_len) + { + // force to apply function in any case + return IR_DECODE_SUCCEEDED; + } + + for (i = 0; i < protocol->function1.comp_data[function - 1].seg_len; i += 2) + { + apply_ac_parameter_type_1(ir_hex_code, &(protocol->function1.comp_data[function - 1]), i, FALSE); + } + + // get return here since function 1 is already applied + return IR_DECODE_SUCCEEDED; + + try_applying_function2: + if (0 == protocol->function2.len) + { + return IR_DECODE_SUCCEEDED; + } + + if (0 == protocol->function2.comp_data[function - 1].seg_len) + { + return IR_DECODE_SUCCEEDED; + } + + for (i = 0; i < protocol->function2.comp_data[function - 1].seg_len; i += 3) + { + apply_ac_parameter_type_2(ir_hex_code, + &(protocol->function2.comp_data[function - 1]), + i, FALSE); + } + return IR_DECODE_SUCCEEDED; +} + INT8 apply_checksum(struct ac_protocol *protocol) { UINT8 i = 0; @@ -615,3 +647,171 @@ INT8 apply_checksum(struct ac_protocol *protocol) return IR_DECODE_SUCCEEDED; } + +INT8 apply_power(remote_ac_status_t ac_status, UINT8 function_code) +{ + apply_ac_power(context, ac_status.acPower); + return IR_DECODE_SUCCEEDED; +} + +INT8 apply_mode(remote_ac_status_t ac_status, UINT8 function_code) +{ + if (IR_DECODE_FAILED == apply_ac_mode(context, ac_status.acMode)) + { + // do not implement this mechanism since mode, temperature, wind + // speed would have unspecified function + //if(FALSE == has_function(context, AC_FUNCTION_MODE)) + { + return IR_DECODE_FAILED; + } + } + + return IR_DECODE_SUCCEEDED; +} + +INT8 apply_wind_speed(remote_ac_status_t ac_status, UINT8 function_code) +{ + if (FALSE == context->n_mode[ac_status.acMode].allspeed) + { + // if this level is not in black list + if(!isin(context->n_mode[ac_status.acMode].speed, + ac_status.acWindSpeed, + context->n_mode[ac_status.acMode].speed_cnt)) + { + if(IR_DECODE_FAILED == apply_ac_wind_speed(context, ac_status.acWindSpeed) && + function_code == AC_FUNCTION_WIND_SPEED) + { + // do not implement this mechanism since mode, temperature, wind + // speed would have unspecified function + //if(FALSE == has_function(context, AC_FUNCTION_WIND_SPEED)) + { + return IR_DECODE_FAILED; + } + } + } + else + { + // if this level is in black list, do not send IR wave if user want to apply this function + if(function_code == AC_FUNCTION_WIND_SPEED) + { + // do not implement this mechanism since mode, temperature, wind + // speed would have unspecified function + //if(FALSE == has_function(context, AC_FUNCTION_WIND_SPEED)) + { + return IR_DECODE_FAILED; + } + } + } + } + else + { + // if this level is in black list, do not send IR wave if user want to apply this function + if(function_code == AC_FUNCTION_WIND_SPEED) + { + // do not implement this mechanism since mode, temperature, wind + // speed would have unspecified function + //if(FALSE == has_function(context, AC_FUNCTION_WIND_SPEED)) + { + return IR_DECODE_FAILED; + } + } + } + return IR_DECODE_SUCCEEDED; +} + +INT8 apply_swing(remote_ac_status_t ac_status, UINT8 function_code) +{ + if(function_code == AC_FUNCTION_WIND_FIX) + { + // adjust fixed wind direction according to current status + if(context->si.type == SWING_TYPE_NORMAL && context->si.mode_count > 1) + { + if (TRUE == context->change_wind_direction) + { + context->si.dir_index++; + } + + if(context->si.dir_index == context->si.mode_count) + { + // reset dir index + context->si.dir_index = 1; + } + context->swing_status = context->si.dir_index; + } + } + else if(function_code == AC_FUNCTION_WIND_SWING) + { + context->swing_status = 0; + } + else + { + // do nothing + } + + 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)) + { + return IR_DECODE_FAILED; + } + else if(function_code == AC_FUNCTION_WIND_FIX && FALSE == has_function(context, AC_FUNCTION_WIND_FIX)) + { + return IR_DECODE_FAILED; + } + } + return IR_DECODE_SUCCEEDED; +} + +INT8 apply_temperature(remote_ac_status_t ac_status, UINT8 function_code) +{ + if (FALSE == context->n_mode[ac_status.acMode].alltemp) + { + if(!isin(context->n_mode[ac_status.acMode].temp, + ac_status.acTemp, + context->n_mode[ac_status.acMode].temp_cnt)) + { + if(IR_DECODE_FAILED == apply_ac_temperature(context, ac_status.acTemp)) + { + if(function_code == AC_FUNCTION_TEMPERATURE_UP + /*&& FALSE == has_function(context, AC_FUNCTION_TEMPERATURE_UP)*/) + { + return IR_DECODE_FAILED; + } + else if(function_code == AC_FUNCTION_TEMPERATURE_DOWN + /*&& FALSE == has_function(context, AC_FUNCTION_TEMPERATURE_DOWN)*/) + { + return IR_DECODE_FAILED; + } + } + } + else + { + // if this level is in black list, do not send IR wave if user want to apply this function + if(function_code == AC_FUNCTION_TEMPERATURE_UP + /*&& FALSE == has_function(context, AC_FUNCTION_TEMPERATURE_UP)*/) + { + return IR_DECODE_FAILED; + } + else if(function_code == AC_FUNCTION_TEMPERATURE_DOWN + /*&& FALSE == has_function(context, AC_FUNCTION_TEMPERATURE_DOWN)*/) + { + return IR_DECODE_FAILED; + } + } + } + else + { + // if this level is in black list, do not send IR wave if user want to apply this function + if(function_code == AC_FUNCTION_TEMPERATURE_UP + /*&& FALSE == has_function(context, AC_FUNCTION_TEMPERATURE_UP)*/) + { + return IR_DECODE_FAILED; + } + else if(function_code == AC_FUNCTION_TEMPERATURE_DOWN + /*&& FALSE == has_function(context, AC_FUNCTION_TEMPERATURE_DOWN)*/) + { + return IR_DECODE_FAILED; + } + } + return IR_DECODE_SUCCEEDED; +} \ No newline at end of file diff --git a/src/ir_decoder/src/ir_ac_binary_parse.c b/src/ir_decoder/src/ir_ac_binary_parse.c new file mode 100644 index 0000000..ca23d8d --- /dev/null +++ b/src/ir_decoder/src/ir_ac_binary_parse.c @@ -0,0 +1,114 @@ +/************************************************************************************************** +Filename: irda_ac_binary_parse.c +Revised: Date: 2017-01-03 +Revision: Revision: 1.0 + +Description: This file provides methods for AC binary parse + +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; +extern INT tag_count; +extern const UINT16 tag_index[TAG_COUNT_FOR_PROTOCOL]; + +INT8 binary_parse_offset() +{ + int i = 0; + UINT16 *phead = (UINT16 *) &p_ir_buffer->data[1]; + + tag_count = p_ir_buffer->data[0]; + if(TAG_COUNT_FOR_PROTOCOL != tag_count) + { + return IR_DECODE_FAILED; + } + + tag_head_offset = (UINT16)((tag_count << 1) + 1); + + tags = (t_tag_head *) irda_malloc(tag_count * sizeof(t_tag_head)); + if (NULL == tags) + { + return IR_DECODE_FAILED; + } + + for (i = 0; i < tag_count; i++) + { + tags[i].tag = tag_index[i]; + tags[i].offset = *(phead + i); + if (tags[i].offset == TAG_INVALID) + { + tags[i].len = 0; + } + } + return IR_DECODE_SUCCEEDED; +} + +INT8 binary_parse_len() +{ + UINT16 i = 0, j = 0; + for (i = 0; i < (tag_count - 1); i++) + { + if (tags[i].offset == TAG_INVALID) + { + continue; + } + + for (j = (UINT16)(i + 1); j < tag_count; j++) + { + if (tags[j].offset != TAG_INVALID) + { + break; + } + } + if (j < tag_count) + { + tags[i].len = tags[j].offset - tags[i].offset; + } + else + { + tags[i].len = p_ir_buffer->len - tags[i].offset - tag_head_offset; + return IR_DECODE_SUCCEEDED; + } + } + if (tags[tag_count - 1].offset != TAG_INVALID) + { + tags[tag_count - 1].len = p_ir_buffer->len - tag_head_offset - tags[tag_count - 1].offset; + } + + return IR_DECODE_SUCCEEDED; +} + +void binary_tags_info() +{ +#if defined BOARD_PC + UINT16 i = 0; + for (i = 0; i < tag_count; i++) + { + if (tags[i].len == 0) + { + continue; + } + IR_PRINTF("tag(%d).len = %d\n", tags[i].tag, tags[i].len); + } +#endif +} + +INT8 binary_parse_data() +{ + UINT16 i = 0; + for (i = 0; i < tag_count; i++) + { + tags[i].pdata = p_ir_buffer->data + tags[i].offset + tag_head_offset; + } + + return IR_DECODE_SUCCEEDED; +} \ No newline at end of file diff --git a/src/ir_decoder/irda_ac_build_frame.c b/src/ir_decoder/src/ir_ac_build_frame.c similarity index 95% rename from src/ir_decoder/irda_ac_build_frame.c rename to src/ir_decoder/src/ir_ac_build_frame.c index db2ceba..5fef1eb 100644 --- a/src/ir_decoder/irda_ac_build_frame.c +++ b/src/ir_decoder/src/ir_ac_build_frame.c @@ -15,8 +15,8 @@ Revision log: #include -#include "include/irda_ac_build_frame.h" -#include "include/irda_decode.h" +#include "../include/ir_ac_build_frame.h" +#include "../include/ir_decode.h" extern protocol* context; @@ -145,12 +145,6 @@ UINT16 create_ir_frame() } } - for (i = 0; i < context->code_cnt; i++) - { - IR_PRINTF("%d,", context->time[i]); - } - IR_PRINTF("\n"); - return context->code_cnt; } diff --git a/src/ir_decoder/src/ir_ac_control.c b/src/ir_decoder/src/ir_ac_control.c new file mode 100644 index 0000000..f3b0338 --- /dev/null +++ b/src/ir_decoder/src/ir_ac_control.c @@ -0,0 +1,449 @@ +/************************************************************************************************** +Filename: irda_ac_control.c +Revised: Date: 2017-01-02 +Revision: Revision: 1.0 + +Description: This file provides methods for AC IR control + +Revision log: +* 2016-10-12: created by strawmanbobi +**************************************************************************************************/ + +#include +#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" + + +extern struct tag_head *tags; +extern INT tag_count; + +static INT8 irda_context_init(); + + +static INT8 irda_context_init() +{ + irda_memset(context, 0, sizeof(protocol)); + return IR_DECODE_SUCCEEDED; +} + + +INT8 irda_ac_lib_parse() { + UINT8 i = 0; + // suggest not to call init function here for de-couple purpose + irda_context_init(); + + if (IR_DECODE_FAILED == binary_parse_offset()) { + return IR_DECODE_FAILED; + } + + if (IR_DECODE_FAILED == binary_parse_len()) { + return IR_DECODE_FAILED; + } + + if (IR_DECODE_FAILED == binary_parse_data()) { + return IR_DECODE_FAILED; + } + + binary_tags_info(); + + context->endian = 0; + context->lastbit = 0; + context->repeat_times = 1; + + for (i = 0; i < N_MODE_MAX; i++) { + context->n_mode[i].enable = TRUE; + context->n_mode[i].allspeed = FALSE; + context->n_mode[i].alltemp = FALSE; + irda_memset(context->n_mode[i].speed, 0x00, AC_WS_MAX); + context->n_mode[i].speed_cnt = 0; + irda_memset(context->n_mode[i].temp, 0x00, AC_TEMP_MAX); + context->n_mode[i].temp_cnt = 0; + } + + // parse TAG 46 in first priority + for (i = 0; i < tag_count; i++) { + if (tags[i].tag == TAG_AC_SWING_INFO) { + if (tags[i].len != 0) { + parse_swing_info(&tags[i], &(context->si)); + } else { + context->si.type = SWING_TYPE_NORMAL; + context->si.mode_count = 2; + } + context->si.dir_index = 0; + } + } + + for (i = 0; i < tag_count; i++) { + if (tags[i].len == 0) { + continue; + } + // then parse TAG 26 or 33 + if (context->si.type == SWING_TYPE_NORMAL) { + UINT16 swing_space_size = 0; + if (tags[i].tag == TAG_AC_SWING_1) { + context->swing1.count = context->si.mode_count; + context->swing1.len = (UINT8) tags[i].len >> 1; + swing_space_size = sizeof(tag_comp) * context->si.mode_count; + context->swing1.comp_data = (tag_comp *) irda_malloc(swing_space_size); + if (NULL == context->swing1.comp_data) { + return IR_DECODE_FAILED; + } + + irda_memset(context->swing1.comp_data, 0x00, swing_space_size); + if (IR_DECODE_FAILED == parse_common_ac_parameter(&tags[i], + context->swing1.comp_data, + context->si.mode_count, + AC_PARAMETER_TYPE_1)) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_SWING_2) { + context->swing2.count = context->si.mode_count; + context->swing2.len = (UINT8) tags[i].len >> 1; + swing_space_size = sizeof(tag_comp) * context->si.mode_count; + context->swing2.comp_data = (tag_comp *) irda_malloc(swing_space_size); + if (NULL == context->swing2.comp_data) { + return IR_DECODE_FAILED; + } + irda_memset(context->swing2.comp_data, 0x00, swing_space_size); + if (IR_DECODE_FAILED == parse_common_ac_parameter(&tags[i], + context->swing2.comp_data, + context->si.mode_count, + AC_PARAMETER_TYPE_2)) { + return IR_DECODE_FAILED; + } + } + } + + if (tags[i].tag == TAG_AC_DEFAULT_CODE) // default code TAG + { + context->default_code.data = (UINT8 *) irda_malloc(((size_t)tags[i].len - 2) >> 1); + if (NULL == context->default_code.data) { + return IR_DECODE_FAILED; + } + if (IR_DECODE_FAILED == parse_default_code(&tags[i], &(context->default_code))) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_POWER_1) // power tag + { + context->power1.len = (UINT8)tags[i].len >> 1; + if (IR_DECODE_FAILED == parse_common_ac_parameter(&tags[i], + context->power1.comp_data, + AC_POWER_MAX, + AC_PARAMETER_TYPE_1)) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_TEMP_1) // temperature tag type 1 + { + if (IR_DECODE_FAILED == parse_temp_1(&tags[i], &(context->temp1))) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_MODE_1) // mode tag + { + context->mode1.len = (UINT8)tags[i].len >> 1; + if (IR_DECODE_FAILED == parse_common_ac_parameter(&tags[i], + context->mode1.comp_data, + AC_MODE_MAX, + AC_PARAMETER_TYPE_1)) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_SPEED_1) // wind speed tag + { + context->speed1.len = (UINT8)tags[i].len >> 1; + if (IR_DECODE_FAILED == parse_common_ac_parameter(&tags[i], + context->speed1.comp_data, + AC_WS_MAX, + AC_PARAMETER_TYPE_1)) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_CHECKSUM_TYPE) { + if (IR_DECODE_FAILED == parse_checksum(&tags[i], &(context->checksum))) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_MODE_2) { + context->mode2.len = (UINT8)tags[i].len >> 1; + if (IR_DECODE_FAILED == + parse_common_ac_parameter(&tags[i], + context->mode2.comp_data, AC_MODE_MAX, AC_PARAMETER_TYPE_1)) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_SPEED_2) { + context->speed2.len = (UINT8)tags[i].len >> 1; + if (IR_DECODE_FAILED == + parse_common_ac_parameter(&tags[i], + context->speed2.comp_data, AC_WS_MAX, AC_PARAMETER_TYPE_1)) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_TEMP_2) { + if (IR_DECODE_FAILED == parse_temp_2(&tags[i], &(context->temp2))) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_SOLO_FUNCTION) { + if (IR_DECODE_FAILED == parse_solo_code(&tags[i], &(context->sc))) { + return IR_DECODE_FAILED; + } + context->solo_function_mark = 1; + } else if (tags[i].tag == TAG_AC_FUNCTION_1) { + if (IR_DECODE_FAILED == parse_function_1_tag29(&tags[i], &(context->function1))) { + IR_PRINTF("\nfunction code parse error\n"); + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_FUNCTION_2) { + if (IR_DECODE_FAILED == parse_function_2_tag34(&tags[i], &(context->function2))) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_FRAME_LENGTH) { + if (IR_DECODE_FAILED == parse_framelen(&tags[i], tags[i].len)) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_ZERO) { + if (IR_DECODE_FAILED == parse_zero(&tags[i])) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_ONE) { + if (IR_DECODE_FAILED == parse_one(&tags[i])) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_BOOT_CODE) { + if (IR_DECODE_FAILED == parse_bootcode(&tags[i])) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_REPEAT_TIMES) { + if (IR_DECODE_FAILED == parse_repeat_times(&tags[i])) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_BITNUM) { + if (IR_DECODE_FAILED == parse_bitnum(&tags[i])) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_ENDIAN) { + if (IR_DECODE_FAILED == parse_endian(&tags[i])) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_BAN_FUNCTION_IN_COOL_MODE) { + if (IR_DECODE_FAILED == parse_nmode(&tags[i], N_COOL)) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_BAN_FUNCTION_IN_HEAT_MODE) { + if (IR_DECODE_FAILED == parse_nmode(&tags[i], N_HEAT)) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_BAN_FUNCTION_IN_AUTO_MODE) { + if (IR_DECODE_FAILED == parse_nmode(&tags[i], N_AUTO)) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_BAN_FUNCTION_IN_FAN_MODE) { + if (IR_DECODE_FAILED == parse_nmode(&tags[i], N_FAN)) { + return IR_DECODE_FAILED; + } + } else if (tags[i].tag == TAG_AC_BAN_FUNCTION_IN_DRY_MODE) { + if (IR_DECODE_FAILED == parse_nmode(&tags[i], N_DRY)) { + return IR_DECODE_FAILED; + } + } + } + + for (i = 0; i < tag_count; i++) { + if (tags[i].len == 0) { + continue; + } + if (tags[i].tag == TAG_AC_DELAY_CODE) { + if (IR_DECODE_FAILED == parse_delaycode(&tags[i])) { + return IR_DECODE_FAILED; + } + } + if (tags[i].tag == TAG_AC_LASTBIT) { + if (IR_DECODE_FAILED == parse_lastbit(&tags[i])) { + return IR_DECODE_FAILED; + } + } + } + + if (NULL != tags) { + irda_free(tags); + tags = NULL; + } + + ir_hex_code = (UINT8 *) irda_malloc(context->default_code.len); + if (NULL == ir_hex_code) { + // warning: this AC bin contains no default code + return IR_DECODE_FAILED; + } + + ir_hex_len = context->default_code.len; + irda_memset(ir_hex_code, 0x00, ir_hex_len); + + // pre-calculate solo function status after parse phase + if (1 == context->solo_function_mark) { + context->solo_function_mark = 0x00; + // bit order from right to left : power, mode, temp+, temp-, wind_speed, swing, fix + for (i = AC_FUNCTION_POWER; i < AC_FUNCTION_MAX; i++) { + if (isin(context->sc.solo_function_codes, i, context->sc.solo_func_count)) { + context->solo_function_mark |= (1 << (i - 1)); + } + } + } + + // it is strongly recommended that we free p_ir_buffer + // or make global buffer shared in extreme memory case + /* in case of running with test - begin */ +#if (defined BOARD_PC || defined BOARD_PC_DLL) + irda_lib_free_inner_buffer(); +#endif + /* in case of running with test - end */ + + return IR_DECODE_SUCCEEDED; +} + + +INT8 free_ac_context() +{ + UINT16 i = 0; + + if (ir_hex_code != NULL) + { + irda_free(ir_hex_code); + ir_hex_code = NULL; + } + ir_hex_len = 0; + + if (context->default_code.data != NULL) + { + irda_free(context->default_code.data); + context->default_code.data = NULL; + context->default_code.len = 0; + } + + for (i = 0; i < AC_POWER_MAX; i++) + { + if (context->power1.comp_data[i].segment != NULL) + { + irda_free(context->power1.comp_data[i].segment); + context->power1.comp_data[i].segment = NULL; + context->power1.comp_data[i].seg_len = 0; + } + } + + for (i = 0; i < AC_TEMP_MAX; i++) + { + if (context->temp1.comp_data[i].segment != NULL) + { + irda_free(context->temp1.comp_data[i].segment); + context->temp1.comp_data[i].segment = NULL; + context->temp1.comp_data[i].seg_len = 0; + } + if (context->temp2.comp_data[i].segment != NULL) + { + irda_free(context->temp2.comp_data[i].segment); + context->temp2.comp_data[i].segment = NULL; + context->temp2.comp_data[i].seg_len = 0; + } + } + + for (i = 0; i < AC_MODE_MAX; i++) + { + if (context->mode1.comp_data[i].segment != NULL) + { + irda_free(context->mode1.comp_data[i].segment); + context->mode1.comp_data[i].segment = NULL; + context->mode1.comp_data[i].seg_len = 0; + } + if (context->mode2.comp_data[i].segment != NULL) + { + irda_free(context->mode2.comp_data[i].segment); + context->mode2.comp_data[i].segment = NULL; + context->mode2.comp_data[i].seg_len = 0; + } + } + for (i = 0; i < AC_WS_MAX; i++) + { + if (context->speed1.comp_data[i].segment != NULL) + { + irda_free(context->speed1.comp_data[i].segment); + context->speed1.comp_data[i].segment = NULL; + context->speed1.comp_data[i].seg_len = 0; + } + if (context->speed2.comp_data[i].segment != NULL) + { + irda_free(context->speed2.comp_data[i].segment); + context->speed2.comp_data[i].segment = NULL; + context->speed2.comp_data[i].seg_len = 0; + } + } + + for (i = 0; i < context->si.mode_count; i++) + { + if (context->swing1.comp_data != NULL && + context->swing1.comp_data[i].segment != NULL) + { + irda_free(context->swing1.comp_data[i].segment); + context->swing1.comp_data[i].segment = NULL; + context->swing1.comp_data[i].seg_len = 0; + } + if (context->swing2.comp_data != NULL && + context->swing2.comp_data[i].segment != NULL) + { + irda_free(context->swing2.comp_data[i].segment); + context->swing2.comp_data[i].segment = NULL; + context->swing2.comp_data[i].seg_len = 0; + } + } + + for (i = 0; i < AC_FUNCTION_MAX - 1; i++) + { + if (context->function1.comp_data[i].segment != NULL) + { + irda_free(context->function1.comp_data[i].segment); + context->function1.comp_data[i].segment = NULL; + context->function1.comp_data[i].seg_len = 0; + } + if (context->function2.comp_data[i].segment != NULL) + { + irda_free(context->function2.comp_data[i].segment); + context->function2.comp_data[i].segment = NULL; + context->function2.comp_data[i].seg_len = 0; + } + } + + // free composite data for swing1 and swing 2 + if(context->swing1.comp_data != NULL) + { + irda_free(context->swing1.comp_data); + context->swing1.comp_data = NULL; + } + if(context->swing2.comp_data != NULL) + { + irda_free(context->swing2.comp_data); + context->swing2.comp_data = NULL; + } + + for(i = 0; i < context->checksum.count; i++) + { + if(context->checksum.checksum_data != NULL && + context->checksum.checksum_data[i].spec_pos != NULL) + { + irda_free(context->checksum.checksum_data[i].spec_pos); + context->checksum.checksum_data[i].len = 0; + context->checksum.checksum_data[i].spec_pos = NULL; + } + } + if(context->checksum.checksum_data != NULL) + { + irda_free(context->checksum.checksum_data); + context->checksum.checksum_data = NULL; + } + + return IR_DECODE_SUCCEEDED; +} + +BOOL is_solo_function(UINT8 function_code) +{ + return (((context->solo_function_mark >> (function_code - 1)) & 0x01) == 0x01) ? TRUE : FALSE; +} diff --git a/src/ir_decoder/irda_ac_parse_forbidden_info.c b/src/ir_decoder/src/ir_ac_parse_forbidden_info.c similarity index 97% rename from src/ir_decoder/irda_ac_parse_forbidden_info.c rename to src/ir_decoder/src/ir_ac_parse_forbidden_info.c index 230ab11..4fc1fa9 100644 --- a/src/ir_decoder/irda_ac_parse_forbidden_info.c +++ b/src/ir_decoder/src/ir_ac_parse_forbidden_info.c @@ -21,8 +21,8 @@ Revision log: #include #include -#include "include/irda_decode.h" -#include "include/irda_ac_parse_forbidden_info.h" +#include "../include/ir_decode.h" +#include "../include/ir_ac_parse_forbidden_info.h" /* * global vars */ diff --git a/src/ir_decoder/irda_ac_parse_frame_info.c b/src/ir_decoder/src/ir_ac_parse_frame_info.c similarity index 98% rename from src/ir_decoder/irda_ac_parse_frame_info.c rename to src/ir_decoder/src/ir_ac_parse_frame_info.c index c727f8b..287fcd9 100644 --- a/src/ir_decoder/irda_ac_parse_frame_info.c +++ b/src/ir_decoder/src/ir_ac_parse_frame_info.c @@ -21,8 +21,8 @@ Revision log: #include #include -#include "include/irda_utils.h" -#include "include/irda_ac_parse_frame_info.h" +#include "../include/ir_utils.h" +#include "../include/ir_ac_parse_frame_info.h" /* * global vars diff --git a/src/ir_decoder/irda_ac_parse_parameter.c b/src/ir_decoder/src/ir_ac_parse_parameter.c similarity index 99% rename from src/ir_decoder/irda_ac_parse_parameter.c rename to src/ir_decoder/src/ir_ac_parse_parameter.c index 711b4f0..58bc64b 100644 --- a/src/ir_decoder/irda_ac_parse_parameter.c +++ b/src/ir_decoder/src/ir_ac_parse_parameter.c @@ -21,8 +21,8 @@ Revision log: #include #include -#include "include/irda_utils.h" -#include "include/irda_ac_parse_parameter.h" +#include "../include/ir_utils.h" +#include "../include/ir_ac_parse_parameter.h" /* * global vars @@ -162,7 +162,7 @@ INT8 parse_common_ac_parameter(t_tag_head *tag, tag_comp *comp_data, UINT8 with_ return IR_DECODE_SUCCEEDED; } -INT8 parse_defaultcode(struct tag_head *tag, ac_hex *default_code) +INT8 parse_default_code(struct tag_head *tag, ac_hex *default_code) { UINT16 byteLen = 0; diff --git a/src/ir_decoder/src/ir_decode.c b/src/ir_decoder/src/ir_decode.c new file mode 100644 index 0000000..d8a15d2 --- /dev/null +++ b/src/ir_decoder/src/ir_decode.c @@ -0,0 +1,502 @@ +/************************************************************************************************** +Filename: irda_decode.c +Revised: Date: 2016-10-01 +Revision: Revision: 1.0 + +Description: This file provides algorithms for IR decode (status type) + +Revision log: +* 2016-10-01: created by strawmanbobi +**************************************************************************************************/ + +#if defined WIN32 +#include "stdafx.h" +#endif + +#include +#include + +#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_ac_control.h" +#include "../include/ir_tv_control.h" + +struct ir_bin_buffer binary_file; +struct ir_bin_buffer* p_ir_buffer = &binary_file; +struct tag_head *tags; + + +UINT8* ir_hex_code = NULL; +UINT8 ir_hex_len = 0; + +UINT8 tag_count = 0; + +UINT8 byteArray[PROTOCOL_SIZE] = { 0 }; +UINT8 tv_bin[EXPECTED_MEM_SIZE] = { 0 }; + +size_t binary_length = 0; +UINT8 *binary_content = NULL; + + +protocol *context = (protocol *) byteArray; + +lp_apply_ac_parameter apply_table[AC_APPLY_MAX] = +{ + apply_power, + apply_mode, + apply_temperature, + apply_temperature, + apply_wind_speed, + apply_swing, + apply_swing +}; + +const UINT16 tag_index[TAG_COUNT_FOR_PROTOCOL] = +{ + 1, 2, 3, 4, 5, 6, 7, + 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 41, 42, 43, 44, 45, 46, 47, 48 +}; + +#if (defined BOARD_PC || defined BOARD_PC_DLL) +void irda_lib_free_inner_buffer(); +#endif + + +///////////////////////////////////////////////// AC Begin ///////////////////////////////////////////////// +INT8 irda_ac_file_open(const char* file_name) +{ + size_t ret = 0; +#if !defined WIN32 + FILE *stream = fopen(file_name, "rb"); +#else + FILE *stream; + fopen_s(&stream, file_name, "rb"); +#endif + if (NULL == stream) + { + IR_PRINTF("\nfile open failed\n"); + return IR_DECODE_FAILED; + } + + fseek(stream, 0, SEEK_END); + binary_length = (size_t) ftell(stream); + binary_content = (UINT8*) irda_malloc(binary_length); + + if (NULL == binary_content) + { + IR_PRINTF("\nfailed to alloc memory for binary\n"); + fclose(stream); + return IR_DECODE_FAILED; + } + + fseek(stream, 0, SEEK_SET); + ret = fread(binary_content, binary_length, 1, stream); + + if (ret <= 0) + { + fclose(stream); + irda_free(binary_content); + binary_length = 0; + return IR_DECODE_FAILED; + } + + fclose(stream); + + if (IR_DECODE_FAILED == irda_ac_lib_open(binary_content, (UINT16)binary_length)) + { + irda_free(binary_content); + binary_length = 0; + return IR_DECODE_FAILED; + } + + return IR_DECODE_SUCCEEDED; +} + +INT8 irda_ac_lib_open(UINT8 *binary, UINT16 binary_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->offset = 0; + return IR_DECODE_SUCCEEDED; +} + +UINT16 irda_ac_lib_control(remote_ac_status_t ac_status, UINT16 *user_data, UINT8 function_code, + BOOL change_wind_direction) +{ + UINT16 time_length = 0; + UINT8 i = 0; + + if (0 == context->default_code.len) + { + IR_PRINTF("\ndefault code is empty\n"); + return 0; + } + + // pre-set change wind direction flag here + context->change_wind_direction = change_wind_direction; + + context->time = user_data; + + // generate temp buffer for frame calculation + irda_memcpy(ir_hex_code, context->default_code.data, context->default_code.len); + +#if defined USE_APPLY_TABLE + if(ac_status.acPower != AC_POWER_OFF) + { + for (i = AC_APPLY_POWER; i < AC_APPLY_MAX; i++) + { + apply_table[i](context, parameter_array[i]); + } + } +#else + if(ac_status.acPower == AC_POWER_OFF) + { + // otherwise, power should always be applied + apply_power(ac_status, function_code); + } + else + { + // check the mode as the first priority, despite any other status + if(TRUE == context->n_mode[ac_status.acMode].enable) + { + if (is_solo_function(function_code)) + { + // this key press function needs to send solo code + apply_table[function_code - 1](ac_status, function_code); + } + else + { + if(!is_solo_function(AC_FUNCTION_POWER)) + { + apply_power(ac_status, function_code); + } + + if(!is_solo_function(AC_FUNCTION_MODE)) + { + if (IR_DECODE_FAILED == apply_mode(ac_status, function_code)) + { + return 0; + } + } + + if(!is_solo_function(AC_FUNCTION_WIND_SPEED)) + { + if (IR_DECODE_FAILED == apply_wind_speed(ac_status, function_code)) + { + return 0; + } + } + + if(!is_solo_function(AC_FUNCTION_WIND_SWING) && + !is_solo_function(AC_FUNCTION_WIND_FIX)) + { + if (IR_DECODE_FAILED == apply_swing(ac_status, function_code)) + { + return 0; + } + } + + if(!is_solo_function(AC_FUNCTION_TEMPERATURE_UP) && + !is_solo_function(AC_FUNCTION_TEMPERATURE_DOWN)) + { + if (IR_DECODE_FAILED == apply_temperature(ac_status, function_code)) + { + return 0; + } + } + } + } + else + { + return 0; + } + } +#endif + apply_function(context, function_code); + // checksum should always be applied + apply_checksum(context); + + time_length = create_ir_frame(); + +#if defined BOARD_PC + for (i = 0; i < context->code_cnt; i++) + { + IR_PRINTF("%d,", context->time[i]); + } + IR_PRINTF("\n"); +#endif + + return time_length; +} + +void irda_ac_lib_close() +{ + // free context + if (NULL != tags) + { + irda_free(tags); + tags = NULL; + } + free_ac_context(); + + return; +} + +// utils +INT8 get_temperature_range(UINT8 ac_mode, INT8* temp_min, INT8* temp_max) +{ + UINT8 i = 0; + + if (ac_mode >= AC_MODE_MAX) + { + return IR_DECODE_FAILED; + } + if (NULL == temp_min || NULL == temp_max) + { + return IR_DECODE_FAILED; + } + + if (1 == context->n_mode[ac_mode].alltemp) + { + *temp_min = *temp_max = -1; + return IR_DECODE_SUCCEEDED; + } + + *temp_min = -1; + *temp_max = -1; + for (i = 0; i < AC_TEMP_MAX; i++) + { + if(isin(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) || + (context->temp2.len != 0 && 0 == context->temp2.comp_data[i].seg_len)) + { + continue; + } + if (-1 == *temp_min) + { + *temp_min = i; + } + if (-1 == *temp_max || i > *temp_max) + { + *temp_max = i; + } + } + return IR_DECODE_SUCCEEDED; +} + +INT8 get_supported_mode(UINT8* supported_mode) +{ + UINT8 i = 0; + if (NULL == supported_mode) + { + return IR_DECODE_FAILED; + } + *supported_mode = 0x1F; + + for (i = 0; i < 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); + } + } + + return IR_DECODE_SUCCEEDED; +} + +INT8 get_supported_wind_speed(UINT8 ac_mode, UINT8* supported_wind_speed) +{ + UINT8 i = 0; + if (ac_mode >= AC_MODE_MAX) + { + return IR_DECODE_FAILED; + } + + if (NULL == supported_wind_speed) + { + return IR_DECODE_FAILED; + } + + if (1 == context->n_mode[ac_mode].allspeed) + { + *supported_wind_speed = 0; + return IR_DECODE_SUCCEEDED; + } + + *supported_wind_speed = 0x0F; + + for (i = 0; i < AC_WS_MAX; i++) + { + if (isin(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); + } + } + + return IR_DECODE_SUCCEEDED; +} + +INT8 get_supported_swing(UINT8 ac_mode, UINT8* supported_swing) +{ + if (ac_mode >= AC_MODE_MAX) + { + return IR_DECODE_FAILED; + } + + if (NULL == supported_swing) + { + return IR_DECODE_FAILED; + } + + if (context->si.type == SWING_TYPE_NORMAL) + { + *supported_swing = 0x03; + } + else if (context->si.type == SWING_TYPE_SWING_ONLY) + { + *supported_swing = 0x02; + } + else if (context->si.type == SWING_TYPE_NOT_SPECIFIED) + { + *supported_swing = 0x00; + } + else + { + *supported_swing = 0x01; + } + return IR_DECODE_SUCCEEDED; +} + +INT8 get_supported_wind_direction(UINT8* supported_wind_direction) +{ + if (NULL != context) + { + *supported_wind_direction = (UINT8)(context->si.mode_count - 1); + return IR_DECODE_SUCCEEDED; + } + else + { + return IR_DECODE_FAILED; + } +} + +///////////////////////////////////////////////// AC End ////////////////////////////////////////////////// + +///////////////////////////////////////////////// TV Begin ///////////////////////////////////////////////// +INT8 irda_tv_file_open(const char* file_name) +{ + size_t ret = 0; + +#if !defined WIN32 + FILE *stream = fopen(file_name, "rb"); +#else + FILE *stream; + fopen_s(&stream, file_name, "rb"); +#endif + + if (stream == NULL) + { + IR_PRINTF("\nfile open failed\n"); + return IR_DECODE_FAILED; + } + + fseek(stream, 0, SEEK_END); + binary_length = (size_t)ftell(stream); + + binary_content = (UINT8*) irda_malloc(binary_length); + if (NULL == binary_content) + { + IR_PRINTF("\nfailed to alloc memory for binary\n"); + fclose(stream); + return IR_DECODE_FAILED; + } + + fseek(stream, 0, SEEK_SET); + ret = fread(binary_content, binary_length, 1, stream); + if (ret <= 0) + { + fclose(stream); + irda_free(binary_content); + binary_length = 0; + return IR_DECODE_FAILED; + } + + fclose(stream); + + if (IR_DECODE_FAILED == irda_tv_lib_open(binary_content, (UINT16)binary_length)) + { + irda_free(binary_content); + binary_length = 0; + return IR_DECODE_FAILED; + } + + return IR_DECODE_SUCCEEDED; +} + +INT8 irda_tv_lib_open(UINT8 *binary, UINT16 binary_length) +{ + return tv_lib_open(binary, binary_length); +} + +INT8 irda_tv_lib_parse(UINT8 irda_hex_encode) +{ + if (FALSE == tv_lib_parse(irda_hex_encode)) + { + IR_PRINTF("parse irda binary failed\n"); + memset(tv_bin, 0x00, EXPECTED_MEM_SIZE); + return IR_DECODE_FAILED; + } + return IR_DECODE_SUCCEEDED; +} + +UINT16 irda_tv_lib_control(UINT8 key, UINT16* l_user_data) +{ + UINT16 print_index = 0; + UINT16 irda_code_length = 0; + memset(l_user_data, 0x00, USER_DATA_SIZE); + irda_code_length = tv_lib_control(key, l_user_data); + +#if defined BOARD_PC + // have some debug + IR_PRINTF("=============================\n"); + IR_PRINTF("length of IRDA code = %d\n", irda_code_length); + for(print_index = 0; print_index < irda_code_length; print_index++) + { + IR_PRINTF("%d ", l_user_data[print_index]); + } + IR_PRINTF("\n=============================\n\n"); +#endif + + return irda_code_length; +} + +INT8 irda_tv_lib_close() +{ +#if (defined BOARD_PC || defined BOARD_PC_DLL) + irda_lib_free_inner_buffer(); +#endif + return IR_DECODE_SUCCEEDED; +} +///////////////////////////////////////////////// TV End ///////////////////////////////////////////////// + + +#if (defined BOARD_PC || defined BOARD_PC_DLL) +void irda_lib_free_inner_buffer() +{ + if (NULL != binary_content) { + irda_free(binary_content); + binary_content = NULL; + } +} +#endif \ No newline at end of file diff --git a/src/ir_decoder/irda_test_main.c b/src/ir_decoder/src/ir_test_main.c similarity index 87% rename from src/ir_decoder/irda_test_main.c rename to src/ir_decoder/src/ir_test_main.c index 8247950..afd86ae 100644 --- a/src/ir_decoder/irda_test_main.c +++ b/src/ir_decoder/src/ir_test_main.c @@ -19,8 +19,8 @@ Revision log: #include #endif -#include "include/irda_defs.h" -#include "include/irda_decode.h" +#include "../include/ir_defs.h" +#include "../include/ir_decode.h" // global variable definition remote_ac_status_t ac_status; @@ -34,8 +34,7 @@ INT8 decode_as_ac(char* file_name) { // keyboard input int in_char = 0; - int count = 0; - BOOL op_match = TRUE; + BOOL op_match; UINT8 function_code = AC_FUNCTION_MAX; // get status @@ -44,8 +43,9 @@ INT8 decode_as_ac(char* file_name) INT8 max_temperature = 0; UINT8 supported_speed = 0x00; UINT8 supported_swing = 0x00; + UINT8 supported_wind_direction = 0x00; - BOOL need_control = TRUE; + BOOL need_control; // init air conditioner status ac_status.acDisplay = 0; @@ -79,12 +79,12 @@ INT8 decode_as_ac(char* file_name) case 'w': case 'W': // temperature plus - ac_status.acTemp = (ac_status.acTemp == AC_TEMP_30) ? AC_TEMP_30 : (ac_status.acTemp + 1); + ac_status.acTemp = (UINT8)((ac_status.acTemp == AC_TEMP_30) ? AC_TEMP_30 : (ac_status.acTemp + 1)); function_code = AC_FUNCTION_TEMPERATURE_UP; break; case 's': case 'S': - ac_status.acTemp = (ac_status.acTemp == AC_TEMP_16) ? AC_TEMP_16 : (ac_status.acTemp - 1); + ac_status.acTemp = (UINT8)((ac_status.acTemp == AC_TEMP_16) ? AC_TEMP_16 : (ac_status.acTemp - 1)); function_code = AC_FUNCTION_TEMPERATURE_DOWN; // temperature minus break; @@ -97,7 +97,7 @@ INT8 decode_as_ac(char* file_name) break; case 'd': case 'D': - ac_status.acWindDir = (ac_status.acWindDir == 0) ? 1 : 0; + ac_status.acWindDir = (UINT8)((ac_status.acWindDir == 0) ? 1 : 0); function_code = AC_FUNCTION_WIND_SWING; // wind swing loop break; @@ -150,6 +150,14 @@ INT8 decode_as_ac(char* file_name) need_control = FALSE; break; + case '7': + if (IR_DECODE_SUCCEEDED == get_supported_wind_direction(&supported_wind_direction)) + { + IR_PRINTF("\nsupported wind direction = %02X\n", supported_wind_direction); + } + need_control = FALSE; + break; + default: op_match = FALSE; break; @@ -178,8 +186,7 @@ INT8 decode_as_tv(char *file_name, UINT8 irda_hex_encode) { // keyboard input int in_char = 0; - int key_code = -1; - int count = 0; + int key_code = 0; if (IR_DECODE_FAILED == irda_tv_file_open(file_name)) { @@ -196,12 +203,12 @@ INT8 decode_as_tv(char *file_name, UINT8 irda_hex_encode) if (in_char >= '0' && in_char <= '9') { key_code = in_char - '0'; - irda_tv_lib_control(key_code, user_data); + irda_tv_lib_control((UINT8)key_code, user_data); } else if (in_char >= 'a' && in_char <= 'f') { key_code = 10 + (in_char - 'a'); - irda_tv_lib_control(key_code, user_data); + irda_tv_lib_control((UINT8)key_code, user_data); } else if (in_char == 'q') { diff --git a/src/ir_decoder/irda_tv_parse_protocol.c b/src/ir_decoder/src/ir_tv_control.c similarity index 80% rename from src/ir_decoder/irda_tv_parse_protocol.c rename to src/ir_decoder/src/ir_tv_control.c index e889bab..f398074 100644 --- a/src/ir_decoder/irda_tv_parse_protocol.c +++ b/src/ir_decoder/src/ir_tv_control.c @@ -9,39 +9,16 @@ Revision log: * 2016-10-21: created by strawmanbobi **************************************************************************************************/ -/************************************************************************************************** - * INCLUDES - **************************************************************************************************/ - #if defined WIN32 #include "stdafx.h" #endif #include -#include "include/irda_defs.h" -#include "include/irda_decode.h" -#include "include/irda_tv_parse_protocol.h" +#include "../include/ir_defs.h" +#include "../include/ir_decode.h" +#include "../include/ir_tv_control.h" -/************************************************************************************************** - * MACROS - **************************************************************************************************/ - - - - - -/************************************************************************************************** - * CONSTANTS - **************************************************************************************************/ - - - - - -/************************************************************************************************** - * LOCAL DATA TYPES - **************************************************************************************************/ struct buffer { @@ -51,28 +28,6 @@ struct buffer } irda_file; - - - -/************************************************************************************************** - * GLOBAL VARIABLES - **************************************************************************************************/ - - - - - -/************************************************************************************************** - * EXTERNAL VARIABLES - **************************************************************************************************/ - - - - - -/************************************************************************************************** - * LOCAL VARIABLES - **************************************************************************************************/ static struct buffer *pbuffer = &irda_file; //static UINT8 *prot_name = NULL; @@ -89,17 +44,7 @@ static UINT8 irda_toggle_bit = FALSE; static UINT8 irda_decode_flag = IRDA_DECODE_1_BIT; static UINT8 cycles_num_size = 0; -/************************************************************************************************** - * LOCAL TABLES - **************************************************************************************************/ - - - - -/************************************************************************************************** - * LOCAL FUNCTION PROTOTYPES - **************************************************************************************************/ static BOOL get_irda_protocol(UINT8 encode_type); static BOOL get_irda_keymap(void); static void print_irda_time(irda_data_t *data, UINT8 keyindex, UINT16 *irda_time); @@ -107,9 +52,7 @@ static void process_decode_number(UINT8 keycode, irda_data_t *data, UINT8 valid_ static void convert_to_irda_time(UINT8 value, UINT16 *irda_time); static void replace_with(irda_cycles_t *pcycles_num, UINT16 *irda_time); -/************************************************************************************************** - * GLOBAL FUNCTIONS - **************************************************************************************************/ + INT8 tv_lib_open(UINT8 *binary, UINT16 binary_length) { // load binary to buffer @@ -150,9 +93,7 @@ UINT16 tv_lib_control(UINT8 key, UINT16 *user_data) return time_index; } -/************************************************************************************************** - * LOCAL FUNCTIONS - **************************************************************************************************/ + static BOOL get_irda_protocol(UINT8 encode_type) { UINT8 i = 0; diff --git a/src/ir_decoder/irda_utils.c b/src/ir_decoder/src/ir_utils.c similarity index 98% rename from src/ir_decoder/irda_utils.c rename to src/ir_decoder/src/ir_utils.c index 0e8eaf1..15400cf 100644 --- a/src/ir_decoder/irda_utils.c +++ b/src/ir_decoder/src/ir_utils.c @@ -13,7 +13,7 @@ Revision log: #include "stdafx.h" #endif -#include "include/irda_utils.h" +#include "../include/ir_utils.h" UINT8 char_to_hex(char chr) {