|
|
|
@ -32,7 +32,7 @@ |
|
|
|
#include "app_ble.h" |
|
|
|
|
|
|
|
/* USER CODE BEGIN Includes */ |
|
|
|
|
|
|
|
#include "commands.h" |
|
|
|
/* USER CODE END Includes */ |
|
|
|
|
|
|
|
/* Private typedef -----------------------------------------------------------*/ |
|
|
|
@ -106,7 +106,28 @@ typedef struct |
|
|
|
}P2P_ClientContext_t; |
|
|
|
|
|
|
|
/* USER CODE BEGIN PTD */ |
|
|
|
typedef struct{ |
|
|
|
uint8_t Device_Led_Selection; |
|
|
|
uint8_t Led1; |
|
|
|
}P2P_LedCharValue_t; |
|
|
|
|
|
|
|
typedef struct{ |
|
|
|
uint8_t Device_Button_Selection; |
|
|
|
uint8_t Button1; |
|
|
|
}P2P_ButtonCharValue_t; |
|
|
|
|
|
|
|
typedef struct |
|
|
|
{ |
|
|
|
|
|
|
|
uint8_t Notification_Status; /* used to chek if P2P Server is enabled to Notify */ |
|
|
|
|
|
|
|
P2P_LedCharValue_t LedControl; |
|
|
|
P2P_ButtonCharValue_t ButtonStatus; |
|
|
|
|
|
|
|
uint16_t ConnectionHandle; |
|
|
|
|
|
|
|
|
|
|
|
} P2P_Client_App_Context_t; |
|
|
|
/* USER CODE END PTD */ |
|
|
|
|
|
|
|
/* Private defines ------------------------------------------------------------*/ |
|
|
|
@ -133,14 +154,16 @@ PLACE_IN_SECTION("BLE_APP_CONTEXT") static P2P_ClientContext_t aP2PClientContext |
|
|
|
* END of Section BLE_APP_CONTEXT |
|
|
|
*/ |
|
|
|
/* USER CODE BEGIN PV */ |
|
|
|
|
|
|
|
PLACE_IN_SECTION("BLE_APP_CONTEXT") static P2P_Client_App_Context_t P2P_Client_App_Context; |
|
|
|
/* USER CODE END PV */ |
|
|
|
|
|
|
|
/* Private function prototypes -----------------------------------------------*/ |
|
|
|
static void Gatt_Notification(P2P_Client_App_Notification_evt_t *pNotification); |
|
|
|
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 Update_Service( void ); |
|
|
|
/* USER CODE END PFP */ |
|
|
|
|
|
|
|
/* Functions Definition ------------------------------------------------------*/ |
|
|
|
@ -153,7 +176,20 @@ void P2PC_APP_Init(void) |
|
|
|
{ |
|
|
|
uint8_t index =0; |
|
|
|
/* USER CODE BEGIN P2PC_APP_Init_1 */ |
|
|
|
log_debug("P2PC_APP_Init", "enter", 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 ); |
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize LedButton Service |
|
|
|
*/ |
|
|
|
P2P_Client_App_Context.Notification_Status=0; |
|
|
|
P2P_Client_App_Context.ConnectionHandle = 0x00; |
|
|
|
|
|
|
|
P2P_Client_App_Context.LedControl.Device_Led_Selection=0x00;/* device Led */ |
|
|
|
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; |
|
|
|
/* USER CODE END P2PC_APP_Init_1 */ |
|
|
|
for(index = 0; index < BLE_CFG_CLT_MAX_NBR_CB; index++) |
|
|
|
{ |
|
|
|
@ -178,7 +214,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); |
|
|
|
/* USER CODE END P2PC_APP_Notification_1 */ |
|
|
|
switch(pNotification->P2P_Evt_Opcode) |
|
|
|
{ |
|
|
|
@ -188,13 +224,26 @@ void P2PC_APP_Notification(P2PC_APP_ConnHandle_Not_evt_t *pNotification) |
|
|
|
|
|
|
|
case PEER_CONN_HANDLE_EVT : |
|
|
|
/* USER CODE BEGIN PEER_CONN_HANDLE_EVT */ |
|
|
|
|
|
|
|
P2P_Client_App_Context.ConnectionHandle = pNotification->ConnectionHandle; |
|
|
|
/* USER CODE END PEER_CONN_HANDLE_EVT */ |
|
|
|
break; |
|
|
|
|
|
|
|
case PEER_DISCON_HANDLE_EVT : |
|
|
|
/* USER CODE BEGIN PEER_DISCON_HANDLE_EVT */ |
|
|
|
|
|
|
|
{ |
|
|
|
uint8_t index = 0; |
|
|
|
P2P_Client_App_Context.ConnectionHandle = 0x00; |
|
|
|
while((index < BLE_CFG_CLT_MAX_NBR_CB) && |
|
|
|
(aP2PClientContext[index].state != APP_BLE_IDLE)) |
|
|
|
{ |
|
|
|
aP2PClientContext[index].state = APP_BLE_IDLE; |
|
|
|
} |
|
|
|
// BSP_LED_Off(LED_BLUE);
|
|
|
|
|
|
|
|
#if OOB_DEMO == 0 |
|
|
|
UTIL_SEQ_SetTask(1<<CFG_TASK_CONN_DEV_1_ID, CFG_SCH_PRIO_0); |
|
|
|
#endif |
|
|
|
} |
|
|
|
/* USER CODE END PEER_DISCON_HANDLE_EVT */ |
|
|
|
break; |
|
|
|
|
|
|
|
@ -210,7 +259,10 @@ void P2PC_APP_Notification(P2PC_APP_ConnHandle_Not_evt_t *pNotification) |
|
|
|
return; |
|
|
|
} |
|
|
|
/* USER CODE BEGIN FD */ |
|
|
|
|
|
|
|
void P2PC_APP_SW1_Button_Action(void) |
|
|
|
{ |
|
|
|
UTIL_SEQ_SetTask(1<<CFG_TASK_SW1_BUTTON_PUSHED_ID, CFG_SCH_PRIO_0); |
|
|
|
} |
|
|
|
/* USER CODE END FD */ |
|
|
|
|
|
|
|
/*************************************************************
|
|
|
|
@ -230,6 +282,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); |
|
|
|
P2P_Client_App_Notification_evt_t Notification; |
|
|
|
|
|
|
|
return_value = SVCCTL_EvtNotAck; |
|
|
|
@ -514,6 +567,7 @@ static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) |
|
|
|
void Gatt_Notification(P2P_Client_App_Notification_evt_t *pNotification) |
|
|
|
{ |
|
|
|
/* USER CODE BEGIN Gatt_Notification_1*/ |
|
|
|
log_debug("Gatt_Notification", "enter", 0); |
|
|
|
|
|
|
|
/* USER CODE END Gatt_Notification_1 */ |
|
|
|
switch(pNotification->P2P_Client_Evt_Opcode) |
|
|
|
@ -524,7 +578,28 @@ void Gatt_Notification(P2P_Client_App_Notification_evt_t *pNotification) |
|
|
|
|
|
|
|
case P2P_NOTIFICATION_INFO_RECEIVED_EVT: |
|
|
|
/* USER CODE BEGIN P2P_NOTIFICATION_INFO_RECEIVED_EVT */ |
|
|
|
{ |
|
|
|
P2P_Client_App_Context.LedControl.Device_Led_Selection=pNotification->DataTransfered.pPayload[0]; |
|
|
|
switch(P2P_Client_App_Context.LedControl.Device_Led_Selection) { |
|
|
|
|
|
|
|
case 0x01 : { |
|
|
|
|
|
|
|
P2P_Client_App_Context.LedControl.Led1=pNotification->DataTransfered.pPayload[1]; |
|
|
|
|
|
|
|
if(P2P_Client_App_Context.LedControl.Led1==0x00){ |
|
|
|
// BSP_LED_Off(LED_BLUE);
|
|
|
|
log_debug("Gatt_Notification", " -- P2P APPLICATION CLIENT : NOTIFICATION RECEIVED - LED OFF ", 0); |
|
|
|
} else { |
|
|
|
log_debug("Gatt_Notification", " -- P2P APPLICATION CLIENT : NOTIFICATION RECEIVED - LED ON", 0); |
|
|
|
// BSP_LED_On(LED_BLUE);
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
default : break; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
/* USER CODE END P2P_NOTIFICATION_INFO_RECEIVED_EVT */ |
|
|
|
break; |
|
|
|
|
|
|
|
@ -544,7 +619,124 @@ uint8_t P2P_Client_APP_Get_State( void ) { |
|
|
|
return aP2PClientContext[0].state; |
|
|
|
} |
|
|
|
/* USER CODE BEGIN LF */ |
|
|
|
/**
|
|
|
|
* @brief Feature Characteristic update |
|
|
|
* @param pFeatureValue: The address of the new value to be written |
|
|
|
* @retval None |
|
|
|
*/ |
|
|
|
tBleStatus Write_Char(uint16_t UUID, uint8_t Service_Instance, uint8_t *pPayload) |
|
|
|
{ |
|
|
|
|
|
|
|
tBleStatus ret = BLE_STATUS_INVALID_PARAMS; |
|
|
|
uint8_t index; |
|
|
|
|
|
|
|
index = 0; |
|
|
|
while((index < BLE_CFG_CLT_MAX_NBR_CB) && |
|
|
|
(aP2PClientContext[index].state != APP_BLE_IDLE)) |
|
|
|
{ |
|
|
|
|
|
|
|
switch(UUID) |
|
|
|
{ |
|
|
|
case P2P_WRITE_CHAR_UUID: /* SERVER RX -- so CLIENT TX */ |
|
|
|
ret =aci_gatt_write_without_resp(aP2PClientContext[index].connHandle, |
|
|
|
aP2PClientContext[index].P2PWriteToServerCharHdle, |
|
|
|
2, /* charValueLen */ |
|
|
|
(uint8_t *) pPayload); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
index++; |
|
|
|
} |
|
|
|
|
|
|
|
return ret; |
|
|
|
}/* end Write_Char() */ |
|
|
|
|
|
|
|
void Button_Trigger_Received(void) |
|
|
|
{ |
|
|
|
log_debug("Button_Trigger_Received", "-- P2P APPLICATION CLIENT : BUTTON PUSHED - WRITE TO SERVER ", 0); |
|
|
|
if(P2P_Client_App_Context.ButtonStatus.Button1==0x00){ |
|
|
|
P2P_Client_App_Context.ButtonStatus.Button1=0x01; |
|
|
|
}else { |
|
|
|
P2P_Client_App_Context.ButtonStatus.Button1=0x00; |
|
|
|
} |
|
|
|
|
|
|
|
Write_Char( P2P_WRITE_CHAR_UUID, 0, (uint8_t *)&P2P_Client_App_Context.ButtonStatus); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
void Update_Service() |
|
|
|
{ |
|
|
|
log_debug("Update_Service", "enter", 0); |
|
|
|
uint16_t enable = 0x0001; |
|
|
|
uint16_t disable = 0x0000; |
|
|
|
|
|
|
|
uint8_t index; |
|
|
|
|
|
|
|
index = 0; |
|
|
|
while((index < BLE_CFG_CLT_MAX_NBR_CB) && |
|
|
|
(aP2PClientContext[index].state != APP_BLE_IDLE)) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
switch(aP2PClientContext[index].state) |
|
|
|
{ |
|
|
|
|
|
|
|
case APP_BLE_DISCOVER_SERVICES: |
|
|
|
log_debug("Update_Service", "P2P_DISCOVER_SERVICES", 0); |
|
|
|
break; |
|
|
|
case APP_BLE_DISCOVER_CHARACS: |
|
|
|
log_debug("Update_Service", "* GATT : Discover P2P Characteristics", 0); |
|
|
|
aci_gatt_disc_all_char_of_service(aP2PClientContext[index].connHandle, |
|
|
|
aP2PClientContext[index].P2PServiceHandle, |
|
|
|
aP2PClientContext[index].P2PServiceEndHandle); |
|
|
|
|
|
|
|
break; |
|
|
|
case APP_BLE_DISCOVER_WRITE_DESC: /* Not Used - No decriptor */ |
|
|
|
log_debug("Update_Service", "* GATT : Discover Descriptor of TX - Write Characteritic", 0); |
|
|
|
aci_gatt_disc_all_char_desc(aP2PClientContext[index].connHandle, |
|
|
|
aP2PClientContext[index].P2PWriteToServerCharHdle, |
|
|
|
aP2PClientContext[index].P2PWriteToServerCharHdle+2); |
|
|
|
|
|
|
|
break; |
|
|
|
case APP_BLE_DISCOVER_NOTIFICATION_CHAR_DESC: |
|
|
|
log_debug("Update_Service", "* GATT : Discover Descriptor of Rx - Notification Characteritic", 0); |
|
|
|
aci_gatt_disc_all_char_desc(aP2PClientContext[index].connHandle, |
|
|
|
aP2PClientContext[index].P2PNotificationCharHdle, |
|
|
|
aP2PClientContext[index].P2PNotificationCharHdle+2); |
|
|
|
|
|
|
|
break; |
|
|
|
case APP_BLE_ENABLE_NOTIFICATION_DESC: |
|
|
|
log_debug("Update_Service", "* GATT : Enable Server Notification", 0); |
|
|
|
aci_gatt_write_char_desc(aP2PClientContext[index].connHandle, |
|
|
|
aP2PClientContext[index].P2PNotificationDescHandle, |
|
|
|
2, |
|
|
|
(uint8_t *)&enable); |
|
|
|
|
|
|
|
aP2PClientContext[index].state = APP_BLE_CONNECTED_CLIENT; |
|
|
|
// BSP_LED_Off(LED_RED);
|
|
|
|
|
|
|
|
break; |
|
|
|
case APP_BLE_DISABLE_NOTIFICATION_DESC : |
|
|
|
log_debug("Update_Service", "* GATT : Disable Server Notification", 0); |
|
|
|
aci_gatt_write_char_desc(aP2PClientContext[index].connHandle, |
|
|
|
aP2PClientContext[index].P2PNotificationDescHandle, |
|
|
|
2, |
|
|
|
(uint8_t *)&disable); |
|
|
|
|
|
|
|
aP2PClientContext[index].state = APP_BLE_CONNECTED_CLIENT; |
|
|
|
|
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
index++; |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
/* USER CODE END LF */ |
|
|
|
|
|
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
|
|
|
|