aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorStan Rokita <srok@google.com>2020-04-16 16:36:00 -0700
committerStan Rokita <srok@google.com>2020-04-30 10:00:25 -0700
commit7f6c7ea1063d3bffab939b306d0eb1a79875fa8a (patch)
tree02678feb8fe6cf3fdd072607224bf52d51f95046 /apps
parent9c9881f9b04f3d8df3669c2dce9ffd5ca8c725ed (diff)
downloadchre-7f6c7ea1063d3bffab939b306d0eb1a79875fa8a.tar.gz
Add proximity sensor support to chre cross validator
Also proximity is a special case since it is the only chreSensorByteData type sensor that is being validated and its isNear property needs to be converted to the float values used by the AP side framework before being sent back from the nanoapp so it has its own handlers helper methods in the nanoapp. AP side code will compare values of 1 as far for CHRE datapoint and 0 for near and will check that in the case that its far that AP will not be too close to , and vice versa that near will not go to close to max value. Change bug number for todo to break up Manager class to new bug that was filed separately for this purpose. Bug: 146052784 Bug: 154271551 Test: proximity chqts test passes Change-Id: I94319e6dc0580c7e4086304753eedcd642d37a74
Diffstat (limited to 'apps')
-rw-r--r--apps/test/common/chre_cross_validator/inc/chre_cross_validator_manager.h47
-rw-r--r--apps/test/common/chre_cross_validator/src/chre_cross_validator_manager.cc78
2 files changed, 123 insertions, 2 deletions
diff --git a/apps/test/common/chre_cross_validator/inc/chre_cross_validator_manager.h b/apps/test/common/chre_cross_validator/inc/chre_cross_validator_manager.h
index adac4f72..5fd6d391 100644
--- a/apps/test/common/chre_cross_validator/inc/chre_cross_validator_manager.h
+++ b/apps/test/common/chre_cross_validator/inc/chre_cross_validator_manager.h
@@ -29,7 +29,7 @@ namespace chre {
namespace cross_validator {
-// TODO(b/146052784): Break up the Manager class into more fine-grained classes
+// TODO(b/154271551): Break up the Manager class into more fine-grained classes
// to avoid it becoming to complex.
/**
@@ -149,6 +149,18 @@ class Manager {
void *const *arg);
/**
+ * Encodes the datapoints into a SensorData message.
+ *
+ * @param stream The stream to write to.
+ * @param field The field to write to (unused).
+ * @param arg The data passed in order to write to the stream.
+ * @return true if successful.
+ */
+ static bool encodeProximitySensorDatapoints(pb_ostream_t *stream,
+ const pb_field_t * /*field*/,
+ void *const *arg);
+
+ /**
* Encodes a single float value into values list of SensorDatapoint object.
*
* @param stream The stream to write to.
@@ -161,6 +173,20 @@ class Manager {
void *const *arg);
/**
+ * Encodes a single promximity value into values list of SensorDatapoint
+ * object, converting the isNear property into 5.0 (false) or 0.0 (true) in
+ * the process.
+ *
+ * @param stream The stream to write to.
+ * @param field The field to write to (unused).
+ * @param arg The data passed in order to write to the stream.
+ * @return true if successful.
+ */
+ static bool encodeProximitySensorDatapointValue(pb_ostream_t *stream,
+ const pb_field_t * /*field*/,
+ void *const *arg);
+
+ /**
* Handle a start sensor message.
*
* @param startSensorCommand The StartSensorCommand proto message received.
@@ -204,7 +230,7 @@ class Manager {
const chreSensorThreeAxisData *threeAxisDataFromChre, uint8_t sensorType);
/**
- * @param floatDataFromChre Three axis sensor data from CHRE.
+ * @param floatDataFromChre Float sensor data from CHRE.
* @param sensorType The sensor type that sent the three axis data.
*
* @return The Data proto message that is ready to be sent to host with float
@@ -214,6 +240,16 @@ class Manager {
const chreSensorFloatData *floatDataFromChre, uint8_t sensorType);
/**
+ * @param proximtyDataFromChre Proximity sensor data from CHRE.
+ * @param sensorType The sensor type that sent the three axis data.
+ *
+ * @return The Data proto message that is ready to be sent to host with float
+ * data.
+ */
+ chre_cross_validation_Data makeSensorProximityData(
+ const chreSensorByteData *proximityDataFromChre);
+
+ /**
* Handle sensor three axis data from CHRE.
*
* @param threeAxisDataFromChre The data from CHRE to parse.
@@ -232,6 +268,13 @@ class Manager {
uint8_t sensorType);
/**
+ * Handle proximity sensor data from CHRE.
+ *
+ * @param proximityDataFromChre The data to parse.
+ */
+ void handleProximityData(const chreSensorByteData *proximityDataFromChre);
+
+ /**
* Encode and send data to be validated to host.
*
* @param data The data to encode and send.
diff --git a/apps/test/common/chre_cross_validator/src/chre_cross_validator_manager.cc b/apps/test/common/chre_cross_validator/src/chre_cross_validator_manager.cc
index a6113fe0..cf9d94f6 100644
--- a/apps/test/common/chre_cross_validator/src/chre_cross_validator_manager.cc
+++ b/apps/test/common/chre_cross_validator/src/chre_cross_validator_manager.cc
@@ -87,10 +87,14 @@ void Manager::handleEvent(uint32_t senderInstanceId, uint16_t eventType,
case CHRE_EVENT_SENSOR_PRESSURE_DATA:
handleSensorFloatData(static_cast<const chreSensorFloatData *>(eventData),
CHRE_SENSOR_TYPE_PRESSURE);
+ break;
case CHRE_EVENT_SENSOR_LIGHT_DATA:
handleSensorFloatData(static_cast<const chreSensorFloatData *>(eventData),
CHRE_SENSOR_TYPE_LIGHT);
break;
+ case CHRE_EVENT_SENSOR_PROXIMITY_DATA:
+ handleProximityData(static_cast<const chreSensorByteData *>(eventData));
+ break;
default:
LOGE("Got unknown event type from senderInstanceId %" PRIu32
" and with eventType %" PRIu16,
@@ -144,6 +148,23 @@ bool Manager::encodeFloatSensorDatapointValue(pb_ostream_t *stream,
return true;
}
+bool Manager::encodeProximitySensorDatapointValue(pb_ostream_t *stream,
+ const pb_field_t * /*field*/,
+ void *const *arg) {
+ const auto *sensorFloatDataSample =
+ static_cast<const chreSensorByteData::chreSensorByteSampleData *>(*arg);
+ if (!pb_encode_tag_for_field(
+ stream, &chre_cross_validation_SensorDatapoint_fields
+ [chre_cross_validation_SensorDatapoint_values_tag - 1])) {
+ return false;
+ }
+ float isNearFloat = sensorFloatDataSample->isNear ? 0.0 : 1.0;
+ if (!pb_encode_fixed32(stream, &isNearFloat)) {
+ return false;
+ }
+ return true;
+}
+
bool Manager::encodeThreeAxisSensorDatapoints(pb_ostream_t *stream,
const pb_field_t * /*field*/,
void *const *arg) {
@@ -197,6 +218,33 @@ bool Manager::encodeFloatSensorDatapoints(pb_ostream_t *stream,
return true;
}
+bool Manager::encodeProximitySensorDatapoints(pb_ostream_t *stream,
+ const pb_field_t * /*field*/,
+ void *const *arg) {
+ const auto *sensorProximityData =
+ static_cast<const chreSensorByteData *>(*arg);
+ uint64_t currentTimestamp = sensorProximityData->header.baseTimestamp +
+ chreGetEstimatedHostTimeOffset();
+ for (size_t i = 0; i < sensorProximityData->header.readingCount; i++) {
+ const chreSensorByteData::chreSensorByteSampleData &sampleData =
+ sensorProximityData->readings[i];
+ currentTimestamp += sampleData.timestampDelta;
+ if (!pb_encode_tag_for_field(
+ stream,
+ &chre_cross_validation_SensorData_fields
+ [chre_cross_validation_SensorData_datapoints_tag - 1])) {
+ return false;
+ }
+ chre_cross_validation_SensorDatapoint datapoint = makeDatapoint(
+ encodeProximitySensorDatapointValue, &sampleData, currentTimestamp);
+ if (!pb_encode_submessage(
+ stream, chre_cross_validation_SensorDatapoint_fields, &datapoint)) {
+ return false;
+ }
+ }
+ return true;
+}
+
bool Manager::handleStartSensorMessage(
const chre_cross_validation_StartSensorCommand &startSensorCommand) {
bool success = true;
@@ -335,6 +383,26 @@ chre_cross_validation_Data Manager::makeSensorFloatData(
return newData;
}
+chre_cross_validation_Data Manager::makeSensorProximityData(
+ const chreSensorByteData *proximityDataFromChre) {
+ chre_cross_validation_SensorData newProximityData = {
+ .has_chreSensorType = true,
+ .chreSensorType = CHRE_SENSOR_TYPE_PROXIMITY,
+ .has_accuracy = true,
+ .accuracy = proximityDataFromChre->header.accuracy,
+ .datapoints = {
+ .funcs = {.encode = encodeProximitySensorDatapoints},
+ .arg = const_cast<chreSensorByteData *>(proximityDataFromChre)}};
+ chre_cross_validation_Data newData = {
+ .which_data = chre_cross_validation_Data_sensorData_tag,
+ .data =
+ {
+ .sensorData = newProximityData,
+ },
+ };
+ return newData;
+}
+
void Manager::handleSensorThreeAxisData(
const chreSensorThreeAxisData *threeAxisDataFromChre, uint8_t sensorType) {
if (processSensorData(threeAxisDataFromChre->header, sensorType)) {
@@ -353,6 +421,16 @@ void Manager::handleSensorFloatData(
}
}
+void Manager::handleProximityData(
+ const chreSensorByteData *proximityDataFromChre) {
+ if (processSensorData(proximityDataFromChre->header,
+ CHRE_SENSOR_TYPE_PROXIMITY)) {
+ chre_cross_validation_Data newData =
+ makeSensorProximityData(proximityDataFromChre);
+ encodeAndSendDataToHost(newData);
+ }
+}
+
void Manager::encodeAndSendDataToHost(const chre_cross_validation_Data &data) {
size_t encodedSize;
if (!pb_get_encoded_size(&encodedSize, chre_cross_validation_Data_fields,