Commit 7663a4aa authored by Hartmut Knaack's avatar Hartmut Knaack Committed by Jonathan Cameron

tools:iio: adjust coding style

Fix various coding style issues, including:
  * have spaces around operators
  * indentation
  * consolidate parameters in same line
  * required braces
  * adjust/drop comments
  * multiline comment style
  * delete unnecessary empty lines
  * add empty lines to visualize logial code blocks
  * typos
Signed-off-by: default avatarHartmut Knaack <knaack.h@gmx.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 4f3ca893
...@@ -51,11 +51,13 @@ int size_from_channelarray(struct iio_channel_info *channels, int num_channels) ...@@ -51,11 +51,13 @@ int size_from_channelarray(struct iio_channel_info *channels, int num_channels)
if (bytes % channels[i].bytes == 0) if (bytes % channels[i].bytes == 0)
channels[i].location = bytes; channels[i].location = bytes;
else else
channels[i].location = bytes - bytes%channels[i].bytes channels[i].location = bytes - bytes % channels[i].bytes
+ channels[i].bytes; + channels[i].bytes;
bytes = channels[i].location + channels[i].bytes; bytes = channels[i].location + channels[i].bytes;
i++; i++;
} }
return bytes; return bytes;
} }
...@@ -136,9 +138,9 @@ void print8byte(uint64_t input, struct iio_channel_info *info) ...@@ -136,9 +138,9 @@ void print8byte(uint64_t input, struct iio_channel_info *info)
/** /**
* process_scan() - print out the values in SI units * process_scan() - print out the values in SI units
* @data: pointer to the start of the scan * @data: pointer to the start of the scan
* @channels: information about the channels. Note * @channels: information about the channels.
* size_from_channelarray must have been called first to fill the * Note: size_from_channelarray must have been called first
* location offsets. * to fill the location offsets.
* @num_channels: number of channels * @num_channels: number of channels
**/ **/
void process_scan(char *data, void process_scan(char *data,
...@@ -213,6 +215,7 @@ int main(int argc, char **argv) ...@@ -213,6 +215,7 @@ int main(int argc, char **argv)
num_loops = strtoul(optarg, &dummy, 10); num_loops = strtoul(optarg, &dummy, 10);
if (errno) if (errno)
return -errno; return -errno;
break; break;
case 'e': case 'e':
noevents = 1; noevents = 1;
...@@ -225,6 +228,7 @@ int main(int argc, char **argv) ...@@ -225,6 +228,7 @@ int main(int argc, char **argv)
buf_len = strtoul(optarg, &dummy, 10); buf_len = strtoul(optarg, &dummy, 10);
if (errno) if (errno)
return -errno; return -errno;
break; break;
case 'n': case 'n':
device_name = optarg; device_name = optarg;
...@@ -257,6 +261,7 @@ int main(int argc, char **argv) ...@@ -257,6 +261,7 @@ int main(int argc, char **argv)
printf("Failed to find the %s\n", device_name); printf("Failed to find the %s\n", device_name);
return dev_num; return dev_num;
} }
printf("iio device number being used is %d\n", dev_num); printf("iio device number being used is %d\n", dev_num);
ret = asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num); ret = asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num);
...@@ -285,9 +290,11 @@ int main(int argc, char **argv) ...@@ -285,9 +290,11 @@ int main(int argc, char **argv)
ret = trig_num; ret = trig_num;
goto error_free_triggername; goto error_free_triggername;
} }
printf("iio trigger number being used is %d\n", trig_num); printf("iio trigger number being used is %d\n", trig_num);
} else } else {
printf("trigger-less mode selected\n"); printf("trigger-less mode selected\n");
}
/* /*
* Parse the files in scan_elements to identify what channels are * Parse the files in scan_elements to identify what channels are
...@@ -314,8 +321,10 @@ int main(int argc, char **argv) ...@@ -314,8 +321,10 @@ int main(int argc, char **argv)
if (!notrigger) { if (!notrigger) {
printf("%s %s\n", dev_dir_name, trigger_name); printf("%s %s\n", dev_dir_name, trigger_name);
/* Set the device trigger to be the data ready trigger found /*
* above */ * Set the device trigger to be the data ready trigger found
* above
*/
ret = write_sysfs_string_and_verify("trigger/current_trigger", ret = write_sysfs_string_and_verify("trigger/current_trigger",
dev_dir_name, dev_dir_name,
trigger_name); trigger_name);
...@@ -334,8 +343,9 @@ int main(int argc, char **argv) ...@@ -334,8 +343,9 @@ int main(int argc, char **argv)
ret = write_sysfs_int("enable", buf_dir_name, 1); ret = write_sysfs_int("enable", buf_dir_name, 1);
if (ret < 0) if (ret < 0)
goto error_free_buf_dir_name; goto error_free_buf_dir_name;
scan_size = size_from_channelarray(channels, num_channels); scan_size = size_from_channelarray(channels, num_channels);
data = malloc(scan_size*buf_len); data = malloc(scan_size * buf_len);
if (!data) { if (!data) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_free_buf_dir_name; goto error_free_buf_dir_name;
...@@ -349,13 +359,12 @@ int main(int argc, char **argv) ...@@ -349,13 +359,12 @@ int main(int argc, char **argv)
/* Attempt to open non blocking the access dev */ /* Attempt to open non blocking the access dev */
fp = open(buffer_access, O_RDONLY | O_NONBLOCK); fp = open(buffer_access, O_RDONLY | O_NONBLOCK);
if (fp == -1) { /* If it isn't there make the node */ if (fp == -1) { /* TODO: If it isn't there make the node */
ret = -errno; ret = -errno;
printf("Failed to open %s\n", buffer_access); printf("Failed to open %s\n", buffer_access);
goto error_free_buffer_access; goto error_free_buffer_access;
} }
/* Wait for events 10 times */
for (j = 0; j < num_loops; j++) { for (j = 0; j < num_loops; j++) {
if (!noevents) { if (!noevents) {
struct pollfd pfd = { struct pollfd pfd = {
...@@ -372,25 +381,22 @@ int main(int argc, char **argv) ...@@ -372,25 +381,22 @@ int main(int argc, char **argv)
} }
toread = buf_len; toread = buf_len;
} else { } else {
usleep(timedelay); usleep(timedelay);
toread = 64; toread = 64;
} }
read_size = read(fp, read_size = read(fp, data, toread * scan_size);
data,
toread*scan_size);
if (read_size < 0) { if (read_size < 0) {
if (errno == EAGAIN) { if (errno == EAGAIN) {
printf("nothing available\n"); printf("nothing available\n");
continue; continue;
} else } else {
break; break;
}
} }
for (i = 0; i < read_size/scan_size; i++) for (i = 0; i < read_size / scan_size; i++)
process_scan(data + scan_size*i, process_scan(data + scan_size * i, channels,
channels,
num_channels); num_channels);
} }
...@@ -409,6 +415,7 @@ int main(int argc, char **argv) ...@@ -409,6 +415,7 @@ int main(int argc, char **argv)
error_close_buffer_access: error_close_buffer_access:
if (close(fp) == -1) if (close(fp) == -1)
perror("Failed to close buffer"); perror("Failed to close buffer");
error_free_buffer_access: error_free_buffer_access:
free(buffer_access); free(buffer_access);
error_free_data: error_free_data:
...@@ -424,6 +431,7 @@ int main(int argc, char **argv) ...@@ -424,6 +431,7 @@ int main(int argc, char **argv)
error_free_triggername: error_free_triggername:
if (datardytrigger) if (datardytrigger)
free(trigger_name); free(trigger_name);
error_free_dev_dir_name: error_free_dev_dir_name:
free(dev_dir_name); free(dev_dir_name);
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
* *
* Usage: * Usage:
* iio_event_monitor <device_name> * iio_event_monitor <device_name>
*
*/ */
#include <unistd.h> #include <unistd.h>
...@@ -209,7 +208,8 @@ static void print_event(struct iio_event_data *event) ...@@ -209,7 +208,8 @@ static void print_event(struct iio_event_data *event)
if (!event_is_known(event)) { if (!event_is_known(event)) {
printf("Unknown event: time: %lld, id: %llx\n", printf("Unknown event: time: %lld, id: %llx\n",
event->timestamp, event->id); event->timestamp, event->id);
return; return;
} }
...@@ -229,6 +229,7 @@ static void print_event(struct iio_event_data *event) ...@@ -229,6 +229,7 @@ static void print_event(struct iio_event_data *event)
if (dir != IIO_EV_DIR_NONE) if (dir != IIO_EV_DIR_NONE)
printf(", direction: %s", iio_ev_dir_text[dir]); printf(", direction: %s", iio_ev_dir_text[dir]);
printf("\n"); printf("\n");
} }
...@@ -251,14 +252,16 @@ int main(int argc, char **argv) ...@@ -251,14 +252,16 @@ int main(int argc, char **argv)
dev_num = find_type_by_name(device_name, "iio:device"); dev_num = find_type_by_name(device_name, "iio:device");
if (dev_num >= 0) { if (dev_num >= 0) {
printf("Found IIO device with name %s with device number %d\n", printf("Found IIO device with name %s with device number %d\n",
device_name, dev_num); device_name, dev_num);
ret = asprintf(&chrdev_name, "/dev/iio:device%d", dev_num); ret = asprintf(&chrdev_name, "/dev/iio:device%d", dev_num);
if (ret < 0) { if (ret < 0) {
return -ENOMEM; return -ENOMEM;
} }
} else { } else {
/* If we can't find a IIO device by name assume device_name is a /*
IIO chrdev */ * If we can't find an IIO device by name assume device_name is
* an IIO chrdev
*/
chrdev_name = strdup(device_name); chrdev_name = strdup(device_name);
if (!chrdev_name) if (!chrdev_name)
return -ENOMEM; return -ENOMEM;
......
This diff is collapsed.
...@@ -51,17 +51,16 @@ struct iio_channel_info { ...@@ -51,17 +51,16 @@ struct iio_channel_info {
}; };
int iioutils_break_up_name(const char *full_name, char **generic_name); int iioutils_break_up_name(const char *full_name, char **generic_name);
int iioutils_get_type(unsigned *is_signed, unsigned *bytes, int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
unsigned *bits_used, unsigned *shift, unsigned *shift, uint64_t *mask, unsigned *be,
uint64_t *mask, unsigned *be, const char *device_dir, const char *name,
const char *device_dir, const char *name, const char *generic_name);
const char *generic_name);
int iioutils_get_param_float(float *output, const char *param_name, int iioutils_get_param_float(float *output, const char *param_name,
const char *device_dir, const char *name, const char *device_dir, const char *name,
const char *generic_name); const char *generic_name);
void bsort_channel_array_by_index(struct iio_channel_info **ci_array, int cnt); void bsort_channel_array_by_index(struct iio_channel_info **ci_array, int cnt);
int build_channel_array(const char *device_dir, int build_channel_array(const char *device_dir,
struct iio_channel_info **ci_array, int *counter); struct iio_channel_info **ci_array, int *counter);
int find_type_by_name(const char *name, const char *type); int find_type_by_name(const char *name, const char *type);
int write_sysfs_int(const char *filename, const char *basedir, int val); int write_sysfs_int(const char *filename, const char *basedir, int val);
int write_sysfs_int_and_verify(const char *filename, const char *basedir, int write_sysfs_int_and_verify(const char *filename, const char *basedir,
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include <sys/dir.h> #include <sys/dir.h>
#include "iio_utils.h" #include "iio_utils.h"
static enum verbosity { static enum verbosity {
VERBLEVEL_DEFAULT, /* 0 gives lspci behaviour */ VERBLEVEL_DEFAULT, /* 0 gives lspci behaviour */
VERBLEVEL_SENSORS, /* 1 lists sensors */ VERBLEVEL_SENSORS, /* 1 lists sensors */
...@@ -29,17 +28,16 @@ static enum verbosity { ...@@ -29,17 +28,16 @@ static enum verbosity {
const char *type_device = "iio:device"; const char *type_device = "iio:device";
const char *type_trigger = "trigger"; const char *type_trigger = "trigger";
static inline int check_prefix(const char *str, const char *prefix) static inline int check_prefix(const char *str, const char *prefix)
{ {
return strlen(str) > strlen(prefix) && return strlen(str) > strlen(prefix) &&
strncmp(str, prefix, strlen(prefix)) == 0; strncmp(str, prefix, strlen(prefix)) == 0;
} }
static inline int check_postfix(const char *str, const char *postfix) static inline int check_postfix(const char *str, const char *postfix)
{ {
return strlen(str) > strlen(postfix) && return strlen(str) > strlen(postfix) &&
strcmp(str + strlen(str) - strlen(postfix), postfix) == 0; strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
} }
static int dump_channels(const char *dev_dir_name) static int dump_channels(const char *dev_dir_name)
...@@ -50,11 +48,11 @@ static int dump_channels(const char *dev_dir_name) ...@@ -50,11 +48,11 @@ static int dump_channels(const char *dev_dir_name)
dp = opendir(dev_dir_name); dp = opendir(dev_dir_name);
if (dp == NULL) if (dp == NULL)
return -errno; return -errno;
while (ent = readdir(dp), ent != NULL) while (ent = readdir(dp), ent != NULL)
if (check_prefix(ent->d_name, "in_") && if (check_prefix(ent->d_name, "in_") &&
check_postfix(ent->d_name, "_raw")) { check_postfix(ent->d_name, "_raw"))
printf(" %-10s\n", ent->d_name); printf(" %-10s\n", ent->d_name);
}
return (closedir(dp) == -1) ? -errno : 0; return (closedir(dp) == -1) ? -errno : 0;
} }
...@@ -69,6 +67,7 @@ static int dump_one_device(const char *dev_dir_name) ...@@ -69,6 +67,7 @@ static int dump_one_device(const char *dev_dir_name)
"%i", &dev_idx); "%i", &dev_idx);
if (retval != 1) if (retval != 1)
return -EINVAL; return -EINVAL;
retval = read_sysfs_string("name", dev_dir_name, name); retval = read_sysfs_string("name", dev_dir_name, name);
if (retval) if (retval)
return retval; return retval;
...@@ -77,6 +76,7 @@ static int dump_one_device(const char *dev_dir_name) ...@@ -77,6 +76,7 @@ static int dump_one_device(const char *dev_dir_name)
if (verblevel >= VERBLEVEL_SENSORS) if (verblevel >= VERBLEVEL_SENSORS)
return dump_channels(dev_dir_name); return dump_channels(dev_dir_name);
return 0; return 0;
} }
...@@ -90,11 +90,13 @@ static int dump_one_trigger(const char *dev_dir_name) ...@@ -90,11 +90,13 @@ static int dump_one_trigger(const char *dev_dir_name)
"%i", &dev_idx); "%i", &dev_idx);
if (retval != 1) if (retval != 1)
return -EINVAL; return -EINVAL;
retval = read_sysfs_string("name", dev_dir_name, name); retval = read_sysfs_string("name", dev_dir_name, name);
if (retval) if (retval)
return retval; return retval;
printf("Trigger %03d: %s\n", dev_idx, name); printf("Trigger %03d: %s\n", dev_idx, name);
return 0; return 0;
} }
...@@ -151,6 +153,7 @@ static int dump_devices(void) ...@@ -151,6 +153,7 @@ static int dump_devices(void)
free(dev_dir_name); free(dev_dir_name);
} }
} }
return (closedir(dp) == -1) ? -errno : 0; return (closedir(dp) == -1) ? -errno : 0;
error_close_dir: error_close_dir:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment