using prefix and suffix to sync on every uart transmit

This commit is contained in:
weiting2
2020-08-12 10:47:33 +08:00
parent 0b5c5d9550
commit 0308969200
3 changed files with 33 additions and 17 deletions
@@ -23,11 +23,13 @@
#define BLE_CHAR3_HANDLE 0x0024 // send instruction
#define BLE_CHAR4_CONFIG_HANDLE 0x0028 // notify enable: 0100=enable; 0000=disable
#define PREAMBLE_32_BIT_M_SEQ1 0xA3 // using preamble here, ensure sync with controller
#define PREAMBLE_32_BIT_M_SEQ2 0x29 // The chosen preamble is a 32-bits M-sequence: 0b1010001100101001 = 0xA329
#define PREAMBLE_16_BIT_M_SEQ1 0xA3 // using preamble here, ensure sync with controller
#define PREAMBLE_16_BIT_M_SEQ2 0x29 // The chosen preamble is a 16-bits M-sequence: 0b1010001100101001 = 0xA329
#define RET_INFO_BUF_SIZE 52
#define CIS_BUFF_PREFIX 4
#define CIS_BUFF_SUFFIX 2
static uint16_t CIS_length = 10;
static char CIS_data[50];
@@ -191,9 +193,9 @@ static void mem_recv_ins(){
// using preamble here, ensure sync with controller
// The chosen preamble is a 32-bits M-sequence: 0b1010001100101001 = 0xA329
if(UART_rxBuf[1] == 0){
uint8_t scan_result[9] = {PREAMBLE_32_BIT_M_SEQ1, PREAMBLE_32_BIT_M_SEQ2, scanRes,
PREAMBLE_32_BIT_M_SEQ1, PREAMBLE_32_BIT_M_SEQ2, scanRes,
PREAMBLE_32_BIT_M_SEQ1, PREAMBLE_32_BIT_M_SEQ2, scanRes};
uint8_t scan_result[9] = {PREAMBLE_16_BIT_M_SEQ1, PREAMBLE_16_BIT_M_SEQ2, scanRes,
PREAMBLE_16_BIT_M_SEQ1, PREAMBLE_16_BIT_M_SEQ2, scanRes,
PREAMBLE_16_BIT_M_SEQ1, PREAMBLE_16_BIT_M_SEQ2, scanRes};
UART_write(uart_handle, scan_result, 9);
}
@@ -233,8 +235,8 @@ static void mem_recv_ins(){
ret_info_buf[index ++] = 0;
ret_info_buf[index ++] = 0;
ret_info_buf[index ++] = 0;
ret_info_buf[index ++] = PREAMBLE_32_BIT_M_SEQ1;
ret_info_buf[index ++] = PREAMBLE_32_BIT_M_SEQ2;
ret_info_buf[index ++] = PREAMBLE_16_BIT_M_SEQ1;
ret_info_buf[index ++] = PREAMBLE_16_BIT_M_SEQ2;
// B_ADDR_LEN = 6
for(int i=0 ; i < B_ADDR_LEN ; i++){
@@ -382,6 +384,9 @@ static void mem_send_ins(uint16_t handle, uint8_t *value){
req.sig = 0;
req.cmd = 0;
status = GATT_WriteCharValue(connHandle, &req, selfEntity);
// uncomment GATT_WriteLongCharValue if we need a long instruction;
// However, there are some error to fix when using GATT_WriteLongCharValue
// status = GATT_WriteLongCharValue(connHandle, &req, selfEntity);
if ( status != SUCCESS )
@@ -399,8 +404,8 @@ static void mem_send_ins(uint16_t handle, uint8_t *value){
if (status == SUCCESS)
{
procedureInProgress = TRUE;
char ACK[4] = {42, 95, 5, 23};
UART_write(uart_handle, ACK, 4);
char ACK[10] = {0,0,PREAMBLE_16_BIT_M_SEQ1, PREAMBLE_16_BIT_M_SEQ2, 42, 95, 5, 23, 0, 0};
UART_write(uart_handle, ACK, 10);
}
}
@@ -427,6 +432,17 @@ static void mem_central_get_cis(uint8_t handle){
}
static void mem_read_data_and_return(){
// CIS_BUFF_PREFIX = {0,0,PREAMBLE_16_BIT_M_SEQ1, PREAMBLE_16_BIT_M_SEQ2}
// CIS_BUFF_SUFFIX = {0,0}
// add prefix and suffix to sync communication
CIS_data[0] = 0;
CIS_data[1] = 0;
CIS_data[2] = PREAMBLE_16_BIT_M_SEQ1;
CIS_data[3] = PREAMBLE_16_BIT_M_SEQ2;
CIS_data[CIS_length++] = 0;
CIS_data[CIS_length++] = 0;
UART_write(uart_handle, CIS_data, CIS_length);
}
@@ -1584,9 +1584,9 @@ static void SimpleBLECentral_processGATTMsg(gattMsgEvent_t *pMsg)
{
// After a successful read, display the read value
// Display_print1(dispHandle, ROW_SIX, 0, "Read rsp: %d", pMsg->msg.readRsp.pValue[0]);
CIS_length = pMsg->msg.readRsp.len;
CIS_length = CIS_BUFF_PREFIX + pMsg->msg.readRsp.len;
for(int i=0 ; i<pMsg->msg.readRsp.len ; i++){
CIS_data[i] = pMsg->msg.readRsp.pValue[i];
CIS_data[CIS_BUFF_PREFIX + i] = pMsg->msg.readRsp.pValue[i];
}
flag_notify(EVT_MEM_RETURN_DATA);
#ifndef BOOSTXL_CC2650MA
@@ -2051,8 +2051,8 @@ static void SimpleBLECentral_processGATTDiscEvent(gattMsgEvent_t *pMsg)
#else
// connect done
selectedMenuItem = MENU_ITEM_READ_WRITE;
uint8_t connect_done[4] = {42, 95, 5, 23};
UART_write(uart_handle, connect_done, 4);
uint8_t connect_done[10] = {0,0,PREAMBLE_16_BIT_M_SEQ1, PREAMBLE_16_BIT_M_SEQ2, 42, 95, 5, 23, 0, 0};
UART_write(uart_handle, connect_done, 10);
#endif
procedureInProgress = FALSE;
}
@@ -4,13 +4,13 @@
#define VERSION_DATE_YEAR 20
#define VERSION_DATE_MONTH 8
#define VERSION_DATE_DAY 11
#define VERSION_DATE_HOUR 11
#define VERSION_DATE_MINUTE 18
#define VERSION_DATE_DAY 12
#define VERSION_DATE_HOUR 10
#define VERSION_DATE_MINUTE 47
// this is NOT the version hash !!
// it's the last version hash
#define VERSION_HASH 8c0dcee65edc72e7f07a6ebc65d5b8ebb15b0226
#define VERSION_HASH 0b5c5d95509394d2fe99931b9e66ed8424a75e1c
#define VERSION_GIT_BRANCH simple_central_ma_pin
#endif