|
|
|
@ -20,6 +20,7 @@ |
|
|
|
|
|
|
|
/* Includes ------------------------------------------------------------------*/ |
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
#include "main.h" |
|
|
|
#include "app_common.h" |
|
|
|
|
|
|
|
@ -33,6 +34,9 @@ |
|
|
|
|
|
|
|
/* USER CODE BEGIN Includes */ |
|
|
|
#include "commands.h" |
|
|
|
#include "cmd_mbx.h" |
|
|
|
#include "ble_cmd_mbx.h" |
|
|
|
#include "usb_cmd_mbx.h" |
|
|
|
/* USER CODE END Includes */ |
|
|
|
|
|
|
|
/* Private typedef -----------------------------------------------------------*/ |
|
|
|
@ -163,6 +167,7 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event); |
|
|
|
/* USER CODE BEGIN PFP */ |
|
|
|
static tBleStatus Write_Char(uint16_t UUID, uint8_t Service_Instance, uint8_t *pPayload); |
|
|
|
static void Button_Trigger_Received( void ); |
|
|
|
static void Send_Command(void); |
|
|
|
static void Update_Service( void ); |
|
|
|
/* USER CODE END PFP */ |
|
|
|
|
|
|
|
@ -176,9 +181,10 @@ void P2PC_APP_Init(void) |
|
|
|
{ |
|
|
|
uint8_t index =0; |
|
|
|
/* USER CODE BEGIN P2PC_APP_Init_1 */ |
|
|
|
log_debug("P2PC_APP_Init", "enter", 0); |
|
|
|
log_debug("P2PC_APP_Init", "start", 0); |
|
|
|
UTIL_SEQ_RegTask( 1<< CFG_TASK_SEARCH_SERVICE_ID, UTIL_SEQ_RFU, Update_Service ); |
|
|
|
UTIL_SEQ_RegTask( 1<< CFG_TASK_SW1_BUTTON_PUSHED_ID, UTIL_SEQ_RFU, Button_Trigger_Received ); |
|
|
|
UTIL_SEQ_RegTask( 1<< CFG_TASK_SEND_COMMAND_ID, UTIL_SEQ_RFU, Send_Command ); |
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize LedButton Service |
|
|
|
@ -190,6 +196,7 @@ void P2PC_APP_Init(void) |
|
|
|
P2P_Client_App_Context.LedControl.Led1=0x00; /* led OFF */ |
|
|
|
P2P_Client_App_Context.ButtonStatus.Device_Button_Selection=0x01;/* Device1 */ |
|
|
|
P2P_Client_App_Context.ButtonStatus.Button1=0x00; |
|
|
|
log_debug("P2PC_APP_Init", "BLE_CFG_CLT_MAX_NBR_CB=%d", 1, BLE_CFG_CLT_MAX_NBR_CB); |
|
|
|
/* USER CODE END P2PC_APP_Init_1 */ |
|
|
|
for(index = 0; index < BLE_CFG_CLT_MAX_NBR_CB; index++) |
|
|
|
{ |
|
|
|
@ -207,6 +214,7 @@ void P2PC_APP_Init(void) |
|
|
|
|
|
|
|
/* USER CODE BEGIN P2PC_APP_Init_2 */ |
|
|
|
|
|
|
|
log_debug("P2PC_APP_Init", "end", 0); |
|
|
|
/* USER CODE END P2PC_APP_Init_2 */ |
|
|
|
return; |
|
|
|
} |
|
|
|
@ -214,7 +222,7 @@ void P2PC_APP_Init(void) |
|
|
|
void P2PC_APP_Notification(P2PC_APP_ConnHandle_Not_evt_t *pNotification) |
|
|
|
{ |
|
|
|
/* USER CODE BEGIN P2PC_APP_Notification_1 */ |
|
|
|
log_debug("P2PC_APP_Notification", "enter", 0); |
|
|
|
log_debug("P2PC_APP_Notification", "start", 0); |
|
|
|
/* USER CODE END P2PC_APP_Notification_1 */ |
|
|
|
switch(pNotification->P2P_Evt_Opcode) |
|
|
|
{ |
|
|
|
@ -224,13 +232,15 @@ void P2PC_APP_Notification(P2PC_APP_ConnHandle_Not_evt_t *pNotification) |
|
|
|
|
|
|
|
case PEER_CONN_HANDLE_EVT : |
|
|
|
/* USER CODE BEGIN PEER_CONN_HANDLE_EVT */ |
|
|
|
log_debug("P2PC_APP_Notification", "PEER_CONN_HANDLE_EVT", 0); |
|
|
|
P2P_Client_App_Context.ConnectionHandle = pNotification->ConnectionHandle; |
|
|
|
/* USER CODE END PEER_CONN_HANDLE_EVT */ |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
case PEER_DISCON_HANDLE_EVT : |
|
|
|
/* USER CODE BEGIN PEER_DISCON_HANDLE_EVT */ |
|
|
|
{ |
|
|
|
log_debug("P2PC_APP_Notification", "PEER_DISCON_HANDLE_EVT", 0); |
|
|
|
uint8_t index = 0; |
|
|
|
P2P_Client_App_Context.ConnectionHandle = 0x00; |
|
|
|
while((index < BLE_CFG_CLT_MAX_NBR_CB) && |
|
|
|
@ -261,6 +271,7 @@ void P2PC_APP_Notification(P2PC_APP_ConnHandle_Not_evt_t *pNotification) |
|
|
|
/* USER CODE BEGIN FD */ |
|
|
|
void P2PC_APP_SW1_Button_Action(void) |
|
|
|
{ |
|
|
|
log_debug("P2PC_APP_SW1_Button_Action", "set task: BLE_CFG_CLT_MAX_NBR_CB", 0); |
|
|
|
UTIL_SEQ_SetTask(1<<CFG_TASK_SW1_BUTTON_PUSHED_ID, CFG_SCH_PRIO_0); |
|
|
|
} |
|
|
|
/* USER CODE END FD */ |
|
|
|
@ -282,7 +293,7 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) |
|
|
|
hci_event_pckt *event_pckt; |
|
|
|
evt_blecore_aci *blecore_evt; |
|
|
|
|
|
|
|
log_debug("Event_Handler", "enter", 0); |
|
|
|
log_debug("Event_Handler", "start", 0); |
|
|
|
P2P_Client_App_Notification_evt_t Notification; |
|
|
|
|
|
|
|
return_value = SVCCTL_EvtNotAck; |
|
|
|
@ -292,12 +303,14 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) |
|
|
|
{ |
|
|
|
case HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE: |
|
|
|
{ |
|
|
|
// log_debug("Event_Handler", "HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE", 0);
|
|
|
|
blecore_evt = (evt_blecore_aci*)event_pckt->data; |
|
|
|
switch(blecore_evt->ecode) |
|
|
|
{ |
|
|
|
|
|
|
|
case ACI_ATT_READ_BY_GROUP_TYPE_RESP_VSEVT_CODE: |
|
|
|
{ |
|
|
|
log_debug("Event_Handler", "blecore_evt->ecode=ACI_ATT_READ_BY_GROUP_TYPE_RESP_VSEVT_CODE", 0); |
|
|
|
aci_att_read_by_group_type_resp_event_rp0 *pr = (void*)blecore_evt->data; |
|
|
|
uint8_t numServ, i, idx; |
|
|
|
uint16_t uuid, handle; |
|
|
|
@ -315,7 +328,7 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) |
|
|
|
if((aP2PClientContext[index].state == APP_BLE_CONNECTED_CLIENT)&& |
|
|
|
(status == APP_BLE_IDLE)) |
|
|
|
{ |
|
|
|
/* Handle deconnected */ |
|
|
|
/* Handle disconnected */ |
|
|
|
|
|
|
|
aP2PClientContext[index].state = APP_BLE_IDLE; |
|
|
|
aP2PClientContext[index].connHandle = 0xFFFF; |
|
|
|
@ -351,16 +364,23 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) |
|
|
|
uuid = UNPACK_2_BYTE_PARAMETER(&pr->Attribute_Data_List[idx]); |
|
|
|
if(uuid == P2P_SERVICE_UUID) |
|
|
|
{ |
|
|
|
log_debug("Event_Handler", "uuid=0x%x", 1, uuid); |
|
|
|
log_debug("Event_Handler", "-- GATT : P2P_SERVICE_UUID FOUND - connection handle=0x%x", 1, aP2PClientContext[index].connHandle); |
|
|
|
#if(CFG_DEBUG_APP_TRACE != 0) |
|
|
|
APP_DBG_MSG("-- GATT : P2P_SERVICE_UUID FOUND - connection handle 0x%x \n", aP2PClientContext[index].connHandle); |
|
|
|
#endif |
|
|
|
#if (UUID_128BIT_FORMAT==1) |
|
|
|
/*
|
|
|
|
| 2 byte | 2 byte | 14 byte | 2 byte | |
|
|
|
| p2p service handle | p2p service end handle | ???? | uuid | |
|
|
|
*/ |
|
|
|
aP2PClientContext[index].P2PServiceHandle = UNPACK_2_BYTE_PARAMETER(&pr->Attribute_Data_List[idx-16]); |
|
|
|
aP2PClientContext[index].P2PServiceEndHandle = UNPACK_2_BYTE_PARAMETER (&pr->Attribute_Data_List[idx-14]); |
|
|
|
#else |
|
|
|
aP2PClientContext[index].P2PServiceHandle = UNPACK_2_BYTE_PARAMETER(&pr->Attribute_Data_List[idx-4]); |
|
|
|
aP2PClientContext[index].P2PServiceEndHandle = UNPACK_2_BYTE_PARAMETER (&pr->Attribute_Data_List[idx-2]); |
|
|
|
#endif |
|
|
|
log_debug("Event_Handler", "aP2PClientContext.state=APP_BLE_DISCOVER_CHARACS", 0); |
|
|
|
aP2PClientContext[index].state = APP_BLE_DISCOVER_CHARACS ; |
|
|
|
} |
|
|
|
idx += 6; |
|
|
|
@ -373,6 +393,7 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) |
|
|
|
case ACI_ATT_READ_BY_TYPE_RESP_VSEVT_CODE: |
|
|
|
{ |
|
|
|
|
|
|
|
log_debug("Event_Handler", "blecore_evt->ecode=ACI_ATT_READ_BY_TYPE_RESP_VSEVT_CODE", 0); |
|
|
|
aci_att_read_by_type_resp_event_rp0 *pr = (void*)blecore_evt->data; |
|
|
|
uint8_t idx; |
|
|
|
uint16_t uuid, handle; |
|
|
|
@ -406,6 +427,7 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) |
|
|
|
pr->Data_Length -= 1; |
|
|
|
while(pr->Data_Length > 0) |
|
|
|
{ |
|
|
|
log_debug("Event_Handler", "uuid=0x%x", 1, uuid); |
|
|
|
uuid = UNPACK_2_BYTE_PARAMETER(&pr->Handle_Value_Pair_Data[idx]); |
|
|
|
/* store the characteristic handle not the attribute handle */ |
|
|
|
#if (UUID_128BIT_FORMAT==1) |
|
|
|
@ -415,6 +437,7 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) |
|
|
|
#endif |
|
|
|
if(uuid == P2P_WRITE_CHAR_UUID) |
|
|
|
{ |
|
|
|
log_debug("Event_Handler", "-- GATT : WRITE_UUID FOUND - connection handle=0x%x", 1, aP2PClientContext[index].connHandle); |
|
|
|
#if(CFG_DEBUG_APP_TRACE != 0) |
|
|
|
APP_DBG_MSG("-- GATT : WRITE_UUID FOUND - connection handle 0x%x\n", aP2PClientContext[index].connHandle); |
|
|
|
#endif |
|
|
|
@ -424,6 +447,7 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) |
|
|
|
|
|
|
|
else if(uuid == P2P_NOTIFY_CHAR_UUID) |
|
|
|
{ |
|
|
|
log_debug("Event_Handler", "-- GATT : NOTIFICATION_CHAR_UUID FOUND - connection handle=0x%x", 1, aP2PClientContext[index].connHandle); |
|
|
|
#if(CFG_DEBUG_APP_TRACE != 0) |
|
|
|
APP_DBG_MSG("-- GATT : NOTIFICATION_CHAR_UUID FOUND - connection handle 0x%x\n", aP2PClientContext[index].connHandle); |
|
|
|
#endif |
|
|
|
@ -445,6 +469,7 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) |
|
|
|
|
|
|
|
case ACI_ATT_FIND_INFO_RESP_VSEVT_CODE: |
|
|
|
{ |
|
|
|
log_debug("Event_Handler", "blecore_evt->ecode=ACI_ATT_FIND_INFO_RESP_VSEVT_CODE", 0); |
|
|
|
aci_att_find_info_resp_event_rp0 *pr = (void*)blecore_evt->data; |
|
|
|
|
|
|
|
uint8_t numDesc, idx, i; |
|
|
|
@ -479,6 +504,7 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) |
|
|
|
|
|
|
|
if(uuid == CLIENT_CHAR_CONFIG_DESCRIPTOR_UUID) |
|
|
|
{ |
|
|
|
log_debug("Event_Handler", "-- GATT : CLIENT_CHAR_CONFIG_DESCRIPTOR_UUID FOUND - connection handle=0x%x", 1, aP2PClientContext[index].connHandle); |
|
|
|
#if(CFG_DEBUG_APP_TRACE != 0) |
|
|
|
APP_DBG_MSG("-- GATT : CLIENT_CHAR_CONFIG_DESCRIPTOR_UUID- connection handle 0x%x\n", aP2PClientContext[index].connHandle); |
|
|
|
#endif |
|
|
|
@ -499,6 +525,7 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) |
|
|
|
|
|
|
|
case ACI_GATT_NOTIFICATION_VSEVT_CODE: |
|
|
|
{ |
|
|
|
log_debug("Event_Handler", "blecore_evt->ecode=ACI_GATT_NOTIFICATION_VSEVT_CODE", 0); |
|
|
|
aci_gatt_notification_event_rp0 *pr = (void*)blecore_evt->data; |
|
|
|
uint8_t index; |
|
|
|
|
|
|
|
@ -509,6 +536,17 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) |
|
|
|
|
|
|
|
if(index < BLE_CFG_CLT_MAX_NBR_CB) |
|
|
|
{ |
|
|
|
#ifdef DEBUG_COMMADS |
|
|
|
uint8_t buffer[512]; |
|
|
|
buffer[0] = (uint8_t)('0'); |
|
|
|
buffer[1] = (uint8_t)('x'); |
|
|
|
uint8_t i; |
|
|
|
for (i = 0; i<pr->Attribute_Value_Length; i++) { |
|
|
|
snprintf((char*)(buffer + i + 2), 512-i-2, "%x", pr->Attribute_Value[i]); |
|
|
|
} |
|
|
|
buffer[i + 3] = (uint8_t)('\0'); |
|
|
|
log_debug("Event_Handler", "Notification payload: %s", 1, buffer); |
|
|
|
#endif /* DEBUG_COMMADS */ |
|
|
|
|
|
|
|
if ( (pr->Attribute_Handle == aP2PClientContext[index].P2PNotificationCharHdle) && |
|
|
|
(pr->Attribute_Value_Length == (2)) ) |
|
|
|
@ -522,6 +560,11 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) |
|
|
|
|
|
|
|
/* INFORM APPLICATION BUTTON IS PUSHED BY END DEVICE */ |
|
|
|
|
|
|
|
} else { |
|
|
|
push_usb_command( |
|
|
|
&pr->Attribute_Value, |
|
|
|
pr->Attribute_Value_Length |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -529,6 +572,7 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) |
|
|
|
|
|
|
|
case ACI_GATT_PROC_COMPLETE_VSEVT_CODE: |
|
|
|
{ |
|
|
|
log_debug("Event_Handler", "blecore_evt->ecode=ACI_GATT_PROC_COMPLETE_VSEVT_CODE", 0); |
|
|
|
aci_gatt_proc_complete_event_rp0 *pr = (void*)blecore_evt->data; |
|
|
|
#if(CFG_DEBUG_APP_TRACE != 0) |
|
|
|
APP_DBG_MSG("-- GATT : ACI_GATT_PROC_COMPLETE_VSEVT_CODE \n"); |
|
|
|
@ -561,6 +605,7 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
log_debug("Event_Handler", "end", 0); |
|
|
|
return(return_value); |
|
|
|
}/* end BLE_CTRL_Event_Acknowledged_Status_t */ |
|
|
|
|
|
|
|
@ -568,6 +613,8 @@ void Gatt_Notification(P2P_Client_App_Notification_evt_t *pNotification) |
|
|
|
{ |
|
|
|
/* USER CODE BEGIN Gatt_Notification_1*/ |
|
|
|
log_debug("Gatt_Notification", "enter", 0); |
|
|
|
log_debug("Gatt_Notification", "pNotification->P2P_Client_Evt_Opcode=0x%x", 1, pNotification->P2P_Client_Evt_Opcode); |
|
|
|
|
|
|
|
|
|
|
|
/* USER CODE END Gatt_Notification_1 */ |
|
|
|
switch(pNotification->P2P_Client_Evt_Opcode) |
|
|
|
@ -580,6 +627,8 @@ void Gatt_Notification(P2P_Client_App_Notification_evt_t *pNotification) |
|
|
|
/* USER CODE BEGIN P2P_NOTIFICATION_INFO_RECEIVED_EVT */ |
|
|
|
{ |
|
|
|
P2P_Client_App_Context.LedControl.Device_Led_Selection=pNotification->DataTransfered.pPayload[0]; |
|
|
|
log_debug("Gatt_Notification", "DataTransfered.pPayload[0]=0x%x", 1, pNotification->DataTransfered.pPayload[0]); |
|
|
|
log_debug("Gatt_Notification", "DataTransfered.pPayload[1]=0x%x", 1, pNotification->DataTransfered.pPayload[1]); |
|
|
|
switch(P2P_Client_App_Context.LedControl.Device_Led_Selection) { |
|
|
|
|
|
|
|
case 0x01 : { |
|
|
|
@ -669,6 +718,37 @@ void Button_Trigger_Received(void) |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
void Send_Command(void) |
|
|
|
{ |
|
|
|
#ifdef DEBUG_COMMADS |
|
|
|
log_debug("Send_Command", "SEND COMMAND TO SERVER ", 0); |
|
|
|
#endif /* DEBUG_COMMADS */ |
|
|
|
|
|
|
|
if (!get_number_of_ble_commands_in_mailbox()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
raw_command_t command = pop_ble_command(); |
|
|
|
|
|
|
|
tBleStatus ret = BLE_STATUS_INVALID_PARAMS; |
|
|
|
uint8_t index = 0; |
|
|
|
|
|
|
|
if (aP2PClientContext[index].state != APP_BLE_IDLE) |
|
|
|
{ |
|
|
|
ret = aci_gatt_write_without_resp( |
|
|
|
aP2PClientContext[index].connHandle, |
|
|
|
aP2PClientContext[index].P2PWriteToServerCharHdle, |
|
|
|
command.size, /* charValueLen */ |
|
|
|
command.payload); |
|
|
|
} |
|
|
|
|
|
|
|
if (ret) { |
|
|
|
log_error("Send_Command", "aci_gatt_write_without_resp() returned %d", 1, ret); |
|
|
|
} |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
void Update_Service() |
|
|
|
{ |
|
|
|
log_debug("Update_Service", "enter", 0); |
|
|
|
|