/********************************************************************* * @fn TimeApp_ProcessEvent * * @brief Time App 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 TimeApp_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( timeAppTaskId )) != NULL ) { timeApp_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 GAPRole_StartDevice( &timeAppPeripheralCB ); // Register with bond manager after starting device GAPBondMgr_Register( (gapBondCBs_t *) &timeAppBondCB ); return ( events ^ START_DEVICE_EVT ); } if ( events & START_DISCOVERY_EVT ) { if ( timeAppPairingStarted ) { // Postpone discovery until pairing completes timeAppDiscPostponed = TRUE; } else { timeAppDiscState = timeAppDiscStart(); } return ( events ^ START_DISCOVERY_EVT ); } if ( events & CLOCK_UPDATE_EVT ) { timeAppClockDisplay(); // Restart clock tick timer osal_start_timerEx( timeAppTaskId, CLOCK_UPDATE_EVT, DEFAULT_CLOCK_UPDATE_PERIOD ); return ( events ^ CLOCK_UPDATE_EVT ); } // Discard unknown events return 0; }
/********************************************************************* * @fn Thermometer_ProcessEvent * * @brief Thermometer 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 Thermometer_ProcessEvent( uint8 task_id, uint16 events ) { VOID task_id; // OSAL required parameter that isn't used in this function uint8 notify_interval; int32 n32; if ( events & SYS_EVENT_MSG ) { uint8 *pMsg; if ( (pMsg = osal_msg_receive( thermometerTaskId )) != NULL ) { thermometer_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 & TH_START_DEVICE_EVT ) { // Start the Device VOID GAPRole_StartDevice( &thermometer_PeripheralCBs ); // Register with bond manager after starting device VOID GAPBondMgr_Register( &thermometer_BondMgrCBs ); updateUI(); return ( events ^ TH_START_DEVICE_EVT ); } if ( events & TH_START_DISCOVERY_EVT ) { if ( timeAppPairingStarted ) { // Postpone discovery until pairing completes timeAppDiscPostponed = TRUE; } else { timeAppDiscState = timeAppDiscStart(); } timeAppDiscState = timeAppDiscStart(); return ( events ^ TH_START_DISCOVERY_EVT ); } //periodic indications - if enabled if ( events & TH_PERIODIC_MEAS_EVT ) { // Perform periodic application task performPeriodicTask(); return (events ^ TH_PERIODIC_MEAS_EVT); } //periodic notifications for IMEAS if ( events & TH_PERIODIC_IMEAS_EVT ) { // Perform periodic application task performPeriodicImeasTask(); return (events ^ TH_PERIODIC_IMEAS_EVT); } // Disconnect after sending measurement if ( events & TH_DISCONNECT_EVT ) { uint8 advEnable = FALSE; //disable advertising on disconnect GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &advEnable ); // Terminate Connection GAPRole_TerminateConnection(); return (events ^ TH_DISCONNECT_EVT); } if ( events & TH_CCC_UPDATE_EVT ) //This event is triggered when CCC is enabled if (gapProfileState == GAPROLE_CONNECTED) { temperatureMeasCharConfig = true; //if previously connected and measurements are active send stored if( connectedToLastAddress == true) { //send stored measurements thermometerSendStoredMeas(); } //Only start meas timer if it's not running if(thMeasTimerRunning == FALSE) { //read stored interval value Thermometer_GetParameter( THERMOMETER_INTERVAL, ¬ify_interval ); n32 = ((uint32)(notify_interval)) * (1000); //zero interval means should not perform meas if (n32 !=0) { // Start interval timer osal_start_timerEx( thermometerTaskId, TH_PERIODIC_MEAS_EVT, n32 ); thMeasTimerRunning = TRUE; } } return (events ^ TH_CCC_UPDATE_EVT); } return 0; }
/********************************************************************* * @fn BloodPressure_ProcessEvent * * @brief BloodPressure 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 BloodPressure_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( bloodPressureTaskId )) != NULL ) { bloodPressure_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 & BP_START_DEVICE_EVT ) { // Start the Device VOID GAPRole_StartDevice( &bloodPressure_PeripheralCBs ); // Register with bond manager after starting device GAPBondMgr_Register( (gapBondCBs_t *) &timeAppBondCB ); updateUI(); return ( events ^ BP_START_DEVICE_EVT ); } if ( events & BP_START_DISCOVERY_EVT ) { if ( timeAppPairingStarted ) { // Postpone discovery until pairing completes timeAppDiscPostponed = TRUE; } else { timeAppDiscState = timeAppDiscStart(); } return ( events ^ BP_START_DISCOVERY_EVT ); } /////////////////////////////////// // BP MEAS DONE /////////////////////////////////// if ( events & TIMER_BPMEAS_EVT ) { // Perform final measurement bpFinalMeas(); return (events ^ TIMER_BPMEAS_EVT); } /////////////////////////////////// // CUFF /////////////////////////////////// if ( events & BP_TIMER_CUFF_EVT ) { // Perform a Cutoff Measurement cuffMeas(); cuffCount++; // If cuff count not met, keep sending cuff measurements if(cuffCount < CUFF_MAX) { // Start interval timer to send BP, just for simulation osal_start_timerEx( bloodPressureTaskId, BP_TIMER_CUFF_EVT, TIMER_CUFF_PERIOD ); } // Get ready to send final measurement else { // Start timer to send final BP meas osal_start_timerEx( bloodPressureTaskId, TIMER_BPMEAS_EVT, TIMER_CUFF_PERIOD ); } return (events ^ BP_TIMER_CUFF_EVT); } // Enable Bloodpressure CCC if ( events & BP_CCC_UPDATE_EVT ) { if (gapProfileState == GAPROLE_CONNECTED) { //if previously connected and measurements are active send stored if( connectedToLastAddress == true) { //send stored measurements bpSendStoredMeas(); } } return (events ^ BP_CCC_UPDATE_EVT); } // Disconnect after sending measurement if ( events & BP_DISCONNECT_EVT ) { uint8 advEnable = FALSE; //disable advertising on disconnect GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &advEnable ); HalLedSet ( HAL_LED_1, HAL_LED_MODE_ON ); // Terminate Connection GAPRole_TerminateConnection(); return (events ^ BP_DISCONNECT_EVT); } return 0; }