void app_param_update_func(void)
{
#if 1 
    int temp=4;    
    uint8_t *temp_v;

    attmdb_att_get_value(ACCEL_HANDLE(ACCEL_IDX_ACCEL_X_EN), &(temp), &(temp_v));
    if(temp_v[1] > 1)
        accel_con_interval = temp_v[1]-1;
    if(accel_con_interval < 2 || accel_con_interval > 500)
        return;
    
    // Send a param update request
    struct gapc_param_update_cmd *cmd = KE_MSG_ALLOC(GAPC_PARAM_UPDATE_CMD,
            KE_BUILD_ID(TASK_GAPC, app_env.conidx), TASK_APP,
            gapc_param_update_cmd);

    // Fill up parameters
    cmd->operation = GAPC_UPDATE_PARAMS;
#if 0
    cmd->params.intv_min = 70;         // 10ms (8*1.25ms)
    cmd->params.intv_max = 80;        // 20ms (16*1.25ms)
    cmd->params.latency  = 0;
//GZ    cmd->params.time_out = 100;
    cmd->params.time_out = 320;
#endif
    
    cmd->params.intv_min = (accel_con_interval-1)*10/1.25;
    cmd->params.intv_max = (accel_con_interval)*10/1.25;
    cmd->params.latency = 0;
    if(accel_con_interval < 30)
        cmd->params.time_out = accel_con_interval*32;
    else
        cmd->params.time_out = 10000;
        
    // Send message
    ke_msg_send(cmd);

//GZ tmp
rwip_env.sleep_enable = false;
    
    // Go to Param update state
    ke_state_set(TASK_APP, APP_PARAM_UPD);
#endif

    return;
}
void app_custom_connection(struct gapc_connection_req_ind const *param)
{
#if BLE_ACCEL
    int temp=4;
    uint8_t *temp_v;
    
    app_accel_adv_stopped();
    
    if (!param->con_latency)
    {
        // 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 = param->conn_info.conhdl;
        //GZ req->conn_par.intv_min = param->conn_info.con_interval;
        //GZ req->conn_par.intv_max = param->conn_info.con_interval;
        attmdb_att_get_value(ACCEL_HANDLE(ACCEL_IDX_ACCEL_X_EN), &(temp), &(temp_v));
        if(temp_v[1] > 1)
            accel_con_interval = temp_v[1];
        
        req->params.intv_min = (accel_con_interval-1)*10/1.25;
        req->params.intv_max = (accel_con_interval)*10/1.25;
        req->params.latency = param->con_latency;
        if(param->sup_to * 8 / 1.25 <= 3200)
            req->params.time_out = param->sup_to * 8 / 1.25;
        else
            req->params.time_out = 3200/1.25;
    #if BLE_HID_DEVICE
        puts("Send GAP_PARAM_UPDATE_REQ");
    #endif
        ke_msg_send(req);
    }    
#endif
}
Example #3
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref ACCEL_ENABLE_REQ message.
 * The handler enables the accelerometer profile.
 * @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 accel_enable_req_handler(ke_msg_id_t const msgid,
                                    struct accel_enable_req const *param,
                                    ke_task_id_t const dest_id,
                                    ke_task_id_t const src_id)
{
    uint16_t disable_val = 0x00;

    //Save Application ID
    accel_env.con_info.appid = src_id;
    accel_env.con_info.prf_id = dest_id;

    // Save the connection index associated to the profile
    accel_env.con_info.conidx = gapc_get_conidx(param->conhdl);


    attmdb_att_set_value(ACCEL_HANDLE(ACCEL_IDX_ENABLE_VAL), sizeof(uint8_t), (uint8_t*) &(disable_val));
    attmdb_att_set_value(ACCEL_HANDLE(ACCEL_IDX_RANGE_VAL), sizeof(uint8_t), (uint8_t*) &(disable_val));

    attmdb_att_set_value(ACCEL_HANDLE(ACCEL_IDX_ACCEL_X_EN), sizeof(uint16_t),(uint8_t*) &(disable_val));
    attmdb_att_set_value(ACCEL_HANDLE(ACCEL_IDX_ACCEL_Y_EN), sizeof(uint16_t),(uint8_t*) &(disable_val));
    attmdb_att_set_value(ACCEL_HANDLE(ACCEL_IDX_ACCEL_Z_EN), sizeof(uint16_t),(uint8_t*) &(disable_val));

{
	uint8_t tb;
	
//	tb = battery_get_lvl(BATT_CR2032);
		tb = battery_get_lvl(BATT_JPLUS);//gsx,jplus battery type.

	 // Update the value in the attribute database
    attmdb_att_set_value(ACCEL_HANDLE(ACCEL_IDX_ENABLE_VAL), sizeof(uint8_t), (uint8_t*) &(tb));
}
	    
    //Enable Service
    attmdb_svc_set_permission(accel_env.shdl, PERM(SVC, ENABLE));

    // Go to active state
    ke_state_set(TASK_ACCEL, ACCEL_ACTIVE);

    return (KE_MSG_CONSUMED);
}
Example #4
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref GL2C_CODE_ATT_WR_CMD_IND message.
 * The handler compares the new values with current ones and notifies them if they changed.
 * @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 gattc_write_cmd_ind_handler(ke_msg_id_t const msgid,
                                      struct gattc_write_cmd_ind const *param,
                                      ke_task_id_t const dest_id,
                                      ke_task_id_t const src_id)
{
    // Update the attribute value
    attmdb_att_update_value(param->handle, param->length, param->offset,
            (uint8_t*)&(param->value[0]));

    switch (ACCEL_IDX(param->handle))
    {
        case ACCEL_IDX_ENABLE_VAL:
        {
            uint16_t len;
            uint8_t* accel_en;
            uint8_t* axis_en;
            uint8_t* range;

            if(*(uint8_t*)&(param->value[0]) > 1)
                accel_threshold = *(uint8_t*)&(param->value[0]) - 2;
//            set_accel_thr();
                        
            attmdb_att_get_value(ACCEL_HANDLE(ACCEL_IDX_ENABLE_VAL), &(len), &(accel_en));

            // Indicate to the application the state of the profile
            if (accel_en)
            {
                // Allocate the start indication message
                struct accel_start_ind *ind = KE_MSG_ALLOC(ACCEL_START_IND,
                                                           accel_env.con_info.appid, dest_id,
                                                           accel_start_ind);

                // Fill in the parameter structure
                for (int i = 0; i < ACCEL_MAX; i++)
                {
                    attmdb_att_get_value(ACCEL_DIR_VAL_HANDLE(i), &(len), &(axis_en));

                    ind->accel_en[i] = *axis_en;
                }


                attmdb_att_get_value(ACCEL_HANDLE(ACCEL_IDX_RANGE_VAL), &(len), &(range));

                ind->range = *range;

                // Send the message
                ke_msg_send(ind);
            }
            else
            {
                // Send the stop indication
                ke_msg_send_basic(ACCEL_STOP_IND, accel_env.con_info.appid, TASK_ACCEL);
            }
        }
        break;

        case ACCEL_IDX_ACCEL_DISPLAY1_VAL:
        case ACCEL_IDX_ACCEL_DISPLAY2_VAL:            
            if(*(uint8_t*)&(param->value[0]) == 0xFF)
            {
                if(param->length > 1 && *(uint8_t*)&(param->value[1]) > 1)
					accel_con_interval = *(uint8_t*)&(param->value[1]);
                if(param->length > 2 && *(uint8_t*)&(param->value[2]) > 1)
					accel_mode = *(uint8_t*)&(param->value[2])-2;
				if(param->length > 3 && *(uint8_t*)&(param->value[3]) > 1)
					accel_latency = *(uint8_t*)&(param->value[3])-2;
				if(param->length > 4 && *(uint8_t*)&(param->value[4]) > 1)
					accel_window = *(uint8_t*)&(param->value[4]);
            }
        {
            uint8_t line;
            uint16_t len;
            uint8_t* display;

            struct accel_write_line_ind *ind = KE_MSG_ALLOC(ACCEL_WRITE_LINE_IND,
                                                            accel_env.con_info.appid, TASK_ACCEL,
                                                            accel_write_line_ind);
            line = (param->handle == ACCEL_HANDLE(ACCEL_IDX_ACCEL_DISPLAY1_VAL))?0:1;


            attmdb_att_get_value(param->handle, &(len), &(display));

            // Fill in the parameter structure
            memcpy(ind->text, display, len);
            ind->line = line;

            // Send the message
            ke_msg_send(ind);
        }
            atts_write_rsp_send(accel_env.con_info.conidx, param->handle, PRF_ERR_OK);
            break;        
        case ACCEL_IDX_ACCEL_X_VAL:
        case ACCEL_IDX_ACCEL_X_EN:
					if(*(uint8_t*)&(param->value[0]) > 1)
					accel_adv_interval1 = *(uint8_t*)&(param->value[0]);
						atts_write_rsp_send(accel_env.con_info.conidx, param->handle, PRF_ERR_OK);
            break;
        case ACCEL_IDX_ACCEL_Y_VAL:
        case ACCEL_IDX_ACCEL_Y_EN:
					if(*(uint8_t*)&(param->value[0]) > 1)
					accel_adv_interval2 = *(uint8_t*)&(param->value[0]);
					if(*(uint8_t*)&(param->value[0]) == 255)
					accel_adv_interval2 = 0;
						atts_write_rsp_send(accel_env.con_info.conidx, param->handle, PRF_ERR_OK);
            break;
        case ACCEL_IDX_ACCEL_Z_VAL:
        case ACCEL_IDX_ACCEL_Z_EN:
					if(*(uint8_t*)&(param->value[0]) > 1)
					accel_adv_interval3 = *(uint8_t*)&(param->value[0]);
					if(*(uint8_t*)&(param->value[0]) == 255)
					accel_adv_interval3 = 0;
						atts_write_rsp_send(accel_env.con_info.conidx, param->handle, PRF_ERR_OK);
            break;
        
        default:
            atts_write_rsp_send(accel_env.con_info.conidx, param->handle, PRF_ERR_OK);
            break;
            
    }

    return (KE_MSG_CONSUMED);
}