-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
local: Sort devices, channels and attributes when adding them.
In this way, other iio utilities will output information in an easy to read/compare way. This has no functionality difference, except to add a small negative performance, but it makes the output of iio_attr and iio_info, much easier to track by hand. Signed-off-by: Robin Getz <[email protected]>
- Loading branch information
Showing
6 changed files
with
140 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* libiio - Library for interfacing industrial I/O (IIO) devices | ||
* | ||
* Copyright (C) 2018 Analog Devices, Inc. | ||
* Author: Robin Getz <[email protected]> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* */ | ||
|
||
#include "iio-private.h" | ||
#include <string.h> | ||
|
||
/* These are a few functions to do sorting for various | ||
* iio structures. For more info, see the qsort(3) man page. | ||
* If the structures are updated, the sort functions may | ||
* need to be updated. | ||
* | ||
* The actual arguments to these function are "pointers to | ||
* pointers to char", but strcmp(3) arguments are "pointers | ||
* to char", hence the cast plus dereference | ||
*/ | ||
|
||
int qsort_iio_channel(const void *p1, const void *p2) | ||
{ | ||
const struct iio_channel *tmp1 = *(struct iio_channel **)p1; | ||
const struct iio_channel *tmp2 = *(struct iio_channel **)p2; | ||
|
||
/* make sure buffer enabled channels are first */ | ||
if (iio_channel_is_scan_element(tmp1) && !iio_channel_is_scan_element(tmp2)) | ||
return -1; | ||
if (!iio_channel_is_scan_element(tmp1) && iio_channel_is_scan_element(tmp2)) | ||
return 1; | ||
/* and sort them by index */ | ||
if (iio_channel_is_scan_element(tmp1) && iio_channel_is_scan_element(tmp2)){ | ||
if (iio_channel_get_index(tmp1) > iio_channel_get_index(tmp2)) | ||
return 1; | ||
return -1; | ||
} | ||
/* otherwise, if the ID is the same, input channels first */ | ||
if (strcmp(tmp1->id, tmp2->id) == 0) | ||
return !iio_channel_is_output(tmp1); | ||
|
||
/* finally by ID */ | ||
return strcmp(tmp1->id, tmp2->id); | ||
} | ||
|
||
int qsort_iio_channel_attr(const void *p1, const void *p2) | ||
{ | ||
const struct iio_channel_attr *tmp1 = (struct iio_channel_attr *)p1; | ||
const struct iio_channel_attr *tmp2 = (struct iio_channel_attr *)p2; | ||
/* qsort channel attributes by name */ | ||
return strcmp(tmp1->name, tmp2->name); | ||
} | ||
|
||
int qsort_iio_device(const void *p1, const void *p2) | ||
{ | ||
const struct iio_device *tmp1 = *(struct iio_device **)p1; | ||
const struct iio_device *tmp2 = *(struct iio_device **)p2; | ||
/* qsort devices by ID */ | ||
return strcmp(tmp1->id, tmp2->id); | ||
} | ||
|
||
int qsort_iio_device_attr(const void *p1, const void *p2) | ||
{ | ||
const char *tmp1 = *(const char **)p1; | ||
const char *tmp2 = *(const char **)p2; | ||
/* qsort device attributes by name */ | ||
return strcmp(tmp1, tmp2); | ||
} | ||
|
||
int qsort_iio_buffer_attr(const void *p1, const void *p2) | ||
{ | ||
const char *tmp1 = *(const char **)p1; | ||
const char *tmp2 = *(const char **)p2; | ||
/* qsort buffer attributes by name */ | ||
return strcmp(tmp1, tmp2); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* libiio - Library for interfacing industrial I/O (IIO) devices | ||
* | ||
* Copyright (C) 2018 Analog Devices, Inc. | ||
* Author: Robin Getz <[email protected]> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* */ | ||
|
||
#ifndef __IIO_QSORT_H__ | ||
#define __IIO_QSORT_H__ | ||
|
||
int qsort_iio_channel(const void *p1, const void *p2); | ||
int qsort_iio_channel_attr(const void *p1, const void *p2); | ||
int qsort_iio_device(const void *p1, const void *p2); | ||
int qsort_iio_device_attr(const void *p1, const void *p2); | ||
int qsort_iio_buffer_attr(const void *p1, const void *p2); | ||
|
||
#endif /* __IIO_QSORT_H__ */ |