Пример #1
0
void ancs_parse_get_attrs_response(ble_ancs_c_t  * p_ancs,
                                   const uint8_t * p_data_src,
                                   const uint16_t  hvx_data_len)
{
    uint32_t index;

    for (index = 0; index < hvx_data_len;)
    {
        switch (p_ancs->parse_info.parse_state)
        {
            case COMMAND_ID:
                p_ancs->parse_info.parse_state = command_id_parse(p_ancs, p_data_src, &index);
                break;

            case NOTIF_UID:
                p_ancs->parse_info.parse_state = notif_uid_parse(p_ancs, p_data_src, &index);
                break;

            case APP_ID:
                p_ancs->parse_info.parse_state = app_id_parse(p_ancs, p_data_src, &index);
                break;

            case ATTR_ID:
                p_ancs->parse_info.parse_state = attr_id_parse(p_ancs, p_data_src, &index);
                break;

            case ATTR_LEN1:
                p_ancs->parse_info.parse_state = attr_len1_parse(p_ancs, p_data_src, &index);
                break;

            case ATTR_LEN2:
                p_ancs->parse_info.parse_state = attr_len2_parse(p_ancs, p_data_src, &index);
                break;

            case ATTR_DATA:
                p_ancs->parse_info.parse_state = attr_data_parse(p_ancs, p_data_src, &index);
                break;

            case ATTR_SKIP:
                p_ancs->parse_info.parse_state = attr_skip(p_ancs, p_data_src, &index);
                break;

            case DONE:
                NRF_LOG_DEBUG("Parse state: Done ");
                index = hvx_data_len;
                break;

            default:
                // Default case will never trigger intentionally. Go to the DONE state to minimize the consequences.
                p_ancs->parse_info.parse_state = DONE;
                break;
        }
    }
}
Пример #2
0
/**@brief Function for parsing received notification attribute response data.
 *
 * @details The data that comes from the Notification Provider can be much longer than what
 *          would fit in a single GATTC notification. Therefore, this function relies on a
 *          state-oriented switch case.
 *          UID and command ID will be received only once at the beginning of the first
 *          GATTC notification of a new attribute request for a given iOS notification.
 *          After this, we can loop several ATTR_ID > LENGTH > DATA > ATTR_ID > LENGTH > DATA until
 *          we have received all attributes we wanted as a Notification Consumer.
 *          The Notification Provider can also simply stop sending attributes.
 *
 *    |1 Byte  |  4 Bytes    |1 Byte |2 Bytes | X Bytes            |1 Bytes| 2 Bytes| X Bytes
 *    +--------+-------------+-------+--------+- - - - - - - - - - +-------+--------+- - - - - - -
 *    | CMD_ID |  NOTIF_UID  |ATTR_ID| LENGTH |        DATA        |ATTR_ID| LENGTH |    DATA
 *    +--------+-------------+-------+--------+- - - - - - - - - - +-------+--------+- - - - - - -
 *
 * @param[in] p_ancs     Pointer to an ANCS instance to which the event belongs.
 * @param[in] p_data_src Pointer to data that was received from the Notification Provider.
 * @param[in] hvx_len    Length of the data that was received from the Notification Provider.
 */
static void parse_get_notif_attrs_response(ble_ancs_c_t  * p_ancs,
                                           const uint8_t * p_data_src,
                                           const uint16_t  hvx_data_len)
{
    uint32_t index;

    for (index = 0; index < hvx_data_len;)
    {
        switch (p_ancs->parse_state)
        {
            case COMMAND_ID_AND_NOTIF_UID:
                p_ancs->parse_state = command_id_and_notif_parse(p_ancs, p_data_src, &index);
                break;

            case ATTR_ID:
                p_ancs->parse_state = attr_id_parse(p_ancs, p_data_src, &index);
                break;

            case ATTR_LEN1:
                p_ancs->parse_state = attr_len1_parse(p_ancs, p_data_src, &index);
                break;

            case ATTR_LEN2:
                p_ancs->parse_state = attr_len2_parse(p_ancs, p_data_src, &index);
                break;

            case ATTR_DATA:
                p_ancs->parse_state = attr_data_parse(p_ancs, p_data_src, &index);
                break;

            case DONE:
                NRF_LOG_INFO("State: Done \r\n");
                index = hvx_data_len;
                break;

            default:
                // Default case will never trigger intentionally. Go to the DONE state to minimize the consequences.
                p_ancs->parse_state = DONE;
                break;
        }
    }
}