Commit Graph

18 Commits

Author SHA1 Message Date
Bastien Nocera
d0ced55668 iio-buffer-utils: Don't throw warnings on ENOENT
As we don't return when the file doesn't exist, don't print a warning
either, as this would pollute logs and throw people off when debugging
real problems.

Closes: #180
2017-08-16 16:52:23 +02:00
Bastien Nocera
d71d4342e4 iio-buffer-utils: Better debug in enable_sensors() 2016-11-22 14:14:18 +01:00
Srinivas Pandruvada
12c137bcf1 iio-buffer-utils: Don't fail on non-existing attributes
build_channel_array() goes through each directory member in
scan_elements folder and tries to get scale and offset of matching
elements. But there will be no scale and offset for some elements
like timestamp.
For example:
in_accel_x_en     in_accel_y_en     in_accel_z_en     in_timestamp_en
in_accel_x_index  in_accel_y_index  in_accel_z_index  in_timestamp_index
in_accel_x_type   in_accel_y_type   in_accel_z_type   in_timestamp_type

When scale and offset not present, iioutils_get_param_float() will fail,
this causes return from the build_channel_array().

It shouldn't return when the error is caused by the attribute not being
present as, in this case, in_time_stamp_scale.

This was fixed in the kernel's iio_utils.c in commit 7868dfd.
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=7868dfd216074fc5f902e7befacda2a0ec76e403

Closes: #114
2016-11-18 11:46:57 +01:00
Srinivas Pandruvada
5d3a83d77d iio-buffer-utils: Really fix sorting of channels
As per the documentation of g_ptr_array_sort
"Note that the comparison function for g_ptr_array_sort() doesn't take the
pointers from the array as arguments, it takes pointers to the pointers in
the array"
So the arguments to the function
	compare_channel_index (gconstpointer a, gconstpointer b)
needs to be dereferenced to get pointer to iio_channel_info.

The error was included in the fixup for commit 984803b by
the maintainer.

Closes #99
2016-09-17 00:49:59 +02:00
Bastien Nocera
c7d00d278d buffer-utils: Fix possible crash handling compasses
The generic_name is supposed to be an allocated string. As we were
passing it a static string, it might have crashed later on.
2016-09-06 14:47:24 +02:00
Bastien Nocera
26b414681b buffer-utils: Fix "const char" build warning 2016-09-06 14:47:20 +02:00
Srinivas Pandruvada
984803bc1b buffer-utils: Fix orientation axis switch using 4.8 kernel
Using 4.8-rc kernel, orientation got flipped. The right-up became normal
and normal became right-up. The reason for this is that orientation code
of iio-sensor-proxy observes x and y swapped (actually they are not in
the data provided by IIO).

Although it is triggered by some kernel change, the reliance on
g_dir_read_name() to get the correct order of channels is not correct.
We should look at the in_xxx_x_index field and calculate correct byte
offset in the iio buffer data.

For example with 4.8 kernel: from log with added index location printed

** (process:4945): DEBUG: Built channel array for in_accel_y: index: 1, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0
** (process:4945): DEBUG: Built channel array for in_accel_x: index: 0, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0
** (process:4945): DEBUG: Built channel array for in_accel_z: index: 2, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0

(Here in_accel_y appeared before in_accel_x in g_dir_read_name(), because
of that channel array ordering is wrong hence location was
calculated wrong as below)
...
...
** (process:4945): DEBUG: process_scan_1: channel_index: 1, chan_name: in_accel_x, channel_data_index: 0 location: 4
** (process:4945): DEBUG: process_scan_1: channel_index: 0, chan_name: in_accel_y, channel_data_index: 1 location: 0
** (process:4945): DEBUG: process_scan_1: channel_index: 2, chan_name: in_accel_z, channel_data_index: 2 location: 8
** (process:4945): DEBUG: Read from IIO: -880449, 32851, -457812

To fix this we need to calculate the byte offset location using
channel_index not in the order they are returned by g_dir_read_name().

The easiest fix is to sort the array of channels in
build_channel_array() based on index. Also added some debug to print
index and location.

After the fix, the above log will change to:
** (process:4674): DEBUG: Built channel array for in_accel_x: index: 0, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0
** (process:4674): DEBUG: Built channel array for in_accel_y: index: 1, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0
** (process:4674): DEBUG: Built channel array for in_accel_z: index: 2, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0

(Sorted above, so location of byte offset is correct)

** (process:4674): DEBUG: process_scan_1: channel_index: 0, chan_name: in_accel_x, channel_data_index: 0 location: 0
** (process:4674): DEBUG: process_scan_1: channel_index: 1, chan_name: in_accel_y, channel_data_index: 1 location: 4
** (process:4674): DEBUG: process_scan_1: channel_index: 2, chan_name: in_accel_z, channel_data_index: 2 location: 8
** (process:4674): DEBUG: Read from IIO: 34804, -878496, -448046

Closes: #99
2016-09-06 14:21:46 +02:00
Bastien Nocera
92fa6ea9ec buffer-utils: Don't warn when sensor was already enabled
Slight regression in commit 3816a34, where an already enabled sensor
would still make enable_sensors() fail.
2016-06-14 18:47:10 +02:00
Bastien Nocera
207b5bbd87 buffer-utils: Warn if a ring buffer could not be setup 2016-06-14 17:07:03 +02:00
Bastien Nocera
3816a34120 buffer-utils: Error out if no sensor is enabled in enable_sensors()
Error out if none of the sensors could be enabled, and throw a warning.
2016-06-14 17:07:03 +02:00
Bastien Nocera
e5ec57dca1 buffer-utils: Add more debug to the scan_elements parsing 2015-07-25 20:40:03 +02:00
Reyad Attiyat
7b22982f76 buffer-utils: Display warning if IIO channel not found
See #38
2015-07-15 08:44:18 +02:00
Bastien Nocera
0eeda7b24f buffer-utils: Sanitise empty scale values
In case we can't read a scale from the IIO buffer, make sure that the
scale is set to 1.0 (no changes) rather than 0.0.
2015-07-11 14:31:38 +02:00
Benjamin Tissoires
f04fe60af3 main: Apply scale from readings for IIO buffered drivers
Add a scale output parameter in process_scan_1 so that we pass scale
information from each driver read to the driver, and apply the scale
before passing it on to the main daemon.

Closes #28
2015-07-01 18:36:55 +02:00
Elad Alfassa
42929a882a main: Workaround sysfs attributes naming quirk for compasses
In most IIO sensor types, _scale and _offset is added to the scan element base
name, for example:
in_accel has in_accel_scale and in_accel_offset

For compasses, this is different. Instead of being named
in_rot_from_north_magnetic_tilt_scale aand similar, the _scale and_offset
attributes are named in_rot_scale and in_rot_offset.

This commit adds a workaround to special-case the attribute naming for this
type of sensor.
2015-06-03 11:43:27 +01:00
Bastien Nocera
6d2fff6c10 COPYING: Clarify GPL v3 license
Closes #26
2015-05-27 11:13:46 +02:00
Bastien Nocera
8fd1a46c8d main: Update copyright headers
And remove documentation from it, it should all be in the newly added
docs.
2015-05-20 10:44:52 +02:00
Elad Alfassa
d486aadd0e main: Split iio buffering sensors utility functions to a helper file 2015-03-24 15:49:15 +01:00