Ejemplo n.º 1
0
/**
 ****************************************************************************************
 * @brief Handles button press after cancel the jitter.
 *
 * @param[in] msgid     Id of the message received
 * @param[in] param     None
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_APP
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int app_button_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)
{
    switch(msgid)
    {
        case APP_SYS_BUTTON_1_TIMER:
            // make sure the button is pressed
            if(gpio_read_pin(BUTTON1_PIN) == GPIO_LOW)
            {
                if(APP_IDLE == ke_state_get(TASK_APP))
                {
                    struct app_proxr_env_tag *app_proxr_env = &app_env.proxr_ev;
                    if(!app_proxr_env->enabled)
                    {
                        // 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);

#if (QN_DEEP_SLEEP_EN)
                        // prevent entering into deep sleep mode
                        sleep_set_pm(PM_SLEEP);
#endif
#if	(FB_OLED)
		ke_timer_set(APP_OLED_STATE_DISPlAY_TIMER,TASK_APP,20);
#endif
                    }
                }
                else if(APP_ADV == ke_state_get(TASK_APP))
                {
                    // stop adv
                    app_gap_adv_stop_req();

#if (QN_DEEP_SLEEP_EN)
                    // allow entering into deep sleep mode
                    sleep_set_pm(PM_DEEP_SLEEP);
#endif
#if	(FB_OLED)
		ke_timer_set(APP_OLED_STATE_DISPlAY_TIMER,TASK_APP,20);
#endif
                }
            }
            break;

        case APP_SYS_BUTTON_2_TIMER:
            if(gpio_read_pin(BUTTON2_PIN) == GPIO_LOW)
            {
                buzzer_off();
            }
            break;

        default:
            ASSERT_ERR(0);
            break;
    }

    return (KE_MSG_CONSUMED);
}
Ejemplo n.º 2
0
void app_neb_msg_rx_resp_cycle_dur(struct app_neb_msg_resp_cycle_dur* msg)
{
    uint8_t status = NEB_ERR_SUCCESS;

    if(msg->duration != 0 && (ke_state_get(TASK_APP_NEB) == APP_NEB_CONNECTED))
    {
        // Allocate message to profile
        struct nbps_neb_record_send_req *req = KE_MSG_ALLOC(NBPS_NEB_RECORD_SEND_REQ,
                TASK_NBPS, TASK_APP_NEB,
                nbps_neb_record_send_req);
        req->conhdl = app_neb_env.conhdl;
        req->neb_rec.neb_id = app_neb_env.curr_neb_id;
        req->neb_rec.rec_id = app_neb_env.next_rec_id;
        req->neb_rec.flags = NEB_REC_RESP_DUR_FLAG;

        // Parameters
        req->neb_rec.resp_cycle_dur = msg->duration;

        ke_msg_send(req);

        // Increment record ID
        app_neb_env.next_rec_id++;
    }

    // Confirm the message
    app_neb_msg_tx_confirm_basic(NEB_MSG_ID_RESP_CYCLE_DUR, status);
}
Ejemplo n.º 3
0
void prf_client_disable_ind_send(prf_env_struct ***p_envs, ke_msg_id_t msg_id,
                                 ke_task_id_t task_id, uint8_t state, uint16_t conhdl)
{
    // retrieve current state
    uint8_t cur_state = ke_state_get(task_id);

    // prevent doing freeing structure if state already of profile is already free.
    if(cur_state != state)
    {
        // Get the address of the environment
        prf_env_struct *env = prf_client_get_env(*p_envs, task_id);

        ASSERT_WARN(env != NULL);

        if (env != NULL)
        {
            struct prf_client_disable_ind *ind = KE_MSG_ALLOC(msg_id,
                                                 env->con_info.appid, env->con_info.prf_id,
                                                 prf_client_disable_ind);

            ind->conhdl    = conhdl;
            ind->status    = prf_client_disable(p_envs, KE_IDX_GET(env->con_info.prf_id));

            // Send the message
            ke_msg_send(ind);

            // Go to idle state
            ke_state_set(task_id, state);
        }
    }
}
Ejemplo n.º 4
0
void rscpc_send_cmp_evt(struct rscpc_env_tag *rscpc_env, uint8_t operation, uint8_t status)
{
    // Free the stored operation if needed
    if (rscpc_env->operation != NULL)
    {
        ke_msg_free(ke_param2msg(rscpc_env->operation));
        rscpc_env->operation = NULL;
    }

    // Go back to the CONNECTED state if the state is busy
    if (ke_state_get(rscpc_env->con_info.prf_id) == RSCPC_BUSY)
    {
        ke_state_set(rscpc_env->con_info.prf_id, RSCPC_CONNECTED);
    }

    // Send the message
    struct rscpc_cmp_evt *evt = KE_MSG_ALLOC(RSCPC_CMP_EVT,
                                             rscpc_env->con_info.appid, rscpc_env->con_info.prf_id,
                                             rscpc_cmp_evt);

    evt->conhdl     = gapc_get_conhdl(rscpc_env->con_info.conidx);
    evt->operation  = operation;
    evt->status     = status;

    ke_msg_send(evt);
}
Ejemplo n.º 5
0
/**
 ****************************************************************************************
 * @brief Handles reception of the APP_MODULE_INIT_CMP_EVT messgage
 * @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_module_init_cmp_evt_handler(ke_msg_id_t const msgid,
                                           const struct app_module_init_cmp_evt *param,
                                           ke_task_id_t const dest_id,
                                           ke_task_id_t const src_id)
{
    if (ke_state_get(dest_id) == APP_DB_INIT)
    {
        if (param->status == CO_ERROR_NO_ERROR)
        {
            // Add next required service in the database
            if (app_db_init())
            {
                // No more service to add in the database, start application
                app_db_init_complete_func();
            }
        }
        else
        {
            // An error has occurred during database creation
            ASSERT_ERR(0);
        }
    }
    else
    {
        // APP_DB_INIT state is used to wait the APP_MODULE_INIT_CMP_EVT message
        ASSERT_ERR(0);
    }
    
    return (KE_MSG_CONSUMED);
}
void app_disconnect_func(ke_task_id_t task_id, struct gapc_disconnect_ind const *param)
{
    
    uint8_t state = ke_state_get(task_id);
    
#if BLE_BATT_SERVER
 app_batt_poll_stop();
#endif // BLE_BATT_SERVER
    
    if ((state == APP_SECURITY) || (state == APP_CONNECTED)  || (state == APP_PARAM_UPD))
    {
        
/**************************************************
            Handle disconnection event
***************************************************/    

        // Restart Advertising
			 //app_adv_start();	


    }
    else
    {
        // We are not in a Connected State
        ASSERT_ERR(0);
    }
      
}    
Ejemplo n.º 7
0
static int htpt_create_db_cfm_handler(ke_msg_id_t const msgid,
                                      struct htpt_create_db_cfm const *param,
                                      ke_task_id_t const dest_id,
                                      ke_task_id_t const src_id)
{
    if (ke_state_get(dest_id) == APP_HT_DISABLED)
    {
        if (param->status == PRF_ERR_OK)
        {
            // Go to Idle state
            ke_state_set(TASK_APP_HT, APP_HT_IDLE);
        }

        // Inform the Application Manager
        struct app_module_init_cmp_evt *cfm = KE_MSG_ALLOC(APP_MODULE_INIT_CMP_EVT,
                                                           TASK_APP, TASK_APP_HT,
                                                           app_module_init_cmp_evt);

        cfm->status = param->status;

        ke_msg_send(cfm);
    }

    return (KE_MSG_CONSUMED);
}
Ejemplo n.º 8
0
/**
 ****************************************************************************************
 * @brief Handles GAP controller 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 gapc_cmp_evt_handler(ke_msg_id_t const msgid,
                                struct gapc_cmp_evt const *param,
                                ke_task_id_t const dest_id,
                                ke_task_id_t const src_id)
{
    switch(param->operation) {
    // reset completed
    case GAPC_UPDATE_PARAMS:
        if (ke_state_get(dest_id) == APP_PARAM_UPD) {
            if ((param->status != CO_ERROR_NO_ERROR)) {
                // it's application specific what to do when the Param Upd request is rejected
                app_update_params_rejected_func(param->status);
            }
            else {
                // Go to Connected State
                ke_state_set(dest_id, APP_CONNECTED);

                // if state is APP_CONNECTED then the request was accepted
                app_update_params_complete_func();
            }
        }
        break;
    default:
        if(param->status != GAP_ERR_NO_ERROR) {
            ASSERT_ERR(0); // unexpected error
        }
        break;
    }

    return (KE_MSG_CONSUMED);
}
Ejemplo n.º 9
0
/**
****************************************************************************************
* @brief Function called to send a message through UART.
*
* @param[in]  msgid   U16 message id from ke_msg.
* @param[in] *param   Pointer to parameters of the message in ke_msg.
* @param[in]  dest_id Destination task id.
* @param[in]  src_id  Source task ID.
*
* @return             Kernel message state, must be KE_MSG_NO_FREE.
*****************************************************************************************
*/
static int my_gtl_msg_send_handler (ke_msg_id_t const msgid,
                          void *param,
                          ke_task_id_t const dest_id,
                          ke_task_id_t const src_id)
{
     //extract the ke_msg pointer from the param passed and push it in GTL queue
    struct ke_msg *msg = ke_param2msg(param);

    // Check if there is no transmission ongoing
    if (ke_state_get(TASK_GTL) != GTL_TX_IDLE)
    {
        if(gtl_env.tx_queue.tx_data_packet > MAX_GTL_PENDING_PACKETS_ADV)
        {
            if(msgid == GAPM_ADV_REPORT_IND || gtl_env.tx_queue.tx_data_packet > MAX_GTL_PENDING_PACKETS)
                return KE_MSG_CONSUMED;
        }
        co_list_push_back(&gtl_env.tx_queue, &(msg->hdr));
    }
    else
    {
        // send the message
        gtl_send_msg(msg);

        // Set GTL task to TX ONGOING state
        ke_state_set(TASK_GTL, GTL_TX_ONGOING);
    }

    //return NO_FREE always since gtl_eif_write handles the freeing
    return KE_MSG_NO_FREE;
}
Ejemplo n.º 10
0
/**
 ****************************************************************************************
 * @brief Handles UART data indication.
 *
 * @param[in] msgid      APP_SYS_UART_DATA_IND
 * @param[in] param      Pointer to struct app_uart_data_ind
 * @param[in] dest_id    TASK_APP
 * @param[in] src_id     TASK_APP
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int app_uart_data_ind_handler(ke_msg_id_t const msgid, struct app_uart_data_ind const *ind,
                               ke_task_id_t const dest_id, ke_task_id_t const src_id)
{
    switch (ke_state_get(dest_id))
    {
    case APP_INIT:
        break;
    case APP_IDLE:
    default:
#if QN_EACI
        app_eaci_msg_hdl((src_id >> 8) & 0xFF,
                                src_id & 0xFF,
                                ind->len,
                                ind->data);
#elif QN_DEMO_MENU
        if (ind->len != 0)
        {
            memcpy(app_env.input, ind->data, ind->len);
            app_menu_hdl();
        }
#endif
        break;
    }

#if (QN_EACI&&(EACI_MSG_BUFFER_EN==TRUE))
    return (KE_MSG_NO_FREE);
#else
    return (KE_MSG_CONSUMED);
#endif
}
Ejemplo n.º 11
0
bool check_gtl_state(void)
{
    uint8_t ret = true;

#if BLE_HOST_PRESENT	
    if ((ke_state_get(TASK_GTL) != GTL_TX_IDLE) ||
            ((gtl_env.rx_state != GTL_STATE_RX_START) &&
            (gtl_env.rx_state != GTL_STATE_RX_OUT_OF_SYNC)) )
            ret = false;
#else
    if ((ke_state_get(TASK_HCI) != HCI_STATE_TX_IDLE) ||
            ((hci_env.rx_state != HCI_STATE_RX_START) &&
            (hci_env.rx_state != HCI_STATE_RX_OUT_OF_SYNC)) )
            ret = false;

#endif
    return ret;
}
Ejemplo n.º 12
0
/**
 ****************************************************************************************
 * @brief Handles button press after cancel the jitter.
 *
 * @param[in] msgid     Id of the message received
 * @param[in] param     None
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_APP
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int app_button_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)
{
    switch(msgid)
    {
        case APP_SYS_BUTTON_1_TIMER:
            // make sure the button is pressed
            if (gpio_read_pin(BUTTON1_PIN) == GPIO_LOW)
            {
                if (APP_IDLE == ke_state_get(TASK_APP))
                {
                    // start adv
                    app_gap_adv_start_req(GAP_GEN_DISCOVERABLE,
                                          adv_data, sizeof(adv_data), 
                                          scan_data, sizeof(scan_data),
                                          GAP_ADV_INTV1, GAP_ADV_INTV2);

                    ke_state_set(TASK_APP, APP_ADV);
#if (QN_DEEP_SLEEP_EN)
                        // prevent entering into deep sleep mode
                        sleep_set_pm(PM_SLEEP);
#endif
                }
                else if (APP_ADV == ke_state_get(TASK_APP))
                {
                    // stop adv
                    app_gap_adv_stop_req();

                    ke_state_set(TASK_APP, APP_IDLE);
#if (QN_DEEP_SLEEP_EN)
                    // allow entering into deep sleep mode
                    sleep_set_pm(PM_DEEP_SLEEP);
#endif
                }
            }
            break;

        default:
            ASSERT_ERR(0);
            break;
    }

    return (KE_MSG_CONSUMED);
}
Ejemplo n.º 13
0
void app_neb_msg_rx_start(struct app_neb_msg_start* msg)
{
    uint8_t status = NEB_ERR_SUCCESS;

    // Check parameters
    switch (msg->reason)
    {
        case NEB_MSG_START_REASON_START:
        {
            // Increment nebulizer ID
            app_neb_env.curr_neb_id++;

            #if (NVDS_SUPPORT)
            // Put the current nebulizer ID into storage
            nvds_put(NVDS_TAG_NEB_ID, NVDS_LEN_NEB_ID, (uint8_t *)&app_neb_env.curr_neb_id);
            #endif // NVDS_SUPPORT

            // Clear record ID
            app_neb_env.next_rec_id = 0;
        }
        break;
        case NEB_MSG_START_REASON_RESTART:
        break;
        default:
        {
            status = NEB_ERR_INVALID_PARAMS;
        }
        break;
    }

    if ((status == NEB_ERR_SUCCESS) && (ke_state_get(TASK_APP_NEB) == APP_NEB_CONNECTED))
    {
        // Allocate message to profile
        struct nbps_neb_record_send_req *req = KE_MSG_ALLOC(NBPS_NEB_RECORD_SEND_REQ,
                TASK_NBPS, TASK_APP_NEB,
                nbps_neb_record_send_req);
        req->conhdl = app_neb_env.conhdl;
        req->neb_rec.neb_id = app_neb_env.curr_neb_id;
        req->neb_rec.rec_id = app_neb_env.next_rec_id;
        req->neb_rec.flags = NEB_REC_START_FLAG;

        // Parameters
        req->neb_rec.reason = msg->reason;

        // Get absolute time stamp
        app_neb_insert_abs_time(req);

        ke_msg_send(req);

        // Increment record ID
        app_neb_env.next_rec_id++;
    }

    // Confirm the message
    app_neb_msg_tx_confirm_basic(NEB_MSG_ID_START, status);
}
Ejemplo n.º 14
0
/**
 ****************************************************************************************
 * @brief Handles accelerometer start advertising request from the Wakeup ISR.
 *
 * @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 accel_msg_handler(ke_msg_id_t const msgid,
									struct accel_create_db_cfm const *param,
									ke_task_id_t const dest_id,
									ke_task_id_t const src_id)
{
	// If state is not idle, ignore the message
	if (ke_state_get(dest_id) == APP_CONNECTABLE)
		app_adv_start();

	return (KE_MSG_CONSUMED);
}
Ejemplo n.º 15
0
/**
 ****************************************************************************************
 * @brief   Start the device to advertising process.
 ****************************************************************************************
 */
void app_start_adv(void)
{
    if(! app_htpt_env->enabled)
    {
        if(APP_IDLE == ke_state_get(TASK_APP))
        {
            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);
        }
    }
}
Ejemplo n.º 16
0
void cpps_send_cmp_evt(uint8_t src_id, uint8_t dest_id, uint16_t conhdl,
                        uint8_t operation, uint8_t status)
{
    // Go back to the Connected state if the state is busy
    if ((ke_state_get(src_id) == CPPS_BUSY)
        || (ke_state_get(src_id) == CPPS_WAIT_FOR_CFM))
    {
        ke_state_set(src_id, CPPS_CONNECTED);
    }

    // Set the operation code
    cpps_env.operation = CPPS_RESERVED_OP_CODE;

    // Send the message
    struct cpps_cmp_evt *evt = KE_MSG_ALLOC(CPPS_CMP_EVT,
                                             dest_id, src_id,
                                             cpps_cmp_evt);

    evt->conhdl     = conhdl;
    evt->operation  = operation;
    evt->status     = status;

    ke_msg_send(evt);
}
Ejemplo n.º 17
0
/**
 ****************************************************************************************
 * @brief Handles advertising mode timer event.
 *
 * @param[in] msgid     APP_ADV_INTV_UPDATE_TIMER
 * @param[in] param     None
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_APP
 *
 * @return If the message was consumed or not.
 * @description
 *
 * This handler is used to inform the application that first phase of adversting mode is timeout.
 ****************************************************************************************
 */
int app_gap_adv_intv_update_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)
{
    if(APP_ADV == ke_state_get(TASK_APP))
    {
        usr_led1_set(LED_ON_DUR_IDLE, LED_OFF_DUR_IDLE);

        // Update Advertising Parameters
        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_SLOW_INTV, GAP_ADV_SLOW_INTV);
        }

    return (KE_MSG_CONSUMED);
}
/**
****************************************************************************************
* @brief Handles Sample128 profile database creation confirmation.
*
* @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 sample128_create_db_cfm_handler(ke_msg_id_t const msgid,
																			 struct sample128_create_db_cfm const *param,
																				ke_task_id_t const dest_id,
																			 ke_task_id_t const src_id)
{
	 // If state is not idle, ignore the message
	 if (ke_state_get(dest_id) == APP_DB_INIT)
	 {
		 // Inform the Application Manager
		 struct app_module_init_cmp_evt *cfm = KE_MSG_ALLOC(APP_MODULE_INIT_CMP_EVT,
		 TASK_APP, TASK_APP,
		 app_module_init_cmp_evt);
		 cfm->status = param->status;
		 ke_msg_send(cfm);
	 }
	 return (KE_MSG_CONSUMED);
}
Ejemplo n.º 19
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);
}
Ejemplo n.º 20
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);
        app_connection_func(param);
    }
    else {
        // APP_CONNECTABLE state is used to wait the GAP_LE_CREATE_CONN_REQ_CMP_EVT message
        ASSERT_ERR(0);
    }

    return (KE_MSG_CONSUMED);
}
/**
 ****************************************************************************************
 * @brief This function handles the disconnection and also restarts the advertising or scanning
 *
 * @param[in] task_id 				Destination task id.
 * @param[in] param 					Pointer to the parameters of the message. 
 *
 * @return void
 ****************************************************************************************
 */
void app_disconnect_func(ke_task_id_t task_id, struct gapc_disconnect_ind const *param)
{
    uint8_t state = ke_state_get(task_id);
    if ((param->reason != CO_ERROR_REMOTE_USER_TERM_CON) && (param->reason != CO_ERROR_CON_TERM_BY_LOCAL_HOST))
    {
        app_reset_app();     	// link loss (timer timeout)  //reset higher layers
        
        // Reset the environment **this is important because otherwise the profile att database will not be re-initiated**
        memset(&app_env, 0, sizeof(app_env));
        
        // Initialize next_prf_init value for first service to add in the database
        app_env.next_prf_init = APP_PRF_LIST_START + 1;
    }
    else
    {
        app_scanning();				// both devices are disconnected correctly
    }
}
Ejemplo n.º 22
0
void app_neb_msg_rx_stop(struct app_neb_msg_stop* msg)
{
    uint8_t status = NEB_ERR_SUCCESS;

    // Check parameters
    switch (msg->reason)
    {
        case NEB_MSG_STOP_REASON_USER:
        case NEB_MSG_STOP_REASON_LOW_BATT:
        case NEB_MSG_STOP_REASON_AUTO:
            break;
        default:
        {
            status = NEB_ERR_INVALID_PARAMS;
        }
        break;
    }

    if ((status == NEB_ERR_SUCCESS) && (ke_state_get(TASK_APP_NEB) == APP_NEB_CONNECTED))
    {
        // Allocate message to profile
        struct nbps_neb_record_send_req *req = KE_MSG_ALLOC(NBPS_NEB_RECORD_SEND_REQ,
                TASK_NBPS, TASK_APP_NEB,
                nbps_neb_record_send_req);
        req->conhdl = app_neb_env.conhdl;
        req->neb_rec.neb_id = app_neb_env.curr_neb_id;
        req->neb_rec.rec_id = app_neb_env.next_rec_id;
        req->neb_rec.flags = NEB_REC_STOP_FLAG;

        // Parameters
        req->neb_rec.reason = msg->reason;

        // Get absolute time stamp
        app_neb_insert_abs_time(req);

        ke_msg_send(req);

        // Increment record ID
        app_neb_env.next_rec_id++;
    }

    // Confirm the message
    app_neb_msg_tx_confirm_basic(NEB_MSG_ID_STOP, status);
}
Ejemplo n.º 23
0
void prf_client_enable_error(prf_env_struct ***p_envs, ke_task_id_t prf_task_id,
                             ke_state_t disc_state, ke_state_t idle_state)
{
    /* An error has been raised, three possibilities:
     *      - Either the state is IDLE, no environment has been created, nothing to do,
     *      - Or the state is DISCOVERING, we need to come back to the IDLE state and to remove the
     * environment,
     *      - Or the state is CONNECTED, the profile was already connected for the provided connection,
     * nothing to do
     */
    if (ke_state_get(prf_task_id) == disc_state)
    {
        // Come back to IDLE State
        ke_state_set(prf_task_id, idle_state);

        // Remove the allocated environment
        prf_client_disable(p_envs, KE_IDX_GET(prf_task_id));
    }
}
Ejemplo n.º 24
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);
}
Ejemplo n.º 25
0
/*
 * Name         : app_hid_timer_handler - Handler of the HID Timer 
 *
 * Scope        : PUBLIC
 *
 * Arguments    : <various>
 *
 * Description  : Sends a Connection Parameters Update Request to the Host
 *
 * Returns      : KE_MSG_CONSUMED
 *
 */
int app_hid_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)
{
//	arch_puts("app_hid_timer_handler()\r\n");
	
    ke_state_t app_state = ke_state_get(TASK_APP);
    
	// Modify Conn Params
	if (app_state == APP_SECURITY || app_state == APP_PARAM_UPD || app_state == APP_CONNECTED) 
	{
		struct gapc_param_update_cmd * req = KE_MSG_ALLOC(GAPC_PARAM_UPDATE_CMD, TASK_GAPC, TASK_APP, gapc_param_update_cmd);

        req->operation = GAPC_UPDATE_PARAMS;
		// Fill in the parameter structure
		req->params.intv_min = 8;	    // N * 1.25ms
		req->params.intv_max = 8;	    // N * 1.25ms
		req->params.latency  = 23;		// Conn Events skipped
		req->params.time_out = 200;		// N * 10ms
		arch_puts("Send GAP_PARAM_UPDATE_REQ\r\n");
		ke_msg_send(req);
        
        ke_state_set(TASK_APP, APP_PARAM_UPD);
	}
	
    // Keyboard test can start here!
    uint32_t press = 100000;    // 100 msec
    uint32_t release = 235000;  // 235 msec
    uint32_t press_incr = 0;    // 0 usec
    uint32_t release_incr = 10; // 10 usec
    uint32_t limit = 275000;    // 275 msec
    
    if ( !start_kbd_single_test(press, press_incr, release, release_incr, limit) ) {
        arch_puts("### Failed to start test!\r\n");
    } else {
        arch_printf("### Started test (press: %d, incr: %d, release: %d, incr: %d, limit: %d)\r\n",
            press, press_incr, release, release_incr, limit);
    }
            
	return (KE_MSG_CONSUMED);
}
Ejemplo n.º 26
0
/**
 ****************************************************************************************
 * @brief Handles ready indication from the GAP. - Reset the stack
 *
 * @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_device_ready_ind_handler(ke_msg_id_t const msgid,
                                         void const *param,
                                         ke_task_id_t const dest_id,
                                         ke_task_id_t const src_id)
{
    if (ke_state_get(dest_id) == APP_DISABLED) {
        // reset the lower layers.
        struct gapm_reset_cmd* cmd = KE_MSG_ALLOC(GAPM_RESET_CMD, TASK_GAPM, TASK_APP,
                                                  gapm_reset_cmd);

        cmd->operation = GAPM_RESET;
        ke_msg_send(cmd);
    }
    else {
        // APP_DISABLED state is used to wait the GAP_READY_EVT message
        ASSERT_ERR(0);
    }

    return (KE_MSG_CONSUMED);
}
Ejemplo n.º 27
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);
}
Ejemplo n.º 28
0
void pasps_send_cmp_evt(ke_task_id_t src_id, ke_task_id_t dest_id, uint16_t conhdl,
                        uint8_t operation, uint8_t status)
{
    // Come back to the Connected state if the state was busy.
    if (ke_state_get(src_id) == PASPS_BUSY)
    {
        ke_state_set(src_id, PASPS_CONNECTED);
    }

    // Send the message to the application
    struct pasps_cmp_evt *evt = KE_MSG_ALLOC(PASPS_CMP_EVT,
                                             dest_id, src_id,
                                             pasps_cmp_evt);

    evt->conhdl      = conhdl;
    evt->operation   = operation;
    evt->status      = status;

    ke_msg_send(evt);
}
Ejemplo n.º 29
0
void app_neb_msg_rx_resp_flow(struct app_neb_msg_resp_flow* msg)
{
    uint8_t status = NEB_ERR_SUCCESS;

    if(ke_state_get(TASK_APP_NEB) == APP_NEB_CONNECTED)
    {
        ASSERT_INFO(app_neb_env.resp_flow_sample_nb < NEB_RESP_FLOW_PCK_NB, app_neb_env.resp_flow_sample_nb, NEB_RESP_FLOW_PCK_NB);

        // Store sample
        app_neb_env.resp_flow_sample_buf[app_neb_env.resp_flow_sample_nb++] = msg->flow;

        // Check the buffer size
        if(app_neb_env.resp_flow_sample_nb == NEB_RESP_FLOW_PCK_NB)
        {
            // Allocate message to profile
            struct nbps_neb_record_send_req *req = KE_MSG_ALLOC(NBPS_NEB_RECORD_SEND_REQ,
                    TASK_NBPS, TASK_APP_NEB,
                    nbps_neb_record_send_req);
            req->conhdl = app_neb_env.conhdl;
            req->neb_rec.neb_id = app_neb_env.curr_neb_id;
            req->neb_rec.rec_id = app_neb_env.next_rec_id;
            req->neb_rec.flags = NEB_REC_RESP_RATE_FLAG;

            // Parameters
            req->neb_rec.nb_resp_rate = NEB_RESP_FLOW_PCK_NB;
            memcpy(&req->neb_rec.resp_rate[0], &app_neb_env.resp_flow_sample_buf[0], NEB_RESP_FLOW_PCK_NB * sizeof(uint16_t));

            ke_msg_send(req);

            // Clear number of samples
            app_neb_env.resp_flow_sample_nb = 0;

            // Increment record ID
            app_neb_env.next_rec_id++;
        }
    }

    // Confirm the message
    app_neb_msg_tx_confirm_basic(NEB_MSG_ID_RESP_FLOW, status);
}
Ejemplo n.º 30
0
/**
 ****************************************************************************************
 * @brief Handles oled display status.
 *
 * @param[in] msgid     APP_OLED_STATE_DISPlAY_TIMER
 * @param[in] param     Null
 * @param[in] dest_id   TASK_APP
 * @param[in] src_id    TASK_NONE
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int app_oled_state_display_timer_handler(ke_msg_id_t const msgid,
                               void *param,
                               ke_task_id_t const dest_id,
                               ke_task_id_t const src_id)
{
    // Stop proxr alert
    switch(ke_state_get(TASK_APP))
		{
			case	APP_ADV	:
			{
				OLED_ShowString(0,2, (uint8_t *)"                ");	
				OLED_ShowString(0,2,(uint8_t *)"  Advertising   ");
			}break;
			case	APP_IDLE	:
			{
					if(app_proxr_env->enabled)
					{
						OLED_ShowString(0,2, (uint8_t *)"                ");	
						OLED_ShowString(0,2,(uint8_t *)"   Connected    ");
					}
					else
					{
						OLED_ShowString(0,2, (uint8_t *)"                ");	
						OLED_ShowString(0,2,(uint8_t *)"   unConected   ");
					}						
			}break;
			case	APP_INIT	:
			{
					OLED_ShowString(0,2, (uint8_t *)"                 ");	
					OLED_ShowString(0,2,(uint8_t *)"    Init!        ");													
			}break;
			default	:
			{
					OLED_ShowString(0,2, (uint8_t *)"                 ");	
					OLED_ShowString(0,2,(uint8_t *)"    Init!        ");													
			}break;				
		}
    return (KE_MSG_CONSUMED);
}