언어 설정

Menu
Sites
Language
Sensor event timestamp

Hello all!

I am trying to figure out how to process data from sensors, particularly with the field "timestamp" on Samsung Gear S2.

The doc says that this field in nanosecond, but by my experiments it is looks like this field measured in microseconds and it is not realtime value (does'n increment  while sleeping and so on). Most similar value have CLOCK_MONOTONIC. After all I ended up with this code to get event time in ms:

static void accelerometer_cb(sensor_h sensor, sensor_event_s *event, void *data)
{
  struct timespec spec;

  clock_gettime(CLOCK_REALTIME, &spec);

  unsigned long long current_time_ms = spec.tv_sec * 1000LL + spec.tv_nsec / 1000000LL;

  clock_gettime(CLOCK_MONOTONIC, &spec);

  unsigned long long monotonic_time_ms = spec.tv_sec * 1000LL + spec.tv_nsec / 1000000LL;

  unsigned long long event_time_ms = current_time_ms - monotonic_time_ms + event->timestamp / 1000LL;

Is this correct way to do this, or I missed something?

Responses

4 댓글
daniel kim

Hi,

I think that you can try a code of this link to check sensor activity.

    https://developer.tizen.org/forums/native-application-development/interval_ms-not-work-function-sensor_listener_set_event_cb-.?tab=active

Regards

Sergey Astakhov

Hi Daniel, thanks for reply.

In your link there is no examples of using value of timestamp field.

I have already installed my own test program into my watches, to logging values of sensor data during the day. This is example from the accelerometer log (interval set to 100 ms):

timestamp,event_time,event_timestamp,x,y,z
1454364713322,1454364713295,41273558480,-1.744368,-1.277767,9.418150
1454364713403,1454364713397,41273661669,-1.586441,-1.134198,9.645468
1454364713503,1454364713499,41273763796,-1.732404,-1.265803,9.470792
1454364713601,1454364713598,41273861529,-1.741975,-1.301696,9.518648
1454364713704,1454364713699,41273962892,-1.689333,-1.222732,9.454042
1454364713801,1454364713798,41274061293,-1.634298,-1.194018,9.604790
1454364713901,1454364713898,41274161653,-1.655833,-1.275374,9.489935
1454364714002,1454364713997,41274261681,-1.627119,-1.215554,9.552148

The first value (timestamp) - is a current time in milliseconds (variable "current_time_ms" from the code above).

The second one (event_time) - event time in milliseconds, calculated in the code above.

The third (event_timestamp) - value from event->timestamp.

Result of calculation is looks like the correct value, just want to make sure that I did not miss anything important.

daniel kim

Hi,

I think that you also can check logging time using dlog_print instead of timestamp.

     dlog_print(DLOG_INFO, "glviewcubesample", "acceleration are X = %lf, Y = %lf, Z = %lf", values[0], values[1], values[2]);

Regards

Sergey Astakhov

Logging time - it is the same value that the function call "clock_gettime(CLOCK_REALTIME)" returns. The problem with simple using the current time you can see in this example:

timestamp,event_time,event_timestamp,x,y,z
1454455464575,1454455464574,45157033873,-1.823331,-4.457829,8.494520
1454455464679,1454455464675,45157134493,-1.775474,-4.381258,8.590233
1454455484303,1454455477696,45157235497,-1.861616,-4.421937,8.432307
1454455484307,1454455477795,45157334391,-1.847259,-4.335794,8.508877
1454455484307,1454455478158,45157698166,-1.335195,-4.622933,8.504091
1454455484308,1454455478253,45157792848,-1.225125,-4.606184,8.504091
1454455484308,1454455478353,45157893638,-1.392623,-4.563113,8.561519

Between 1454455464679 and 1454455484303 application did not receive any mesurement (device looks like goes to the sleep mode), but after wake up it began receive them at an accelerated rate.