示例#1
0
/*
 ****************************************************************************************
 * @brief Handles the ind/ntf indication message from the HOGPD.    *//**
 *
 * @param[in] msgid     HOGPD_NTF_CFG_IND
 * @param[in] param     Pointer to the struct hogpd_ntf_cfg_ind
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_HOGPD
 *
 * @return If the message was consumed or not.
 * @description
 *
 ****************************************************************************************
 */
int app_hogpd_ntf_cfg_ind_handler(ke_msg_id_t const msgid,
                                  struct hogpd_ntf_cfg_ind *param,
                                  ke_task_id_t const dest_id,
                                  ke_task_id_t const src_id)
{
    switch (param->cfg_code)
    {
        case HOGPD_BOOT_KB_IN_REPORT_CFG:
            if (param->ntf_en == PRF_CLI_START_NTF)
            {
                //DEVELOPER NOTE: SET boot_kb_in_report and boot_kb_out_report to REAL VALUE OF USER APPLICATION HERE
                app_hogpd_env->features[param->hids_nb].svc_features |= HOGPD_BOOT_KB_IN_NTF_CFG_MASK;
                ke_timer_set(APP_HOGPD_BOOT_KB_IN_REPORT_TIMER, TASK_APP, APP_HOGPD_BOOT_KB_IN_REPORT_TO);
            }
            else
            {
                app_hogpd_env->features[param->hids_nb].svc_features &= ~HOGPD_BOOT_KB_IN_NTF_CFG_MASK;
                ke_timer_clear(APP_HOGPD_BOOT_KB_IN_REPORT_TIMER, TASK_APP);
            }
            break;
        case HOGPD_BOOT_MOUSE_IN_REPORT_CFG:
            if (param->ntf_en == PRF_CLI_START_NTF)
            {
                //DEVELOPER NOTE: SET boot_mouse_in_report to REAL VALUE OF USER APPLICATION HERE
                app_hogpd_env->features[param->hids_nb].svc_features |= HOGPD_BOOT_MOUSE_IN_NTF_CFG_MASK;
                ke_timer_set(APP_HOGPD_BOOT_MOUSE_IN_REPORT_TIMER, TASK_APP, APP_HOGPD_BOOT_MOUSE_IN_REPORT_TO);
            }
            else
            {
                app_hogpd_env->features[param->hids_nb].svc_features &= ~HOGPD_BOOT_MOUSE_IN_NTF_CFG_MASK;
                ke_timer_clear(APP_HOGPD_BOOT_MOUSE_IN_REPORT_TIMER, TASK_APP);
            }
            break;
        case HOGPD_REPORT_CFG:
            if (param->ntf_en == PRF_CLI_START_NTF)
            {
                // only input report support notify property
                if (app_hogpd_env->features[param->hids_nb].report_char_cfg[param->report_nb] & HOGPD_CFG_REPORT_IN)
                {
                    //DEVELOPER NOTE: SET report to REAL VALUE OF USER APPLICATION HERE
                    app_hogpd_env->features[param->hids_nb].report_char_cfg[param->report_nb] |= HOGPD_REPORT_NTF_CFG_MASK;
                    ke_timer_set(APP_HOGPD_REPORT_TIMER, TASK_APP, APP_HOGPD_BOOT_KB_IN_REPORT_TO);
                }
            }
            else
            {
                app_hogpd_env->features[param->hids_nb].report_char_cfg[param->report_nb] &= ~HOGPD_REPORT_NTF_CFG_MASK;
                ke_timer_clear(APP_HOGPD_REPORT_TIMER, TASK_APP);
            }
            break;
        default:
            break;
    }
    return (KE_MSG_CONSUMED);
}
示例#2
0
/*
 ****************************************************************************************
 * @brief Handles the HOGPD disable indication message from the HOGPD.    *//**
 *
 * @param[in] msgid     HOGPD_DISABLE_IND
 * @param[in] param     Pointer to the struct hogpd_disable_ind
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_HOGPD
 *
 * @return If the message was consumed or not.
 * @description
 * This handler is used to inform the Application of a correct disable. 
 ****************************************************************************************
 */
int app_hogpd_disable_ind_handler(ke_msg_id_t const msgid,
                                  struct hogpd_disable_ind *param,
                                  ke_task_id_t const dest_id,
                                  ke_task_id_t const src_id)
{
    app_hogpd_env->conhdl = 0xFFFF;
    app_hogpd_env->enabled = false;
    app_hogpd_env->ntf_sending = 0;
    ke_timer_clear(APP_HOGPD_BOOT_KB_IN_REPORT_TIMER, TASK_APP);
    ke_timer_clear(APP_HOGPD_BOOT_MOUSE_IN_REPORT_TIMER, TASK_APP);
    ke_timer_clear(APP_HOGPD_REPORT_TIMER, TASK_APP);
    return (KE_MSG_CONSUMED);
}
示例#3
0
/**
 ****************************************************************************************
 * @brief Disconnection indication to ANPC.
 * @param[in] msgid     Id of the message received.
 * @param[in] param     Pointer to the parameters of the message.
 * @param[in] dest_id   ID of the receiving task instance
 * @param[in] src_id    ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int gap_discon_cmp_evt_handler(ke_msg_id_t const msgid,
                                      struct gap_discon_cmp_evt const *param,
                                      ke_task_id_t const dest_id,
                                      ke_task_id_t const src_id)
{
    // Get the address of the environment
    struct cscpc_env_tag *cscpc_env = PRF_CLIENT_GET_ENV(dest_id, cscpc);

    ASSERT_ERR(cscpc_env != NULL);

    // Free the stored operation if needed
    if (cscpc_env->operation != NULL)
    {
        // Check if we were waiting for a SC Control Point indication
        if (((struct cscpc_cmd *)cscpc_env->operation)->operation == CSCPC_CTNL_PT_CFG_IND_OP_CODE)
        {
            // Stop the procedure timeout timer
            ke_timer_clear(CSCPC_TIMEOUT_TIMER_IND, dest_id);
        }

        ke_msg_free(ke_param2msg(cscpc_env->operation));
        cscpc_env->operation = NULL;
    }

    PRF_CLIENT_DISABLE_IND_SEND(cscpc_envs, dest_id, CSCPC);

    return (KE_MSG_CONSUMED);
}
示例#4
0
/**
 ****************************************************************************************
 * @brief  If the intermediate temperature value is stable, indicate to client and stop notify. 
 *         otherwise notify to client.
 *
 * To avoid transmitting unnecessary data, the Time Stamp and Temperature Type fields
 * should not be used in the Intermediate Temperature characteristic.
 ****************************************************************************************
 */
void app_interm_temp_notify(void)
{
    int32_t temperature_x10;
    struct htp_temp_meas temp_meas;

    temperature_x10 = app_get_imeas_notify_data(&temp_meas);

    if(app_is_interm_temp_stable(temperature_x10))
    {
        usr_env.is_imeas_send_busy = false;
        usr_env.is_temp_imeas_config = false;
        if(usr_env.is_temp_meas_config)
        {
            app_temp_meas_indicate();
        }

        if(! usr_env.is_temp_meas_config && usr_env.is_meas_running)
        {
            usr_env.is_meas_running = false;
            ke_timer_clear(APP_HTPT_PERIOD_MEAS_TIMER, TASK_APP);
        }
    }
    else
    {
        // send the notify
        usr_env.is_imeas_send_busy = true;
        app_htpt_temp_send(app_htpt_env->conhdl, &temp_meas, INTERMEDIATE_MEASUREMENT);
    }

}
示例#5
0
文件: oled.c 项目: charliexp/FireBLE
int app_oled_display_timer_handler(ke_msg_id_t const msgid, void const *param,
                               ke_task_id_t const dest_id, ke_task_id_t const src_id)
{

		OLED_ShowString(0,0,"  Firefly Team  ");
		ke_timer_clear(APP_OLED_DISPLAY_TIMER,TASK_APP);
		return(KE_MSG_CONSUMED);
}
示例#6
0
/*
 * Name         : app_disconnect_func - Configure app at disconnection 
 *
 * Scope        : PUBLIC
 *
 * Arguments    : task_id - id of the kernel task calling this function
 *                param - parameters passed from the stack
 *
 * Description  : Configures keyboard application when connection is terminated.
 *
 * Returns      : void
 *
 */
void app_disconnect_func(ke_task_id_t const task_id, struct gapc_disconnect_ind const *param)
{
    arch_printf("** Clear param update timer\r\n");
    ke_timer_clear(APP_HID_TIMER, task_id);
    
    // Call test code here
    stop_kbd_single_test();
}
/**
 ****************************************************************************************
 * @brief Handles disable indication from ADC notify profile.
 *
 * @param[in] msgid     Id of the message received.
 * @param[in] param     Pointer to the parameters of the message.
 * @param[in] dest_id   ID of the receiving task instance.
 * @param[in] src_id    ID of the sending task instance.
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int app_adc_notify_disable_ind_handler(ke_msg_id_t const msgid,
                                      struct adc_notify_disable_ind const *param,
                                      ke_task_id_t const dest_id,
                                      ke_task_id_t const src_id)
{
    ke_timer_clear(APP_ADC_SAMPLING_TIMER, TASK_APP); //5 sec

    return (KE_MSG_CONSUMED);
}
示例#8
0
int app_accel_adv_timer_handler(ke_msg_id_t const msgid,
                                   void const *param,
                                   ke_task_id_t const dest_id,
                                   ke_task_id_t const src_id)
{
    // Shedule interval is: adv starts with APP_ADV_INT_MIN, then after 500ms goes to 200ms, 
    // then after 3 mins goes to 1sec, then after 3 mins goes to 2 sec
    
    // Check if we need to change Advertising interval
    if( accel_adv_count == 0 )
    {
        // First schedule for advertising interval has been reached. Move to the next schedule
        accel_adv_interval = 0x140; // 200ms  (200ms/0.625)
        // Increment counter in retension memory
        accel_adv_count += 1; 
//        ke_timer_set(APP_ACCEL_ADV_TIMER, TASK_APP, 18000);
        ke_timer_set(APP_ACCEL_ADV_TIMER, TASK_APP, 3000);
		//stop Accelerometer
		acc_stop();
    }    
    else if( accel_adv_count == 1 )
    {
        accel_adv_interval = 0x640; // 1sec  (1000ms/0.625)
        // Increment counter in retension memory
        accel_adv_count += 1; 
//        ke_timer_set(APP_ACCEL_ADV_TIMER, TASK_APP, 18000);
        ke_timer_set(APP_ACCEL_ADV_TIMER, TASK_APP, 3000);
    }
    else if( accel_adv_count == 2 )
    {
        accel_adv_interval = 0xc80; // 2sec  (2000ms/0.625)
        // Increment counter in retension memory
        accel_adv_count += 1; 
//        ke_timer_set(APP_ACCEL_ADV_TIMER, TASK_APP, 18000);
        ke_timer_set(APP_ACCEL_ADV_TIMER, TASK_APP, 3000);
    }
    
	if( accel_adv_count == 3 )
    {
        accel_adv_count = 0; 
		accel_adv_interval = APP_ADV_INT_MIN;
        // Max schedule for advertising interval has been reached. Stop timer
        ke_timer_clear(APP_ACCEL_ADV_TIMER, TASK_APP);
		// Stop Advertising
		app_adv_stop();
		// Update APP State
		ke_state_set(TASK_APP, APP_IDLE);
		// Activate Accelerometer
		set_accel_freefall();
		acc_enable_wakeup_irq();
    }
	else
		app_adv_start();
    
    return (KE_MSG_CONSUMED);
}
示例#9
0
/**
 ****************************************************************************************
 * @brief Handles measurement interval start indication from the Health Thermometer
 *        profile.
 *        Start or stop a timer following the value of the param intv.
 *
 * @param[in] msgid     Id of the message received.
 * @param[in] param     Pointer to the parameters of the message.
 * @param[in] dest_id   ID of the receiving task instance (TASK_GAP).
 * @param[in] src_id    ID of the sending task instance.
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int htpt_meas_intv_chg_ind_handler(ke_msg_id_t const msgid,
                                          struct htpt_meas_intv_chg_ind const *param,
                                          ke_task_id_t const dest_id,
                                          ke_task_id_t const src_id)
{
    if (ke_state_get(dest_id) == APP_HT_CONNECTED)
    {
        // Store the received Measurement Interval value
        app_ht_env.htpt_meas_intv = param->intv;

        // Check the new Measurement Interval Value
        if (app_ht_env.htpt_meas_intv != 0)
        {
            // Check if a Timer already exists
            if (!app_ht_env.timer_enable)
            {
                // Set a Timer
                ke_timer_set(APP_HT_TIMER, TASK_APP_HT, app_ht_env.htpt_meas_intv*100);
                app_ht_env.timer_enable = true;
            }
            else
            {
                // Clear the previous timer
                ke_timer_clear(APP_HT_TIMER, TASK_APP_HT);
                // Create a new timer with the received measurement interval
                ke_timer_set(APP_HT_TIMER, TASK_APP_HT, app_ht_env.htpt_meas_intv*100);
            }
        }
        else
        {
            // Check if a Timer exists
            if (app_ht_env.timer_enable)
            {
                // Measurement Interval is 0, clear the timer
                ke_timer_clear(APP_HT_TIMER, TASK_APP_HT);
                app_ht_env.timer_enable = false;
            }
        }
    }

    return (KE_MSG_CONSUMED);
}
示例#10
0
文件: glpc_task.c 项目: imGit/DA14580
/**
 ****************************************************************************************
 * @brief Disconnection indication to GLPC.
 * @param[in] msgid     Id of the message received.
 * @param[in] param     Pointer to the parameters of the message.
 * @param[in] dest_id   ID of the receiving task instance
 * @param[in] src_id    ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int gapc_disconnect_ind_handler(ke_msg_id_t const msgid,
                                        struct gapc_disconnect_ind const *param,
                                        ke_task_id_t const dest_id,
                                        ke_task_id_t const src_id)
{
    PRF_CLIENT_DISABLE_IND_SEND(glpc_envs, dest_id, GLPC, param->conhdl);

    // Stop timer.
    ke_timer_clear(GLPC_RACP_REQ_TIMEOUT, dest_id);

    return (KE_MSG_CONSUMED);
}
示例#11
0
文件: app_proxr.c 项目: imGit/DA14580
void app_proxr_alert_stop(void)
{

	alert_state.lvl = PROXR_ALERT_NONE; //level;
	
	alert_state.blink_timeout = 0;
	alert_state.blink_toggle = 0;
	
    GPIO_SetInactive( alert_state.port, alert_state.pin);
	
    ke_timer_clear(APP_PXP_TIMER, TASK_APP);
}
示例#12
0
void app_connection_func(struct gapc_connection_req_ind const *param)
{
    accel_adv_interval = APP_ADV_INT_MIN;
    accel_adv_count = 0;
    ke_timer_clear(APP_ACCEL_ADV_TIMER, TASK_APP);
    
    /*--------------------------------------------------------------
    * ENABLE REQUIRED PROFILES
    *-------------------------------------------------------------*/

    app_accel_enable();

}
示例#13
0
void app_batt_alert_start(void)
{
	batt_alert_en = 1;

    if (bat_lvl_alert_used )
        GPIO_SetActive( bat_led_port, bat_led_pin);

	bat_led_state = 1;
    
    ke_timer_clear(APP_BATT_ALERT_TIMER, TASK_APP);
	app_timer_set(APP_BATT_ALERT_TIMER, TASK_APP, 200);
    
}
示例#14
0
void com_event_uart_rx_frame_handler(void)
{
    uart_rx_int_enable(QN_COM_UART, MASK_DISABLE);  //disable uart rx interrupt
    struct app_uart_data_ind *com_data = ke_msg_alloc(APP_COM_UART_RX_DONE_IND,
                                         TASK_APP,
                                         TASK_APP,
                                         com_env.com_rx_len+1);
    com_data->len=com_env.com_rx_len;
    memcpy(com_data->data,com_env.com_rx_buf,com_env.com_rx_len);
    ke_msg_send(com_data);

    ke_timer_clear(APP_COM_RX_TIMEOUT_TIMER, TASK_APP);
    ke_evt_clear(1UL << EVENT_UART_RX_FRAME_ID);
}
示例#15
0
/**
 ****************************************************************************************
 * @brief Handles connection complete event from the GAP. Will enable profile.
 *
 * @param[in] msgid     Id of the message received.
 * @param[in] param     Pointer to the parameters of the message.
 * @param[in] dest_id   ID of the receiving task instance (TASK_GAP).
 * @param[in] src_id    ID of the sending task instance.
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int gapc_connection_req_ind_handler(ke_msg_id_t const msgid,
                                           struct gapc_connection_req_ind const *param,
                                           ke_task_id_t const dest_id,
                                           ke_task_id_t const src_id)
{
		// Connection Index
		if (ke_state_get(dest_id) == APP_CONNECTABLE)
		{
				app_env.conidx = KE_IDX_GET(src_id);
				
				if (app_env.conidx != GAP_INVALID_CONIDX)
				{
						//Disable timer of the establishment of the connection
						ke_timer_clear(APP_CONN_TIMER, TASK_APP);
						
						ke_state_set(dest_id, APP_CONNECTED);
						
						app_connection_func(param);
						
						// Retrieve the connection info from the parameters
						app_env.conhdl = param->conhdl;
						
						app_env.peer_addr_type = param->peer_addr_type;
						memcpy(app_env.peer_addr.addr, param->peer_addr.addr, BD_ADDR_LEN);
             
						// send connection confirmation    // 发送连接确认aiwesky 20151004
						app_connect_confirm(GAP_AUTH_REQ_NO_MITM_NO_BOND);            
						
						// Start param update
						app_param_update_start();         // 此时,就可以进行profile读取了  aiwesky 20151004
				}
				else
				{
						// No connection has been establish, restart advertising
						app_adv_start();    // 如果没有连接,则继续进行广播 aiwesky 20151005
				}        
				
		}
		else
		{
				// APP_CONNECTABLE state is used to wait the GAP_LE_CREATE_CONN_REQ_CMP_EVT message
				ASSERT_ERR(0);
    }

    return (KE_MSG_CONSUMED);
}
示例#16
0
void app_disconnect_func(struct gapc_disconnect_ind const *param)
{
    
            #if BLE_ACCEL
            //Stop the accelerometer
            acc_stop();
            // Disable accelerometer profile
            ke_msg_send_basic(ACCEL_DISABLE_REQ, TASK_ACCEL, TASK_APP);
            // Stop the accelerometer timer
			update_conn_params = 0;
            ke_timer_clear(APP_ACCEL_TIMER, TASK_APP);
            // Set accel advertising interval to initial value
            accel_adv_interval = APP_ADV_INT_MIN;
            accel_adv_count = 0;
            rwip_env.sleep_enable = true;
    		#endif //(BLE_ACCEL)
    
    
}
示例#17
0
void free_notic_onoff(unsigned char on)
{
	static unsigned char on_flag = 0;

	if(on == 0)
	{
	//	QPRINTF("close free notice\r\n");
		on_flag = 0;
		ke_timer_clear(USR_FREE_NOTICE_INFO_TIMER);
	}
	else{
		if(on_flag == 0)
		{
		//	QPRINTF("open free notice\r\n");
			on_flag = 1;
			free_notic_info.count_time = 0; //clear count when open it!
			ke_timer_set(USR_FREE_NOTICE_INFO_TIMER, 60*100);
		}
	}
}
示例#18
0
static int htpt_disable_ind_handler(ke_msg_id_t const msgid,
                                    struct htpt_disable_ind const *param,
                                    ke_task_id_t const dest_id,
                                    ke_task_id_t const src_id)
{
    if (ke_state_get(dest_id) == APP_HT_CONNECTED)
    {
        // Stop the Health Thermometer timer if enabled
        if (app_ht_env.timer_enable)
        {
            ke_timer_clear(APP_HT_TIMER, TASK_APP_HT);
            app_ht_env.timer_enable = false;
        }

        // Go to Idle state
        ke_state_set(TASK_APP_HT, APP_HT_IDLE);
    }

    return (KE_MSG_CONSUMED);
}
示例#19
0
/**
 ****************************************************************************************
 * @brief parametter update
 ****************************************************************************************
 */
void app_param_update(const struct gap_le_create_conn_req_cmp_evt * pconnect)
{
    ke_timer_clear(APP_ADV_INTV_UPDATE_TIMER, TASK_APP);
    usr_led1_set(LED_ON_DUR_CON, LED_OFF_DUR_CON);

    // Update cnx parameters
    if (pconnect->conn_info.con_interval < GAP_PPCP_CONN_INTV_MIN)
    {
        // Update connection parameters here
        struct gap_conn_param_update conn_par;
        /// Connection interval minimum
        conn_par.intv_min = GAP_PPCP_CONN_INTV_MIN;
        /// Connection interval maximum
        conn_par.intv_max = GAP_PPCP_CONN_INTV_MAX;
        /// Latency
        conn_par.latency = GAP_PPCP_SLAVE_LATENCY;
        /// Supervision timeout, Time = N * 10 msec
        conn_par.time_out = GAP_PPCP_STO_MULT;
        app_gap_param_update_req(pconnect->conn_info.conhdl, &conn_par);
    }
}
int app_adc_notify_cfg_ind_handler(ke_msg_id_t const msgid,
                                      struct adc_notify_cfg_ind const *param,
                                      ke_task_id_t const dest_id,
                                      ke_task_id_t const src_id)
{	
    
    if (param->val == PRF_CLI_START_NTF)
    {
        adc_init(GP_ADC_SE, 0); // Single ended mode
        adc_enable_channel(ADC_CHANNEL_P01);  //
    
        app_adc_notify_upd_char(SWAP(adc_get_sample()));
    
        app_timer_set(APP_ADC_SAMPLING_TIMER, TASK_APP, APP_ADC_SAMPLING_TIMEOUT); //5 sec
    }
    else if (param->val == PRF_CLI_STOP_NTFIND)
    {
        ke_timer_clear(APP_ADC_SAMPLING_TIMER, TASK_APP); //5 sec
    }
    
    return (KE_MSG_CONSUMED);
}
示例#21
0
/**
 ****************************************************************************************
 * @brief   Led1 for BLE status
 ****************************************************************************************
 */
static void usr_led1_set(uint16_t timer_on, uint16_t timer_off)
{
    usr_env.led1_on_dur = timer_on;
    usr_env.led1_off_dur = timer_off;

    if (timer_on == 0 || timer_off == 0)
    {
        if (timer_on == 0)
        {
            led_set(1, LED_OFF);
        }
        if (timer_off == 0)
        {
            led_set(1, LED_ON);
        }
        ke_timer_clear(APP_SYS_LED_1_TIMER, TASK_APP);
    }
    else
    {
        led_set(1, LED_OFF);
        ke_timer_set(APP_SYS_LED_1_TIMER, TASK_APP, timer_off);
    }
}
示例#22
0
void app_batt_alert_stop(void)
{	
	batt_alert_en = 0;

    if (bat_lvl_alert_used)
    {
#ifdef CUSTOM_BATTERY_LEVEL_MEASUREMENTS___LED_IS_ACTIVE_LOW        
        GPIO_SetActive( bat_led_port, bat_led_pin);    
#else
        GPIO_SetInactive( bat_led_port, bat_led_pin);        
#endif //CUSTOM_BATTERY_LEVEL_MEASUREMENTS___LED_IS_ACTIVE_LOW    
    }
	ke_timer_clear(APP_BATT_ALERT_TIMER, TASK_APP);
    
#ifdef CUSTOM_BATTERY_LEVEL_MEASUREMENTS___BOOST_MODE_CONFIGURATION
    if (bat_led_state == 0)
        app_restore_sleep_mode(); 
#endif //CUSTOM_BATTERY_LEVEL_MEASUREMENTS___BOOST_MODE_CONFIGURATION
	
	bat_led_state = 0;


}
示例#23
0
/**
 ****************************************************************************************
 * @brief   Show proxr alert. User can add their own code here to show alert.
 ****************************************************************************************
 */
static void usr_proxr_alert(struct proxr_alert_ind *param)
{
    // If it is PROXR_LLS_CHAR writting indication, don't alert,
    // otherwise (PROXR_IAS_CHAR, disconnect) to alert
    if (param->char_code == PROXR_IAS_CHAR || app_proxr_env->enabled == false)
    {
        if(param->alert_lvl == 2)
        {
            buzzer_on(BUZZ_VOL_HIGH);
            ke_timer_set(APP_PROXR_ALERT_STOP_TIMER, TASK_APP, 500);    // 5 seconds
        }
        else if(param->alert_lvl == 1)
        {
            buzzer_on(BUZZ_VOL_LOW);
            ke_timer_set(APP_PROXR_ALERT_STOP_TIMER, TASK_APP, 500);    // 5 seconds
        }
        else
        {
            buzzer_off();
            ke_timer_clear(APP_PROXR_ALERT_STOP_TIMER, TASK_APP);
        }
    }

}
示例#24
0
/**
 ****************************************************************************************
 * @brief   Application task message handler
 ****************************************************************************************
 */
void app_task_msg_hdl(ke_msg_id_t const msgid, void const *param)
{
    switch(msgid)
    {
        case GAP_SET_MODE_REQ_CMP_EVT:
            if(APP_IDLE == ke_state_get(TASK_APP))
            {
                usr_led1_set(LED_ON_DUR_ADV_FAST, LED_OFF_DUR_ADV_FAST);
                ke_timer_set(APP_ADV_INTV_UPDATE_TIMER, TASK_APP, 30 * 100);
            }
            else if(APP_ADV == ke_state_get(TASK_APP))
            {
                usr_led1_set(LED_ON_DUR_ADV_SLOW, LED_OFF_DUR_ADV_SLOW);
            }
            break;

        case GAP_ADV_REQ_CMP_EVT:
            usr_led1_set(LED_ON_DUR_IDLE, LED_OFF_DUR_IDLE);
            ke_timer_clear(APP_ADV_INTV_UPDATE_TIMER, TASK_APP);
            break;

        case GAP_DISCON_CMP_EVT:
            usr_led1_set(LED_ON_DUR_IDLE, LED_OFF_DUR_IDLE);

            // start adv
            app_gap_adv_start_req(GAP_GEN_DISCOVERABLE|GAP_UND_CONNECTABLE,
                    app_env.adv_data, app_set_adv_data(GAP_GEN_DISCOVERABLE),
                    app_env.scanrsp_data, app_set_scan_rsp_data(app_get_local_service_flag()),
                    GAP_ADV_FAST_INTV1, GAP_ADV_FAST_INTV2);
            break;

        case GAP_LE_CREATE_CONN_REQ_CMP_EVT:
            if(((struct gap_le_create_conn_req_cmp_evt *)param)->conn_info.status == CO_ERROR_NO_ERROR)
            {
                if(GAP_PERIPHERAL_SLV == app_get_role())
                {
                    ke_timer_clear(APP_ADV_INTV_UPDATE_TIMER, TASK_APP);
                    usr_led1_set(LED_ON_DUR_CON, LED_OFF_DUR_CON);

                    // Update cnx parameters
                    if (((struct gap_le_create_conn_req_cmp_evt *)param)->conn_info.con_interval < GAP_PPCP_CONN_INTV_MIN)
                    {
                        // Update connection parameters here
                        struct gap_conn_param_update conn_par;
                        /// Connection interval minimum
                        conn_par.intv_min = GAP_PPCP_CONN_INTV_MIN;
                        /// Connection interval maximum
                        conn_par.intv_max = GAP_PPCP_CONN_INTV_MAX;
                        /// Latency
                        conn_par.latency = GAP_PPCP_SLAVE_LATENCY;
                        /// Supervision timeout, Time = N * 10 msec
                        conn_par.time_out = GAP_PPCP_STO_MULT;
                        app_gap_param_update_req(((struct gap_le_create_conn_req_cmp_evt *)param)->conn_info.conhdl, &conn_par);
                    }
                }
            }
            break;

        case GLPS_DISABLE_IND:
            ke_timer_clear(APP_GLPS_MEAS_SEND_TIMER, TASK_APP);
            break;

        case GLPS_CFG_INDNTF_IND:
            if (app_glps_env->evt_cfg & GLPS_MEAS_NTF_CFG && !(((struct glps_cfg_indntf_ind *)param)->evt_cfg & GLPS_MEAS_NTF_CFG))
            {
                ke_timer_clear(APP_GLPS_MEAS_SEND_TIMER, TASK_APP);
            }

            if (app_glps_env->evt_cfg & GLPS_MEAS_CTX_NTF_CFG && !(((struct glps_cfg_indntf_ind *)param)->evt_cfg & GLPS_MEAS_CTX_NTF_CFG))
            {
                ke_timer_clear(APP_GLPS_MEAS_SEND_TIMER, TASK_APP);
            }
            break;

        case GLPS_RACP_REQ_IND:
        {
            uint8_t res;
            switch (((struct glps_racp_req_ind *)param)->racp_req.op_code)
            {
                case GLP_REQ_REP_STRD_RECS:         // Report stored records (Operator: Value from Operator Table)
                    res = app_glps_racp_procedure_handle(&app_glps_env->racp_req);
                    if (res == GLP_RSP_SUCCESS)
                    {    
                        ke_timer_set(APP_GLPS_MEAS_SEND_TIMER, TASK_APP, APP_GLPS_MEAS_SEND_TO);
                    }
                    else
                    {    
                        app_glps_racp_rsp_req_send(app_glps_env->conhdl, 0, GLP_REQ_REP_STRD_RECS, res);
                    }
                    break;

                case GLP_REQ_DEL_STRD_RECS:         // Delete stored records (Operator: Value from Operator Table)
                    app_glps_racp_rsp_req_send(app_glps_env->conhdl, 0, GLP_REQ_DEL_STRD_RECS, GLP_RSP_SUCCESS);
                    break;

                case GLP_REQ_ABORT_OP:              // Abort operation (Operator: Null 'value of 0x00 from Operator Table')
                    ke_timer_clear(APP_GLPS_MEAS_SEND_TIMER, TASK_APP);
                    app_glps_racp_rsp_req_send(app_glps_env->conhdl, 0, GLP_REQ_ABORT_OP, GLP_RSP_SUCCESS);
                    break;

                case GLP_REQ_REP_NUM_OF_STRD_RECS:  // Report number of stored records (Operator: Value from Operator Table)
                    res = app_glps_racp_procedure_handle(&app_glps_env->racp_req);
                    app_glps_racp_rsp_req_send(app_glps_env->conhdl, APP_GLPS_STROED_RECORDS_NUM, GLP_REQ_REP_NUM_OF_STRD_RECS, res);
                    break;

                default:
                    app_glps_racp_rsp_req_send(app_glps_env->conhdl, 0, ((struct glps_racp_req_ind *)param)->racp_req.op_code, GLP_RSP_OP_CODE_NOT_SUP);
                    break;
            }
            break;
        }

        default:
            break;
    }
}
示例#25
0
/**
 ****************************************************************************************
 * @brief   Application task message handler
 ****************************************************************************************
 */
void app_task_msg_hdl(ke_msg_id_t const msgid, void const *param)
{
    switch(msgid)
    {
        case GAP_SET_MODE_REQ_CMP_EVT:
            if(APP_IDLE == ke_state_get(TASK_APP))
            {
                usr_led1_set(LED_ON_DUR_ADV_FAST, LED_OFF_DUR_ADV_FAST);
                ke_timer_set(APP_ADV_INTV_UPDATE_TIMER, TASK_APP, 30 * 100);
#if (defined(QN_ADV_WDT))
                usr_env.adv_wdt_enable = true;
#endif
            }
            else if(APP_ADV == ke_state_get(TASK_APP))
            {
                usr_led1_set(LED_ON_DUR_ADV_SLOW, LED_OFF_DUR_ADV_SLOW);
#if (defined(QN_ADV_WDT))
                usr_env.adv_wdt_enable = true;
#endif
            }
            else if(APP_INIT == ke_state_get(TASK_APP))
            {
                const qn_tm_t time = {2013,8,20,14,40,00};
                
                // initialize ble time
                qn_time_init();
                
                // Set a real time, this is only a example.
                // User should use this function in other condition.
                qn_time_set(&time);
            }
            break;

        case GAP_ADV_REQ_CMP_EVT:
            usr_led1_set(LED_ON_DUR_IDLE, LED_OFF_DUR_IDLE);
            ke_timer_clear(APP_ADV_INTV_UPDATE_TIMER, TASK_APP);
            break;

        case GAP_DISCON_CMP_EVT:
            usr_led1_set(LED_ON_DUR_IDLE, LED_OFF_DUR_IDLE);
            usr_env.is_idle_connection_overtime = false;
            ke_timer_clear(APP_HTPT_IDLE_CONNECTION_TIMEOUT_TIMER, TASK_APP);
            break;

        case GAP_LE_CREATE_CONN_REQ_CMP_EVT:
            {
                const struct gap_le_create_conn_req_cmp_evt * const pconnect = param;
                if(pconnect->conn_info.status == CO_ERROR_NO_ERROR)
                {
                    if(GAP_PERIPHERAL_SLV == app_get_role())
                    {
                        // Update cnx parameters
                        app_param_update(pconnect);

                        // set idle connection timeout event
                        app_set_idle_connection();

#if (defined(QN_ADV_WDT))
                        usr_env.adv_wdt_enable = false;
#endif
                    }
                }
            }
            break;

        case HTPT_DISABLE_IND:
            if(! usr_env.is_temp_meas_config)
            {
                usr_env.is_meas_running = false;
                //always stop intermediate timer
                ke_timer_clear(APP_HTPT_PERIOD_MEAS_TIMER, TASK_APP);
            }
            break;

        case HTPT_CFG_INDNTF_IND:
            app_char_config_desc_change(param);
            break;

        case HTPT_TEMP_SEND_CFM:
            QPRINTF("Temperature send confirm: %d\r\n", ((struct gatt_notify_cmp_evt const *)param)->status);
            app_send_stored_meas();
            break;

        case HTPT_MEAS_INTV_CHG_IND:
            if(usr_env.is_temp_meas_config)
            {
                if(app_htpt_env->meas_intv != 0)
                {
                    ke_timer_set(APP_HTPT_PERIOD_MEAS_TIMER, TASK_APP,
                                app_htpt_env->meas_intv * 100); // trans unit from 1sec to 10ms
                }
                else
                {
                    ke_timer_clear(APP_HTPT_PERIOD_MEAS_TIMER, TASK_APP);
                }
            }
            break;

        default:
            break;
    }
}
示例#26
0
/**
 ****************************************************************************************
 * @brief  dealwith new configuration value
 ****************************************************************************************
 */
void app_char_config_desc_change(const struct htpt_cfg_indntf_ind *pcfg)
{
    switch (pcfg->char_code)
    {
        case HTPT_TEMP_MEAS_CHAR:
            if (pcfg->cfg_val == PRF_CLI_START_IND)
            {
                usr_env.is_temp_meas_config = true;

                // send store measure if sending is not busy
                if(! usr_env.is_meas_send_busy)
                    app_send_stored_meas();

                usr_env.meas_counter = 0;

                if(! usr_env.is_meas_running && app_htpt_env->meas_intv != 0)
                {
                    usr_env.is_meas_running = true;
                        
                    // measure and indicate immediately
                    usr_env.is_should_indicate = true;
                    start_measure_temperature();
            
                    ke_timer_set(APP_HTPT_PERIOD_MEAS_TIMER, TASK_APP, HTPT_PERIOD_MEAS_TIME);
                }
            }
            else
            {
                usr_env.is_temp_meas_config = false;
                usr_env.is_should_indicate = false;
                
                // clear store measure
                app_clear_stored_meas();
                
                if(! usr_env.is_temp_imeas_config && usr_env.is_meas_running)
                {
                    usr_env.is_meas_running = false;
                    ke_timer_clear(APP_HTPT_PERIOD_MEAS_TIMER, TASK_APP);
                }
            }
            break;

        case HTPT_INTERM_TEMP_CHAR:
            if (pcfg->cfg_val == PRF_CLI_START_NTF)
            {
                usr_env.is_temp_imeas_config = true;
                app_interm_temp_stable_status_reset();
                if(! usr_env.is_meas_running)
                {
                    usr_env.is_meas_running = true;
                    ke_timer_set(APP_HTPT_PERIOD_MEAS_TIMER, TASK_APP, HTPT_PERIOD_MEAS_TIME);
                }

            }
            else
            {
                usr_env.is_temp_imeas_config = false;
                usr_env.is_imeas_send_busy = false;
                if(! usr_env.is_temp_meas_config && usr_env.is_meas_running)
                {
                    usr_env.is_meas_running = false;
                    ke_timer_clear(APP_HTPT_PERIOD_MEAS_TIMER, TASK_APP);
                }
            }
            break;

        case HTPT_MEAS_INTV_CHAR:
            if (pcfg->cfg_val == PRF_CLI_START_IND)
            {
                usr_env.is_temp_interval_config = true;
                // This is not must
                app_htpt_measurement_intv_send(app_htpt_env->conhdl, app_htpt_env->meas_intv);
            }
            else
            {
                usr_env.is_temp_interval_config = false;
            }
            break;

        default:
            break;
    }
}
示例#27
0
int app_accel_timer_handler(ke_msg_id_t const msgid,
                                   void const *param,
                                   ke_task_id_t const dest_id,
                                   ke_task_id_t const src_id)
{
	  AxesRaw_t data;
		volatile unsigned char response;
		i8_t x_val_new,y_val_new,z_val_new;
//vm actual accel hardware used	

#if 0    
	if (!update_conn_params) {
		update_conn_params = 1;
//	    acc_init();

		// Not completely verified, but this improves the stability of the connection.
		
		struct gapc_param_update_req_ind * req = KE_MSG_ALLOC(GAPC_PARAM_UPDATE_REQ_IND, TASK_GAPC, TASK_APP, gapc_param_update_req_ind);

		// Fill in the parameter structure
		//req->conhdl = app_env.conhdl;
		req->params.intv_min = 80;
		req->params.intv_max = 80;
		req->params.latency = 0;
		req->params.time_out = 2000;
		ke_msg_send(req);
	}
#endif
	if (update_conn_params) {
        rwip_env.sleep_enable = true;
        if(update_conn_params != 2)
        {
            update_conn_params = 0;            
            ke_timer_clear(APP_ACCEL_TIMER, TASK_APP);
            return (KE_MSG_CONSUMED);
        }
        update_conn_params = 0;            
    }
    
#if 1
	LIS3DH_ReadReg(LIS3DH_STATUS_REG, &response);
	if (response & 8) 
	{

		response = LIS3DH_GetAccAxesRaw(&data);
		data.AXIS_X = data.AXIS_X/256;//acc_read_x();
		data.AXIS_Y = data.AXIS_Y/256;//acc_read_y();
		data.AXIS_Z = data.AXIS_Z/256;//acc_read_z();
		
		if((data.AXIS_X)>50)
			data.AXIS_X = 50; 
		if((data.AXIS_X)<-50)
			data.AXIS_X = -50; 

		if((data.AXIS_Y)>50)
			data.AXIS_Y = 50; 
		if((data.AXIS_Y)<-50)
			data.AXIS_Y = -50; 

		if((data.AXIS_Z)>50)
			data.AXIS_Z = 50; 
		if((data.AXIS_Z)<-50)
			data.AXIS_Z = -50; 
		
		x_val_new = data.AXIS_X;
		y_val_new = data.AXIS_Y;
		z_val_new = data.AXIS_Z;

//	if ((x_val_new!=x_val)||(y_val_new!=y_val)||(z_val_new!=z_val))
	{
    //send value change request to ACCEL profile
    struct accel_value_req *req = KE_MSG_ALLOC(ACCEL_VALUE_REQ, TASK_ACCEL,
                                                TASK_APP, accel_value_req);
//vm
		req->accel[0] = x_val_new;//data.AXIS_X/256;//acc_read_x();
    req->accel[1] = y_val_new;// data.AXIS_Y/256;//acc_read_y();
    req->accel[2] = z_val_new;// data.AXIS_Z/256;//acc_read_z();

// 		x_val = x_val_new;
// 		y_val = y_val_new;
// 		z_val = z_val_new;
		
    ke_msg_send(req);
	}
}
#endif
//vm simulated accel reading
#if 0   //GZ tmp	

    //send value change request to ACCEL profile
    struct accel_value_req *req = KE_MSG_ALLOC(ACCEL_VALUE_REQ, TASK_ACCEL,
                                                TASK_APP, accel_value_req);
		req->accel[0] = x_val;//data.AXIS_X;//acc_read_x();
    req->accel[1] = y_val;//data.AXIS_Y;//acc_read_y();
    req->accel[2] = z_val;//data.AXIS_Z;//acc_read_z();
    ke_msg_send(req);

x_val++;
y_val++;
z_val++;	
#endif	
    // Restart the accelerometer timer
    ke_timer_set(APP_ACCEL_TIMER, dest_id, 5);


    return (KE_MSG_CONSUMED);
}
示例#28
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref GATT_HANDLE_VALUE_IND message.
 * @param[in] msgid Id of the message received (probably unused).
 * @param[in] param Pointer to the parameters of the message.
 * @param[in] dest_id ID of the receiving task instance (probably unused).
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int gatt_handle_value_ind_handler(ke_msg_id_t const msgid,
                                         struct gatt_handle_value_ind const *param,
                                         ke_task_id_t const dest_id,
                                         ke_task_id_t const src_id)
{
    // Get the address of the environment
    struct cscpc_env_tag *cscpc_env = PRF_CLIENT_GET_ENV(dest_id, cscpc);

    if (cscpc_env != NULL)
    {
        // Check if we were waiting for the indication
        if (cscpc_env->operation != NULL)
        {
            if (((struct cscpc_cmd *)cscpc_env->operation)->operation == CSCPC_CTNL_PT_CFG_IND_OP_CODE)
            {
                // Stop the procedure timeout timer
                ke_timer_clear(CSCPC_TIMEOUT_TIMER_IND, dest_id);

                // CSC Measurement value has been received
                struct cscpc_value_ind *ind = KE_MSG_ALLOC(CSCPC_VALUE_IND,
                                                           cscpc_env->con_info.appid,
                                                           cscpc_env->con_info.prf_id,
                                                           cscpc_value_ind);

                // Connection Handle
                ind->conhdl   = param->conhdl;
                // Attribute code
                ind->att_code = CSCPC_IND_SC_CTNL_PT;

                // Requested operation code
                ind->value.ctnl_pt_rsp.req_op_code = param->value[1];
                // Response value
                ind->value.ctnl_pt_rsp.resp_value  = param->value[2];

                // Get the list of supported sensor locations if needed
                if ((ind->value.ctnl_pt_rsp.req_op_code == CSCP_CTNL_PT_OP_REQ_SUPP_LOC) &&
                    (ind->value.ctnl_pt_rsp.resp_value == CSCP_CTNL_PT_RESP_SUCCESS) &&
                    (param->size > 3))
                {
                    // Get the number of supported locations that have been received
                    uint8_t nb_supp_loc = (param->size - 3);
                    // Counter
                    uint8_t counter;
                    // Location
                    uint8_t loc;

                    for (counter = 0; counter < nb_supp_loc; counter++)
                    {
                        loc = param->value[counter + 3];

                        // Check if valid
                        if (loc < CSCP_LOC_MAX)
                        {
                            ind->value.ctnl_pt_rsp.supp_loc |= (1 << loc);
                        }
                    }
                }

                // Send the message
                ke_msg_send(ind);

                // Send the complete event message
                cscpc_send_cmp_evt(cscpc_env, CSCPC_CTNL_PT_CFG_WR_OP_CODE, PRF_ERR_OK);
            }
            // else drop the message
        }
        // else drop the message
    }
    // else ignore the message

    return (KE_MSG_CONSUMED);
}
示例#29
0
/**
 ****************************************************************************************
 * @brief   Application task message handler
 ****************************************************************************************
 */
void app_task_msg_hdl(ke_msg_id_t const msgid, void const *param)
{
    switch(msgid)
    {
        case GAP_SET_MODE_REQ_CMP_EVT:
            if(APP_IDLE == ke_state_get(TASK_APP))
            {
                usr_led1_set(LED_ON_DUR_ADV_FAST, LED_OFF_DUR_ADV_FAST);
				  //delay some time let adv slow
                ke_timer_set(APP_ADV_INTV_UPDATE_TIMER, TASK_APP, 30 * 100);
            }
            else if(APP_ADV == ke_state_get(TASK_APP))
            {
                usr_led1_set(LED_ON_DUR_ADV_SLOW, LED_OFF_DUR_ADV_SLOW);
            }
            break;

        case GAP_ADV_REQ_CMP_EVT:
            usr_led1_set(LED_ON_DUR_IDLE, LED_OFF_DUR_IDLE);
            ke_timer_clear(APP_ADV_INTV_UPDATE_TIMER, TASK_APP);
            break;

        case GAP_DISCON_CMP_EVT:
            usr_led1_set(LED_ON_DUR_IDLE, LED_OFF_DUR_IDLE);

            // start adv
            app_gap_adv_start_req(GAP_GEN_DISCOVERABLE|GAP_UND_CONNECTABLE,
                    app_env.adv_data, app_set_adv_data(GAP_GEN_DISCOVERABLE),
                    app_env.scanrsp_data, app_set_scan_rsp_data(app_get_local_service_flag()),
                    GAP_ADV_FAST_INTV1, GAP_ADV_FAST_INTV2);
            break;

        case GAP_LE_CREATE_CONN_REQ_CMP_EVT:
            if(((struct gap_le_create_conn_req_cmp_evt *)param)->conn_info.status == CO_ERROR_NO_ERROR)
            {
                if(GAP_PERIPHERAL_SLV == app_get_role())
                {
                    ke_timer_clear(APP_ADV_INTV_UPDATE_TIMER, TASK_APP);
                    usr_led1_set(LED_ON_DUR_CON, LED_OFF_DUR_CON);

                    // Update cnx parameters
                    //if (((struct gap_le_create_conn_req_cmp_evt *)param)->conn_info.con_interval >  IOS_CONN_INTV_MAX)
                    {
                        // Update connection parameters here
                        struct gap_conn_param_update conn_par;
                        /// Connection interval minimum
                        conn_par.intv_min = IOS_CONN_INTV_MIN;
                        /// Connection interval maximum
                        conn_par.intv_max = IOS_CONN_INTV_MAX;
                        /// Latency
                        conn_par.latency = IOS_SLAVE_LATENCY;
                        /// Supervision timeout, Time = N * 10 msec
                        conn_par.time_out = IOS_STO_MULT;
                        app_gap_param_update_req(((struct gap_le_create_conn_req_cmp_evt *)param)->conn_info.conhdl, &conn_par);
                    }
                }
            }
            break;

        case QPPS_DISABLE_IND:
            break;

        case QPPS_CFG_INDNTF_IND:
            break;

        default:
            break;
    }
}
示例#30
0
void app_batt_poll_stop(void)
{
  ke_timer_clear(APP_BATT_TIMER, TASK_APP);
}