if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
return SR_ERR;
sr_atoi(buf, &out);
+ g_free(buf);
g_usleep(s);
} while (out == 0);
if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
return SR_ERR;
sr_atoi(buf, &out);
+ g_free(buf);
g_usleep(s);
/* XXX
* Now this loop condition looks suspicious! A bitwise
if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
return SR_ERR;
sr_atoi(buf, &out);
+ g_free(buf);
if (out == DEVICE_STATE_TRIG_RDY) {
siglent_sds_set_wait_event(devc, WAIT_TRIGGER);
} else if (out == DEVICE_STATE_DATA_TRIG_RDY) {
if (sr_scpi_get_string(sdi->conn, ":INR?", &buf) != SR_OK)
return SR_ERR;
sr_atoi(buf, &out);
+ g_free(buf);
if (out == DEVICE_STATE_TRIG_RDY) {
siglent_sds_set_wait_event(devc, WAIT_TRIGGER);
} else if (out == DEVICE_STATE_DATA_TRIG_RDY) {
gboolean low_channels; /* Lower channels enabled */
gboolean high_channels; /* Higher channels enabled */
int len, channel_index;
- long samples_index;
+ uint64_t samples_index;
len = 0;
channel_index = 0;
for (l = sdi->channels; l; l = l->next) {
ch = l->data;
samples_index = 0;
- if (ch->type == SR_CHANNEL_LOGIC) {
- if (ch->enabled) {
- if (sr_scpi_send(sdi->conn, "D%d:WF? DAT2", ch->index) != SR_OK)
- return SR_ERR;
- if (sr_scpi_read_begin(scpi) != SR_OK)
- return TRUE;
- len = sr_scpi_read_data(scpi, buf, -1);
- if (len < 0)
- return TRUE;
- len -= 15;
- buffdata = g_array_sized_new(FALSE, FALSE, sizeof(uint8_t), len);
- buf += 15; /* Skipping the data header. */
- g_array_append_vals(buffdata, buf, len);
- tmp_samplebuf = g_array_sized_new(FALSE, FALSE, sizeof(uint8_t), len); /* New temp buffer. */
- for (uint64_t cur_sample_index = 0; cur_sample_index < devc->memory_depth_digital; cur_sample_index++) {
- char sample = (char)g_array_index(buffdata, uint8_t, cur_sample_index);
- for (int ii = 0; ii < 8; ii++, sample >>= 1) {
- if (ch->index < 8) {
- channel_index = ch->index;
- if (data_low_channels->len <= samples_index) {
- tmp_value = 0; /* New sample. */
- low_channels = TRUE; /* We have at least one enabled low channel. */
- } else {
- /* Get previous stored sample from low channel buffer. */
- tmp_value = g_array_index(data_low_channels, uint8_t, samples_index);
- }
- } else {
- channel_index = ch->index - 8;
- if (data_high_channels->len <= samples_index) {
- tmp_value = 0; /* New sample. */
- high_channels = TRUE; /* We have at least one enabled high channel. */
- } else {
- /* Get previous stored sample from high channel buffer. */
- tmp_value = g_array_index(data_high_channels, uint8_t, samples_index);
- }
- }
- /* Check if the current scope sample bit is set. */
- if (sample & 0x1)
- tmp_value |= 1UL << channel_index; /* Set current scope sample bit based on channel index. */
- g_array_append_val(tmp_samplebuf, tmp_value);
- samples_index++;
- }
- }
-
- /* Clear the buffers to prepare for the new samples */
+ if (ch->type != SR_CHANNEL_LOGIC)
+ continue;
+ if (!ch->enabled)
+ continue;
+ if (sr_scpi_send(sdi->conn, "D%d:WF? DAT2", ch->index) != SR_OK)
+ return SR_ERR;
+ if (sr_scpi_read_begin(scpi) != SR_OK)
+ return TRUE;
+ len = sr_scpi_read_data(scpi, buf, -1);
+ if (len < 0)
+ return TRUE;
+ len -= 15;
+ buffdata = g_array_sized_new(FALSE, FALSE, sizeof(uint8_t), len);
+ buf += 15; /* Skipping the data header. */
+ g_array_append_vals(buffdata, buf, len);
+ tmp_samplebuf = g_array_sized_new(FALSE, FALSE, sizeof(uint8_t), len); /* New temp buffer. */
+ for (uint64_t cur_sample_index = 0; cur_sample_index < devc->memory_depth_digital; cur_sample_index++) {
+ char sample = (char)g_array_index(buffdata, uint8_t, cur_sample_index);
+ for (int ii = 0; ii < 8; ii++, sample >>= 1) {
if (ch->index < 8) {
- g_array_free(data_low_channels, FALSE);
- data_low_channels = g_array_new(FALSE, FALSE, sizeof(uint8_t));
+ channel_index = ch->index;
+ if (data_low_channels->len <= samples_index) {
+ tmp_value = 0; /* New sample. */
+ low_channels = TRUE; /* We have at least one enabled low channel. */
+ } else {
+ /* Get previous stored sample from low channel buffer. */
+ tmp_value = g_array_index(data_low_channels, uint8_t, samples_index);
+ }
} else {
- g_array_free(data_high_channels, FALSE);
- data_high_channels = g_array_new(FALSE, FALSE, sizeof(uint8_t));
- }
-
- /* Storing the converted temp values from the the scope into the buffers. */
- for (long index = 0; index < tmp_samplebuf->len; index++) {
- uint8_t value = g_array_index(tmp_samplebuf, uint8_t, index);
- if (ch->index < 8)
- g_array_append_val(data_low_channels, value);
- else
- g_array_append_val(data_high_channels, value);
+ channel_index = ch->index - 8;
+ if (data_high_channels->len <= samples_index) {
+ tmp_value = 0; /* New sample. */
+ high_channels = TRUE; /* We have at least one enabled high channel. */
+ } else {
+ /* Get previous stored sample from high channel buffer. */
+ tmp_value = g_array_index(data_high_channels, uint8_t, samples_index);
+ }
}
- g_array_free(tmp_samplebuf, TRUE);
- g_array_free(buffdata, TRUE);
+ /* Check if the current scope sample bit is set. */
+ if (sample & 0x1)
+ tmp_value |= 1UL << channel_index; /* Set current scope sample bit based on channel index. */
+ g_array_append_val(tmp_samplebuf, tmp_value);
+ samples_index++;
}
}
+
+ /* Clear the buffers to prepare for the new samples */
+ if (ch->index < 8) {
+ g_array_free(data_low_channels, TRUE);
+ data_low_channels = g_array_new(FALSE, FALSE, sizeof(uint8_t));
+ } else {
+ g_array_free(data_high_channels, TRUE);
+ data_high_channels = g_array_new(FALSE, FALSE, sizeof(uint8_t));
+ }
+
+ /* Storing the converted temp values from the the scope into the buffers. */
+ for (uint64_t index = 0; index < tmp_samplebuf->len; index++) {
+ uint8_t value = g_array_index(tmp_samplebuf, uint8_t, index);
+ if (ch->index < 8)
+ g_array_append_val(data_low_channels, value);
+ else
+ g_array_append_val(data_high_channels, value);
+ }
+ g_array_free(tmp_samplebuf, TRUE);
+ g_array_free(buffdata, TRUE);
}
/* Combining the lower and higher channel buffers into one buffer for sigrok. */
struct sr_channel *ch;
int len, i;
float wait;
- gboolean read_complete = false;
+ gboolean read_complete = FALSE;
(void)fd;
return TRUE;
if (len == -1) {
sr_err("Read error, aborting capture.");
- packet.type = SR_DF_FRAME_END;
- sr_session_send(sdi, &packet);
+ std_session_send_df_frame_end(sdi);
sdi->driver->dev_acquisition_stop(sdi);
return TRUE;
}
if (len == -1) {
sr_err("Read error, aborting capture.");
- packet.type = SR_DF_FRAME_END;
- sr_session_send(sdi, &packet);
+ std_session_send_df_frame_end(sdi);
sdi->driver->dev_acquisition_stop(sdi);
return TRUE;
}
do {
- read_complete = false;
+ read_complete = FALSE;
if (devc->num_block_bytes > devc->num_samples) {
/* We received all data as one block. */
/* Offset the data block buffer past the IEEE header and description header. */
devc->buffer += devc->block_header_size;
len = devc->num_samples;
} else {
- sr_dbg("Requesting: %li bytes.", devc->num_samples - devc->num_block_bytes);
+ sr_dbg("Requesting: %" PRIu64 " bytes.", devc->num_samples - devc->num_block_bytes);
len = sr_scpi_read_data(scpi, (char *)devc->buffer, devc->num_samples-devc->num_block_bytes);
if (len == -1) {
sr_err("Read error, aborting capture.");
- packet.type = SR_DF_FRAME_END;
- sr_session_send(sdi, &packet);
+ std_session_send_df_frame_end(sdi);
sdi->driver->dev_acquisition_stop(sdi);
return TRUE;
}
sr_dbg("Transfer has been completed.");
devc->num_header_bytes = 0;
devc->num_block_bytes = 0;
- read_complete = true;
+ read_complete = TRUE;
if (!sr_scpi_read_complete(scpi)) {
sr_err("Read should have been completed.");
- packet.type = SR_DF_FRAME_END;
- sr_session_send(sdi, &packet);
+ std_session_send_df_frame_end(sdi);
sdi->driver->dev_acquisition_stop(sdi);
return TRUE;
}
siglent_sds_channel_start(sdi);
} else {
/* Done with this frame. */
- packet.type = SR_DF_FRAME_END;
- sr_session_send(sdi, &packet);
+ std_session_send_df_frame_end(sdi);
if (++devc->num_frames == devc->limit_frames) {
/* Last frame, stop capture. */
sdi->driver->dev_acquisition_stop(sdi);
siglent_sds_capture_start(sdi);
/* Start of next frame. */
- packet.type = SR_DF_FRAME_BEGIN;
- sr_session_send(sdi, &packet);
+ std_session_send_df_frame_begin(sdi);
}
}
}
packet.type = SR_DF_LOGIC;
packet.payload = &logic;
sr_session_send(sdi, &packet);
- packet.type = SR_DF_FRAME_END;
- sr_session_send(sdi, &packet);
+ std_session_send_df_frame_end(sdi);
sdi->driver->dev_acquisition_stop(sdi);
if (++devc->num_frames == devc->limit_frames) {
siglent_sds_capture_start(sdi);
/* Start of next frame. */
- packet.type = SR_DF_FRAME_BEGIN;
- sr_session_send(sdi, &packet);
+ std_session_send_df_frame_begin(sdi);
}
}
// sr_session_send(sdi, &packet);
- // packet.type = SR_DF_FRAME_END;
- // sr_session_send(sdi, &packet);
+ // std_session_send_df_frame_end(sdi);
// sdi->driver->dev_acquisition_stop(sdi);
return TRUE;
/* Coupling. */
for (i = 0; i < devc->model->analog_channels; i++) {
cmd = g_strdup_printf("C%d:CPL?", i + 1);
+ g_free(devc->coupling[i]);
+ devc->coupling[i] = NULL;
res = sr_scpi_get_string(sdi->conn, cmd, &devc->coupling[i]);
g_free(cmd);
if (res != SR_OK)
if (sr_scpi_get_string(sdi->conn, "TRSE?", &response) != SR_OK)
return SR_ERR;
tokens = g_strsplit(response, ",", 0);
- for (num_tokens = 0; tokens[num_tokens] != NULL; num_tokens++);
+ num_tokens = g_strv_length(tokens);
if (num_tokens < 4) {
sr_dbg("IDN response not according to spec: %80.s.", response);
g_strfreev(tokens);
/* Trigger slope. */
cmd = g_strdup_printf("%s:TRSL?", devc->trigger_source);
+ g_free(devc->trigger_slope);
+ devc->trigger_slope = NULL;
res = sr_scpi_get_string(sdi->conn, cmd, &devc->trigger_slope);
g_free(cmd);
if (res != SR_OK)
g_free(cmd);
samplerate_scope = 0;
fvalue = 0;
- if (res != SR_OK)
+ if (res != SR_OK) {
+ g_free(sample_points_string);
return SR_ERR;
+ }
if (g_strstr_len(sample_points_string, -1, "Mpts") != NULL) {
sample_points_string[strlen(sample_points_string) - 4] = '\0';
if (sr_atof_ascii(sample_points_string, &fvalue) != SR_OK) {
sr_dbg("Invalid float converted from scope response.");
+ g_free(sample_points_string);
return SR_ERR;
}
samplerate_scope = fvalue * 1000000;
sample_points_string[strlen(sample_points_string) - 4] = '\0';
if (sr_atof_ascii(sample_points_string, &fvalue) != SR_OK) {
sr_dbg("Invalid float converted from scope response.");
+ g_free(sample_points_string);
return SR_ERR;
}
samplerate_scope = fvalue * 10000;
sr_dbg("Current timebase: %g.", devc->timebase);
devc->samplerate = devc->memory_depth_analog / (devc->timebase * devc->model->series->num_horizontal_divs);
sr_dbg("Current samplerate: %0f.", devc->samplerate);
- sr_dbg("Current memory depth: %lu.", devc->memory_depth_analog);
+ sr_dbg("Current memory depth: %" PRIu64 ".", devc->memory_depth_analog);
return SR_OK;
}