Hello,

Since a few days I have been working on adding cputime to sensor samples. This 
would help in doing interpolation of data coming from different sensors in a 
sensor network with sensors connected to different nodes.

If multiple sensors are connected to the same device, this would help in 
implementing sensor fusion algorithms.

After going back and forth on various designs this is the one I have finalized 
and implemented and works great IMO.

Design:

sensor timestamp update os_callout fires every 2146 seconds and avoids multiple 
overflows of the os_timeval.tv_usec fields filling up global os_timeval 
structure which gets updated every time a sensor is read.

There is also a timestamp which is part of the sensor structure which gets 
filled up every time a sensor is read.

The seconds, micro seconds and cputime field gets updated accordingly.

Following is an output of the timestamped samples:

> sensor read color0 0x20000000 -n 10 -i 100
> 864:ts: [ secs: 6 usecs: 777617 cputime: 7212189 ]
> 865:r = 101, g = 111, b = 118, c = 243,
> 866:lux = 21, cct = 6317K, ir = 43,
> 867:sat = 65535, sat75 = 65535, not saturated, cRatio = 0.176954736, max lux 
> = 11029,
> 
> 877:ts: [ secs: 6 usecs: 877631 cputime: 7312203 ]
> 878:r = 101, g = 111, b = 118, c = 243,
> 879:lux = 21, cct = 6317K, ir = 43,
> 880:sat = 65535, sat75 = 65535, not saturated, cRatio = 0.176954736, max lux 
> = 11029,
> 
> 889:ts: [ secs: 6 usecs: 977645 cputime: 7412217 ]
> 890:r = 101, g = 111, b = 118, c = 243,
> 891:lux = 21, cct = 6317K, ir = 43,
> 892:sat = 65535, sat75 = 65535, not saturated, cRatio = 0.176954736, max lux 
> = 11029,
> 
> 902:ts: [ secs: 7 usecs: 77659 cputime: 7512231 ]
> 903:r = 101, g = 111, b = 118, c = 243,
> 904:lux = 21, cct = 6317K, ir = 43,
> 905:sat = 65535, sat75 = 65535, not saturated, cRatio = 0.176954736, max lux 
> = 11029,
> 
> 915:ts: [ secs: 7 usecs: 177673 cputime: 7612245 ]
> 916:r = 101, g = 112, b = 118, c = 243,
> 917:lux = 21, cct = 6337K, ir = 44,
> 918:sat = 65535, sat75 = 65535, not saturated, cRatio = 0.181069952, max lux 
> = 11029,
> 
> 927:ts: [ secs: 7 usecs: 277687 cputime: 7712259 ]
> 928:r = 101, g = 112, b = 118, c = 243,
> 929:lux = 21, cct = 6337K, ir = 44,
> 930:sat = 65535, sat75 = 65535, not saturated, cRatio = 0.181069952, max lux 
> = 11029,
> 
> 940:ts: [ secs: 7 usecs: 377701 cputime: 7812273 ]
> 941:r = 101, g = 111, b = 118, c = 243,
> 942:lux = 21, cct = 6317K, ir = 43,
> 943:sat = 65535, sat75 = 65535, not saturated, cRatio = 0.176954736, max lux 
> = 11029,
> 
> 953:ts: [ secs: 7 usecs: 477715 cputime: 7912287 ]
> 954:r = 101, g = 111, b = 118, c = 243,
> 955:lux = 21, cct = 6317K, ir = 43,
> 956:sat = 65535, sat75 = 65535, not saturated, cRatio = 0.176954736, max lux 
> = 11029,
> 
> 965:ts: [ secs: 7 usecs: 577729 cputime: 8012301 ]
> 966:r = 101, g = 112, b = 118, c = 244,
> 967:lux = 22, cct = 6317K, ir = 43,
> 968:sat = 65535, sat75 = 65535, not saturated, cRatio = 0.176229504, max lux 
> = 11029,
> 
> 978:ts: [ secs: 7 usecs: 677743 cputime: 8112315 ]
> 979:r = 101, g = 112, b = 118, c = 244,
> 980:lux = 22, cct = 6317K, ir = 43,
> 981:sat = 65535, sat75 = 65535, not saturated, cRatio = 0.176229504, max lux 
> = 11029,


I have created a ticket to track this:
MYNEWT-703 <https://issues.apache.org/jira/browse/MYNEWT-703>SensorAPI: Add 
cputime timestamps and timeofday to SensorAPI samples

Suggestions are welcome.

Regards,
Vipul Rahane

Reply via email to