Skip to content

Commit

Permalink
examples: Add -Wextra & -pedantic-errors to the example Makefile
Browse files Browse the repository at this point in the history
can clean up the resulting errors. This resolves a few codacy issues
that have been lingering for awhile. There shouldn't be any functional
changes from these. I tested most, but not all, since they were all
pretty similar.

Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz committed Mar 30, 2020
1 parent 67d3c05 commit a2e5814
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 33 deletions.
2 changes: 1 addition & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

TARGETS := ad9361-iiostream ad9371-iiostream adrv9009-iiostream dummy-iiostream iio-monitor

CFLAGS = -Wall -DIIO_CHECK_RET
CFLAGS = -Wall -Wextra -pedantic -DIIO_CHECK_RET

UNAME_S := $(shell uname -s)

Expand Down
4 changes: 2 additions & 2 deletions examples/ad9361-iiostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static void shutdown()

static void handle_sig(int sig)
{
printf("Waiting for process to finish...\n");
printf("Waiting for process to finish... Got signal %d\n", sig);
stop = true;
}

Expand Down Expand Up @@ -134,7 +134,7 @@ static bool get_ad9361_stream_dev(struct iio_context *ctx, enum iodev d, struct
}

/* finds AD9361 streaming IIO channels */
static bool get_ad9361_stream_ch(struct iio_context *ctx, enum iodev d, struct iio_device *dev, int chid, struct iio_channel **chn)
static bool get_ad9361_stream_ch(__notused struct iio_context *ctx, enum iodev d, struct iio_device *dev, int chid, struct iio_channel **chn)
{
*chn = iio_device_find_channel(dev, get_ch_name("voltage", chid), d == TX);
if (!*chn)
Expand Down
6 changes: 3 additions & 3 deletions examples/ad9371-iiostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static void shutdown()

static void handle_sig(int sig)
{
printf("Waiting for process to finish...\n");
printf("Waiting for process to finish... Got signal %d\n", sig);
stop = true;
}

Expand Down Expand Up @@ -152,7 +152,7 @@ static bool get_ad9371_stream_dev(struct iio_context *ctx, enum iodev d, struct
}

/* finds AD9371 streaming IIO channels */
static bool get_ad9371_stream_ch(struct iio_context *ctx, enum iodev d, struct iio_device *dev, int chid, char modify, struct iio_channel **chn)
static bool get_ad9371_stream_ch(__notused struct iio_context *ctx, enum iodev d, struct iio_device *dev, int chid, char modify, struct iio_channel **chn)
{
*chn = iio_device_find_channel(dev, modify ? get_ch_name_mod("voltage", chid, modify) : get_ch_name("voltage", chid), d == TX);
if (!*chn)
Expand Down Expand Up @@ -201,7 +201,7 @@ bool cfg_ad9371_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg, en
}

/* simple configuration and streaming */
int main (int argc, char **argv)
int main (__notused int argc, __notused char **argv)
{
// Streaming devices
struct iio_device *tx;
Expand Down
6 changes: 3 additions & 3 deletions examples/adrv9009-iiostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static void shutdown()

static void handle_sig(int sig)
{
printf("Waiting for process to finish...\n");
printf("Waiting for process to finish... Got signal %d\n", sig);
stop = true;
}

Expand Down Expand Up @@ -152,7 +152,7 @@ static bool get_adrv9009_stream_dev(struct iio_context *ctx, enum iodev d, struc
}

/* finds adrv9009 streaming IIO channels */
static bool get_adrv9009_stream_ch(struct iio_context *ctx, enum iodev d, struct iio_device *dev, int chid, char modify, struct iio_channel **chn)
static bool get_adrv9009_stream_ch(__notused struct iio_context *ctx, enum iodev d, struct iio_device *dev, int chid, char modify, struct iio_channel **chn)
{
*chn = iio_device_find_channel(dev, modify ? get_ch_name_mod("voltage", chid, modify) : get_ch_name("voltage", chid), d == TX);
if (!*chn)
Expand Down Expand Up @@ -197,7 +197,7 @@ bool cfg_adrv9009_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg,
}

/* simple configuration and streaming */
int main (int argc, char **argv)
int main (__notused int argc, __notused char **argv)
{
// Streaming devices
struct iio_device *tx;
Expand Down
43 changes: 24 additions & 19 deletions examples/dummy-iiostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static struct iio_device *dev;
static struct iio_context *ctx;
static struct iio_buffer *rxbuf;
static struct iio_channel **channels;
static int channel_count;
static unsigned int channel_count;

static bool stop;
static bool has_repeat;
Expand Down Expand Up @@ -146,17 +146,17 @@ static void shutdown()

static void handle_sig(int sig)
{
printf("Waiting for process to finish...\n");
printf("Waiting for process to finish... got signal : %d\n", sig);
stop = true;
}

static ssize_t sample_cb(const struct iio_channel *chn, void *src, size_t bytes, void *d)
static ssize_t sample_cb(const struct iio_channel *chn, void *src, size_t bytes, __notused void *d)
{
const struct iio_data_format *fmt = iio_channel_get_data_format(chn);
unsigned int repeat = has_repeat ? fmt->repeat : 1;
unsigned int j, repeat = has_repeat ? fmt->repeat : 1;

printf("%s ", iio_channel_get_id(chn));
for (int j = 0; j < repeat; ++j) {
for (j = 0; j < repeat; ++j) {
if (bytes == sizeof(int16_t))
printf("%" PRIi16 " ", ((int16_t *)src)[j]);
else if (bytes == sizeof(int64_t))
Expand All @@ -166,7 +166,7 @@ static ssize_t sample_cb(const struct iio_channel *chn, void *src, size_t bytes,
return bytes * repeat;
}

static void usage(int argc, char *argv[])
static void usage(__notused int argc, char *argv[])
{
printf("Usage: %s [OPTION]\n", argv[0]);
printf(" -d\tdevice name (default \"iio_dummy_part_no\")\n");
Expand Down Expand Up @@ -227,13 +227,14 @@ int main (int argc, char **argv)
// Listen to ctrl+c and assert
signal(SIGINT, handle_sig);

unsigned int major, minor;
unsigned int i, j, major, minor;
char git_tag[8];
iio_library_get_version(&major, &minor, git_tag);
printf("Library version: %u.%u (git tag: %s)\n", major, minor, git_tag);

/* check for struct iio_data_format.repeat support */
has_repeat = major >= 0 && minor >= 8 ? true : false;
/* check for struct iio_data_format.repeat support
* 0.8 has repeat support, so anything greater than that */
has_repeat = ((major * 10000) + minor) >= 8 ? true : false;

printf("* Acquiring IIO context\n");
assert((ctx = iio_create_default_context()) && "No context");
Expand All @@ -247,7 +248,7 @@ int main (int argc, char **argv)
}

printf("* Initializing IIO streaming channels:\n");
for (int i = 0; i < iio_device_get_channels_count(dev); ++i) {
for (i = 0; i < iio_device_get_channels_count(dev); ++i) {
struct iio_channel *chn = iio_device_get_channel(dev, i);
if (iio_channel_is_scan_element(chn)) {
printf("%s\n", iio_channel_get_id(chn));
Expand All @@ -263,7 +264,7 @@ int main (int argc, char **argv)
perror("Channel array allocation failed");
shutdown();
}
for (int i = 0; i < channel_count; ++i) {
for (i = 0; i < channel_count; ++i) {
struct iio_channel *chn = iio_device_get_channel(dev, i);
if (iio_channel_is_scan_element(chn))
channels[i] = chn;
Expand All @@ -277,7 +278,7 @@ int main (int argc, char **argv)
}

printf("* Enabling IIO streaming channels for buffered capture\n");
for (int i = 0; i < channel_count; ++i)
for (i = 0; i < channel_count; ++i)
iio_channel_enable(channels[i]);

printf("* Enabling IIO buffer trigger\n");
Expand All @@ -299,7 +300,11 @@ int main (int argc, char **argv)
while (!stop)
{
ssize_t nbytes_rx;
void *p_dat, *p_end;
/* we use a char pointer, rather than a void pointer, for p_dat & p_end
* to ensure the compiler understands the size is a byte, and then we
* can do math on it.
*/
char *p_dat, *p_end;
ptrdiff_t p_inc;
int64_t now_ts;

Expand All @@ -325,13 +330,13 @@ int main (int argc, char **argv)
switch (buffer_read_method)
{
case BUFFER_POINTER:
for (int i = 0; i < channel_count; ++i) {
for (i = 0; i < channel_count; ++i) {
const struct iio_data_format *fmt = iio_channel_get_data_format(channels[i]);
unsigned int repeat = has_repeat ? fmt->repeat : 1;

printf("%s ", iio_channel_get_id(channels[i]));
for (p_dat = iio_buffer_first(rxbuf, channels[i]); p_dat < p_end; p_dat += p_inc) {
for (int j = 0; j < repeat; ++j) {
for (j = 0; j < repeat; ++j) {
if (fmt->length/8 == sizeof(int16_t))
printf("%" PRIi16 " ", ((int16_t *)p_dat)[j]);
else if (fmt->length/8 == sizeof(int64_t))
Expand All @@ -355,9 +360,9 @@ int main (int argc, char **argv)
}
case CHANNEL_READ_RAW:
case CHANNEL_READ:
for (int i = 0; i < channel_count; ++i) {
for (i = 0; i < channel_count; ++i) {
uint8_t *buf;
size_t bytes;
size_t sample, bytes;
const struct iio_data_format *fmt = iio_channel_get_data_format(channels[i]);
unsigned int repeat = has_repeat ? fmt->repeat : 1;
size_t sample_size = fmt->length / 8 * repeat;
Expand All @@ -370,8 +375,8 @@ int main (int argc, char **argv)
bytes = iio_channel_read(channels[i], rxbuf, buf, sample_size * buffer_length);

printf("%s ", iio_channel_get_id(channels[i]));
for (int sample = 0; sample < bytes / sample_size; ++sample) {
for (int j = 0; j < repeat; ++j) {
for (sample = 0; sample < bytes / sample_size; ++sample) {
for (j = 0; j < repeat; ++j) {
if (fmt->length / 8 == sizeof(int16_t))
printf("%" PRIi16 " ", ((int16_t *)buf)[sample+j]);
else if (fmt->length / 8 == sizeof(int64_t))
Expand Down
10 changes: 5 additions & 5 deletions examples/iio-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@

#define ARRAY_SIZE(x) (sizeof(x) ? sizeof(x) / sizeof((x)[0]) : 0)

#define RED 020
#define YELLOW 040
#define BLUE 050
#define RED 020u
#define YELLOW 040u
#define BLUE 050u

static int selected = -1;

Expand Down Expand Up @@ -224,11 +224,11 @@ static struct iio_context *show_contexts_screen(void)
struct iio_context *ctx = NULL;
struct iio_scan_context *scan_ctx;
struct iio_context_info **info;
unsigned int num_contexts;
int num_contexts;
CDKSCREEN *screen;
CDKSCROLL *list;
const char *uri;
unsigned int i;
int i;
bool free_uri;
char **items;
int ret;
Expand Down

0 comments on commit a2e5814

Please sign in to comment.