# Requesting message

Source: [https://docs.qualcomm.com/doc/80-PK177-134/topic/requesting_message.html](https://docs.qualcomm.com/doc/80-PK177-134/topic/requesting_message.html)

Sensor subsystem can understand only protocol-buffer encoded requests. You must prepare `sns_client_request_msg` for enabling `activity_recognition` sensor with protocol-buffer Java APIs that were generated from the .proto files.

## Encoding request message

To send all types of client requests to sensors subsystem `sns_client_request_msg` proto message is used, and it must be encoded using generated Java Protobuf APIs.

To fill values of required fields of `sns_client_request_msg`, get Builder of this message with `newBuilder()` method.

**SUID request**

Sensor subsystem contains a SUID sensor that has &lt;data type, SUID&gt; map of all the sensors that are available on the subsystem. Upon receiving SUID request, this SUID sensor provides a SUID of the sensor that client looking for.

To send SUID request, sns\_client\_request\_msg must be encoded with SUID request configuration. sns\_std\_suid, suspend\_config submessages must fill as per SUID request and sns\_suid\_req message is used for SUID request and high and low SUID must be "12370169555311111083”, which must be filled with values as follows:

    sns_suid_req.Builder suid_req_build = sns_suid_req.newBuilder();
    suid_req_build.setDataType("activity_recognition");
    suid_req_build.setDefaultOnly(true);
    suid_req_build.setRegisterUpdates(true);
    sns_std_suid.Builder std_suid_build = sns_std_suid.newBuilder();
    LOOKUP_SUID = Long.parseUnsignedLong("12370169555311111083");
    std_suid_build.setSuidHigh(LOOKUP_SUID);
    std_suid_build.setSuidLow(LOOKUP_SUID);
    sns_std_suid std_suid = std_suid_build.build();Copy to clipboard

Filled sns\_suid\_req message must be set as payload field of sns\_std\_request as follows:

    sns_std_request.Builder std_request = sns_std_request.newBuilder();
    std_request.setPayload(suid_req_build.build().toByteString());
    \\ sns_std_request must be set as request field for sns_client_request_msg as follows:
    request_msg.setRequest(std_request.build());
    sns_client_request_msg.Builder client_req_msg = sns_client_request_msg.newBuilder();
    client_req_msg.setMsgId(sns_suid_msgid.SNS_SUID_MSGID_SNS_SUID_REQ_VALUE);
    client_req_msg.setSuid(std_suid);
    client_req_msg.setSuspConfig(suspend_config.build());
    client_req_msg.setRequest(std_request);Copy to clipboard

client\_req\_msg should be converted to byteArray and sent to the sensor
        subsystem using the send\_request() API.

    byte[] bytedata = request_msg.build().toByteArray();Copy to clipboard

## SNS builder

    sns_client_request_msg.Builder request_msg=sns_client_request_msg.newBuilder();Copy to clipboard

sns\_client\_request\_msg has submessages within it, that are `sns_std_suid`, `suspend_config`, `sns_std_request`. `sns_std_suid` is for holding the SUID of the sensor that is intended for the request.

The following is the code to encode the `sns_std_suid` submessage:

    sns_std_suid.Builder std_suid_build = sns_std_suid.newBuilder();
    std_suid_build.setSuidHigh(SuidHigh);
    std_suid_build.setSuidLow(SuidLow);
    sns_std_suid std_suid = std_suid_build.build();Copy to clipboard

suspend\_config is for holding the client processor, delivery type configuration.

The following is an example code to encode this submessage:

    sns_client_request_msg.suspend_config.Builder suspend_config = sns_client_request_msg.suspend_config.newBuilder();
    suspend_config.setClientProcType(sns_std_client_processor.SNS_STD_CLIENT_PROCESSOR_APSS);
    suspend_config.setDeliveryType(sns_client_delivery.SNS_CLIENT_DELIVERY_WAKEUP);Copy to clipboard

sns\_std\_request is used for setting the batching configuration, sending attribute requests, and SUID requests.

## Start Sensor with configuration

For client to collect data of a particular sensor that is available at sensors subsystem, a special protobuf encoded, sns\_client\_request\_msg start request must be sent to subsystem using send\_request API.

`sns_std_suid` submessage must be filled with the SUID value of the sensor that has to be started. `suspend_config` submessages must fill as per the Client type.

`sns_std_request` submessage must filled with values as follows:

    sns_std_request.Builder std_request = sns_std_request.newBuilder();
    request_msg.setSuid(std_suid);
    request_msg.setMsgId(SNS_STD_SENSOR_MSGID_SNS_STD_ON_CHANGE_CONFIG_VALUE); // MsgId 514 is for on-change Sensor configuration 
    request_msg.setSuspConfig(suspend_config.build());Copy to clipboard

Filled `sns_std_request` must be set as request field for `sns_client_request_msg` as follows:

    request_msg.setRequest(std_request.build());Copy to clipboard

`client_req_msg` should be converted to byteArray and sent to sensor subsystem using the send\_request() API.

    byte[] bytedata = request_msg.build().toByteArray();Copy to clipboard

## Stop sensor

For Client to stop collecting data from the sensor, a special, protobuf encoded,
          `sns_client_request_msg` stop request must be sent to sensors subsystem
        using the `send_request()` API.

sns\_std\_suid submessage must be filled with the SUID value of the sensor that has to be
          started.`suspend_config` submessages must be filled as per the client type.

`sns_std_request` submessage must filled with the following values:

    sns_std_request.Builder std_request = sns_std_request.newBuilder();
    request_msg.setSuid(std_suid); request_msg.setMsgId(10); // MsgId 10 is to stop a Sensor
    request_msg.setSuspConfig(suspend_config.build());Copy to clipboard

Filled `sns_std_request` must be set as request field for
          `sns_client_request_msg` as follows:

    request_msg.setRequest(std_request.build());Copy to clipboard

`client_req_msg` should be converted to `byteArray` and sent
        to sensor subsystem using the `send_request()` API.

    byte[] bytedata = request_msg.build().toByteArray();Copy to clipboard

**Parent Topic:** [Encoding and decoding protobuf messages](https://docs.qualcomm.com/doc/80-PK177-134/topic/encoding_and_decoding_protobuf_messages.html)

Last Published: Nov 14, 2024

[Previous Topic
Encoding and decoding protobuf messages](https://docs.qualcomm.com/bundle/publicresource/80-PK177-134/topics/encoding_and_decoding_protobuf_messages.md) [Next Topic
Decoding message](https://docs.qualcomm.com/bundle/publicresource/80-PK177-134/topics/decoding_message.md)