Beispiel #1
0
ret_code_t nrf_ble_cgms_meas_create(nrf_ble_cgms_t * p_cgms, ble_cgms_rec_t * p_rec)
{
    uint32_t err_code       = NRF_SUCCESS;
    uint8_t  nb_rec_to_send = 1;

    err_code = cgms_db_record_add(p_rec);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    if ((p_cgms->conn_handle != BLE_CONN_HANDLE_INVALID) && (p_cgms->comm_interval != 0))
    {
        err_code = cgms_meas_send(p_cgms, p_rec, &nb_rec_to_send);
    }
    return err_code;
}
Beispiel #2
0
/**@brief Function for responding to the FIRST or the LAST operation.
 *
 * @param[in]   p_cgms   Service instance.
 *
 * @return      NRF_SUCCESS on success, otherwise an error code.
 */
static uint32_t racp_report_records_first_last(nrf_ble_cgms_t * p_cgms)
{
    uint32_t       err_code;
    ble_cgms_rec_t rec;
    uint16_t       total_records;
    uint8_t        nb_rec_to_send = 1;

    total_records = cgms_db_num_records_get();

    if ((p_cgms->racp_data.racp_proc_records_reported != 0) || (total_records == 0))
    {
        p_cgms->cgms_com_state = STATE_NO_COMM;
    }
    else
    {
        if (p_cgms->racp_data.racp_proc_operator == RACP_OPERATOR_FIRST)
        {
            err_code = cgms_db_record_get(0, &rec);
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }
        }
        else if (p_cgms->racp_data.racp_proc_operator == RACP_OPERATOR_LAST)
        {
            err_code = cgms_db_record_get(total_records - 1, &rec);
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }
        }

        err_code = cgms_meas_send(p_cgms, &rec, &nb_rec_to_send);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
        p_cgms->racp_data.racp_proc_record_ndx++;
    }

    return NRF_SUCCESS;
}
Beispiel #3
0
/**@brief Function for responding to the ALL operation.
 *
 * @param[in]   p_cgms   Service instance.
 *
 * @return      NRF_SUCCESS on success, otherwise an error code.
 */
static uint32_t racp_report_records_all(nrf_ble_cgms_t * p_cgms)
{
    uint16_t total_records = cgms_db_num_records_get();
    uint16_t cur_nb_rec;
    uint8_t  i;
    uint8_t  nb_rec_to_send;

    if (p_cgms->racp_data.racp_proc_record_ndx >= total_records)
    {
        p_cgms->cgms_com_state = STATE_NO_COMM;
    }
    else
    {
        uint32_t       err_code;
        ble_cgms_rec_t rec[NRF_BLE_CGMS_MEAS_REC_PER_NOTIF_MAX];

        cur_nb_rec = total_records - p_cgms->racp_data.racp_proc_record_ndx;
        if (cur_nb_rec > NRF_BLE_CGMS_MEAS_REC_PER_NOTIF_MAX)
        {
            cur_nb_rec = NRF_BLE_CGMS_MEAS_REC_PER_NOTIF_MAX;
        }
        nb_rec_to_send = (uint8_t)cur_nb_rec;

        for (i = 0; i < cur_nb_rec; i++)
        {
            err_code = cgms_db_record_get(p_cgms->racp_data.racp_proc_record_ndx + i, &(rec[i]));
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }
        }
        err_code = cgms_meas_send(p_cgms, rec, &nb_rec_to_send);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
        p_cgms->racp_data.racp_proc_record_ndx += nb_rec_to_send;
    }

    return NRF_SUCCESS;
}
Beispiel #4
0
/**@brief Function for responding to the GREATER OR EQUAL operation.
 *
 * @param[in]   p_cgms   Service instance.
 *
 * @return      NRF_SUCCESS on success, otherwise an error code.
 */
static ret_code_t racp_report_records_greater_equal(nrf_ble_cgms_t * p_cgms)
{
    uint16_t total_rec_nb;
    uint16_t total_rec_nb_to_send;
    uint16_t rec_nb_left_to_send;
    uint8_t nb_rec_to_send;
    uint16_t offset;
    uint16_t i;

    if(p_cgms->racp_data.racp_request.operand_len != 2)
    {
        if (p_cgms->error_handler != NULL)
        {
            p_cgms->error_handler(NRF_ERROR_INVALID_LENGTH);
        }
    }

    total_rec_nb         = cgms_db_num_records_get();

    offset = uint16_decode(p_cgms->racp_data.racp_request.p_operand);
    if (offset >= total_rec_nb)
    {
        p_cgms->cgms_com_state = STATE_NO_COMM;
        return NRF_SUCCESS;
    }

    total_rec_nb_to_send = total_rec_nb - offset;

    if (p_cgms->racp_data.racp_proc_record_ndx >= total_rec_nb_to_send)
    {
        p_cgms->cgms_com_state = STATE_NO_COMM;
    }
    else
    {
        uint32_t       err_code;
        ble_cgms_rec_t rec[NRF_BLE_CGMS_MEAS_REC_PER_NOTIF_MAX];

        rec_nb_left_to_send = total_rec_nb_to_send - p_cgms->racp_data.racp_proc_records_reported;

        if (rec_nb_left_to_send > NRF_BLE_CGMS_MEAS_REC_PER_NOTIF_MAX)
        {
            nb_rec_to_send = NRF_BLE_CGMS_MEAS_REC_PER_NOTIF_MAX;
        }
        else
        {
            nb_rec_to_send = (uint8_t)rec_nb_left_to_send;
        }

        p_cgms->racp_data.racp_proc_record_ndx = offset;

        for (i = 0; i < nb_rec_to_send; i++)
        {
            err_code = cgms_db_record_get(p_cgms->racp_data.racp_proc_record_ndx + i, &(rec[i]));
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }
        }
        err_code = cgms_meas_send(p_cgms, rec, &nb_rec_to_send);
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
        p_cgms->racp_data.racp_proc_record_ndx += nb_rec_to_send;
    }

   return NRF_SUCCESS;
}