/**
 ****************************************************************************************
 * @brief Handles GAP manager command complete events.
 *
 * @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 gapm_cmp_evt_handler(ke_msg_id_t const msgid,
                                struct gapm_cmp_evt const *param,
                                ke_task_id_t const dest_id,
                                ke_task_id_t const src_id)
{
    switch(param->operation) {
    // reset completed
    case GAPM_RESET:
        if(param->status != GAP_ERR_NO_ERROR) {
            ASSERT_ERR(0); // unexpected error
        }
        else {
            // set device configuration
            struct gapm_set_dev_config_cmd* cmd = KE_MSG_ALLOC(GAPM_SET_DEV_CONFIG_CMD,
                    TASK_GAPM, TASK_APP, gapm_set_dev_config_cmd);

            app_configuration_func(dest_id, cmd);

            ke_msg_send(cmd);
        }
        break;
    // device configuration updated
    case GAPM_SET_DEV_CONFIG:
        if(param->status != GAP_ERR_NO_ERROR) {
            ASSERT_ERR(0); // unexpected error
        }
        else {
            app_set_dev_config_complete_func();
        }
        break;
    // Advertising finished
    case GAPM_ADV_UNDIRECT:
        app_adv_undirect_complete(param->status);
        break;
    // Directed advertising finished
    case GAPM_ADV_DIRECT:
        app_adv_direct_complete(param->status);  
        break;
    case GAPM_RESOLV_ADDR:
    case GAPM_ADD_DEV_IN_WLIST:
    case GAPM_RMV_DEV_FRM_WLIST:
#if (USE_CONNECTION_FSM)
        app_con_fsm_handle_cmp_evt(param);
#endif
        break;
    case GAPM_CANCEL:
        if(param->status != GAP_ERR_NO_ERROR) {
            ASSERT_ERR(0); // unexpected error
        }
        break;
    default:
        ASSERT_ERR(0); // unexpected error
        break;
    }

    return (KE_MSG_CONSUMED);
}
Beispiel #2
0
/**
 ****************************************************************************************
 * @brief Handles GAP manager command complete events.
 *
 * @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 gapm_cmp_evt_handler(ke_msg_id_t const msgid,
                                struct gapm_cmp_evt const *param,
                                ke_task_id_t const dest_id,
                                ke_task_id_t const src_id)
{	
    switch(param->operation)
    {
        // reset completed
        case GAPM_RESET:
        {
            if(param->status != GAP_ERR_NO_ERROR)
            {
                ASSERT_ERR(0); // unexpected error
            }
            else
            {

                // set device configuration
                struct gapm_set_dev_config_cmd* cmd = KE_MSG_ALLOC(GAPM_SET_DEV_CONFIG_CMD,
                        TASK_GAPM, TASK_APP, gapm_set_dev_config_cmd);

                app_configuration_func(dest_id, cmd);

                ke_msg_send(cmd);
            }
        }
        break;

        // device configuration updated
        case GAPM_SET_DEV_CONFIG:
        {
            if(param->status != GAP_ERR_NO_ERROR)
            {
                ASSERT_ERR(0); // unexpected error
            }
            else
            {
              app_set_dev_config_complete_func();
            }
        }
        break;

        // Advertising finished
        case GAPM_ADV_UNDIRECT:
        {
            app_adv_undirect_complete(param->status);
        }
        break;
        
        // Directed advertising finished
        case GAPM_ADV_DIRECT:
        {
            app_adv_direct_complete(param->status);  
        }
        break;
				
        case GAPM_SCAN_PASSIVE:
		case GAPM_SCAN_ACTIVE:
        {
            if (param->status == GAP_ERR_CANCELED)
            {
                app_connect();
            }						
            else 
            {
                app_scanning();
            }
        }				
        break;
        /* end */
				
        case GAPM_CANCEL:
        {
            if(param->status != GAP_ERR_NO_ERROR)
            {
                ASSERT_ERR(0); // unexpected error
            }
        }
		case GAPM_CONNECTION_DIRECT:
            if (param->status == GAP_ERR_CANCELED)
            {
				app_connect_failed_func();
            }
				break;
        default:
        {
            ASSERT_ERR(0); // unexpected error
        }
        break;
    }
		
    return (KE_MSG_CONSUMED);
}