/******************************************************************************* * Function Name: attrHandleInit ******************************************************************************** * * Summary: * This function gathhers all the information like attribute handles and MTU size * from the server. * * Parameters: * None. * * Return: * None. * *******************************************************************************/ void attrHandleInit() { switch(infoExchangeState) { case INFO_EXCHANGE_START: CyBle_GattcDiscoverPrimaryServiceByUuid(cyBle_connHandle, bleUartServiceUuidInfo); break; case BLE_UART_SERVICE_HANDLE_FOUND: attrHandleRange.startHandle = bleUartServiceHandle; attrHandleRange.endHandle = bleUartServiceEndHandle; CyBle_GattcDiscoverAllCharacteristics(cyBle_connHandle, attrHandleRange); break; case (SERVICE_AND_CHAR_HANDLES_FOUND): charDescHandleRange.startHandle = txCharHandle + 1; charDescHandleRange.endHandle = bleUartServiceEndHandle; CyBle_GattcDiscoverAllCharacteristicDescriptors(cyBle_connHandle, &charDescHandleRange); break; case (ALL_HANDLES_FOUND): CyBle_GattcExchangeMtuReq(cyBle_connHandle, CYBLE_GATT_MTU); break; default: break; } CyBle_ProcessEvents(); }
void AppCallBack(uint32 event, void* eventParam) { CYBLE_API_RESULT_T apiResult; CYBLE_GATTS_WRITE_REQ_PARAM_T *wrReqParam; uint8 len; #ifdef DEBUG_OUT DebugOut(event, eventParam); //printf("ACB evt: %ld \r\n",event); #endif switch(event) { case CYBLE_EVT_STACK_ON: printf("EVT_STACK_ON \r\n"); goto start_scan; case CYBLE_EVT_GAP_DEVICE_DISCONNECTED: BleConnected = 0; printf("EVT_GAP_DEVICE_DISCONNECTED \r\n"); goto start_scan; case CYBLE_EVT_TIMEOUT: printf("EVT_TIMEOUT \r\n"); start_scan: if(BleConnected == 0) { StartScan(CYBLE_UUID_CUSTOM_UART_TX_SERVICE); //Scanning_LED_Write(LED_ON); ble_state = BLE_SCAN_STATE; } break; #ifndef DEBUG_OUT case CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT: ScanProgressEventHandler((CYBLE_GAPC_ADV_REPORT_T *)eventParam); break; case CYBLE_EVT_GAPC_SCAN_START_STOP: printf("EVT_GAPC_SCAN_START_STOP \r\n"); if(0u != (flag & CONNECT)) { printf("Connect to the Device: %x \r\n", deviceN); /* Connect to selected device */ apiResult = CyBle_GapcConnectDevice(&peerAddr[deviceN]); if(apiResult != CYBLE_ERROR_OK) { printf("ConnectDevice API Error: %x \r\n", apiResult); } flag &= ~CONNECT; BleConnected = 1; } break; case CYBLE_EVT_GATTC_HANDLE_VALUE_NTF: wrReqParam = (CYBLE_GATTS_WRITE_REQ_PARAM_T *) eventParam; if(wrReqParam->handleValPair.attrHandle == UART_TX_HANDLE) { len = wrReqParam->handleValPair.value.len; Buffer[0] = len; memcpy(&Buffer[1],wrReqParam->handleValPair.value.val,len); uCommState.Bit.BLERxFinshed = ENABLED; //printf("len %d buf[0] %d \r\n", len,Buffer[0]); } break; case CYBLE_EVT_GATT_CONNECT_IND: printf("EVT_GATT_CONNECT_IND \r\n"); break; case CYBLE_EVT_GATTC_XCHNG_MTU_RSP: printf("CYBLE_EVT_GATTC_XCHNG_MTU_RSP \r\n"); break; #endif case CYBLE_EVT_GAP_DEVICE_CONNECTED: printf("EVT_GAP_DEVICE_CONNECTED \r\n"); apiResult = CyBle_GattcExchangeMtuReq(cyBle_connHandle,0x200); if(apiResult == CYBLE_ERROR_OK) { printf("zozo test exchg mtu req send\r\n"); } ble_state = BLE_CONNECTED_STATE; break; case CYBLE_EVT_GATTC_DISCOVERY_COMPLETE: break; default: break; } }