beaglelogic: Minor whitespace and consistency fixes.

This commit is contained in:
Uwe Hermann 2017-09-26 19:47:55 +02:00
parent 00f2e9bc6b
commit f82525e60d
3 changed files with 29 additions and 16 deletions

View File

@ -93,7 +93,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
} }
/* Probe for /dev/beaglelogic if not connecting via TCP */ /* Probe for /dev/beaglelogic if not connecting via TCP */
if (conn == NULL) { if (!conn) {
if (!g_file_test(BEAGLELOGIC_DEV_NODE, G_FILE_TEST_EXISTS)) if (!g_file_test(BEAGLELOGIC_DEV_NODE, G_FILE_TEST_EXISTS))
return NULL; return NULL;
} else { } else {
@ -110,10 +110,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
} }
} }
if (maxch > 8) maxch = (maxch > 8) ? NUM_CHANNELS : 8;
maxch = NUM_CHANNELS;
else
maxch = 8;
sdi = g_new0(struct sr_dev_inst, 1); sdi = g_new0(struct sr_dev_inst, 1);
sdi->status = SR_ST_INACTIVE; sdi->status = SR_ST_INACTIVE;
@ -122,7 +119,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
devc = beaglelogic_devc_alloc(); devc = beaglelogic_devc_alloc();
if (conn == NULL) { if (!conn) {
devc->beaglelogic = &beaglelogic_native_ops; devc->beaglelogic = &beaglelogic_native_ops;
sr_info("BeagleLogic device found at "BEAGLELOGIC_DEV_NODE); sr_info("BeagleLogic device found at "BEAGLELOGIC_DEV_NODE);
} else { } else {
@ -141,6 +138,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sr_info("BeagleLogic device found at %s : %s", sr_info("BeagleLogic device found at %s : %s",
devc->address, devc->port); devc->address, devc->port);
} }
/* Fill the channels */ /* Fill the channels */
for (i = 0; i < maxch; i++) for (i = 0; i < maxch; i++)
sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
@ -149,6 +147,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
sdi->priv = devc; sdi->priv = devc;
return std_scan_complete(di, g_slist_append(NULL, sdi)); return std_scan_complete(di, g_slist_append(NULL, sdi));
err_free: err_free:
g_free(sdi->model); g_free(sdi->model);
g_free(sdi->version); g_free(sdi->version);
@ -337,9 +336,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
devc->beaglelogic->set_sampleunit(devc); devc->beaglelogic->set_sampleunit(devc);
/* If continuous sampling, set the limit_samples to max possible value */ /* If continuous sampling, set the limit_samples to max possible value */
if (devc->triggerflags == BL_TRIGGERFLAGS_CONTINUOUS) { if (devc->triggerflags == BL_TRIGGERFLAGS_CONTINUOUS)
devc->limit_samples = (uint64_t)-1; devc->limit_samples = (uint64_t)-1;
}
/* Configure triggers & send header packet */ /* Configure triggers & send header packet */
if ((trigger = sr_session_trigger_get(sdi->session))) { if ((trigger = sr_session_trigger_get(sdi->session))) {

View File

@ -23,7 +23,8 @@
static int beaglelogic_open_nonblock(struct dev_context *devc) static int beaglelogic_open_nonblock(struct dev_context *devc)
{ {
devc->fd = open(BEAGLELOGIC_DEV_NODE, O_RDONLY | O_NONBLOCK); devc->fd = open(BEAGLELOGIC_DEV_NODE, O_RDONLY | O_NONBLOCK);
return (devc->fd == -1 ? SR_ERR : SR_OK);
return ((devc->fd == -1) ? SR_ERR : SR_OK);
} }
static int beaglelogic_close(struct dev_context *devc) static int beaglelogic_close(struct dev_context *devc)
@ -45,8 +46,10 @@ static int beaglelogic_set_buffersize(struct dev_context *devc)
static int beaglelogic_get_samplerate(struct dev_context *devc) static int beaglelogic_get_samplerate(struct dev_context *devc)
{ {
uint32_t arg, err; uint32_t arg, err;
err = ioctl(devc->fd, IOCTL_BL_GET_SAMPLE_RATE, &arg); err = ioctl(devc->fd, IOCTL_BL_GET_SAMPLE_RATE, &arg);
devc->cur_samplerate = arg; devc->cur_samplerate = arg;
return err; return err;
} }
@ -120,7 +123,8 @@ static int beaglelogic_mmap(struct dev_context *devc)
beaglelogic_get_buffersize(devc); beaglelogic_get_buffersize(devc);
devc->sample_buf = mmap(NULL, devc->buffersize, devc->sample_buf = mmap(NULL, devc->buffersize,
PROT_READ, MAP_SHARED, devc->fd, 0); PROT_READ, MAP_SHARED, devc->fd, 0);
return (devc->sample_buf == MAP_FAILED ? -1 : SR_OK);
return ((devc->sample_buf == MAP_FAILED) ? -1 : SR_OK);
} }
static int beaglelogic_munmap(struct dev_context *devc) static int beaglelogic_munmap(struct dev_context *devc)

View File

@ -116,6 +116,7 @@ static int beaglelogic_tcp_send_cmd(struct dev_context *devc,
} }
sr_spew("Sent command: '%s'.", buf); sr_spew("Sent command: '%s'.", buf);
g_free(buf); g_free(buf);
return SR_OK; return SR_OK;
@ -152,14 +153,14 @@ SR_PRIV int beaglelogic_tcp_drain(struct dev_context *devc)
do { do {
ret = select(devc->socket + 1, &rset, NULL, NULL, &tv); ret = select(devc->socket + 1, &rset, NULL, NULL, &tv);
if (ret > 0) { if (ret > 0)
len += beaglelogic_tcp_read_data(devc, buf, 1024); len += beaglelogic_tcp_read_data(devc, buf, 1024);
}
} while (ret > 0); } while (ret > 0);
sr_spew("Drained %d bytes of data.", len); sr_spew("Drained %d bytes of data.", len);
g_free(buf); g_free(buf);
return SR_OK; return SR_OK;
} }
@ -171,9 +172,8 @@ static int beaglelogic_tcp_get_string(struct dev_context *devc, const char *cmd,
gint64 timeout; gint64 timeout;
if (cmd) { if (cmd) {
if (beaglelogic_tcp_send_cmd(devc, cmd) != SR_OK) { if (beaglelogic_tcp_send_cmd(devc, cmd) != SR_OK)
return SR_ERR; return SR_ERR;
}
} }
timeout = g_get_monotonic_time() + devc->read_timeout; timeout = g_get_monotonic_time() + devc->read_timeout;
@ -185,9 +185,8 @@ static int beaglelogic_tcp_get_string(struct dev_context *devc, const char *cmd,
return SR_ERR; return SR_ERR;
} }
if (len > 0) { if (len > 0)
g_string_set_size(response, len); g_string_set_size(response, len);
}
if (g_get_monotonic_time() > timeout) { if (g_get_monotonic_time() > timeout) {
sr_err("Timed out waiting for response."); sr_err("Timed out waiting for response.");
@ -207,6 +206,7 @@ static int beaglelogic_tcp_get_string(struct dev_context *devc, const char *cmd,
response->str, response->len); response->str, response->len);
*tcp_resp = g_string_free(response, FALSE); *tcp_resp = g_string_free(response, FALSE);
return SR_OK; return SR_OK;
} }
@ -242,6 +242,7 @@ SR_PRIV int beaglelogic_tcp_detect(struct dev_context *devc)
ret = SR_ERR; ret = SR_ERR;
g_free(resp); g_free(resp);
return ret; return ret;
} }
@ -277,14 +278,17 @@ static int beaglelogic_set_buffersize(struct dev_context *devc)
ret = SR_ERR; ret = SR_ERR;
g_free(resp); g_free(resp);
return ret; return ret;
} }
static int beaglelogic_get_samplerate(struct dev_context *devc) static int beaglelogic_get_samplerate(struct dev_context *devc)
{ {
int arg, err; int arg, err;
err = beaglelogic_tcp_get_int(devc, "samplerate", &arg); err = beaglelogic_tcp_get_int(devc, "samplerate", &arg);
devc->cur_samplerate = arg; devc->cur_samplerate = arg;
return err; return err;
} }
@ -302,6 +306,7 @@ static int beaglelogic_set_samplerate(struct dev_context *devc)
ret = SR_ERR; ret = SR_ERR;
g_free(resp); g_free(resp);
return ret; return ret;
} }
@ -324,6 +329,7 @@ static int beaglelogic_set_sampleunit(struct dev_context *devc)
ret = SR_ERR; ret = SR_ERR;
g_free(resp); g_free(resp);
return ret; return ret;
} }
@ -346,18 +352,21 @@ static int beaglelogic_set_triggerflags(struct dev_context *devc)
ret = SR_ERR; ret = SR_ERR;
g_free(resp); g_free(resp);
return ret; return ret;
} }
static int beaglelogic_get_lasterror(struct dev_context *devc) static int beaglelogic_get_lasterror(struct dev_context *devc)
{ {
devc->last_error = 0; devc->last_error = 0;
return SR_OK; return SR_OK;
} }
static int beaglelogic_start(struct dev_context *devc) static int beaglelogic_start(struct dev_context *devc)
{ {
beaglelogic_tcp_drain(devc); beaglelogic_tcp_drain(devc);
return beaglelogic_tcp_send_cmd(devc, "get"); return beaglelogic_tcp_send_cmd(devc, "get");
} }
@ -385,12 +394,14 @@ static int beaglelogic_set_bufunitsize(struct dev_context *devc)
ret = SR_ERR; ret = SR_ERR;
g_free(resp); g_free(resp);
return ret; return ret;
} }
static int dummy(struct dev_context *devc) static int dummy(struct dev_context *devc)
{ {
(void)devc; (void)devc;
return SR_ERR_NA; return SR_ERR_NA;
} }