completed TV binary transfer and decode
This commit is contained in:
@@ -62,7 +62,7 @@ extern void PrintString(uint8 *str);
|
|||||||
|
|
||||||
extern void PrintValue(char *title, uint32 value, uint8 format);
|
extern void PrintValue(char *title, uint32 value, uint8 format);
|
||||||
|
|
||||||
extern void WriteBytes(uint8 *str);
|
extern void WriteBytes(uint8 *data, uint16_t len);
|
||||||
|
|
||||||
extern void WriteValue(char *title, uint32 value, uint8 format);
|
extern void WriteValue(char *title, uint32 value, uint8 format);
|
||||||
|
|
||||||
|
|||||||
@@ -154,9 +154,9 @@ void PrintValue(char *content, uint32 value, uint8 format)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WriteBytes(uint8 *str)
|
void WriteBytes(uint8 *data, uint16_t len)
|
||||||
{
|
{
|
||||||
UART_WriteTransport(str, (strlen((char*)str)));
|
UART_WriteTransport(data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteValue(char *content, uint32 value, uint8 format)
|
void WriteValue(char *content, uint32 value, uint8 format)
|
||||||
@@ -169,7 +169,7 @@ void WriteValue(char *content, uint32 value, uint8 format)
|
|||||||
memcpy(buf, content, tmpLen);
|
memcpy(buf, content, tmpLen);
|
||||||
err = (uint32)(value);
|
err = (uint32)(value);
|
||||||
_ltoa(err, &buf[tmpLen], format);
|
_ltoa(err, &buf[tmpLen], format);
|
||||||
WriteBytes(buf);
|
WriteBytes(buf, strlen(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SEND_BUF_MAX_SIZE 320
|
#define SEND_BUF_MAX_SIZE 256
|
||||||
|
|
||||||
extern bool queue_write(uint8 *WrBuf, unsigned short WrLen);
|
extern bool queue_write(uint8 *WrBuf, unsigned short WrLen);
|
||||||
|
|
||||||
|
|||||||
@@ -135,17 +135,11 @@ static transfer_control_block btcb =
|
|||||||
static decode_control_block dccb =
|
static decode_control_block dccb =
|
||||||
{
|
{
|
||||||
.ir_type = IR_TYPE_NONE,
|
.ir_type = IR_TYPE_NONE,
|
||||||
.ir_state = IR_STATE_NONE,
|
.ir_state = IR_STATE_STANDBY,
|
||||||
.source_code_length = 0,
|
.source_code_length = 0,
|
||||||
.decoded_length = 0,
|
.decoded_length = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* source code holder */
|
|
||||||
static uint8_t binary_source[BINARY_SOURCE_SIZE_MAX] =
|
|
||||||
{
|
|
||||||
0x00,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// local function prototypes
|
// local function prototypes
|
||||||
static void IRext_uartDebug();
|
static void IRext_uartDebug();
|
||||||
@@ -160,31 +154,50 @@ static void ParseCommand(uint8_t* data, uint16_t len);
|
|||||||
// IR operation
|
// IR operation
|
||||||
static void IRext_processState()
|
static void IRext_processState()
|
||||||
{
|
{
|
||||||
if (IR_STATE_NONE == dccb.ir_state)
|
if (IR_STATE_STANDBY == dccb.ir_state)
|
||||||
{
|
{
|
||||||
if (IR_DECODE_SUCCEEDED == ir_tv_lib_open(dccb.source_code, dccb.source_code_length))
|
dccb.ir_state = IR_STATE_NONE;
|
||||||
|
LCD_WRITE_STRING("IR READY", LCD_PAGE7);
|
||||||
|
}
|
||||||
|
else if (IR_STATE_READY == dccb.ir_state)
|
||||||
|
{
|
||||||
|
if (dccb.ir_type == IR_TYPE_TV)
|
||||||
{
|
{
|
||||||
LCD_WRITE_STRING("IR OPENED", LCD_PAGE7);
|
if (IR_DECODE_SUCCEEDED == ir_tv_lib_open(dccb.source_code, dccb.source_code_length))
|
||||||
HalLedSet(HAL_LED_1, HAL_LED_MODE_ON);
|
{
|
||||||
dccb.ir_state = IR_STATE_OPENED;
|
LCD_WRITE_STRING("IR OPENED", LCD_PAGE7);
|
||||||
|
HalLedSet(HAL_LED_1, HAL_LED_MODE_ON);
|
||||||
|
dccb.ir_state = IR_STATE_OPENED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LCD_WRITE_STRING("OPEN ERROR", LCD_PAGE7);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (IR_STATE_OPENED == dccb.ir_state)
|
else if (IR_STATE_OPENED == dccb.ir_state)
|
||||||
{
|
{
|
||||||
if (IR_DECODE_SUCCEEDED == ir_tv_lib_parse(0))
|
if (dccb.ir_type == IR_TYPE_TV)
|
||||||
{
|
{
|
||||||
LCD_WRITE_STRING("IR PARSED", LCD_PAGE7);
|
if (IR_DECODE_SUCCEEDED == ir_tv_lib_parse(0))
|
||||||
HalLedSet(HAL_LED_2, HAL_LED_MODE_ON);
|
{
|
||||||
dccb.ir_state = IR_STATE_PARSED;
|
LCD_WRITE_STRING("IR PARSED", LCD_PAGE7);
|
||||||
|
HalLedSet(HAL_LED_2, HAL_LED_MODE_ON);
|
||||||
|
dccb.ir_state = IR_STATE_PARSED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LCD_WRITE_STRING("PARSE ERROR", LCD_PAGE7);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (IR_STATE_PARSED == dccb.ir_state)
|
else if (IR_STATE_PARSED == dccb.ir_state)
|
||||||
{
|
{
|
||||||
if (IR_DECODE_SUCCEEDED == ir_tv_lib_close())
|
if (IR_DECODE_SUCCEEDED == ir_tv_lib_close())
|
||||||
{
|
{
|
||||||
LCD_WRITE_STRING("IR NONE", LCD_PAGE7);
|
LCD_WRITE_STRING("IR READY", LCD_PAGE7);
|
||||||
HalLedSet(HAL_LED_1 | HAL_LED_2, HAL_LED_MODE_OFF);
|
HalLedSet(HAL_LED_1 | HAL_LED_2, HAL_LED_MODE_OFF);
|
||||||
dccb.ir_state = IR_STATE_NONE;
|
dccb.ir_state = IR_STATE_READY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -214,10 +227,9 @@ static void IRext_processKey(uint8_t ir_type, uint8_t ir_key, char* key_display)
|
|||||||
// UART operation
|
// UART operation
|
||||||
static void IRext_uartDebug()
|
static void IRext_uartDebug()
|
||||||
{
|
{
|
||||||
#if defined UART_DEBUG
|
|
||||||
uint16_t index = 0;
|
uint16_t index = 0;
|
||||||
|
|
||||||
if (user_data_length > 0)
|
if (dccb.source_code_length > 0)
|
||||||
{
|
{
|
||||||
// output to UART
|
// output to UART
|
||||||
char debug[16] = { 0 };
|
char debug[16] = { 0 };
|
||||||
@@ -230,7 +242,6 @@ static void IRext_uartDebug()
|
|||||||
}
|
}
|
||||||
UART_WriteTransport((uint8_t*)"\n", 1);
|
UART_WriteTransport((uint8_t*)"\n", 1);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void IRext_processUartMsg(uint8_t* data, uint16_t len)
|
static void IRext_processUartMsg(uint8_t* data, uint16_t len)
|
||||||
@@ -256,15 +267,16 @@ static void IRext_processUartMsg(uint8_t* data, uint16_t len)
|
|||||||
|
|
||||||
if (HEADER_SR == header)
|
if (HEADER_SR == header)
|
||||||
{
|
{
|
||||||
|
// since there is 1 more byte for eos
|
||||||
ParseSummary(&data[1], len - 2);
|
ParseSummary(&data[1], len - 2);
|
||||||
}
|
}
|
||||||
else if (HEADER_BT == header)
|
else if (HEADER_BT == header)
|
||||||
{
|
{
|
||||||
ParseBinary(&data[1], len - 2);
|
ParseBinary(&data[1], len - 1);
|
||||||
}
|
}
|
||||||
else if (HEADER_CMD == header)
|
else if (HEADER_CMD == header)
|
||||||
{
|
{
|
||||||
ParseCommand(&data[1], len - 2);
|
ParseCommand(&data[1], len - 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -286,6 +298,8 @@ static void ParseSummary(uint8_t* data, uint16_t len)
|
|||||||
// 4 bytes length in ASCII format value = n
|
// 4 bytes length in ASCII format value = n
|
||||||
memcpy(cat_char, &data[0], CATEGORY_LENGTH_SIZE);
|
memcpy(cat_char, &data[0], CATEGORY_LENGTH_SIZE);
|
||||||
dccb.ir_type = (ir_type_t)atoi(cat_char);
|
dccb.ir_type = (ir_type_t)atoi(cat_char);
|
||||||
|
dccb.source_code_length = 0;
|
||||||
|
memset(dccb.source_code, 0x00, BINARY_SOURCE_SIZE_MAX);
|
||||||
|
|
||||||
memcpy(len_char, &data[1], BINARY_LENGTH_SIZE);
|
memcpy(len_char, &data[1], BINARY_LENGTH_SIZE);
|
||||||
btcb.binary_recv_expected_length = atoi(len_char);
|
btcb.binary_recv_expected_length = atoi(len_char);
|
||||||
@@ -304,7 +318,7 @@ static void ParseSummary(uint8_t* data, uint16_t len)
|
|||||||
static void ParseBinary(uint8_t* data, uint16_t len)
|
static void ParseBinary(uint8_t* data, uint16_t len)
|
||||||
{
|
{
|
||||||
// n bytes payload fragment
|
// n bytes payload fragment
|
||||||
memcpy(&binary_source[btcb.binary_recv_length],
|
memcpy(&dccb.source_code[btcb.binary_recv_length],
|
||||||
data,
|
data,
|
||||||
len);
|
len);
|
||||||
btcb.binary_recv_length += len;
|
btcb.binary_recv_length += len;
|
||||||
@@ -312,6 +326,7 @@ static void ParseBinary(uint8_t* data, uint16_t len)
|
|||||||
{
|
{
|
||||||
// finish binary transfer
|
// finish binary transfer
|
||||||
dccb.source_code_length = btcb.binary_recv_length;
|
dccb.source_code_length = btcb.binary_recv_length;
|
||||||
|
dccb.ir_state = IR_STATE_READY;
|
||||||
btcb.transfer_on_going = 0;
|
btcb.transfer_on_going = 0;
|
||||||
}
|
}
|
||||||
// feed back next expected offset in any cases
|
// feed back next expected offset in any cases
|
||||||
@@ -323,6 +338,12 @@ static void ParseCommand(uint8_t* data, uint16_t len)
|
|||||||
// TODO:
|
// TODO:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TransportDataToUart(uint8_t* data, uint16_t len)
|
||||||
|
{
|
||||||
|
UART_WriteTransport(data, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* IREXT - end */
|
/* IREXT - end */
|
||||||
|
|
||||||
|
|
||||||
@@ -736,7 +757,7 @@ static void SimpleBLEPeripheral_init(void)
|
|||||||
#endif // HAL_IMAGE_A
|
#endif // HAL_IMAGE_A
|
||||||
#else
|
#else
|
||||||
LCD_WRITE_STRING("IRext sample", LCD_PAGE0);
|
LCD_WRITE_STRING("IRext sample", LCD_PAGE0);
|
||||||
LCD_WRITE_STRING("IR NONE", LCD_PAGE7);
|
LCD_WRITE_STRING("STANDBY", LCD_PAGE7);
|
||||||
HalLedSet(HAL_LED_1, HAL_LED_MODE_OFF);
|
HalLedSet(HAL_LED_1, HAL_LED_MODE_OFF);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -1119,7 +1140,14 @@ static void SimpleBLEPeripheral_processAppMsg(sbpEvt_t *pMsg)
|
|||||||
uint8 len = queue_read(valueToCopy, UART_BUFFER_SIZE);
|
uint8 len = queue_read(valueToCopy, UART_BUFFER_SIZE);
|
||||||
if(len > 0)
|
if(len > 0)
|
||||||
{
|
{
|
||||||
IRext_processUartMsg(valueToCopy, len);
|
if (IR_STATE_STANDBY == dccb.ir_state)
|
||||||
|
{
|
||||||
|
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR6, len, valueToCopy);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IRext_processUartMsg(valueToCopy, len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(queue_total() > 0)
|
if(queue_total() > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -64,7 +64,9 @@ typedef enum
|
|||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
IR_STATE_NONE = 0,
|
IR_STATE_STANDBY = 0,
|
||||||
|
IR_STATE_NONE,
|
||||||
|
IR_STATE_READY,
|
||||||
IR_STATE_OPENED,
|
IR_STATE_OPENED,
|
||||||
IR_STATE_PARSED,
|
IR_STATE_PARSED,
|
||||||
IR_STATE_MAX
|
IR_STATE_MAX
|
||||||
@@ -94,6 +96,8 @@ typedef struct
|
|||||||
* FUNCTIONS
|
* FUNCTIONS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
extern void TransportDataToUart(uint8_t* data, uint16_t len);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Task creation function for the Simple BLE Peripheral.
|
* Task creation function for the Simple BLE Peripheral.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user