#include "protocol.h"
#include "beaglelogic.h"
-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);
return (devc->fd == -1 ? SR_ERR : SR_OK);
}
-static int beaglelogic_close(struct dev_context *devc) {
+static int beaglelogic_close(struct dev_context *devc)
+{
return close(devc->fd);
}
-static int beaglelogic_get_buffersize(struct dev_context *devc) {
+static int beaglelogic_get_buffersize(struct dev_context *devc)
+{
return ioctl(devc->fd, IOCTL_BL_GET_BUFFER_SIZE, &devc->buffersize);
}
-static int beaglelogic_set_buffersize(struct dev_context *devc) {
+static int beaglelogic_set_buffersize(struct dev_context *devc)
+{
return ioctl(devc->fd, IOCTL_BL_SET_BUFFER_SIZE, devc->buffersize);
}
/* This is treated differently as it gets a uint64_t while a uint32_t is read */
-static int beaglelogic_get_samplerate(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;
}
-static int beaglelogic_set_samplerate(struct dev_context *devc) {
+static int beaglelogic_set_samplerate(struct dev_context *devc)
+{
return ioctl(devc->fd, IOCTL_BL_SET_SAMPLE_RATE,
(uint32_t)devc->cur_samplerate);
}
-static int beaglelogic_get_sampleunit(struct dev_context *devc) {
+static int beaglelogic_get_sampleunit(struct dev_context *devc)
+{
return ioctl(devc->fd, IOCTL_BL_GET_SAMPLE_UNIT, &devc->sampleunit);
}
-static int beaglelogic_set_sampleunit(struct dev_context *devc) {
+static int beaglelogic_set_sampleunit(struct dev_context *devc)
+{
return ioctl(devc->fd, IOCTL_BL_SET_SAMPLE_UNIT, devc->sampleunit);
}
-static int beaglelogic_get_triggerflags(struct dev_context *devc) {
+static int beaglelogic_get_triggerflags(struct dev_context *devc)
+{
return ioctl(devc->fd, IOCTL_BL_GET_TRIGGER_FLAGS, &devc->triggerflags);
}
-static int beaglelogic_set_triggerflags(struct dev_context *devc) {
+static int beaglelogic_set_triggerflags(struct dev_context *devc)
+{
return ioctl(devc->fd, IOCTL_BL_SET_TRIGGER_FLAGS, devc->triggerflags);
}
-static int beaglelogic_get_lasterror(struct dev_context *devc) {
+static int beaglelogic_get_lasterror(struct dev_context *devc)
+{
int fd;
char buf[16];
int ret;
return SR_OK;
}
-static int beaglelogic_start(struct dev_context *devc) {
+static int beaglelogic_start(struct dev_context *devc)
+{
return ioctl(devc->fd, IOCTL_BL_START);
}
-static int beaglelogic_stop(struct dev_context *devc) {
+static int beaglelogic_stop(struct dev_context *devc)
+{
return ioctl(devc->fd, IOCTL_BL_STOP);
}
-static int beaglelogic_get_bufunitsize(struct dev_context *devc) {
+static int beaglelogic_get_bufunitsize(struct dev_context *devc)
+{
return ioctl(devc->fd, IOCTL_BL_GET_BUFUNIT_SIZE, &devc->bufunitsize);
}
-static int beaglelogic_set_bufunitsize(struct dev_context *devc) {
+static int beaglelogic_set_bufunitsize(struct dev_context *devc)
+{
return ioctl(devc->fd, IOCTL_BL_SET_BUFUNIT_SIZE, devc->bufunitsize);
}
-static int beaglelogic_mmap(struct dev_context *devc) {
+static int beaglelogic_mmap(struct dev_context *devc)
+{
if (!devc->buffersize)
beaglelogic_get_buffersize(devc);
devc->sample_buf = mmap(NULL, devc->buffersize,
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)
+{
return munmap(devc->sample_buf, devc->buffersize);
}
#include "protocol.h"
#include "beaglelogic.h"
-static int beaglelogic_tcp_open(struct dev_context *devc) {
+static int beaglelogic_tcp_open(struct dev_context *devc)
+{
struct addrinfo hints;
struct addrinfo *results, *res;
int err;
}
static int beaglelogic_tcp_send_cmd(struct dev_context *devc,
- const char *format, ...) {
+ const char *format, ...)
+{
int len, out;
va_list args, args_copy;
char *buf;
}
static int beaglelogic_tcp_read_data(struct dev_context *devc, char *buf,
- int maxlen) {
+ int maxlen)
+{
int len;
len = recv(devc->socket, buf, maxlen, 0);
return len;
}
-SR_PRIV int beaglelogic_tcp_drain(struct dev_context *devc) {
+SR_PRIV int beaglelogic_tcp_drain(struct dev_context *devc)
+{
char *buf = g_malloc(1024);
fd_set rset;
int ret, len = 0;
}
static int beaglelogic_tcp_get_string(struct dev_context *devc, const char *cmd,
- char **tcp_resp) {
+ char **tcp_resp)
+{
GString *response = g_string_sized_new(1024);
int len;
gint64 timeout;
}
static int beaglelogic_tcp_get_int(struct dev_context *devc,
- const char *cmd, int *response) {
+ const char *cmd, int *response)
+{
int ret;
char *resp = NULL;
return ret;
}
-SR_PRIV int beaglelogic_tcp_detect(struct dev_context *devc) {
+SR_PRIV int beaglelogic_tcp_detect(struct dev_context *devc)
+{
char *resp = NULL;
int ret;
return ret;
}
-static int beaglelogic_open(struct dev_context *devc) {
+static int beaglelogic_open(struct dev_context *devc)
+{
return beaglelogic_tcp_open(devc);
}
-static int beaglelogic_close(struct dev_context *devc) {
+static int beaglelogic_close(struct dev_context *devc)
+{
if (close(devc->socket) < 0)
return SR_ERR;
return SR_OK;
}
-static int beaglelogic_get_buffersize(struct dev_context *devc) {
+static int beaglelogic_get_buffersize(struct dev_context *devc)
+{
return beaglelogic_tcp_get_int(devc, "memalloc",
(int *)&devc->buffersize);
}
-static int beaglelogic_set_buffersize(struct dev_context *devc) {
+static int beaglelogic_set_buffersize(struct dev_context *devc)
+{
int ret;
char *resp;
return ret;
}
-static int beaglelogic_get_samplerate(struct dev_context *devc) {
+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;
}
-static int beaglelogic_set_samplerate(struct dev_context *devc) {
+static int beaglelogic_set_samplerate(struct dev_context *devc)
+{
int ret;
char *resp;
return ret;
}
-static int beaglelogic_get_sampleunit(struct dev_context *devc) {
+static int beaglelogic_get_sampleunit(struct dev_context *devc)
+{
return beaglelogic_tcp_get_int(devc, "sampleunit",
(int *)&devc->sampleunit);
}
-static int beaglelogic_set_sampleunit(struct dev_context *devc) {
+static int beaglelogic_set_sampleunit(struct dev_context *devc)
+{
int ret;
char *resp;
return ret;
}
-static int beaglelogic_get_triggerflags(struct dev_context *devc) {
+static int beaglelogic_get_triggerflags(struct dev_context *devc)
+{
return beaglelogic_tcp_get_int(devc, "triggerflags",
(int *)&devc->triggerflags);
}
-static int beaglelogic_set_triggerflags(struct dev_context *devc) {
+static int beaglelogic_set_triggerflags(struct dev_context *devc)
+{
int ret;
char *resp;
return ret;
}
-static int beaglelogic_get_lasterror(struct dev_context *devc) {
+static int beaglelogic_get_lasterror(struct dev_context *devc)
+{
devc->last_error = 0;
return SR_OK;
}
-static int beaglelogic_start(struct dev_context *devc) {
+static int beaglelogic_start(struct dev_context *devc)
+{
beaglelogic_tcp_drain(devc);
return beaglelogic_tcp_send_cmd(devc, "get");
}
-static int beaglelogic_stop(struct dev_context *devc) {
+static int beaglelogic_stop(struct dev_context *devc)
+{
return beaglelogic_tcp_send_cmd(devc, "close");
}
-static int beaglelogic_get_bufunitsize(struct dev_context *devc) {
+static int beaglelogic_get_bufunitsize(struct dev_context *devc)
+{
return beaglelogic_tcp_get_int(devc, "bufunitsize",
(int *)&devc->bufunitsize);
}
-static int beaglelogic_set_bufunitsize(struct dev_context *devc) {
+static int beaglelogic_set_bufunitsize(struct dev_context *devc)
+{
int ret;
char *resp;
return ret;
}
-static int dummy(struct dev_context *devc) {
+static int dummy(struct dev_context *devc)
+{
(void)devc;
return SR_ERR_NA;
}