From f052d7d48e10fdf2f396e18de18567ab4421461b Mon Sep 17 00:00:00 2001 From: Patrick Porlan Date: Fri, 30 May 2014 11:57:11 +0200 Subject: [PATCH] STPK-1429 Slight improvement to timestamp accuracy Use date immediately before the iio device read operation instead of sensor report propagation time as the event timestamp. That's only an intermediate step towards higher precision timestamps though, as some drivers expose a timestamp channel we can read at the same time as associated sample data. Issue: STPK-1429 Change-Id: Iad5e1dc35fcbd422d3d1390cab202e3c36de8504 Signed-off-by: Patrick Porlan --- common.h | 8 ++++++++ control.c | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/common.h b/common.h index b46449b..670aa88 100644 --- a/common.h +++ b/common.h @@ -130,6 +130,14 @@ struct sensor_info_t */ int report_pending; + /* + * Timestamp closely matching the date of sampling, preferably retrieved + * from a iio channel alongside sample data. Value zero indicates that + * we couldn't get such a closely correlated timestamp, and that one + * has to be generated before the report gets sent up to Android. + */ + int64_t report_ts; + unsigned char report_buffer[MAX_SENSOR_REPORT_SIZE]; int64_t last_integration_ts; /* Last time an event was reported */ diff --git a/control.c b/control.c index b1a1126..188cd6c 100644 --- a/control.c +++ b/control.c @@ -368,6 +368,7 @@ static int integrate_device_report(int dev_num) unsigned char *source; int size; int expected_size = 0; + int ts; /* There's an incoming report on the specified fd */ @@ -386,6 +387,8 @@ static int integrate_device_report(int dev_num) for (c=0; cversion = sizeof(sensors_event_t); data->sensor = s; data->type = sensor_type; - data->timestamp = current_ts; + + if (sensor_info[s].report_ts) + data->timestamp = sensor_info[s].report_ts; + else + data->timestamp = current_ts; switch (sensor_type) { case SENSOR_TYPE_ACCELEROMETER: /* m/s^2 */ -- 2.11.0