Exemplo n.º 1
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref HTPC_ENABLE_REQ message.
 * The handler enables the Health Thermometer Profile Collector Role.
 * @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 htpc_enable_req_handler(ke_msg_id_t const msgid,
                                   struct htpc_enable_req const *param,
                                   ke_task_id_t const dest_id,
                                   ke_task_id_t const src_id)
{
    // Status
    uint8_t status;
    // Health Thermometer Profile Collector Role Task Environment
    struct htpc_env_tag *htpc_env;
    // Connection Information
    struct prf_con_info con_info;

    // Fill the Connection Information structure
    con_info.conhdl = 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, htpc);

    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)
    {
        htpc_env = PRF_CLIENT_GET_ENV(dest_id, htpc);

        //Config connection, start discovering
        if(param->con_type == PRF_CON_DISCOVERY)
        {
            htpc_env->last_uuid_req = ATT_SVC_HEALTH_THERMOM;

            // Start discovering HTS on peer
            prf_disc_svc_send(&htpc_env->con_info, ATT_SVC_HEALTH_THERMOM);

            // Go to DISCOVERING state
            ke_state_set(dest_id, HTPC_DISCOVERING);
        }
        // Normal connection, get saved att details
        else
        {
            htpc_env->hts = param->hts;

            //send APP confirmation that can start normal connection to TH
            htpc_enable_cfm_send(htpc_env, &htpc_env->con_info, PRF_ERR_OK);
        }
    }
    else
    {
        // An error has been raised during the process, hts is NULL and won't be handled
        htpc_enable_cfm_send(NULL, &con_info, status);
    }

    return (KE_MSG_CONSUMED);
}
Exemplo n.º 2
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref GATT_CMP_EVT message.
 * This generic event is received for different requests, so need to keep track.
 * @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 gatt_cmp_evt_handler(ke_msg_id_t const msgid,
                                struct gatt_cmp_evt const *param,
                                ke_task_id_t const dest_id,
                                ke_task_id_t const src_id)
{
    // Status
    uint8_t status;
    // Get the address of the environment
    struct htpc_env_tag *htpc_env = PRF_CLIENT_GET_ENV(dest_id, htpc);

    if ((param->status == ATT_ERR_ATTRIBUTE_NOT_FOUND)||
        (param->status == ATT_ERR_NO_ERROR))
    {
        // Service start/end handles has been received
        if(htpc_env->last_uuid_req == ATT_SVC_HEALTH_THERMOM)
        {
            // check if service handles are not ok
            if (htpc_env->hts.svc.shdl == ATT_INVALID_HANDLE)
            {
                // stop discovery procedure.
                htpc_enable_cfm_send(htpc_env, &htpc_env->con_info, PRF_ERR_STOP_DISC_CHAR_MISSING);
            }
            //too many services found only one such service should exist
            else if(htpc_env->nb_svc > 1)
            {
                // stop discovery procedure.
                htpc_enable_cfm_send(htpc_env, &htpc_env->con_info, PRF_ERR_MULTIPLE_SVC);
            }
            // check if service handles are ok
            else
            {
                //discover all HTS characteristics
                htpc_env->last_uuid_req = ATT_DECL_CHARACTERISTIC;
                prf_disc_char_all_send(&(htpc_env->con_info), &(htpc_env->hts.svc));
            }
        }
        else if(htpc_env->last_uuid_req == ATT_DECL_CHARACTERISTIC)
        {
            status = prf_check_svc_char_validity(HTPC_CHAR_HTS_MAX, htpc_env->hts.chars,
                                                 htpc_hts_char);

            // Check for characteristic properties.
            if(status == PRF_ERR_OK)
            {
                htpc_env->last_uuid_req = ATT_INVALID_HANDLE;
                htpc_env->last_char_code = htpc_hts_char_desc[HTPC_DESC_HTS_TEMP_MEAS_CLI_CFG].char_code;
                //Discover Temperature Measurement Char. Descriptor - Mandatory
                prf_disc_char_desc_send(&(htpc_env->con_info),
                                        &(htpc_env->hts.chars[htpc_env->last_char_code]));
            }
            else
            {
                // Stop discovery procedure.
                htpc_enable_cfm_send(htpc_env, &htpc_env->con_info, status);
            }
        }
        else //Descriptors
        {
            //Get code of next char. having descriptors
            htpc_env->last_char_code = htpc_get_next_desc_char_code(htpc_env, &htpc_hts_char_desc[0]);
            if (htpc_env->last_char_code != HTPC_DESC_HTS_MAX)
            {
                prf_disc_char_desc_send(&(htpc_env->con_info),
                        &(htpc_env->hts.chars[htpc_env->last_char_code]));
            }
            else
            {
                status = prf_check_svc_char_desc_validity(HTPC_DESC_HTS_MAX,
                                                          htpc_env->hts.descs,
                                                          htpc_hts_char_desc,
                                                          htpc_env->hts.chars);

                htpc_enable_cfm_send(htpc_env, &htpc_env->con_info, status);
            }
        }
    }
    else
    {
        htpc_enable_cfm_send(htpc_env, &htpc_env->con_info, param->status);
    }

    return (KE_MSG_CONSUMED);
}
Exemplo n.º 3
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref GATTC_CMP_EVT message.
 * This generic event is received for different requests, so need to keep track.
 * @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_cmp_evt_handler(ke_msg_id_t const msgid,
                                struct gattc_cmp_evt const *param,
                                ke_task_id_t const dest_id,
                                ke_task_id_t const src_id)
{
    uint8_t state = ke_state_get(dest_id);
    // Status
    uint8_t status;
    // Get the address of the environment
    struct htpc_env_tag *htpc_env = PRF_CLIENT_GET_ENV(dest_id, htpc);

    if(state == HTPC_DISCOVERING)
    {
        if ((param->status == ATT_ERR_ATTRIBUTE_NOT_FOUND)||
                (param->status == ATT_ERR_NO_ERROR))
        {
            // Service start/end handles has been received
            if(htpc_env->last_uuid_req == ATT_SVC_HEALTH_THERMOM)
            {
                // check if service handles are not ok
                if (htpc_env->hts.svc.shdl == ATT_INVALID_HANDLE)
                {
                    // stop discovery procedure.
                    htpc_enable_cfm_send(htpc_env, &htpc_env->con_info, PRF_ERR_STOP_DISC_CHAR_MISSING);
                }
                //too many services found only one such service should exist
                else if(htpc_env->nb_svc > 1)
                {
                    // stop discovery procedure.
                    htpc_enable_cfm_send(htpc_env, &htpc_env->con_info, PRF_ERR_MULTIPLE_SVC);
                }
                // check if service handles are ok
                else
                {
                    //discover all HTS characteristics
                    htpc_env->last_uuid_req = ATT_DECL_CHARACTERISTIC;
                    prf_disc_char_all_send(&(htpc_env->con_info), &(htpc_env->hts.svc));
                }
            }
            else if(htpc_env->last_uuid_req == ATT_DECL_CHARACTERISTIC)
            {
                status = prf_check_svc_char_validity(HTPC_CHAR_HTS_MAX, htpc_env->hts.chars,
                        htpc_hts_char);

                // Check for characteristic properties.
                if(status == PRF_ERR_OK)
                {
                    htpc_env->last_uuid_req = ATT_INVALID_HANDLE;
                    htpc_env->last_char_code = htpc_hts_char_desc[HTPC_DESC_HTS_TEMP_MEAS_CLI_CFG].char_code;
                    //Discover Temperature Measurement Char. Descriptor - Mandatory
                    prf_disc_char_desc_send(&(htpc_env->con_info),
                            &(htpc_env->hts.chars[htpc_env->last_char_code]));
                }
                else
                {
                    // Stop discovery procedure.
                    htpc_enable_cfm_send(htpc_env, &htpc_env->con_info, status);
                }
            }
            else //Descriptors
            {
                //Get code of next char. having descriptors
                htpc_env->last_char_code = htpc_get_next_desc_char_code(htpc_env, &htpc_hts_char_desc[0]);
                if (htpc_env->last_char_code != HTPC_DESC_HTS_MAX)
                {
                    prf_disc_char_desc_send(&(htpc_env->con_info),
                            &(htpc_env->hts.chars[htpc_env->last_char_code]));
                }
                else
                {
                    status = prf_check_svc_char_desc_validity(HTPC_DESC_HTS_MAX,
                            htpc_env->hts.descs,
                            htpc_hts_char_desc,
                            htpc_env->hts.chars);

                    htpc_enable_cfm_send(htpc_env, &htpc_env->con_info, status);
                }
            }
        }
        else
        {
            htpc_enable_cfm_send(htpc_env, &htpc_env->con_info, param->status);
        }
    }
    else if(state == HTPC_CONNECTED)
    {
        switch(param->req_type)
        {
            case GATTC_WRITE:
            case GATTC_WRITE_NO_RESPONSE:
            {
                // Get the address of the environment
                struct htpc_wr_char_rsp *wr_cfm = KE_MSG_ALLOC(HTPC_WR_CHAR_RSP,
                        htpc_env->con_info.appid, dest_id,
                        htpc_wr_char_rsp);

                wr_cfm->conhdl    = gapc_get_conhdl(htpc_env->con_info.conidx);
                //it will be a GATT status code
                wr_cfm->status    = param->status;
                // send the message
                ke_msg_send(wr_cfm);
            }
            break;

            case GATTC_READ:
            {
                if(param->status != GATT_ERR_NO_ERROR)
                {
                    prf_client_att_info_rsp((prf_env_struct*) htpc_env, HTPC_RD_CHAR_RSP,
                            param->status, NULL);
                }
            }
            break;
            default: break;
        }
    }

    return (KE_MSG_CONSUMED);
}