Example #1
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref TIPS_ENABLE_REQ message.
 * The handler enables the Time Server 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 tips_enable_req_handler(ke_msg_id_t const msgid,
                                   struct tips_enable_req const *param,
                                   ke_task_id_t const dest_id,
                                   ke_task_id_t const src_id)
{
    // Status
    uint8_t status;
    // Time Profile Server Role Task Index Environment
    struct tips_idx_env_tag *tips_idx_env;
    // Connection Information
    struct prf_con_info con_info;

    // Value used to initialize readable value in DB
    uint16_t value = 0;
    // Value used to initialize readable value whose size is upper than 2 bytes
    struct attm_elmt *att = NULL;

    // Fill the Connection Information structure
    con_info.conidx = gapc_get_conidx(param->conhdl);
    con_info.prf_id = dest_id;
    con_info.appid  = src_id;

    // Add an environment for the provided device
    status = PRF_CLIENT_ENABLE(con_info, param, tips_idx);

    if (status == PRF_ERR_FEATURE_NOT_SUPPORTED)
    {
        // The message has been forwarded to another task id.
        return (KE_MSG_NO_FREE);
    }
    else if (status == PRF_ERR_OK)
    {
        //If this connection is a not configuration one, apply configuration saved by APP
        if(param->con_type == PRF_CON_NORMAL)
        {
            memcpy(&value, &param->current_time_ntf_en, sizeof(uint16_t));

            if (param->current_time_ntf_en == PRF_CLI_START_NTF)
            {
                // Get the environment for the device
                tips_idx_env = PRF_CLIENT_GET_ENV(dest_id, tips_idx);

                tips_idx_env->ntf_state |= TIPS_CTS_CURRENT_TIME_CFG;
            }
        }

        //Set Current Time Char. NTF Configuration in database
        attmdb_att_set_value(tips_env.cts_shdl + CTS_IDX_CURRENT_TIME_CFG, sizeof(uint16_t),
                             (uint8_t *)&value);

        //Reset value
        value = 0;

        // Initialize Local Time Info Char. Value - (UTC+0.00 / Standard Time)
        if (TIPS_IS_SUPPORTED(TIPS_CTS_LOC_TIME_INFO_SUP))
        {
            //sizeof(struct tip_ref_time_info) = sizeof(uint16_t)
            attmdb_att_set_value(tips_env.cts_shdl + CTS_IDX_LOCAL_TIME_INFO_VAL,
                                 sizeof(struct tip_loc_time_info), (uint8_t *)&value);
        }

        // Initialize Reference Time Info Char. Value
        if (TIPS_IS_SUPPORTED(TIPS_CTS_REF_TIME_INFO_SUP))
        {
            att = attmdb_get_attribute(tips_env.cts_shdl + tips_env.cts_att_tbl[CTS_REF_TIME_INFO_CHAR] + 1);

            att->length = sizeof(struct tip_ref_time_info);
            memset(att->value, 0, sizeof(struct tip_ref_time_info));
        }

        //Enable CTS + Set Security Level
        attmdb_svc_set_permission(tips_env.cts_shdl, param->sec_lvl);

        if (TIPS_IS_SUPPORTED(TIPS_NDCS_SUP))
        {
            att = attmdb_get_attribute(tips_env.ndcs_shdl + NDCS_IDX_TIME_DST_VAL);

            // Initialize Time With DST Char. Value - (Idle / Successful)
            att->length = NDCS_TIME_DST_VAL_LEN;
            memset(att->value, 0, NDCS_TIME_DST_VAL_LEN);

            attmdb_svc_set_permission(tips_env.ndcs_shdl, param->sec_lvl);
        }
        if (TIPS_IS_SUPPORTED(TIPS_RTUS_SUP))
        {
            // Initialize Time Update State Char. Value - (Idle / Successful)
            attmdb_att_set_value(tips_env.rtus_shdl + RTUS_IDX_TIME_UPD_STATE_VAL,
                                 sizeof(struct tip_time_upd_state), (uint8_t *)&value);

            attmdb_svc_set_permission(tips_env.rtus_shdl, param->sec_lvl);
        }

        // Go to Connected State
        ke_state_set(dest_id, TIPS_CONNECTED);

        //send APP confirmation that can start normal connection
        tips_enable_cfm_send(&con_info, PRF_ERR_OK);
    }
    else
    {
        // Send confirmation that can start normal connection
        tips_enable_cfm_send(&con_info, status);
    }

    return (KE_MSG_CONSUMED);
}
Example #2
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref GLPS_MEAS_SEND_REQ message.
 * @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 glps_meas_send_req_handler(ke_msg_id_t const msgid,
                                      struct glps_send_meas_with_ctx_req const *param,
                                      ke_task_id_t const dest_id,
                                      ke_task_id_t const src_id)
{
    uint8_t status = PRF_ERR_OK;

    if(param->conhdl == gapc_get_conhdl(glps_env.con_info.conidx))
    {
        // device already sending a measurement
        if(GLPS_IS(SENDING_MEAS))
        {
            //Cannot send another measurement in parallel
            status = (PRF_ERR_REQ_DISALLOWED);
        }
        else
        {
            // inform that device is sending a measurement
            GLPS_SET(SENDING_MEAS);


            // check if context is supported
            if((msgid == GLPS_SEND_MEAS_WITH_CTX_REQ) && !(GLPS_IS(MEAS_CTX_SUPPORTED)))
            {
                // Context not supported
                status = (PRF_ERR_FEATURE_NOT_SUPPORTED);
            }
            // check if notifications enabled
            else if(((glps_env.evt_cfg & GLPS_MEAS_NTF_CFG) == 0)
                    || (((glps_env.evt_cfg & GLPS_MEAS_CTX_NTF_CFG) == 0)
                        && (msgid == GLPS_SEND_MEAS_WITH_CTX_REQ)))
            {
                // Not allowed to send measurement if Notifications not enabled.
                status = (PRF_ERR_NTF_DISABLED);

            }
            else
            {
                struct attm_elmt * attm_elmt;

                // retrieve value pointer in database
                attm_elmt = attmdb_get_attribute(GLPS_HANDLE(GLS_IDX_MEAS_VAL));

                // pack measured value in database
                attm_elmt->length = glps_pack_meas_value(attm_elmt->value, &(param->meas),
                        param->seq_num);

                prf_server_send_event((prf_env_struct *)&glps_env, false,
                        GLPS_HANDLE(GLS_IDX_MEAS_VAL));

                // Measurement value notification not yet sent
                GLPS_CLEAR(MEAS_SENT);

                if(msgid == GLPS_SEND_MEAS_WITH_CTX_REQ)
                {
                    // 2 notification complete messages expected
                    GLPS_SET(MEAS_CTX_SENT);

                    // retrieve value pointer in database
                    attm_elmt = attmdb_get_attribute(GLPS_HANDLE(GLS_IDX_MEAS_CTX_VAL));

                    // pack measured value in database
                    attm_elmt->length = glps_pack_meas_ctx_value(attm_elmt->value,
                                                            &(param->ctx), param->seq_num);

                    prf_server_send_event((prf_env_struct *)&glps_env, false,
                            GLPS_HANDLE(GLS_IDX_MEAS_CTX_VAL));
                }
                else
                {
                    // 1 notification complete messages expected
                    GLPS_CLEAR(MEAS_CTX_SENT);
                }
            }
        }
    }
    else
    {
        //Wrong Connection Handle
        status = (PRF_ERR_INVALID_PARAM);
    }

    // send command complete if an error occurs
    if(status != PRF_ERR_OK)
    {
        // allow to send other measurements
        GLPS_CLEAR(SENDING_MEAS);

        // send completed information to APP task that contains error status
        struct glps_req_cmp_evt * cmp_evt = KE_MSG_ALLOC(GLPS_REQ_CMP_EVT, glps_env.con_info.appid,
                TASK_GLPS, glps_req_cmp_evt);

        cmp_evt->conhdl     = param->conhdl;
        cmp_evt->request    = GLPS_SEND_MEAS_REQ_NTF_CMP;
        cmp_evt->status     = status;

        ke_msg_send(cmp_evt);
    }

    return (KE_MSG_CONSUMED);
}