}
/* 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))
return NULL;
} else {
}
}
- if (maxch > 8)
- maxch = NUM_CHANNELS;
- else
- maxch = 8;
+ maxch = (maxch > 8) ? NUM_CHANNELS : 8;
sdi = g_new0(struct sr_dev_inst, 1);
sdi->status = SR_ST_INACTIVE;
devc = beaglelogic_devc_alloc();
- if (conn == NULL) {
+ if (!conn) {
devc->beaglelogic = &beaglelogic_native_ops;
sr_info("BeagleLogic device found at "BEAGLELOGIC_DEV_NODE);
} else {
sr_info("BeagleLogic device found at %s : %s",
devc->address, devc->port);
}
+
/* Fill the channels */
for (i = 0; i < maxch; i++)
sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE,
sdi->priv = devc;
return std_scan_complete(di, g_slist_append(NULL, sdi));
+
err_free:
g_free(sdi->model);
g_free(sdi->version);
devc->beaglelogic->set_sampleunit(devc);
/* 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;
- }
/* Configure triggers & send header packet */
if ((trigger = sr_session_trigger_get(sdi->session))) {
static int beaglelogic_open_nonblock(struct dev_context *devc)
{
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_get_samplerate(struct dev_context *devc)
{
uint32_t arg, err;
+
err = ioctl(devc->fd, IOCTL_BL_GET_SAMPLE_RATE, &arg);
devc->cur_samplerate = arg;
+
return err;
}
beaglelogic_get_buffersize(devc);
devc->sample_buf = mmap(NULL, devc->buffersize,
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)
}
sr_spew("Sent command: '%s'.", buf);
+
g_free(buf);
return SR_OK;
do {
ret = select(devc->socket + 1, &rset, NULL, NULL, &tv);
- if (ret > 0) {
+ if (ret > 0)
len += beaglelogic_tcp_read_data(devc, buf, 1024);
- }
} while (ret > 0);
sr_spew("Drained %d bytes of data.", len);
g_free(buf);
+
return SR_OK;
}
gint64 timeout;
if (cmd) {
- if (beaglelogic_tcp_send_cmd(devc, cmd) != SR_OK) {
+ if (beaglelogic_tcp_send_cmd(devc, cmd) != SR_OK)
return SR_ERR;
- }
}
timeout = g_get_monotonic_time() + devc->read_timeout;
return SR_ERR;
}
- if (len > 0) {
+ if (len > 0)
g_string_set_size(response, len);
- }
if (g_get_monotonic_time() > timeout) {
sr_err("Timed out waiting for response.");
response->str, response->len);
*tcp_resp = g_string_free(response, FALSE);
+
return SR_OK;
}
ret = SR_ERR;
g_free(resp);
+
return ret;
}
ret = SR_ERR;
g_free(resp);
+
return ret;
}
static int beaglelogic_get_samplerate(struct dev_context *devc)
{
int arg, err;
+
err = beaglelogic_tcp_get_int(devc, "samplerate", &arg);
devc->cur_samplerate = arg;
+
return err;
}
ret = SR_ERR;
g_free(resp);
+
return ret;
}
ret = SR_ERR;
g_free(resp);
+
return ret;
}
ret = SR_ERR;
g_free(resp);
+
return ret;
}
static int beaglelogic_get_lasterror(struct dev_context *devc)
{
devc->last_error = 0;
+
return SR_OK;
}
static int beaglelogic_start(struct dev_context *devc)
{
beaglelogic_tcp_drain(devc);
+
return beaglelogic_tcp_send_cmd(devc, "get");
}
ret = SR_ERR;
g_free(resp);
+
return ret;
}
static int dummy(struct dev_context *devc)
{
(void)devc;
+
return SR_ERR_NA;
}