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 }, { 100, 1 },
}; };
#define NUM_TIMEBASE ARRAY_SIZE(timebases)
#define NUM_VDIV ARRAY_SIZE(vdivs)
static const char *trigger_sources[] = { static const char *trigger_sources[] = {
"CH1", "CH2", "Ext", "Ext /5", "AC Line", "CH1", "CH2", "Ext", "Ext /5", "AC Line",
"D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
@ -169,11 +166,9 @@ enum series {
SDS2000X, SDS2000X,
}; };
/* short name, full name, USB name */ /* short name, full name */
static const struct siglent_sds_vendor supported_vendors[] = { static const struct siglent_sds_vendor supported_vendors[] = {
[SIGLENT] = { [SIGLENT] = {"Siglent", "Siglent Technologies"},
"Siglent", "Siglent Technologies", "Siglent Technologies Co,. Ltd.",
},
}; };
#define VENDOR(x) &supported_vendors[x] #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); 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]))) if (!memcmp(&devc->model->min_timebase, &timebases[i], sizeof(uint64_t[2])))
devc->timebases = &timebases[i]; 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; 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]; devc->vdivs = &vdivs[i];
if (!memcmp(&devc->model->series->min_vdiv, if (!memcmp(&devc->model->series->min_vdiv,
&vdivs[i], sizeof(uint64_t[2]))) { &vdivs[i], sizeof(uint64_t[2]))) {
devc->vdivs = &vdivs[i]; devc->vdivs = &vdivs[i];
devc->num_vdivs = NUM_VDIV - i; devc->num_vdivs = ARRAY_SIZE(vdivs) - i;
break; break;
} }
} }
@ -437,7 +432,7 @@ static int config_get(uint32_t key, GVariant **data,
break; break;
case SR_CONF_SAMPLERATE: case SR_CONF_SAMPLERATE:
siglent_sds_get_dev_cfg_horizontal(sdi); siglent_sds_get_dev_cfg_horizontal(sdi);
*data = g_variant_new_uint64(devc->sampleRate); *data = g_variant_new_uint64(devc->samplerate);
break; break;
case SR_CONF_TRIGGER_SOURCE: case SR_CONF_TRIGGER_SOURCE:
if (!strcmp(devc->trigger_source, "ACL")) if (!strcmp(devc->trigger_source, "ACL"))
@ -583,7 +578,6 @@ static int config_set(uint32_t key, GVariant *data,
devc->trigger_level = t_dbl; devc->trigger_level = t_dbl;
break; break;
case SR_CONF_TIMEBASE: case SR_CONF_TIMEBASE:
sr_dbg("Setting device Timebase");
g_variant_get(data, "(tt)", &p, &q); g_variant_get(data, "(tt)", &p, &q);
for (i = 0; i < devc->num_timebases; i++) { for (i = 0; i < devc->num_timebases; i++) {
char *cmd; char *cmd;
@ -732,7 +726,7 @@ static int config_set(uint32_t key, GVariant *data,
break; break;
case SR_CONF_SAMPLERATE: case SR_CONF_SAMPLERATE:
siglent_sds_get_dev_cfg_horizontal(sdi); siglent_sds_get_dev_cfg_horizontal(sdi);
data = g_variant_new_uint64(devc->sampleRate); data = g_variant_new_uint64(devc->samplerate);
break; break;
default: default:
return SR_ERR_NA; 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_channel *ch;
struct sr_datafeed_packet packet; struct sr_datafeed_packet packet;
gboolean some_digital; gboolean some_digital;
GSList *l; GSList *l, *d;
GSList *d;
if (sdi->status != SR_ST_ACTIVE) if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED; 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); memcpy(&framecount, buf + 40, 4);
if (devc->limit_frames > framecount) 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) else if (devc->limit_frames == 0)
devc->limit_frames = framecount; devc->limit_frames = framecount;
sr_dbg("Starting data capture for history frameset %" PRIu64 " of %" PRIu64, 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 sr_scpi_dev_inst *scpi = sdi->conn;
struct dev_context *devc = sdi->priv; struct dev_context *devc = sdi->priv;
char *buf = (char *)devc->buffer; char *buf = (char *)devc->buffer;
int ret; int ret, desc_length;
int descLength; int block_offset = 15; /* Offset for descriptor block. */
int blockOffset = 15; /* Offset for descriptor block. */
long dataLength = 0; long dataLength = 0;
/* Read header from device. */ /* 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); sr_dbg("Device returned %i bytes.", ret);
devc->num_header_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. */ /* 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 */ memcpy(&dataLength, buf + 60, 4); /* Data block length */
devc->vdiv[channelIndex] = 2; devc->vdiv[channelIndex] = 2;
devc->vert_offset[channelIndex] = 0; devc->vert_offset[channelIndex] = 0;
devc->blockHeaderSize = descLength + 15; devc->block_header_size = desc_length + 15;
ret = dataLength; 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; return ret;
} }
@ -381,7 +380,7 @@ SR_PRIV int siglent_sds_receive(int fd, int revents, void *cb_data)
len = ACQ_BUFFER_SIZE; len = ACQ_BUFFER_SIZE;
/* Offset the data block buffer past the IEEE header and description header. */ /* 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) { if (len == -1) {
sr_err("Read error, aborting capture."); 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]; float offset = devc->vert_offset[ch->index];
GArray *float_data; GArray *float_data;
static GArray *data; static GArray *data;
float voltage; float voltage, vdivlog;
float vdivlog;
int digits; int digits;
data = g_array_sized_new(FALSE, FALSE, sizeof(uint8_t), len); 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 dev_context *devc;
struct sr_channel *ch; struct sr_channel *ch;
char *cmd; char *cmd, *response;
unsigned int i; unsigned int i;
int res; int res, num_tokens;
char *response;
gchar **tokens; gchar **tokens;
int num_tokens;
devc = sdi->priv; 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; struct dev_context *devc;
char *cmd; char *cmd;
int res; int res;
char *samplePointsString; char *sample_points_string;
float samplerateScope; float samplerate_scope, fvalue;
float fvalue;
char *first, *concat; char *first, *concat;
devc = sdi->priv; devc = sdi->priv;
cmd = g_strdup_printf("SANU? C1"); 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); g_free(cmd);
if (res != SR_OK) if (res != SR_OK)
return SR_ERR; return SR_ERR;
if (g_strstr_len(samplePointsString, -1, "Mpts") != NULL) { if (g_strstr_len(sample_points_string, -1, "Mpts") != NULL) {
samplePointsString[strlen(samplePointsString) - 4] = '\0'; sample_points_string[strlen(sample_points_string) - 4] = '\0';
if (g_strstr_len(samplePointsString, -1, ".") != NULL) { if (g_strstr_len(sample_points_string, -1, ".") != NULL) {
first = strtok(samplePointsString, "."); first = strtok(sample_points_string, ".");
concat = strcat(first, strtok(NULL, ".")); concat = strcat(first, strtok(NULL, "."));
if (sr_atof_ascii(concat, &fvalue) != SR_OK || fvalue == 0.0) { if (sr_atof_ascii(concat, &fvalue) != SR_OK || fvalue == 0.0) {
sr_dbg("Invalid float converted from scope response."); sr_dbg("Invalid float converted from scope response.");
return SR_ERR; return SR_ERR;
} }
} else { } 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."); sr_dbg("Invalid float converted from scope response.");
return SR_ERR; return SR_ERR;
} }
} }
samplerateScope = fvalue * 100000; samplerate_scope = fvalue * 100000;
} else { } else {
samplePointsString[strlen(samplePointsString) - 4] = '\0'; sample_points_string[strlen(sample_points_string) - 4] = '\0';
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."); sr_dbg("Invalid float converted from scope response.");
return SR_ERR; return SR_ERR;
} }
samplerateScope = fvalue * 1000; samplerate_scope = fvalue * 1000;
} }
/* Get the timebase. */ /* Get the timebase. */
if (sr_scpi_get_float(sdi->conn, ":TDIV?", &devc->timebase) != SR_OK) if (sr_scpi_get_float(sdi->conn, ":TDIV?", &devc->timebase) != SR_OK)
return SR_ERR; return SR_ERR;
sr_dbg("Current timebase: %g.", devc->timebase); 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; return SR_OK;
} }

View File

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