update 2016-11-07 b1
1. resolved TV and AC decoding process for main function
This commit is contained in:
@@ -9,11 +9,56 @@ Revision log:
|
||||
* 2016-11-05: created by strawmanbobi
|
||||
**************************************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "./include/irda_defs.h"
|
||||
#include "./include/irda_decode.h"
|
||||
#include "./include/irda_main.h"
|
||||
|
||||
#if (defined BOARD_PC) || (defined BOARD_ANDROID)
|
||||
// global variable definition
|
||||
UINT16 binary_length = 0;
|
||||
UINT8 *binary_content = NULL;
|
||||
|
||||
UINT8 decode_as_ac(char *file_name)
|
||||
INT8 irda_ac_file_open(const char* file_name);
|
||||
INT8 irda_tv_file_open(const char* file_name);
|
||||
|
||||
INT8 irda_ac_file_open(const char* file_name)
|
||||
{
|
||||
FILE *stream = fopen(file_name, "rb");
|
||||
if (NULL == stream)
|
||||
{
|
||||
IR_PRINTF("\nfile open failed : %d\n", errno);
|
||||
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");
|
||||
return IR_DECODE_FAILED;
|
||||
}
|
||||
|
||||
fseek(stream, 0, SEEK_SET);
|
||||
fread(binary_content, binary_length, 1, stream);
|
||||
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;
|
||||
}
|
||||
|
||||
UINT8 decode_as_ac(const char* file_name)
|
||||
{
|
||||
// keyboard input
|
||||
int in_char = 0;
|
||||
@@ -40,7 +85,7 @@ UINT8 decode_as_ac(char *file_name)
|
||||
ac_status.acWindDir = AC_SWING_ON;
|
||||
ac_status.acWindSpeed = AC_WS_AUTO;
|
||||
|
||||
if (IR_DECODE_FAILED == irda_ac_lib_open(file_name))
|
||||
if (IR_DECODE_FAILED == irda_ac_file_open(file_name))
|
||||
{
|
||||
irda_ac_lib_close();
|
||||
return IR_DECODE_FAILED;
|
||||
@@ -156,6 +201,43 @@ UINT8 decode_as_ac(char *file_name)
|
||||
|
||||
irda_ac_lib_close();
|
||||
|
||||
// free binary buffer
|
||||
irda_free(binary_content);
|
||||
binary_length = 0;
|
||||
|
||||
return IR_DECODE_SUCCEEDED;
|
||||
}
|
||||
|
||||
INT8 irda_tv_file_open(const char* file_name)
|
||||
{
|
||||
int print_index = 0;
|
||||
FILE *stream = fopen(file_name, "rb");
|
||||
|
||||
IR_PRINTF("file name = %s\n", file_name);
|
||||
|
||||
if (stream == NULL)
|
||||
{
|
||||
IR_PRINTF("\nfile open failed : %d\n", errno);
|
||||
return IR_DECODE_FAILED;
|
||||
}
|
||||
|
||||
fseek(stream, 0, SEEK_END);
|
||||
binary_length = ftell(stream);
|
||||
IR_PRINTF("length of binary = %d\n", binary_length);
|
||||
|
||||
binary_content = (UINT8*) irda_malloc(binary_length);
|
||||
|
||||
fseek(stream, 0, SEEK_SET);
|
||||
fread(binary_content, binary_length, 1, stream);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -166,7 +248,7 @@ UINT8 decode_as_tv(char *file_name, UINT8 irda_hex_encode)
|
||||
int key_code = -1;
|
||||
int count = 0;
|
||||
|
||||
if (IR_DECODE_FAILED == irda_tv_lib_open(file_name))
|
||||
if (IR_DECODE_FAILED == irda_tv_file_open(file_name))
|
||||
{
|
||||
return IR_DECODE_FAILED;
|
||||
}
|
||||
@@ -198,13 +280,13 @@ UINT8 decode_as_tv(char *file_name, UINT8 irda_hex_encode)
|
||||
}
|
||||
} while('Q' != in_char);
|
||||
|
||||
// free binary buffer
|
||||
irda_free(binary_content);
|
||||
binary_length = 0;
|
||||
|
||||
return IR_DECODE_SUCCEEDED;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined BOARD_PC
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char function = '0';
|
||||
@@ -236,6 +318,4 @@ int main(int argc, char *argv[])
|
||||
IR_PRINTF("decode functionality error !\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user