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
|
||||||
|
|||||||
@@ -37,8 +37,6 @@
|
|||||||
contact Texas Instruments Incorporated at www.TI.com.
|
contact Texas Instruments Incorporated at www.TI.com.
|
||||||
**************************************************************************************************/
|
**************************************************************************************************/
|
||||||
|
|
||||||
// 修改---amomcu---------2015.08.31----
|
|
||||||
// 阿莫单片机淘宝店 https://amomcu.taobao.com/
|
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
@@ -55,11 +53,15 @@
|
|||||||
#include "gapbondmgr.h"
|
#include "gapbondmgr.h"
|
||||||
|
|
||||||
#include "simpleGATTprofile.h"
|
#include "simpleGATTprofile.h"
|
||||||
|
#include "simpleBlePeripheral.h"
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* MACROS
|
* MACROS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define USE_CUSTOM_CHARACTERISTIC
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* CONSTANTS
|
* CONSTANTS
|
||||||
*/
|
*/
|
||||||
@@ -199,11 +201,11 @@ static uint8 simpleProfileChar5[SIMPLEPROFILE_CHAR5_LEN] = { 0, 0, 0, 0, 0 };
|
|||||||
static uint8 simpleProfileChar5UserDesp[17] = "Characteristic 5";
|
static uint8 simpleProfileChar5UserDesp[17] = "Characteristic 5";
|
||||||
|
|
||||||
|
|
||||||
// Simple Profile Characteristic 6 Properties 可读,可写, 可通知
|
// Simple Profile Characteristic 6 Properties
|
||||||
static uint8 simpleProfileChar6Props = GATT_PROP_READ | GATT_PROP_WRITE_NO_RSP | GATT_PROP_NOTIFY;
|
static uint8 simpleProfileChar6Props = GATT_PROP_READ | GATT_PROP_WRITE_NO_RSP | GATT_PROP_NOTIFY;
|
||||||
|
|
||||||
// Characteristic 6 Value
|
// Characteristic 6 Value
|
||||||
static uint8 simpleProfileChar6[SIMPLEPROFILE_CHAR6_LEN] = {0};// 特征值初始化
|
static uint8 simpleProfileChar6[SIMPLEPROFILE_CHAR6_LEN] = {0};
|
||||||
static uint8 simpleProfileChar6Len = 0;
|
static uint8 simpleProfileChar6Len = 0;
|
||||||
|
|
||||||
// Simple Profile Characteristic 6 Configuration Each client has its own
|
// Simple Profile Characteristic 6 Configuration Each client has its own
|
||||||
@@ -213,7 +215,7 @@ static uint8 simpleProfileChar6Len = 0;
|
|||||||
static gattCharCfg_t *simpleProfileChar6Config;
|
static gattCharCfg_t *simpleProfileChar6Config;
|
||||||
|
|
||||||
// Simple Profile Characteristic 6 User Description
|
// Simple Profile Characteristic 6 User Description
|
||||||
static uint8 simpleProfileChar6UserDesp[17] = "Characteristic 6"; // 特征值描述
|
static uint8 simpleProfileChar6UserDesp[17] = "Characteristic 6";
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* Profile Attributes - Table
|
* Profile Attributes - Table
|
||||||
*/
|
*/
|
||||||
@@ -331,7 +333,7 @@ static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =
|
|||||||
0,
|
0,
|
||||||
simpleProfileChar4UserDesp
|
simpleProfileChar4UserDesp
|
||||||
},
|
},
|
||||||
#if 1
|
#if defined USE_CUSTOM_CHARACTERISTIC
|
||||||
// Characteristic 5 Declaration
|
// Characteristic 5 Declaration
|
||||||
{
|
{
|
||||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||||
@@ -577,8 +579,6 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SIMPLEPROFILE_CHAR6:
|
case SIMPLEPROFILE_CHAR6:
|
||||||
//LCD_WRITE_STRING_VALUE( "SetParameter 6 len=", len, 10, HAL_LCD_LINE_1 );
|
|
||||||
//if ( len == SIMPLEPROFILE_CHAR6_LEN )
|
|
||||||
if ( len <= SIMPLEPROFILE_CHAR6_LEN )
|
if ( len <= SIMPLEPROFILE_CHAR6_LEN )
|
||||||
{
|
{
|
||||||
memcpy( simpleProfileChar6, value, len );
|
memcpy( simpleProfileChar6, value, len );
|
||||||
@@ -726,15 +726,10 @@ static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SIMPLEPROFILE_CHAR6_UUID:
|
case SIMPLEPROFILE_CHAR6_UUID:
|
||||||
//*Len = SIMPLEPROFILE_CHAR6_LEN;
|
|
||||||
//VOID osal_memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR6_LEN );
|
|
||||||
//LCD_WRITE_STRING_VALUE( "ReadAttrCB 6 len=", simpleProfileChar6Len, 10, HAL_LCD_LINE_1 );
|
|
||||||
*pLen = simpleProfileChar6Len;
|
*pLen = simpleProfileChar6Len;
|
||||||
memcpy( pValue, pAttr->pValue, simpleProfileChar6Len );
|
memcpy( pValue, pAttr->pValue, simpleProfileChar6Len );
|
||||||
{
|
{
|
||||||
// 这个变量用于表明上一次写数据到从机已经成功, 可用于判断写数据时的判断, 以确保数据的完整性
|
// Characteristic 6 is likely a customized characteristic
|
||||||
// extern bool simpleBLEChar6DoWrite2;
|
|
||||||
// simpleBLEChar6DoWrite2 = TRUE;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -768,7 +763,7 @@ static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle,
|
|||||||
* @param method - type of write message
|
* @param method - type of write message
|
||||||
*
|
*
|
||||||
* @return SUCCESS, blePending or Failure
|
* @return SUCCESS, blePending or Failure
|
||||||
*/ // 收到主机发送过来的数据
|
*/
|
||||||
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,
|
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,
|
||||||
gattAttribute_t *pAttr,
|
gattAttribute_t *pAttr,
|
||||||
uint8_t *pValue, uint16_t len,
|
uint8_t *pValue, uint16_t len,
|
||||||
@@ -828,8 +823,6 @@ static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,
|
|||||||
case SIMPLEPROFILE_CHAR6_UUID:
|
case SIMPLEPROFILE_CHAR6_UUID:
|
||||||
// Validate the value
|
// Validate the value
|
||||||
// Make sure it's not a blob oper
|
// Make sure it's not a blob oper
|
||||||
//LCD_WRITE_STRING_VALUE( "WriteAttrCB 6 len=", len, 10, HAL_LCD_LINE_1 );
|
|
||||||
//LCD_WRITE_STRING_VALUE( "WriteAttrCB 6 len2=", simpleProfileChar6Len, 10, HAL_LCD_LINE_1 );
|
|
||||||
if ( offset == 0 )
|
if ( offset == 0 )
|
||||||
{
|
{
|
||||||
//if ( len != SIMPLEPROFILE_CHAR6_LEN )
|
//if ( len != SIMPLEPROFILE_CHAR6_LEN )
|
||||||
@@ -846,7 +839,6 @@ static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,
|
|||||||
// Write the value
|
// Write the value
|
||||||
if ( status == SUCCESS )
|
if ( status == SUCCESS )
|
||||||
{
|
{
|
||||||
//VOID osal_memcpy( pAttr->pValue, pValue, SIMPLEPROFILE_CHAR6_LEN );
|
|
||||||
memcpy( pAttr->pValue, pValue, len );
|
memcpy( pAttr->pValue, pValue, len );
|
||||||
simpleProfileChar6Len = len;
|
simpleProfileChar6Len = len;
|
||||||
notifyApp = SIMPLEPROFILE_CHAR6;
|
notifyApp = SIMPLEPROFILE_CHAR6;
|
||||||
|
|||||||
@@ -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,7 +154,14 @@ 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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
if (IR_DECODE_SUCCEEDED == ir_tv_lib_open(dccb.source_code, dccb.source_code_length))
|
if (IR_DECODE_SUCCEEDED == ir_tv_lib_open(dccb.source_code, dccb.source_code_length))
|
||||||
{
|
{
|
||||||
@@ -168,8 +169,15 @@ static void IRext_processState()
|
|||||||
HalLedSet(HAL_LED_1, HAL_LED_MODE_ON);
|
HalLedSet(HAL_LED_1, HAL_LED_MODE_ON);
|
||||||
dccb.ir_state = IR_STATE_OPENED;
|
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 (dccb.ir_type == IR_TYPE_TV)
|
||||||
{
|
{
|
||||||
if (IR_DECODE_SUCCEEDED == ir_tv_lib_parse(0))
|
if (IR_DECODE_SUCCEEDED == ir_tv_lib_parse(0))
|
||||||
{
|
{
|
||||||
@@ -177,14 +185,19 @@ static void IRext_processState()
|
|||||||
HalLedSet(HAL_LED_2, HAL_LED_MODE_ON);
|
HalLedSet(HAL_LED_2, HAL_LED_MODE_ON);
|
||||||
dccb.ir_state = IR_STATE_PARSED;
|
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
|
||||||
}
|
}
|
||||||
@@ -1118,9 +1139,16 @@ static void SimpleBLEPeripheral_processAppMsg(sbpEvt_t *pMsg)
|
|||||||
uint8_t valueToCopy[UART_BUFFER_SIZE] = {0};
|
uint8_t valueToCopy[UART_BUFFER_SIZE] = {0};
|
||||||
uint8 len = queue_read(valueToCopy, UART_BUFFER_SIZE);
|
uint8 len = queue_read(valueToCopy, UART_BUFFER_SIZE);
|
||||||
if(len > 0)
|
if(len > 0)
|
||||||
|
{
|
||||||
|
if (IR_STATE_STANDBY == dccb.ir_state)
|
||||||
|
{
|
||||||
|
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR6, len, valueToCopy);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
IRext_processUartMsg(valueToCopy, len);
|
IRext_processUartMsg(valueToCopy, len);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(queue_total() > 0)
|
if(queue_total() > 0)
|
||||||
{
|
{
|
||||||
// receive next frame
|
// receive next frame
|
||||||
|
|||||||
@@ -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