Ejemplo n.º 1
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);
}
Ejemplo n.º 2
0
/**
 ****************************************************************************************
 * @brief Handles accelerometer stop indication from the Accelerometer profile.
 *        No axis of the accelerometer has been enabled through ATT, so upt it in stand by.
 *
 * @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_stop_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)
{
    // Stop the accelerometer
//vm	
    acc_stop();

    return (KE_MSG_CONSUMED);
}
Ejemplo n.º 3
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)
    
    
}
Ejemplo n.º 4
0
int
test_ws_server() {
    con_table = idtable_create(1024);
    assert(con_table);

    r = reactor_create();
    assert(r);

    acc_t* acc = acc_create(r);
    assert(acc);
    acc_set_read_func(acc, _accept_read, NULL);

    struct sockaddr_in addr;
    int res = sock_addr_aton(WS_IP, WS_PORT, &addr);
    assert(res == 0);

    res = acc_start(acc, (struct sockaddr*)&addr);
    assert(res == 0);

    while (1) {
        res = reactor_dispatch(r, 1);
        if(res < 0) return -1;
        if(res == 0) usleep(100);
    }

    acc_stop(acc);
    acc_release(acc);
    for (int i = 0; i < 1024; i++) {
        WSCtx* ctx = idtable_get(con_table, i);
        if (ctx) {
            wsconn_release(ctx->con);
            FREE(ctx);
        }
    }
    idtable_release(con_table);
    reactor_release(r);
    return 0;
}