/********************************************************************* * @fn SimpleBLECentral_ProcessEvent * * @brief Simple BLE Central Application Task event processor. This function * is called to process all events for the task. Events * include timers, messages and any other user defined events. * * @param task_id - The OSAL assigned task ID. * @param events - events to process. This is a bit map and can * contain more than one event. * * @return events not processed */ uint16 SimpleBLECentral_ProcessEvent( uint8 task_id, uint16 events ) { VOID task_id; // OSAL required parameter that isn't used in this function if ( events & SYS_EVENT_MSG ) { uint8 *pMsg; if ( (pMsg = osal_msg_receive( simpleBLETaskId )) != NULL ) { simpleBLECentral_ProcessOSALMsg( (osal_event_hdr_t *)pMsg ); // Release the OSAL message VOID osal_msg_deallocate( pMsg ); } // return unprocessed events return (events ^ SYS_EVENT_MSG); } if ( events & START_DEVICE_EVT ) { // Start the Device VOID GAPCentralRole_StartDevice( (gapCentralRoleCB_t *) &simpleBLERoleCB ); // Register with bond manager after starting device GAPBondMgr_Register( (gapBondCBs_t *) &simpleBLEBondCB ); return ( events ^ START_DEVICE_EVT ); } if ( events & START_DISCOVERY_EVT ) { simpleBLECentralStartDiscovery( ); return ( events ^ START_DISCOVERY_EVT ); } if ( events & SBP_PERIODIC_EVT ) { // Restart timer if ( SBP_PERIODIC_EVT_PERIOD && simpleBLEState == BLE_STATE_CONNECTED ) { osal_start_timerEx( simpleBLETaskId, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD ); } // Perform periodic application task performPeriodicTask(); return (events ^ SBP_PERIODIC_EVT); } // Discard unknown events return 0; }
/********************************************************************************************* * @fn simpleBLECentralEventCB * * @brief Central event callback function. * * @param pEvent - pointer to event structure * * @return none **********************************************************************************************/ void CentralClientInitiat(void){ SwitchCentral_Init(); uint8 return_status; if(return_status = GAPCentralRole_StartDevice((gapCentralRoleCB_t *) &simpleBLERoleCB)) LCDPrintText("Central Init Error",return_status,PRINT_VALUE); if(return_status = GATT_InitClient()) LCDPrintText("Client Init Error",return_status,PRINT_VALUE); GATT_RegisterForInd(MasterSlaveSwitchTaskID); }
/********************************************************************* * @fn SimpleBLECentral_ProcessEvent * * @brief Simple BLE Central Application Task event processor. This function * is called to process all events for the task. Events * include timers, messages and any other user defined events. * * @param task_id - The OSAL assigned task ID. * @param events - events to process. This is a bit map and can * contain more than one event. * * @return events not processed */ uint16 SimpleBLECentral_ProcessEvent( uint8 task_id, uint16 events ) { VOID task_id; // OSAL required parameter that isn't used in this function if ( events & SYS_EVENT_MSG ) { uint8 *pMsg; if ( (pMsg = osal_msg_receive( simpleBLETaskId )) != NULL ) { controlBLECentral_ProcessOSALMsg( (osal_event_hdr_t *)pMsg ); // Release the OSAL message VOID osal_msg_deallocate( pMsg ); } // return unprocessed events return (events ^ SYS_EVENT_MSG); } if ( events & START_DEVICE_EVT ) { // Start the Device VOID GAPCentralRole_StartDevice( (gapCentralRoleCB_t *) &simpleBLERoleCB ); // Register with bond manager after starting device GAPBondMgr_Register( (gapBondCBs_t *) &simpleBLEBondCB ); return ( events ^ START_DEVICE_EVT ); } if ( events & START_DISCOVERY_EVT ) { controlBLECentralStartDiscovery( ); return ( events ^ START_DISCOVERY_EVT ); } // Discard unknown events return 0; }
void bleshield_central_init() { GAPCentralRole_StartDevice(); }
/********************************************************************* * * @fn hidappStart * * @brief Start up the application * * @param None * * @return None */ static void hidappStart(void) { GAPCentralRole_StartDevice( &hidApp_centralCBs ); }
/********************************************************************* * @fn glucCollCentral_Init * * @brief Initialization function for the Glucose Collector App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notification). * * * @return none */ static void glucCollCentral_Init() { // ****************************************************************** // N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp // ****************************************************************** // Register the current thread as an ICall dispatcher application // so that the application can send and receive messages. ICall_registerApp(&selfEntity, &sem); // Set device's Sleep Clock Accuracy //HCI_EXT_SetSCACmd(40); // Save the taskId glucCollTaskId = selfEntity; // Create an RTOS queue for message from profile to be sent to app. appMsgQueue = Util_constructQueue(&appMsg); Board_openLCD(); // Create clock objects for discovery and procedure timeout Util_constructClock(&discoveryClock, glucCollCentral_clockHandler, DEFAULT_SVC_DISCOVERY_DELAY, 0, false, GLUCOLL_START_DISCOVERY_EVT); Util_constructClock(&procTimeoutClock, glucCollCentral_clockHandler, GLUCOSE_PROCEDURE_TIMEOUT, 0, false, GLUCOLL_PROCEDURE_TIMEOUT_EVT); // Setup Central Profile { uint8_t scanRes = DEFAULT_MAX_SCAN_RES; GAPCentralRole_SetParameter (GAPCENTRALROLE_MAX_SCAN_RES, sizeof(uint8_t), &scanRes); } // Setup GAP GAP_SetParamValue(TGAP_GEN_DISC_SCAN, DEFAULT_SCAN_DURATION); GAP_SetParamValue(TGAP_LIM_DISC_SCAN, DEFAULT_SCAN_DURATION); GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, (uint8_t *)glucCollDeviceName); // Setup the GAP Bond Manager { uint32_t passkey = DEFAULT_PASSCODE; uint8_t pairMode = DEFAULT_PAIRING_MODE; uint8_t mitm = DEFAULT_MITM_MODE; uint8_t ioCap = DEFAULT_IO_CAPABILITIES; uint8_t bonding = DEFAULT_BONDING_MODE; GAPBondMgr_SetParameter(GAPBOND_DEFAULT_PASSCODE, sizeof(uint32_t), &passkey); GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode); GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm); GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap); GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding); } // Initialize GATT Client VOID GATT_InitClient(); // Register to receive incoming ATT Indications/Notifications GATT_RegisterForInd(glucCollTaskId); // Initialize GATT attributes GGS_AddService(GATT_ALL_SERVICES); // GAP GATTServApp_AddService(GATT_ALL_SERVICES); // GATT attributes // Register for all key events - This app will handle all key events Board_initKeys(glucCollCentral_keyChangeHandler); // Register with bond manager after starting device GAPBondMgr_Register((gapBondCBs_t *)&glucCollBondCB); // Start the Device VOID GAPCentralRole_StartDevice((gapCentralRoleCB_t *)&glucCollRoleCB); }
/********************************************************************* * @fn GlucColl_ProcessEvent * * @brief Glucose Collector Application Task event processor. This function * is called to process all events for the task. Events * include timers, messages and any other user defined events. * * @param task_id - The OSAL assigned task ID. * @param events - events to process. This is a bit map and can * contain more than one event. * * @return events not processed */ uint16 GlucColl_ProcessEvent( uint8 task_id, uint16 events ) { VOID task_id; // OSAL required parameter that isn't used in this function if ( events & SYS_EVENT_MSG ) { uint8 *pMsg; if ( (pMsg = osal_msg_receive( glucCollTaskId )) != NULL ) { glucCollCentral_ProcessOSALMsg( (osal_event_hdr_t *)pMsg ); // Release the OSAL message VOID osal_msg_deallocate( pMsg ); } // return unprocessed events return (events ^ SYS_EVENT_MSG); } if ( events & PROCEDURE_TIMEOUT_EVT ) { if ( glucCollState == BLE_STATE_CONNECTED ) { // disconnect glucCollState = BLE_STATE_DISCONNECTING; GAPCentralRole_TerminateLink( glucCollConnHandle ); LCD_WRITE_STRING( "Timeout", HAL_LCD_LINE_1 ); LCD_WRITE_STRING( "", HAL_LCD_LINE_2 ); LCD_WRITE_STRING( "", HAL_LCD_LINE_3 ); } // return unprocessed events return ( events ^ PROCEDURE_TIMEOUT_EVT ); } if ( events & START_DEVICE_EVT ) { // Start the Device VOID GAPCentralRole_StartDevice( (gapCentralRoleCB_t *) &glucCollRoleCB ); // Register with bond manager after starting device GAPBondMgr_Register( (gapBondCBs_t *) &glucCollBondCB ); return ( events ^ START_DEVICE_EVT ); } if ( events & START_DISCOVERY_EVT ) { if ( glucCollPairingStarted ) { // Postpone discovery until pairing completes glucCollDiscPostponed = TRUE; } else { glucCollCentralStartDiscovery( ); } return ( events ^ START_DISCOVERY_EVT ); } // Discard unknown events return 0; }
/********************************************************************* * @fn OADManager_ProcessEvent * * @brief OAD Manager Application Task event processor. This function * is called to process all events for the task. Events * include timers, messages and any other user defined events. * * @param task_id - The OSAL assigned task ID. * @param events - events to process. This is a bit map and can * contain more than one event. * * @return events not processed */ uint16 OADManager_ProcessEvent( uint8 task_id, uint16 events ) { if ( events & SYS_EVENT_MSG ) { uint8 *pMsg; if ( (pMsg = osal_msg_receive( task_id )) != NULL ) { oadManager_ProcessOSALMsg( (osal_event_hdr_t *)pMsg ); VOID osal_msg_deallocate( pMsg ); } return (events ^ SYS_EVENT_MSG); } if ( events & DEV_DISCOVERY_EVT ) { oadManagerDevDiscovery(); return ( events ^ DEV_DISCOVERY_EVT ); } if ( events & SVC_DISCOVERY_EVT ) { oadManagerSvcDiscovery(); return ( events ^ SVC_DISCOVERY_EVT ); } if ( events & CCC_DISCOVERY_EVT ) { oadManagerCCCDiscovery(); return ( events ^ CCC_DISCOVERY_EVT ); } if ( events & CHAR_DISCOVERY_EVT ) { oadManagerCharDiscovery(); return ( events ^ CHAR_DISCOVERY_EVT ); } if ( events & CONN_INTERVAL_EVT ) { (void)osal_set_event(oadManagerTaskId, SVC_DISCOVERY_EVT); GAPCentralRole_UpdateLink( oadManagerConnHandle, DEFAULT_OAD_MIN_CONN_INTERVAL, DEFAULT_OAD_MAX_CONN_INTERVAL, DEFAULT_OAD_SLAVE_LATENCY, DEFAULT_OAD_CONN_TIMEOUT ); return ( events ^ CONN_INTERVAL_EVT ); } if ( events & START_DEVICE_EVT ) { VOID GAPCentralRole_StartDevice( (gapCentralRoleCB_t *) &oadManagerRoleCB ); oadManagerDevDiscovery(); return ( events ^ START_DEVICE_EVT ); } if ( events & OAD_DOWNLOAD_EVT ) { #if (defined HAL_LCD) && (HAL_LCD == TRUE) if ( (oadBlkNum + 1) >= oadBlkTot ) { LCD_WRITE_STRING("OAD Completed!", HAL_LCD_LINE_3); } else { LCD_WRITE_STRING("OAD Failed!", HAL_LCD_LINE_3); } #endif return ( events ^ OAD_DOWNLOAD_EVT ); } return 0; }