Qualcomm Enhanced SDK (QESDK) API Reference (9)
-
-
- 3.3.4 Sample code
-
- 4 Sensor API
-
- 4.1 Sensor function
-
- 4.1.1 Sensor session
- 4.1.2 create_session
- 4.1.3 get_sensors_list
- 4.1.4 delete_session
- 4.2 Sensor interface
-
- 4.2.1 Send request
- 4.2.2 register_event_callback
- 4.2.3 register_error_callback
- 4.2.4 Ierror_callback_type.onValues
- 4.2.5 Event_callback_type.onValues
- 4.3 Activity recognition
-
- 4.3.1 Activity Identification Enumeration
3.3.4 Sample code
Java
Need to import
import com.qualcomm.qti.qesdk.Modem.ILinkLatencyCBs; import com.qualcomm.qti.qesdk.Modem.LinkLatencyEnums.level; import com.qualcomm.qti.qesdk.Modem.LinkLatencyEnums.slotId; import com.qualcomm.qti.qesdk.Modem.LinkLatencyManager; import com.qualcomm.qti.qesdk.QesdkStatusException;
Declare required objects
private IQesdk mQesdkManager; private PP_eDGNSSManager mPpeEdgnssManager; private PP_RTKManager mPpeRtkManager;
Create a QESDK manager instance
mQesdkManager = IQesdk.createInstance(this);
Create a data path priority manager instance
datapathPriorityManager = new DataPathPriorityManager(qesdkManager)
Set callback
// For Registering flow datapathPriorityManager.registerFlowStatusUpdates(new IDataPathPriorityCBs.IflowStatus() {<!-- --> @Override public void onValues(long l, DataPathPriorityEnums.flowStatusEnum flowStatusEnum, String s) {<!-- --> } });
Add process
datapathPriorityManager.addFlow(directionEnum, srcIp, srcPort, dstIp, dstPort, protocolEnum, apptypeEnum, inactivityTimer, dscp, new IDataPathPriorityCBs.IflowStatus() {<!-- --> @Override public void onValues(long l, DataPathPriorityEnums.flowStatusEnum flowStatusEnum, String s) {<!-- --> } });
Get process from stack
datapathPriorityManager.getFlows(new IDataPathPriorityCBs.IflowStatus() {<!-- --> @Override public void onValues(long l, DataPathPriorityEnums.flowStatusEnum flowStatusEnum, String s) {<!-- --> } });
Delete a single process
datapathPriorityManager.deleteFlow(FilterID)
Delete all processes
datapathPriorityManager.deleteAllFlows();
Native
What to include
#include "qesdk_ndk.h" #include "qesdk_Modem_LinkLatency.h"
initialization
qesdk_handle_t qesdk_handle = qesdk_init(nativeLicense, len, event_callback_handler); LinkLatencyManager *llmManager = new LinkLatencyManager(); int ret = llmManager->init(nativeLicense, len, event_callback_handler);
Set callback
void flowStatusCallback(uint32_t id, dpp_flowStatusEnum status, std::string statusString) {<!-- --> // Handle DPP flow Status callback }
Register callback
if(dppManager->registerFlowStatusUpdates(flowStatusCallback) != SUCCESS)
Add process
dppManager->addFlow(directionEnum, reinterpret_cast<const char *>(src_ip), src_port,reinterpret_cast<const char *>(dst_ip), dst_port, protocolEnum, apptypeEnum, inactivity_timer, dscp, flowStatusCallback);
Get process from stack
dppManager->getFlows(flowStatusCallback);
Delete a single process
dppManager->deleteFlow(flowid);
Delete all processes
dppManager->deleteAllFlows();
4 Sensor API
QESDK is an interface for client applications to communicate with non-Android sensor types through the QESDK sensor subsystem (Snapdragon sensor core).
The QESDK library provides sensor APIs for communicating with sensor subsystems to obtain sensor data. Some APIs are used to manage sessions and some APIs are used to communicate with sensors in the sensor subsystem. The following subsections detail the QESDK sensor API.
4.1 Sensor function
4.1.1 Sensor Session
Sensor sessions simplify communication between applications and sensor subsystems. Only one active session can be created per application. For example, if the first call to create_session has already created sensor_session_id, the second call to the create_session API will return -1. If a new session needs to be created, delete_session should be called to delete the existing session before creating a sensor session.
4.1.2 create_session
Creates a session and returns a session ID that can be used by other QESDK sensor APIs in the current session.
int create_session()
Return results
Session ID
Its values are as follows:
- > 0 – valid session ID
- -1 – failed; session was previously initialized or QESDK manager is NULL
- -2 – Insufficient application permissions
- < 0 - all other exceptions
4.1.3 get_sensors_list
Returns a list of available sensors, or NULL if the sensor is not available. The client application can check whether the required sensor data type is present in the returned list, and can subsequently use the list for SUID queries. For SUID requests, see request messages. This API can be called before creating a sensor session. Only supports activity recognition
ArrayList<String> get_sensors_list()
Return results
String array of sensor data types
Its values are as follows:
- List of sensor data types
- NULL – the list is empty when no sensors are available
- Exception – QESDK exception
4.1.4 delete_session
Remove the session from the sensor subsystem. All sensor communication will be terminated when this API is called.
int delete_session(int sensor_session_id)
Parameters
sensor_session_id
Sensor session ID
Return results
state
Its values are as follows:
- 0 – Success
- 1 – Failure; session has been previously initialized or QESDK manager is NULL
- Not 0 or 1 – exception
4.2 Sensor interface
4.2.1 Send request
Send request messages to the sensor subsystem through the session. The messages a client can send are described in Encoding and Decoding protobuf messages. If a client attempts to send a message to a sensor that is not available, the client will get an error back.
int send_request(int sensor_session_id, byte[] data)
parameter
sensor_session_id
Specifies the sensor’s session ID.
data
byte array of encoded protobuf message
Return results
state
Its values are as follows:
- 0 – Success
- -1 – failed
- Not 0 or 1 – QESDK exception
4.2.2 register_event_callback
Register the callback interface Ievent_callback_type for sensor events. The registered callback is called whenever a sensor event is generated by a client-activated sensor.
void register_event_callback( int sensor_session_id, final Ievent_callback_type cb)
parameter
sensor_session_id
Specifies the sensor’s session ID.
cb
A callback function that will be triggered when an event occurs.
Ievent_callback_type is an interface in the ISensorsCBs interface. The onValues() method is triggered by the QESDK’s sensor manager to handle sensor events from the sensor subsystem.
public interface Ievent_callback_type {<!-- --> void onValues(byte[] bytes, int sensor_session_id); }
bytes
Encoded Protobuf message
sensor_session_id
Specifies the sensor’s session ID.
4.2.3 register_error_callback
Register callback interface cb for error events. The registered callback will be called when an error occurs and the error must be reported to the client from the sensor subsystem.
void register_error_callback(int sensor_session_id, final Ierror_callback_type cb)
parameter
sensor_session_id
Specifies the sensor’s session ID.
cb
A callback function that will be fired when an error is reported.
Ierror_callback_type is an interface in the ISensorsCBs interface. The onValues() method is triggered by the QESDK’s sensor manager and is used to handle sensor events and errors from the sensor subsystem.
public interface Ierror_callback_type {<!-- --> void onValues(int error, int sensor_session_id); }
error
The session must be restarted when any errors are encountered.
sensor_session_id
Specifies the sensor’s session ID.
4.2.4 Ierror_callback_type.onValues
This callback will be called asynchronously if an error occurs in the underlying module while processing sensor data. The client must stop ongoing operations and clean up resources, and then the sensor session should be started from scratch.
Ierror_callback_type.onValues(int error, int sensor_session_id)
parameter
error
error code.
sensor_session_id
Specifies the sensor’s session ID.
4.2.5 Ievent_callback_type.onValues
This callback is called whenever sensor data is available. The actual sensor data encoded in the proto message is passed through this callback. The client needs to decode proto_encoded_message to get sensor data. See Encoding and Decoding protobuf messages for details.
Ievent_callback_type.onValues(byte[] proto_encoded_message, int sensor_session_id)
parameter
proto_encoded_message
proto encodes a message containing sensor data.
sensor_session_id
Specifies the sensor’s session ID.
4.3 Activity recognition
Activity recognition methods can be used to understand what the user is doing, making applications smarter. Applications must have the android.permission.ACTIVITY_RECOGNITION runtime permission to access the API. Activity can only be tracked if you have this access. Without activity awareness permissions, QESDK sensor session creation will fail with a -2 error.
4.3.1 Activity Identification Enumeration
All enumerations defined in activity recognition are used by the QESDK sensor API.
Enumeration value | |
---|---|
S_AR_UNKNOWN = 0 | UNKNOWN is reported when the algorithm cannot detect the current active state. |
SNS_AR_STATIONARY = 1; | The user is relatively stationary. |
SNS_AR_PED = 2; | The user is classified as a pedestrian. |
SNS_AR_NMV = 3; | The user is in a non-motorized vehicle. |
SNS_AR_MV = 4; | The user is in a motor vehicle. |
SNS_AR_WALK = 5; | The user is walking |
SNS_AR_RUN = 6; | The user is running |
SNS_AR_BICYCLE = 7; | The user is on a bicycle |
SNS_AR_CAR = 8; | User in car |