siglent-sds: Random cosmetics, drop unused stuff.

This commit is contained in:
Uwe Hermann 2018-02-17 17:18:32 +01:00
parent 641107aa6c
commit e5896840f6
3 changed files with 34 additions and 47 deletions

View File

@ -124,9 +124,6 @@ static const uint64_t vdivs[][2] = {
{ 100, 1 },
};
#define NUM_TIMEBASE ARRAY_SIZE(timebases)
#define NUM_VDIV ARRAY_SIZE(vdivs)
static const char *trigger_sources[] = {
"CH1", "CH2", "Ext", "Ext /5", "AC Line",
"D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
@ -169,11 +166,9 @@ enum series {
SDS2000X,
};
/* short name, full name, USB name */
/* short name, full name */
static const struct siglent_sds_vendor supported_vendors[] = {
[SIGLENT] = {
"Siglent", "Siglent Technologies", "Siglent Technologies Co,. Ltd.",
},
[SIGLENT] = {"Siglent", "Siglent Technologies"},
};
#define VENDOR(x) &supported_vendors[x]
@ -326,7 +321,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
devc->digital_group);
}
for (i = 0; i < NUM_TIMEBASE; i++) {
for (i = 0; i < ARRAY_SIZE(timebases); i++) {
if (!memcmp(&devc->model->min_timebase, &timebases[i], sizeof(uint64_t[2])))
devc->timebases = &timebases[i];
@ -334,12 +329,12 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
devc->num_timebases = &timebases[i] - devc->timebases + 1;
}
for (i = 0; i < NUM_VDIV; i++) {
for (i = 0; i < ARRAY_SIZE(vdivs); i++) {
devc->vdivs = &vdivs[i];
if (!memcmp(&devc->model->series->min_vdiv,
&vdivs[i], sizeof(uint64_t[2]))) {
devc->vdivs = &vdivs[i];
devc->num_vdivs = NUM_VDIV - i;
devc->num_vdivs = ARRAY_SIZE(vdivs) - i;
break;
}
}
@ -437,7 +432,7 @@ static int config_get(uint32_t key, GVariant **data,
break;
case SR_CONF_SAMPLERATE:
siglent_sds_get_dev_cfg_horizontal(sdi);
*data = g_variant_new_uint64(devc->sampleRate);
*data = g_variant_new_uint64(devc->samplerate);
break;
case SR_CONF_TRIGGER_SOURCE:
if (!strcmp(devc->trigger_source, "ACL"))
@ -583,7 +578,6 @@ static int config_set(uint32_t key, GVariant *data,
devc->trigger_level = t_dbl;
break;
case SR_CONF_TIMEBASE:
sr_dbg("Setting device Timebase");
g_variant_get(data, "(tt)", &p, &q);
for (i = 0; i < devc->num_timebases; i++) {
char *cmd;
@ -732,7 +726,7 @@ static int config_set(uint32_t key, GVariant *data,
break;
case SR_CONF_SAMPLERATE:
siglent_sds_get_dev_cfg_horizontal(sdi);
data = g_variant_new_uint64(devc->sampleRate);
data = g_variant_new_uint64(devc->samplerate);
break;
default:
return SR_ERR_NA;
@ -874,8 +868,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
struct sr_channel *ch;
struct sr_datafeed_packet packet;
gboolean some_digital;
GSList *l;
GSList *d;
GSList *l, *d;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;

View File

@ -193,7 +193,7 @@ SR_PRIV int siglent_sds_capture_start(const struct sr_dev_inst *sdi)
}
memcpy(&framecount, buf + 40, 4);
if (devc->limit_frames > framecount)
sr_err("Frame limit higher that frames in buffer of device!");
sr_err("Frame limit higher than frames in buffer of device!");
else if (devc->limit_frames == 0)
devc->limit_frames = framecount;
sr_dbg("Starting data capture for history frameset %" PRIu64 " of %" PRIu64,
@ -257,9 +257,8 @@ static int siglent_sds_read_header(struct sr_dev_inst *sdi, int channelIndex)
struct sr_scpi_dev_inst *scpi = sdi->conn;
struct dev_context *devc = sdi->priv;
char *buf = (char *)devc->buffer;
int ret;
int descLength;
int blockOffset = 15; /* Offset for descriptor block. */
int ret, desc_length;
int block_offset = 15; /* Offset for descriptor block. */
long dataLength = 0;
/* Read header from device. */
@ -271,18 +270,18 @@ static int siglent_sds_read_header(struct sr_dev_inst *sdi, int channelIndex)
}
sr_dbg("Device returned %i bytes.", ret);
devc->num_header_bytes += ret;
buf += blockOffset; /* Skip to start descriptor block. */
buf += block_offset; /* Skip to start descriptor block. */
/* Parse WaveDescriptor header. */
memcpy(&descLength, buf + 36, 4); /* Descriptor block length */
memcpy(&desc_length, buf + 36, 4); /* Descriptor block length */
memcpy(&dataLength, buf + 60, 4); /* Data block length */
devc->vdiv[channelIndex] = 2;
devc->vert_offset[channelIndex] = 0;
devc->blockHeaderSize = descLength + 15;
devc->block_header_size = desc_length + 15;
ret = dataLength;
sr_dbg("Received data block header: '%s' -> block length %d", buf, ret);
sr_dbg("Received data block header: '%s' -> block length %d.", buf, ret);
return ret;
}
@ -381,7 +380,7 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
len = ACQ_BUFFER_SIZE;
/* Offset the data block buffer past the IEEE header and description header. */
devc->buffer += devc->blockHeaderSize;
devc->buffer += devc->block_header_size;
if (len == -1) {
sr_err("Read error, aborting capture.");
@ -400,8 +399,7 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
float offset = devc->vert_offset[ch->index];
GArray *float_data;
static GArray *data;
float voltage;
float vdivlog;
float voltage, vdivlog;
int digits;
data = g_array_sized_new(FALSE, FALSE, sizeof(uint8_t), len);
@ -489,12 +487,10 @@ SR_PRIV int siglent_sds_get_dev_cfg(const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
struct sr_channel *ch;
char *cmd;
char *cmd, *response;
unsigned int i;
int res;
char *response;
int res, num_tokens;
gchar **tokens;
int num_tokens;
devc = sdi->priv;
@ -661,47 +657,46 @@ SR_PRIV int siglent_sds_get_dev_cfg_horizontal(const struct sr_dev_inst *sdi)
struct dev_context *devc;
char *cmd;
int res;
char *samplePointsString;
float samplerateScope;
float fvalue;
char *sample_points_string;
float samplerate_scope, fvalue;
char *first, *concat;
devc = sdi->priv;
cmd = g_strdup_printf("SANU? C1");
res = sr_scpi_get_string(sdi->conn, cmd, &samplePointsString);
res = sr_scpi_get_string(sdi->conn, cmd, &sample_points_string);
g_free(cmd);
if (res != SR_OK)
return SR_ERR;
if (g_strstr_len(samplePointsString, -1, "Mpts") != NULL) {
samplePointsString[strlen(samplePointsString) - 4] = '\0';
if (g_strstr_len(sample_points_string, -1, "Mpts") != NULL) {
sample_points_string[strlen(sample_points_string) - 4] = '\0';
if (g_strstr_len(samplePointsString, -1, ".") != NULL) {
first = strtok(samplePointsString, ".");
if (g_strstr_len(sample_points_string, -1, ".") != NULL) {
first = strtok(sample_points_string, ".");
concat = strcat(first, strtok(NULL, "."));
if (sr_atof_ascii(concat, &fvalue) != SR_OK || fvalue == 0.0) {
sr_dbg("Invalid float converted from scope response.");
return SR_ERR;
}
} else {
if (sr_atof_ascii(samplePointsString, &fvalue) != SR_OK || fvalue == 0.0) {
if (sr_atof_ascii(sample_points_string, &fvalue) != SR_OK || fvalue == 0.0) {
sr_dbg("Invalid float converted from scope response.");
return SR_ERR;
}
}
samplerateScope = fvalue * 100000;
samplerate_scope = fvalue * 100000;
} else {
samplePointsString[strlen(samplePointsString) - 4] = '\0';
if (sr_atof_ascii(samplePointsString, &fvalue) != SR_OK || fvalue == 0.0) {
sample_points_string[strlen(sample_points_string) - 4] = '\0';
if (sr_atof_ascii(sample_points_string, &fvalue) != SR_OK || fvalue == 0.0) {
sr_dbg("Invalid float converted from scope response.");
return SR_ERR;
}
samplerateScope = fvalue * 1000;
samplerate_scope = fvalue * 1000;
}
/* Get the timebase. */
if (sr_scpi_get_float(sdi->conn, ":TDIV?", &devc->timebase) != SR_OK)
return SR_ERR;
sr_dbg("Current timebase: %g.", devc->timebase);
devc->sampleRate = samplerateScope / (devc->timebase * devc->model->series->num_horizontal_divs);
devc->samplerate = samplerate_scope / (devc->timebase * devc->model->series->num_horizontal_divs);
return SR_OK;
}

View File

@ -55,7 +55,6 @@ enum data_source {
struct siglent_sds_vendor {
const char *name;
const char *full_name;
const char *usb_name;
};
struct siglent_sds_series {
@ -106,8 +105,8 @@ struct dev_context {
uint64_t analog_frame_size;
uint64_t digital_frame_size;
uint64_t num_samples;
long blockHeaderSize;
float sampleRate;
long block_header_size;
float samplerate;
/* Device settings */
gboolean analog_channels[MAX_ANALOG_CHANNELS];