rigol-ds1xx2: Cosmetics, whitespace.
This commit is contained in:
parent
fb6e5ba8c7
commit
29d957ceae
|
@ -177,17 +177,11 @@ static GSList *hw_scan(GSList *options)
|
||||||
const gchar *prefix = "usbtmc";
|
const gchar *prefix = "usbtmc";
|
||||||
gchar *device;
|
gchar *device;
|
||||||
const gchar *idn_query = "*IDN?";
|
const gchar *idn_query = "*IDN?";
|
||||||
gchar *idn_reply;
|
int len, num_tokens, fd, i;
|
||||||
const gchar *idn_reply_prefix = "*IDN ";
|
|
||||||
int len;
|
|
||||||
const gchar *delimiter = ",";
|
const gchar *delimiter = ",";
|
||||||
gchar **tokens;
|
gchar **tokens;
|
||||||
int num_tokens;
|
|
||||||
int fd;
|
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
(void)options;
|
(void)options;
|
||||||
|
|
||||||
devices = NULL;
|
devices = NULL;
|
||||||
|
@ -199,8 +193,7 @@ static GSList *hw_scan(GSList *options)
|
||||||
if (dir == NULL)
|
if (dir == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
while ((dev_name = g_dir_read_name(dir)) != NULL)
|
while ((dev_name = g_dir_read_name(dir)) != NULL) {
|
||||||
{
|
|
||||||
if (strncmp(dev_name, prefix, strlen(prefix)))
|
if (strncmp(dev_name, prefix, strlen(prefix)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -210,8 +203,7 @@ static GSList *hw_scan(GSList *options)
|
||||||
len = write(fd, idn_query, strlen(idn_query));
|
len = write(fd, idn_query, strlen(idn_query));
|
||||||
len = read(fd, buf, sizeof(buf));
|
len = read(fd, buf, sizeof(buf));
|
||||||
close(fd);
|
close(fd);
|
||||||
if (len == 0)
|
if (len == 0) {
|
||||||
{
|
|
||||||
g_free(device);
|
g_free(device);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -223,16 +215,16 @@ static GSList *hw_scan(GSList *options)
|
||||||
for (num_tokens = 0; tokens[num_tokens] != NULL; num_tokens++);
|
for (num_tokens = 0; tokens[num_tokens] != NULL; num_tokens++);
|
||||||
|
|
||||||
if (!(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, tokens[0],
|
if (!(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, tokens[0],
|
||||||
num_tokens > 1 ? tokens[1] : NULL, num_tokens > 3 ? tokens[3] : NULL)))
|
num_tokens > 1 ? tokens[1] : NULL,
|
||||||
{
|
num_tokens > 3 ? tokens[3] : NULL))) {
|
||||||
g_strfreev(tokens);
|
g_strfreev(tokens);
|
||||||
g_free(device);
|
g_free(device);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
g_strfreev(tokens);
|
g_strfreev(tokens);
|
||||||
|
|
||||||
if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
|
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
|
||||||
{
|
sr_err("Device context malloc failed.");
|
||||||
g_free(device);
|
g_free(device);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -242,9 +234,9 @@ static GSList *hw_scan(GSList *options)
|
||||||
sdi->priv = devc;
|
sdi->priv = devc;
|
||||||
sdi->driver = di;
|
sdi->driver = di;
|
||||||
|
|
||||||
for (i = 0; i < 2; i++)
|
for (i = 0; i < 2; i++) {
|
||||||
{
|
if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE,
|
||||||
if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, i == 0 ? "CH1" : "CH2")))
|
i == 0 ? "CH1" : "CH2")))
|
||||||
return NULL;
|
return NULL;
|
||||||
sdi->probes = g_slist_append(sdi->probes, probe);
|
sdi->probes = g_slist_append(sdi->probes, probe);
|
||||||
}
|
}
|
||||||
|
@ -269,11 +261,12 @@ static GSList *hw_dev_list(void)
|
||||||
|
|
||||||
static int hw_dev_open(struct sr_dev_inst *sdi)
|
static int hw_dev_open(struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
struct dev_context *devc = sdi->priv;
|
struct dev_context *devc;
|
||||||
|
int fd;
|
||||||
|
|
||||||
int fd = open(devc->device, O_RDWR);
|
devc = sdi->priv;
|
||||||
|
|
||||||
if (fd == -1)
|
if ((fd = open(devc->device, O_RDWR)) == -1)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
|
||||||
devc->fd = fd;
|
devc->fd = fd;
|
||||||
|
@ -285,7 +278,9 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
|
||||||
|
|
||||||
static int hw_dev_close(struct sr_dev_inst *sdi)
|
static int hw_dev_close(struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
struct dev_context *devc = sdi->priv;
|
struct dev_context *devc;
|
||||||
|
|
||||||
|
devc = sdi->priv;
|
||||||
|
|
||||||
close(devc->fd);
|
close(devc->fd);
|
||||||
|
|
||||||
|
@ -337,13 +332,15 @@ static int hw_info_get(int info_id, const void **data,
|
||||||
static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
|
static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
|
||||||
const void *value)
|
const void *value)
|
||||||
{
|
{
|
||||||
struct dev_context *devc = sdi->priv;
|
struct dev_context *devc;
|
||||||
uint64_t tmp_u64;
|
uint64_t tmp_u64;
|
||||||
float tmp_float;
|
float tmp_float;
|
||||||
struct sr_rational tmp_rat;
|
struct sr_rational tmp_rat;
|
||||||
int ret, i, j;
|
int ret, i, j;
|
||||||
char *channel;
|
char *channel;
|
||||||
|
|
||||||
|
devc = sdi->priv;
|
||||||
|
|
||||||
if (sdi->status != SR_ST_ACTIVE) {
|
if (sdi->status != SR_ST_ACTIVE) {
|
||||||
sr_err("Device inactive, can't set config options.");
|
sr_err("Device inactive, can't set config options.");
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
@ -356,7 +353,8 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
|
||||||
break;
|
break;
|
||||||
case SR_HWCAP_TRIGGER_SLOPE:
|
case SR_HWCAP_TRIGGER_SLOPE:
|
||||||
tmp_u64 = *(const int *)value;
|
tmp_u64 = *(const int *)value;
|
||||||
rigol_ds1xx2_send_data(devc->fd, ":TRIG:EDGE:SLOP %s\n", tmp_u64 ? "POS" : "NEG");
|
rigol_ds1xx2_send_data(devc->fd, ":TRIG:EDGE:SLOP %s\n",
|
||||||
|
tmp_u64 ? "POS" : "NEG");
|
||||||
break;
|
break;
|
||||||
case SR_HWCAP_HORIZ_TRIGGERPOS:
|
case SR_HWCAP_HORIZ_TRIGGERPOS:
|
||||||
tmp_float = *(const float *)value;
|
tmp_float = *(const float *)value;
|
||||||
|
@ -364,7 +362,8 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
|
||||||
break;
|
break;
|
||||||
case SR_HWCAP_TIMEBASE:
|
case SR_HWCAP_TIMEBASE:
|
||||||
tmp_rat = *(const struct sr_rational *)value;
|
tmp_rat = *(const struct sr_rational *)value;
|
||||||
rigol_ds1xx2_send_data(devc->fd, ":TIM:SCAL %.9f\n", (float) tmp_rat.p / tmp_rat.q);
|
rigol_ds1xx2_send_data(devc->fd, ":TIM:SCAL %.9f\n",
|
||||||
|
(float)tmp_rat.p / tmp_rat.q);
|
||||||
break;
|
break;
|
||||||
case SR_HWCAP_TRIGGER_SOURCE:
|
case SR_HWCAP_TRIGGER_SOURCE:
|
||||||
if (!strcmp(value, "CH1"))
|
if (!strcmp(value, "CH1"))
|
||||||
|
@ -375,8 +374,7 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
|
||||||
channel = "EXT";
|
channel = "EXT";
|
||||||
else if (!strcmp(value, "AC Line"))
|
else if (!strcmp(value, "AC Line"))
|
||||||
channel = "ACL";
|
channel = "ACL";
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
ret = SR_ERR_ARG;
|
ret = SR_ERR_ARG;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -390,7 +388,8 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
|
||||||
&& vdivs[i].q == tmp_rat.q) {
|
&& vdivs[i].q == tmp_rat.q) {
|
||||||
devc->scale = (float)tmp_rat.p / tmp_rat.q;
|
devc->scale = (float)tmp_rat.p / tmp_rat.q;
|
||||||
for (j = 0; j < 2; j++)
|
for (j = 0; j < 2; j++)
|
||||||
rigol_ds1xx2_send_data(devc->fd, ":CHAN%d:SCAL %.3f\n", j, devc->scale);
|
rigol_ds1xx2_send_data(devc->fd,
|
||||||
|
":CHAN%d:SCAL %.3f\n", j, devc->scale);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -402,7 +401,8 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
|
||||||
for (i = 0; coupling[i]; i++) {
|
for (i = 0; coupling[i]; i++) {
|
||||||
if (!strcmp(value, coupling[i])) {
|
if (!strcmp(value, coupling[i])) {
|
||||||
for (j = 0; j < 2; j++)
|
for (j = 0; j < 2; j++)
|
||||||
rigol_ds1xx2_send_data(devc->fd, ":CHAN%d:COUP %s\n", j, coupling[i]);
|
rigol_ds1xx2_send_data(devc->fd,
|
||||||
|
":CHAN%d:COUP %s\n", j, coupling[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -412,6 +412,7 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
|
||||||
default:
|
default:
|
||||||
sr_err("Unknown hardware capability: %d.", hwcap);
|
sr_err("Unknown hardware capability: %d.", hwcap);
|
||||||
ret = SR_ERR_ARG;
|
ret = SR_ERR_ARG;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -420,14 +421,17 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
|
||||||
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
void *cb_data)
|
void *cb_data)
|
||||||
{
|
{
|
||||||
struct dev_context *devc = sdi->priv;
|
struct dev_context *devc;
|
||||||
struct sr_datafeed_packet packet;
|
struct sr_datafeed_packet packet;
|
||||||
struct sr_datafeed_header header;
|
struct sr_datafeed_header header;
|
||||||
struct sr_datafeed_meta_analog meta;
|
struct sr_datafeed_meta_analog meta;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
(void)cb_data;
|
(void)cb_data;
|
||||||
|
|
||||||
|
devc = sdi->priv;
|
||||||
|
|
||||||
devc->num_frames = 0;
|
devc->num_frames = 0;
|
||||||
|
|
||||||
sr_source_add(devc->fd, G_IO_IN, 50, rigol_ds1xx2_receive_data, (void *)sdi);
|
sr_source_add(devc->fd, G_IO_IN, 50, rigol_ds1xx2_receive_data, (void *)sdi);
|
||||||
|
@ -449,12 +453,12 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
len = read(devc->fd, buf, sizeof(buf));
|
len = read(devc->fd, buf, sizeof(buf));
|
||||||
buf[len] = 0;
|
buf[len] = 0;
|
||||||
devc->scale = atof(buf);
|
devc->scale = atof(buf);
|
||||||
sr_dbg("scale is %.3f", devc->scale);
|
sr_dbg("Scale is %.3f.", devc->scale);
|
||||||
rigol_ds1xx2_send_data(devc->fd, ":CHAN1:OFFS?\n");
|
rigol_ds1xx2_send_data(devc->fd, ":CHAN1:OFFS?\n");
|
||||||
len = read(devc->fd, buf, sizeof(buf));
|
len = read(devc->fd, buf, sizeof(buf));
|
||||||
buf[len] = 0;
|
buf[len] = 0;
|
||||||
devc->offset = atof(buf);
|
devc->offset = atof(buf);
|
||||||
sr_dbg("offset is %.6f", devc->offset);
|
sr_dbg("Offset is %.6f.", devc->offset);
|
||||||
rigol_ds1xx2_send_data(devc->fd, ":WAV:DATA?\n");
|
rigol_ds1xx2_send_data(devc->fd, ":WAV:DATA?\n");
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
|
@ -462,9 +466,12 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
|
|
||||||
static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
|
static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
|
||||||
{
|
{
|
||||||
struct dev_context *devc = sdi->priv;
|
struct dev_context *devc;
|
||||||
|
|
||||||
(void)cb_data;
|
(void)cb_data;
|
||||||
|
|
||||||
|
devc = sdi->priv;
|
||||||
|
|
||||||
if (sdi->status != SR_ST_ACTIVE) {
|
if (sdi->status != SR_ST_ACTIVE) {
|
||||||
sr_err("Device inactive, can't stop acquisition.");
|
sr_err("Device inactive, can't stop acquisition.");
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
|
|
@ -44,7 +44,7 @@ SR_PRIV int rigol_ds1xx2_receive_data(int fd, int revents, void *cb_data)
|
||||||
|
|
||||||
if (revents == G_IO_IN) {
|
if (revents == G_IO_IN) {
|
||||||
len = read(fd, buf, WAVEFORM_SIZE);
|
len = read(fd, buf, WAVEFORM_SIZE);
|
||||||
sr_dbg("received %d", len);
|
sr_dbg("Received %d bytes.", len);
|
||||||
if (len == -1)
|
if (len == -1)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
|
@ -57,6 +57,7 @@ SR_PRIV int rigol_ds1xx2_receive_data(int fd, int revents, void *cb_data)
|
||||||
packet.type = SR_DF_ANALOG;
|
packet.type = SR_DF_ANALOG;
|
||||||
packet.payload = &analog;
|
packet.payload = &analog;
|
||||||
sr_session_send(cb_data, &packet);
|
sr_session_send(cb_data, &packet);
|
||||||
|
|
||||||
if (++devc->num_frames == devc->limit_frames)
|
if (++devc->num_frames == devc->limit_frames)
|
||||||
sdi->driver->dev_acquisition_stop(sdi, cb_data);
|
sdi->driver->dev_acquisition_stop(sdi, cb_data);
|
||||||
else
|
else
|
||||||
|
@ -70,10 +71,13 @@ SR_PRIV int rigol_ds1xx2_send_data(int fd, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
int len;
|
||||||
|
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
int len = vsprintf(buf, format, args);
|
len = vsprintf(buf, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
len = write(fd, buf, len);
|
len = write(fd, buf, len);
|
||||||
sr_dbg("sent %s", buf);
|
sr_dbg("Sent '%s'.", buf);
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue