diff options
Diffstat (limited to 'Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_MultiAppAt/STM32_WPAN/App/p2p_client_app.c')
-rw-r--r-- | Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_MultiAppAt/STM32_WPAN/App/p2p_client_app.c | 806 |
1 files changed, 806 insertions, 0 deletions
diff --git a/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_MultiAppAt/STM32_WPAN/App/p2p_client_app.c b/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_MultiAppAt/STM32_WPAN/App/p2p_client_app.c new file mode 100644 index 000000000..6648246d6 --- /dev/null +++ b/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_MultiAppAt/STM32_WPAN/App/p2p_client_app.c @@ -0,0 +1,806 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file p2p_server_app.c + * @author MCD Application Team + * @brief peer to peer Server Application + ****************************************************************************** + * @attention + * + * <h2><center>© Copyright (c) 2019 STMicroelectronics. + * All rights reserved.</center></h2> + * + * This software component is licensed by ST under Ultimate Liberty license + * SLA0044, the "License"; You may not use this file except in compliance with + * the License. You may obtain a copy of the License at: + * www.st.com/SLA0044 + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ + +#include "main.h" +#include "app_common.h" + +#include "dbg_trace.h" + +#include "ble.h" +#include "p2p_client_app.h" + +#include "stm32_seq.h" +#include "app_ble_cl.h" +#include "uart_app.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern APP_Mode_t Next_Mode; + +extern uint8_t WriteCharData[2]; + +/* Private typedef -----------------------------------------------------------*/ + +typedef enum +{ + P2P_START_TIMER_EVT, + P2P_STOP_TIMER_EVT, + P2P_NOTIFICATION_INFO_RECEIVED_EVT, +} P2P_Client_Opcode_Notification_evt_t; + +typedef struct +{ + uint8_t * pPayload; + uint8_t Length; +}P2P_Client_Data_t; + +typedef struct +{ + P2P_Client_Opcode_Notification_evt_t P2P_Client_Evt_Opcode; + P2P_Client_Data_t DataTransfered; +}P2P_Client_App_Notification_evt_t; + +typedef struct +{ + /** + * state of the P2P Client + * state machine + */ + APP_BLE_ConnStatus_t state; + + /** + * connection handle + */ + uint16_t connHandle; + + /** + * handle of the P2P service + */ + uint16_t P2PServiceHandle; + + /** + * end handle of the P2P service + */ + uint16_t P2PServiceEndHandle; + + /** + * handle of the Tx characteristic - Write To Server + * + */ + uint16_t P2PWriteToServerCharHdle; + + /** + * handle of the client configuration + * descriptor of Tx characteristic + */ + uint16_t P2PWriteToServerDescHandle; + + /** + * handle of the Rx characteristic - Notification From Server + * + */ + uint16_t P2PNotificationCharHdle; + + /** + * handle of the client configuration + * descriptor of Rx characteristic + */ + uint16_t P2PNotificationDescHandle; + +}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 ------------------------------------------------------------*/ +/* USER CODE BEGIN PD */ + +/* USER CODE END PD */ + +/* Private macros -------------------------------------------------------------*/ +#define UNPACK_2_BYTE_PARAMETER(ptr) \ + (uint16_t)((uint16_t)(*((uint8_t *)ptr))) | \ + (uint16_t)((((uint16_t)(*((uint8_t *)ptr + 1))) << 8)) +/* USER CODE BEGIN PM */ + +/* USER CODE END PM */ + +/* Private variables ---------------------------------------------------------*/ +/** + * START of Section BLE_APP_CONTEXT + */ + +PLACE_IN_SECTION("BLE_APP_CONTEXT") static P2P_ClientContext_t aP2PClientContext[BLE_CFG_CLT_MAX_NBR_CB]; + +/** + * 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 ); +static void Send_Data_To_Write_Characterisitc( void ); +/* USER CODE END PFP */ + +/* Functions Definition ------------------------------------------------------*/ +/** + * @brief Service initialization + * @param None + * @retval None + */ +void P2PC_APP_Init(void) +{ + uint8_t index =0; +/* USER CODE BEGIN P2PC_APP_Init_1 */ + 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_DATA_TO_SERVER_ID, UTIL_SEQ_RFU, Send_Data_To_Write_Characterisitc ); + + BSP_LED_Off(LED_GREEN); + + /** + * 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++) + { + aP2PClientContext[index].state= APP_BLE_IDLE; + } + + /** + * Register the event handler to the BLE controller + */ + SVCCTL_RegisterCltHandler(Event_Handler); + +#if(CFG_DEBUG_APP_TRACE != 0) + APP_DBG_MSG("-- P2P CLIENT INITIALIZED \n"); +#endif + +/* USER CODE BEGIN P2PC_APP_Init_2 */ + +/* USER CODE END P2PC_APP_Init_2 */ + return; +} + +void P2PC_APP_Notification(P2PC_APP_ConnHandle_Not_evt_t *pNotification) +{ +/* USER CODE BEGIN P2PC_APP_Notification_1 */ + +/* USER CODE END P2PC_APP_Notification_1 */ + switch(pNotification->P2P_Evt_Opcode) + { +/* USER CODE BEGIN P2P_Evt_Opcode */ + +/* USER CODE END P2P_Evt_Opcode */ + + case PEERC_CONN_HANDLE_EVT : +/* USER CODE BEGIN PEER_CONN_HANDLE_EVT */ + P2P_Client_App_Context.ConnectionHandle = pNotification->ConnectionHandle; + UART_App_SendData("\r\nC\r\n", 5); +// BSP_LED_On(LED_GREEN); +/* USER CODE END PEER_CONN_HANDLE_EVT */ + break; + + case PEERC_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; + } + UART_App_SendData("\r\nD\r\n", 5); + BSP_LED_Off(LED_BLUE); + BSP_LED_Off(LED_GREEN); + } +/* USER CODE END PEER_DISCON_HANDLE_EVT */ + break; + case PEERC_DISCON_SWITCH_HANDLE_EVT : + switch (Next_Mode) { + case P2P_SERVER : + *(volatile uint32_t*) SRAM1_BASE = SRAM1_BASE_P2P_SERVER; + break; + case HEART_RATE : + *(volatile uint32_t*) SRAM1_BASE = SRAM1_BASE_HEART_RATE; + break; + default : break; + } + NVIC_SystemReset(); + break; + + default: +/* USER CODE BEGIN P2P_Evt_Opcode_Default */ + +/* USER CODE END P2P_Evt_Opcode_Default */ + break; + } +/* USER CODE BEGIN P2PC_APP_Notification_2 */ + +/* USER CODE END P2PC_APP_Notification_2 */ + 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 */ + +/************************************************************* + * + * LOCAL FUNCTIONS + * + *************************************************************/ + +/** + * @brief Event handler + * @param Event: Address of the buffer holding the Event + * @retval Ack: Return whether the Event has been managed or not + */ +static SVCCTL_EvtAckStatus_t Event_Handler(void *Event) +{ + SVCCTL_EvtAckStatus_t return_value; + hci_event_pckt *event_pckt; + evt_blue_aci *blue_evt; + + P2P_Client_App_Notification_evt_t Notification; + + return_value = SVCCTL_EvtNotAck; + event_pckt = (hci_event_pckt *)(((hci_uart_pckt*)Event)->data); + + + + switch(event_pckt->evt) + { + case EVT_VENDOR: + { + blue_evt = (evt_blue_aci*)event_pckt->data; + switch(blue_evt->ecode) + { + + case EVT_BLUE_ATT_READ_BY_GROUP_TYPE_RESP: + { + aci_att_read_by_group_type_resp_event_rp0 *pr = (void*)blue_evt->data; + uint8_t numServ, i, idx; + uint16_t uuid, handle; + + uint8_t index; + handle = pr->Connection_Handle; + index = 0; + while((index < BLE_CFG_CLT_MAX_NBR_CB) && + (aP2PClientContext[index].state != APP_BLE_IDLE)) + { + APP_BLE_ConnStatus_t status; + + status = APP_BLE_CL_Get_Client_Connection_Status(aP2PClientContext[index].connHandle); + + if((aP2PClientContext[index].state == APP_BLE_CONNECTED_CLIENT)&& + (status == APP_BLE_IDLE)) + { + /* Handle deconnected */ + + aP2PClientContext[index].state = APP_BLE_IDLE; + aP2PClientContext[index].connHandle = 0xFFFF; + break; + } + index++; + } + + if(index < BLE_CFG_CLT_MAX_NBR_CB) + { + aP2PClientContext[index].connHandle= handle; + + + numServ = (pr->Data_Length) / pr->Attribute_Data_Length; + + /* the event data will be + * 2bytes start handle + * 2bytes end handle + * 2 or 16 bytes data + * we are intersted only if the UUID is 16 bit. + * So check if the data length is 6 + */ +#if (UUID_128BIT_FORMAT==1) + if (pr->Attribute_Data_Length == 20) + { + idx = 16; +#else + if (pr->Attribute_Data_Length == 6) + { + idx = 4; +#endif + for (i=0; i<numServ; i++) + { + uuid = UNPACK_2_BYTE_PARAMETER(&pr->Attribute_Data_List[idx]); + if(uuid == P2P_SERVICE_UUID) + { +#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) + 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 + aP2PClientContext[index].state = APP_BLE_DISCOVER_CHARACS ; + } + idx += 6; + } + } + } + } + break; + + case EVT_BLUE_ATT_READ_BY_TYPE_RESP: + { + + aci_att_read_by_type_resp_event_rp0 *pr = (void*)blue_evt->data; + uint8_t idx; + uint16_t uuid, handle; + + /* the event data will be + * 2 bytes start handle + * 1 byte char properties + * 2 bytes handle + * 2 or 16 bytes data + */ + + uint8_t index; + + index = 0; + while((index < BLE_CFG_CLT_MAX_NBR_CB) && + (aP2PClientContext[index].connHandle != pr->Connection_Handle)) + index++; + + if(index < BLE_CFG_CLT_MAX_NBR_CB) + { + + /* we are interested in only 16 bit UUIDs */ +#if (UUID_128BIT_FORMAT==1) + idx = 17; + if (pr->Handle_Value_Pair_Length == 21) +#else + idx = 5; + if (pr->Handle_Value_Pair_Length == 7) +#endif + { + pr->Data_Length -= 1; + while(pr->Data_Length > 0) + { + uuid = UNPACK_2_BYTE_PARAMETER(&pr->Handle_Value_Pair_Data[idx]); + /* store the characteristic handle not the attribute handle */ +#if (UUID_128BIT_FORMAT==1) + handle = UNPACK_2_BYTE_PARAMETER(&pr->Handle_Value_Pair_Data[idx-14]); +#else + handle = UNPACK_2_BYTE_PARAMETER(&pr->Handle_Value_Pair_Data[idx-2]); +#endif + if(uuid == P2P_WRITE_CHAR_UUID) + { +#if(CFG_DEBUG_APP_TRACE != 0) + APP_DBG_MSG("-- GATT : WRITE_UUID FOUND - connection handle 0x%x\n", aP2PClientContext[index].connHandle); +#endif + aP2PClientContext[index].state = APP_BLE_DISCOVER_WRITE_DESC; + aP2PClientContext[index].P2PWriteToServerCharHdle = handle; + } + + else if(uuid == P2P_NOTIFY_CHAR_UUID) + { +#if(CFG_DEBUG_APP_TRACE != 0) + APP_DBG_MSG("-- GATT : NOTIFICATION_CHAR_UUID FOUND - connection handle 0x%x\n", aP2PClientContext[index].connHandle); +#endif + aP2PClientContext[index].state = APP_BLE_DISCOVER_NOTIFICATION_CHAR_DESC; + aP2PClientContext[index].P2PNotificationCharHdle = handle; + } +#if (UUID_128BIT_FORMAT==1) + pr->Data_Length -= 21; + idx += 21; +#else + pr->Data_Length -= 7; + idx += 7; +#endif + } + } + } + } + break; + + case EVT_BLUE_ATT_FIND_INFORMATION_RESP: + { + aci_att_find_info_resp_event_rp0 *pr = (void*)blue_evt->data; + + uint8_t numDesc, idx, i; + uint16_t uuid, handle; + + /* + * event data will be of the format + * 2 bytes handle + * 2 bytes UUID + */ + + uint8_t index; + + index = 0; + while((index < BLE_CFG_CLT_MAX_NBR_CB) && + (aP2PClientContext[index].connHandle != pr->Connection_Handle)) + + index++; + + if(index < BLE_CFG_CLT_MAX_NBR_CB) + { + + numDesc = (pr->Event_Data_Length) / 4; + /* we are interested only in 16 bit UUIDs */ + idx = 0; + if (pr->Format == UUID_TYPE_16) + { + for (i=0; i<numDesc; i++) + { + handle = UNPACK_2_BYTE_PARAMETER(&pr->Handle_UUID_Pair[idx]); + uuid = UNPACK_2_BYTE_PARAMETER(&pr->Handle_UUID_Pair[idx+2]); + + if(uuid == CLIENT_CHAR_CONFIG_DESCRIPTOR_UUID) + { +#if(CFG_DEBUG_APP_TRACE != 0) + APP_DBG_MSG("-- GATT : CLIENT_CHAR_CONFIG_DESCRIPTOR_UUID- connection handle 0x%x\n", aP2PClientContext[index].connHandle); +#endif + if( aP2PClientContext[index].state == APP_BLE_DISCOVER_NOTIFICATION_CHAR_DESC) + { + + aP2PClientContext[index].P2PNotificationDescHandle = handle; +// aP2PClientContext[index].state = APP_BLE_ENABLE_NOTIFICATION_DESC; + aP2PClientContext[index].state = APP_BLE_CONNECTED_CLIENT; + + } + } + idx += 4; + } + } + } + } + break; /*EVT_BLUE_ATT_FIND_INFORMATION_RESP*/ + + case EVT_BLUE_GATT_NOTIFICATION: + { + aci_gatt_notification_event_rp0 *pr = (void*)blue_evt->data; + uint8_t index; + + index = 0; + while((index < BLE_CFG_CLT_MAX_NBR_CB) && + (aP2PClientContext[index].connHandle != pr->Connection_Handle)) + index++; + + if(index < BLE_CFG_CLT_MAX_NBR_CB) + { + + if ( (pr->Attribute_Handle == aP2PClientContext[index].P2PNotificationCharHdle) && + (pr->Attribute_Value_Length == (2)) ) + { + + Notification.P2P_Client_Evt_Opcode = P2P_NOTIFICATION_INFO_RECEIVED_EVT; + Notification.DataTransfered.Length = pr->Attribute_Value_Length; + Notification.DataTransfered.pPayload = &pr->Attribute_Value[0]; + + Gatt_Notification(&Notification); + + /* INFORM APPLICATION BUTTON IS PUSHED BY END DEVICE */ + + } + } + } + break;/* end EVT_BLUE_GATT_NOTIFICATION */ + + case EVT_BLUE_GATT_PROCEDURE_COMPLETE: + { + aci_gatt_proc_complete_event_rp0 *pr = (void*)blue_evt->data; +#if(CFG_DEBUG_APP_TRACE != 0) + APP_DBG_MSG("-- GATT : EVT_BLUE_GATT_PROCEDURE_COMPLETE \n"); + APP_DBG_MSG("\n"); +#endif + + + uint8_t index; + + index = 0; + while((index < BLE_CFG_CLT_MAX_NBR_CB) && + (aP2PClientContext[index].connHandle != pr->Connection_Handle)) + index++; + + if(index < BLE_CFG_CLT_MAX_NBR_CB) + { + + UTIL_SEQ_SetTask( 1<<CFG_TASK_SEARCH_SERVICE_ID, CFG_SCH_PRIO_0); + + } + } + break; /*EVT_BLUE_GATT_PROCEDURE_COMPLETE*/ + + default: + break; + } + } + + break; /* HCI_EVT_VENDOR_SPECIFIC */ + + default: + break; + } + + return(return_value); +}/* end BLE_CTRL_Event_Acknowledged_Status_t */ + +void Gatt_Notification(P2P_Client_App_Notification_evt_t *pNotification) +{ +/* USER CODE BEGIN Gatt_Notification_1*/ + +/* USER CODE END Gatt_Notification_1 */ + switch(pNotification->P2P_Client_Evt_Opcode) + { +/* USER CODE BEGIN P2P_Client_Evt_Opcode */ + +/* USER CODE END P2P_Client_Evt_Opcode */ + + case P2P_NOTIFICATION_INFO_RECEIVED_EVT: +/* USER CODE BEGIN P2P_NOTIFICATION_INFO_RECEIVED_EVT */ + { + UART_App_SendData("\r\nR=", 4); + char received_val_str[4]; + uint8_t received_val[2]; + uint8_t k; + for(k = 0; k < 2; k++) received_val[k] = pNotification->DataTransfered.pPayload[k]; + UART_App_ConvertBleDataToString(received_val, received_val_str, 4); + UART_App_SendData((char *)received_val_str, 4); + UART_App_SendData("\r\n", 2); + + 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); + APP_DBG_MSG(" -- P2P APPLICATION CLIENT : NOTIFICATION RECEIVED - LED OFF \n\r"); + APP_DBG_MSG(" \n\r"); + } else { + APP_DBG_MSG(" -- P2P APPLICATION CLIENT : NOTIFICATION RECEIVED - LED ON\n\r"); + APP_DBG_MSG(" \n\r"); + BSP_LED_On(LED_BLUE); + } + + break; + } + default : break; + } + + } +/* USER CODE END P2P_NOTIFICATION_INFO_RECEIVED_EVT */ + break; + + default: +/* USER CODE BEGIN P2P_Client_Evt_Opcode_Default */ + +/* USER CODE END P2P_Client_Evt_Opcode_Default */ + break; + } +/* USER CODE BEGIN Gatt_Notification_2*/ + +/* USER CODE END Gatt_Notification_2 */ + return; +} + +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) +{ + + + APP_DBG_MSG("-- P2P APPLICATION CLIENT : BUTTON PUSHED - WRITE TO SERVER \n "); + APP_DBG_MSG(" \n\r"); + 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 Send_Data_To_Write_Characterisitc(void) +{ + Write_Char( P2P_WRITE_CHAR_UUID, 0, (uint8_t *)WriteCharData); + + UART_App_SendData("\r\nOK\r\n", 6); +} + +void Enable_Notification( void ) +{ + aP2PClientContext[0].state = APP_BLE_ENABLE_NOTIFICATION_DESC; + + UTIL_SEQ_SetTask( 1<<CFG_TASK_SEARCH_SERVICE_ID, CFG_SCH_PRIO_0); +} + +void Disable_Notification( void ) +{ + aP2PClientContext[0].state = APP_BLE_DISABLE_NOTIFICATION_DESC; + + UTIL_SEQ_SetTask( 1<<CFG_TASK_SEARCH_SERVICE_ID, CFG_SCH_PRIO_0); +} + +void Update_Service() +{ + 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: + APP_DBG_MSG("P2P_DISCOVER_SERVICES\n"); + break; + case APP_BLE_DISCOVER_CHARACS: + APP_DBG_MSG("* GATT : Discover P2P Characteristics\n"); + 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 */ + APP_DBG_MSG("* GATT : Discover Descriptor of TX - Write Characteritic\n"); + aci_gatt_disc_all_char_desc(aP2PClientContext[index].connHandle, + aP2PClientContext[index].P2PWriteToServerCharHdle, + aP2PClientContext[index].P2PWriteToServerCharHdle+2); + + break; + case APP_BLE_DISCOVER_NOTIFICATION_CHAR_DESC: + APP_DBG_MSG("* GATT : Discover Descriptor of Rx - Notification Characteritic\n"); + aci_gatt_disc_all_char_desc(aP2PClientContext[index].connHandle, + aP2PClientContext[index].P2PNotificationCharHdle, + aP2PClientContext[index].P2PNotificationCharHdle+2); + + break; + case APP_BLE_ENABLE_NOTIFICATION_DESC: + APP_DBG_MSG("* GATT : Enable Server Notification\n"); + 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); + UART_App_SendData("\r\nOK\r\n", 6); + + break; + case APP_BLE_DISABLE_NOTIFICATION_DESC : + APP_DBG_MSG("* GATT : Disable Server Notification\n"); + aci_gatt_write_char_desc(aP2PClientContext[index].connHandle, + aP2PClientContext[index].P2PNotificationDescHandle, + 2, + (uint8_t *)&disable); + + aP2PClientContext[index].state = APP_BLE_CONNECTED_CLIENT; + UART_App_SendData("\r\nOK\r\n", 6); + break; + default: + break; + } + index++; + } + return; +} +/* USER CODE END LF */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |