drivers: Reduce unnecessarily high indentation in some places.
This commit is contained in:
parent
612336970d
commit
3782e57129
|
@ -158,55 +158,55 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WAIT_FOR_TRANSFER_OF_BEGIN_TRANSMISSION_COMPLETE:
|
case WAIT_FOR_TRANSFER_OF_BEGIN_TRANSMISSION_COMPLETE:
|
||||||
if (read_data(sdi, scpi, devc, 1) == SR_OK) {
|
if (read_data(sdi, scpi, devc, 1) < 0)
|
||||||
if (devc->rcv_buffer[0] == '#')
|
break;
|
||||||
devc->state = WAIT_FOR_TRANSFER_OF_DATA_SIZE_DIGIT_COMPLETE;
|
if (devc->rcv_buffer[0] == '#')
|
||||||
}
|
devc->state = WAIT_FOR_TRANSFER_OF_DATA_SIZE_DIGIT_COMPLETE;
|
||||||
break;
|
break;
|
||||||
case WAIT_FOR_TRANSFER_OF_DATA_SIZE_DIGIT_COMPLETE:
|
case WAIT_FOR_TRANSFER_OF_DATA_SIZE_DIGIT_COMPLETE:
|
||||||
if (read_data(sdi, scpi, devc, 1) == SR_OK) {
|
if (read_data(sdi, scpi, devc, 1) < 0)
|
||||||
if (devc->rcv_buffer[0] != '4' &&
|
break;
|
||||||
devc->rcv_buffer[0] != '5' &&
|
if (devc->rcv_buffer[0] != '4' &&
|
||||||
devc->rcv_buffer[0] != '6') {
|
devc->rcv_buffer[0] != '5' &&
|
||||||
sr_err("Data size digits is not 4, 5 or 6 but "
|
devc->rcv_buffer[0] != '6') {
|
||||||
"'%c'.", devc->rcv_buffer[0]);
|
sr_err("Data size digits is not 4, 5 or 6 but "
|
||||||
sr_dev_acquisition_stop(sdi);
|
"'%c'.", devc->rcv_buffer[0]);
|
||||||
return TRUE;
|
sr_dev_acquisition_stop(sdi);
|
||||||
} else {
|
return TRUE;
|
||||||
devc->data_size_digits = devc->rcv_buffer[0] - '0';
|
} else {
|
||||||
devc->state = WAIT_FOR_TRANSFER_OF_DATA_SIZE_COMPLETE;
|
devc->data_size_digits = devc->rcv_buffer[0] - '0';
|
||||||
}
|
devc->state = WAIT_FOR_TRANSFER_OF_DATA_SIZE_COMPLETE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WAIT_FOR_TRANSFER_OF_DATA_SIZE_COMPLETE:
|
case WAIT_FOR_TRANSFER_OF_DATA_SIZE_COMPLETE:
|
||||||
if (read_data(sdi, scpi, devc, devc->data_size_digits) == SR_OK) {
|
if (read_data(sdi, scpi, devc, devc->data_size_digits) < 0)
|
||||||
devc->rcv_buffer[devc->data_size_digits] = 0;
|
break;
|
||||||
if (sr_atoi(devc->rcv_buffer, &devc->data_size) != SR_OK) {
|
devc->rcv_buffer[devc->data_size_digits] = 0;
|
||||||
sr_err("Could not parse data size '%s'", devc->rcv_buffer);
|
if (sr_atoi(devc->rcv_buffer, &devc->data_size) != SR_OK) {
|
||||||
sr_dev_acquisition_stop(sdi);
|
sr_err("Could not parse data size '%s'", devc->rcv_buffer);
|
||||||
return TRUE;
|
sr_dev_acquisition_stop(sdi);
|
||||||
} else
|
return TRUE;
|
||||||
devc->state = WAIT_FOR_TRANSFER_OF_SAMPLE_RATE_COMPLETE;
|
} else
|
||||||
}
|
devc->state = WAIT_FOR_TRANSFER_OF_SAMPLE_RATE_COMPLETE;
|
||||||
break;
|
break;
|
||||||
case WAIT_FOR_TRANSFER_OF_SAMPLE_RATE_COMPLETE:
|
case WAIT_FOR_TRANSFER_OF_SAMPLE_RATE_COMPLETE:
|
||||||
if (read_data(sdi, scpi, devc, sizeof(float)) == SR_OK) {
|
if (read_data(sdi, scpi, devc, sizeof(float)) < 0)
|
||||||
/*
|
break;
|
||||||
* Contrary to the documentation, this field is
|
/*
|
||||||
* transfered with most significant byte first!
|
* Contrary to the documentation, this field is
|
||||||
*/
|
* transfered with most significant byte first!
|
||||||
sample_rate = RB32(devc->rcv_buffer);
|
*/
|
||||||
memcpy(&devc->sample_rate, &sample_rate, sizeof(float));
|
sample_rate = RB32(devc->rcv_buffer);
|
||||||
devc->state = WAIT_FOR_TRANSFER_OF_CHANNEL_INDICATOR_COMPLETE;
|
memcpy(&devc->sample_rate, &sample_rate, sizeof(float));
|
||||||
|
devc->state = WAIT_FOR_TRANSFER_OF_CHANNEL_INDICATOR_COMPLETE;
|
||||||
|
|
||||||
if (!devc->df_started) {
|
if (!devc->df_started) {
|
||||||
std_session_send_df_header(sdi);
|
std_session_send_df_header(sdi);
|
||||||
|
|
||||||
packet.type = SR_DF_FRAME_BEGIN;
|
packet.type = SR_DF_FRAME_BEGIN;
|
||||||
sr_session_send(sdi, &packet);
|
sr_session_send(sdi, &packet);
|
||||||
|
|
||||||
devc->df_started = TRUE;
|
devc->df_started = TRUE;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WAIT_FOR_TRANSFER_OF_CHANNEL_INDICATOR_COMPLETE:
|
case WAIT_FOR_TRANSFER_OF_CHANNEL_INDICATOR_COMPLETE:
|
||||||
|
@ -218,72 +218,73 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data)
|
||||||
devc->state = WAIT_FOR_TRANSFER_OF_CHANNEL_DATA_COMPLETE;
|
devc->state = WAIT_FOR_TRANSFER_OF_CHANNEL_DATA_COMPLETE;
|
||||||
break;
|
break;
|
||||||
case WAIT_FOR_TRANSFER_OF_CHANNEL_DATA_COMPLETE:
|
case WAIT_FOR_TRANSFER_OF_CHANNEL_DATA_COMPLETE:
|
||||||
if (read_data(sdi, scpi, devc, devc->data_size - 8) == SR_OK) {
|
if (read_data(sdi, scpi, devc, devc->data_size - 8) < 0)
|
||||||
/* Fetch data needed for conversion from device. */
|
break;
|
||||||
snprintf(command, sizeof(command), ":CHAN%d:SCAL?",
|
|
||||||
devc->cur_acq_channel + 1);
|
/* Fetch data needed for conversion from device. */
|
||||||
if (sr_scpi_get_string(scpi, command, &response) != SR_OK) {
|
snprintf(command, sizeof(command), ":CHAN%d:SCAL?",
|
||||||
sr_err("Failed to get volts per division.");
|
devc->cur_acq_channel + 1);
|
||||||
|
if (sr_scpi_get_string(scpi, command, &response) != SR_OK) {
|
||||||
|
sr_err("Failed to get volts per division.");
|
||||||
|
sr_dev_acquisition_stop(sdi);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
volts_per_division = g_ascii_strtod(response, &end_ptr);
|
||||||
|
if (!strcmp(end_ptr, "mV"))
|
||||||
|
volts_per_division *= 1.e-3;
|
||||||
|
g_free(response);
|
||||||
|
|
||||||
|
num_samples = (devc->data_size - 8) / 2;
|
||||||
|
sr_spew("Received %d number of samples from channel "
|
||||||
|
"%d.", num_samples, devc->cur_acq_channel + 1);
|
||||||
|
|
||||||
|
float vbit = volts_per_division * VERTICAL_DIVISIONS / 256.0;
|
||||||
|
float vbitlog = log10f(vbit);
|
||||||
|
int digits = -(int)vbitlog + (vbitlog < 0.0);
|
||||||
|
|
||||||
|
/* Convert data. */
|
||||||
|
for (i = 0; i < num_samples; i++)
|
||||||
|
samples[i] = ((float) ((int16_t) (RB16(&devc->rcv_buffer[i*2])))) * vbit;
|
||||||
|
|
||||||
|
/* Fill frame. */
|
||||||
|
sr_analog_init(&analog, &encoding, &meaning, &spec, digits);
|
||||||
|
analog.meaning->channels = g_slist_append(NULL, g_slist_nth_data(sdi->channels, devc->cur_acq_channel));
|
||||||
|
analog.num_samples = num_samples;
|
||||||
|
analog.data = samples;
|
||||||
|
analog.meaning->mq = SR_MQ_VOLTAGE;
|
||||||
|
analog.meaning->unit = SR_UNIT_VOLT;
|
||||||
|
analog.meaning->mqflags = 0;
|
||||||
|
packet.type = SR_DF_ANALOG;
|
||||||
|
packet.payload = &analog;
|
||||||
|
sr_session_send(sdi, &packet);
|
||||||
|
g_slist_free(analog.meaning->channels);
|
||||||
|
|
||||||
|
/* All channels acquired. */
|
||||||
|
if (devc->cur_acq_channel == ANALOG_CHANNELS - 1) {
|
||||||
|
sr_spew("All channels acquired.");
|
||||||
|
|
||||||
|
if (devc->cur_acq_frame == devc->frame_limit - 1) {
|
||||||
|
/* All frames acquired. */
|
||||||
|
sr_spew("All frames acquired.");
|
||||||
sr_dev_acquisition_stop(sdi);
|
sr_dev_acquisition_stop(sdi);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
|
||||||
volts_per_division = g_ascii_strtod(response, &end_ptr);
|
|
||||||
if (!strcmp(end_ptr, "mV"))
|
|
||||||
volts_per_division *= 1.e-3;
|
|
||||||
g_free(response);
|
|
||||||
|
|
||||||
num_samples = (devc->data_size - 8) / 2;
|
|
||||||
sr_spew("Received %d number of samples from channel "
|
|
||||||
"%d.", num_samples, devc->cur_acq_channel + 1);
|
|
||||||
|
|
||||||
float vbit = volts_per_division * VERTICAL_DIVISIONS / 256.0;
|
|
||||||
float vbitlog = log10f(vbit);
|
|
||||||
int digits = -(int)vbitlog + (vbitlog < 0.0);
|
|
||||||
|
|
||||||
/* Convert data. */
|
|
||||||
for (i = 0; i < num_samples; i++)
|
|
||||||
samples[i] = ((float) ((int16_t) (RB16(&devc->rcv_buffer[i*2])))) * vbit;
|
|
||||||
|
|
||||||
/* Fill frame. */
|
|
||||||
sr_analog_init(&analog, &encoding, &meaning, &spec, digits);
|
|
||||||
analog.meaning->channels = g_slist_append(NULL, g_slist_nth_data(sdi->channels, devc->cur_acq_channel));
|
|
||||||
analog.num_samples = num_samples;
|
|
||||||
analog.data = samples;
|
|
||||||
analog.meaning->mq = SR_MQ_VOLTAGE;
|
|
||||||
analog.meaning->unit = SR_UNIT_VOLT;
|
|
||||||
analog.meaning->mqflags = 0;
|
|
||||||
packet.type = SR_DF_ANALOG;
|
|
||||||
packet.payload = &analog;
|
|
||||||
sr_session_send(sdi, &packet);
|
|
||||||
g_slist_free(analog.meaning->channels);
|
|
||||||
|
|
||||||
/* All channels acquired. */
|
|
||||||
if (devc->cur_acq_channel == ANALOG_CHANNELS - 1) {
|
|
||||||
sr_spew("All channels acquired.");
|
|
||||||
|
|
||||||
if (devc->cur_acq_frame == devc->frame_limit - 1) {
|
|
||||||
/* All frames acquired. */
|
|
||||||
sr_spew("All frames acquired.");
|
|
||||||
sr_dev_acquisition_stop(sdi);
|
|
||||||
return TRUE;
|
|
||||||
} else {
|
|
||||||
/* Start acquiring next frame. */
|
|
||||||
if (devc->df_started) {
|
|
||||||
packet.type = SR_DF_FRAME_END;
|
|
||||||
sr_session_send(sdi, &packet);
|
|
||||||
|
|
||||||
packet.type = SR_DF_FRAME_BEGIN;
|
|
||||||
sr_session_send(sdi, &packet);
|
|
||||||
}
|
|
||||||
devc->cur_acq_frame++;
|
|
||||||
devc->state = START_ACQUISITION;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/* Start acquiring next channel. */
|
/* Start acquiring next frame. */
|
||||||
devc->state = START_TRANSFER_OF_CHANNEL_DATA;
|
if (devc->df_started) {
|
||||||
devc->cur_acq_channel++;
|
packet.type = SR_DF_FRAME_END;
|
||||||
return TRUE;
|
sr_session_send(sdi, &packet);
|
||||||
|
|
||||||
|
packet.type = SR_DF_FRAME_BEGIN;
|
||||||
|
sr_session_send(sdi, &packet);
|
||||||
|
}
|
||||||
|
devc->cur_acq_frame++;
|
||||||
|
devc->state = START_ACQUISITION;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
/* Start acquiring next channel. */
|
||||||
|
devc->state = START_TRANSFER_OF_CHANNEL_DATA;
|
||||||
|
devc->cur_acq_channel++;
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,28 +176,24 @@ static int config_get(uint32_t key, GVariant **data,
|
||||||
(*model->timebases)[state->timebase][1]);
|
(*model->timebases)[state->timebase][1]);
|
||||||
break;
|
break;
|
||||||
case SR_CONF_NUM_VDIV:
|
case SR_CONF_NUM_VDIV:
|
||||||
if (!cg) {
|
if (!cg)
|
||||||
return SR_ERR_CHANNEL_GROUP;
|
return SR_ERR_CHANNEL_GROUP;
|
||||||
} else if (cg_type == CG_ANALOG) {
|
if (cg_type != CG_ANALOG)
|
||||||
if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) < 0)
|
|
||||||
return SR_ERR_ARG;
|
|
||||||
*data = g_variant_new_int32(model->num_ydivs);
|
|
||||||
} else {
|
|
||||||
return SR_ERR_NA;
|
return SR_ERR_NA;
|
||||||
}
|
if (std_cg_idx(cg, devc->analog_groups, model->analog_channels) < 0)
|
||||||
|
return SR_ERR_ARG;
|
||||||
|
*data = g_variant_new_int32(model->num_ydivs);
|
||||||
break;
|
break;
|
||||||
case SR_CONF_VDIV:
|
case SR_CONF_VDIV:
|
||||||
if (!cg) {
|
if (!cg)
|
||||||
return SR_ERR_CHANNEL_GROUP;
|
return SR_ERR_CHANNEL_GROUP;
|
||||||
} else if (cg_type == CG_ANALOG) {
|
if (cg_type != CG_ANALOG)
|
||||||
if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
|
|
||||||
return SR_ERR_ARG;
|
|
||||||
*data = g_variant_new("(tt)",
|
|
||||||
(*model->vdivs)[state->analog_channels[idx].vdiv][0],
|
|
||||||
(*model->vdivs)[state->analog_channels[idx].vdiv][1]);
|
|
||||||
} else {
|
|
||||||
return SR_ERR_NA;
|
return SR_ERR_NA;
|
||||||
}
|
if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
|
||||||
|
return SR_ERR_ARG;
|
||||||
|
*data = g_variant_new("(tt)",
|
||||||
|
(*model->vdivs)[state->analog_channels[idx].vdiv][0],
|
||||||
|
(*model->vdivs)[state->analog_channels[idx].vdiv][1]);
|
||||||
break;
|
break;
|
||||||
case SR_CONF_TRIGGER_SOURCE:
|
case SR_CONF_TRIGGER_SOURCE:
|
||||||
*data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]);
|
*data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]);
|
||||||
|
@ -209,15 +205,13 @@ static int config_get(uint32_t key, GVariant **data,
|
||||||
*data = g_variant_new_double(state->horiz_triggerpos);
|
*data = g_variant_new_double(state->horiz_triggerpos);
|
||||||
break;
|
break;
|
||||||
case SR_CONF_COUPLING:
|
case SR_CONF_COUPLING:
|
||||||
if (!cg) {
|
if (!cg)
|
||||||
return SR_ERR_CHANNEL_GROUP;
|
return SR_ERR_CHANNEL_GROUP;
|
||||||
} else if (cg_type == CG_ANALOG) {
|
if (cg_type != CG_ANALOG)
|
||||||
if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
|
|
||||||
return SR_ERR_ARG;
|
|
||||||
*data = g_variant_new_string((*model->coupling_options)[state->analog_channels[idx].coupling]);
|
|
||||||
} else {
|
|
||||||
return SR_ERR_NA;
|
return SR_ERR_NA;
|
||||||
}
|
if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
|
||||||
|
return SR_ERR_ARG;
|
||||||
|
*data = g_variant_new_string((*model->coupling_options)[state->analog_channels[idx].coupling]);
|
||||||
break;
|
break;
|
||||||
case SR_CONF_SAMPLERATE:
|
case SR_CONF_SAMPLERATE:
|
||||||
*data = g_variant_new_uint64(state->sample_rate);
|
*data = g_variant_new_uint64(state->sample_rate);
|
||||||
|
|
|
@ -495,8 +495,21 @@ SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi)
|
||||||
channel_found = FALSE;
|
channel_found = FALSE;
|
||||||
|
|
||||||
for (i = 0; i < config->analog_channels; i++) {
|
for (i = 0; i < config->analog_channels; i++) {
|
||||||
if (state->analog_channels[i].state) {
|
if (!state->analog_channels[i].state)
|
||||||
g_snprintf(chan_name, sizeof(chan_name), "CHAN%d", i + 1);
|
continue;
|
||||||
|
g_snprintf(chan_name, sizeof(chan_name), "CHAN%d", i + 1);
|
||||||
|
g_snprintf(tmp_str, sizeof(tmp_str),
|
||||||
|
(*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE],
|
||||||
|
chan_name);
|
||||||
|
channel_found = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!channel_found) {
|
||||||
|
for (i = 0; i < config->digital_pods; i++) {
|
||||||
|
if (!state->digital_pods[i])
|
||||||
|
continue;
|
||||||
|
g_snprintf(chan_name, sizeof(chan_name), "POD%d", i);
|
||||||
g_snprintf(tmp_str, sizeof(tmp_str),
|
g_snprintf(tmp_str, sizeof(tmp_str),
|
||||||
(*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE],
|
(*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE],
|
||||||
chan_name);
|
chan_name);
|
||||||
|
@ -505,19 +518,6 @@ SR_PRIV int hmo_update_sample_rate(const struct sr_dev_inst *sdi)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!channel_found) {
|
|
||||||
for (i = 0; i < config->digital_pods; i++) {
|
|
||||||
if (state->digital_pods[i]) {
|
|
||||||
g_snprintf(chan_name, sizeof(chan_name), "POD%d", i);
|
|
||||||
g_snprintf(tmp_str, sizeof(tmp_str),
|
|
||||||
(*config->scpi_dialect)[SCPI_CMD_GET_SAMPLE_RATE_LIVE],
|
|
||||||
chan_name);
|
|
||||||
channel_found = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* No channel is active, ask the instrument for the sample rate
|
/* No channel is active, ask the instrument for the sample rate
|
||||||
* in single shot mode */
|
* in single shot mode */
|
||||||
if (!channel_found) {
|
if (!channel_found) {
|
||||||
|
|
|
@ -312,35 +312,29 @@ static int config_get(uint32_t key, GVariant **data,
|
||||||
case SR_CONF_TRIGGER_SLOPE:
|
case SR_CONF_TRIGGER_SLOPE:
|
||||||
if (devc->edge >= ARRAY_SIZE(trigger_slopes))
|
if (devc->edge >= ARRAY_SIZE(trigger_slopes))
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
else
|
*data = g_variant_new_string(trigger_slopes[devc->edge]);
|
||||||
*data = g_variant_new_string(trigger_slopes[devc->edge]);
|
|
||||||
break;
|
break;
|
||||||
case SR_CONF_BUFFERSIZE:
|
case SR_CONF_BUFFERSIZE:
|
||||||
*data = g_variant_new_uint64(buffersizes[devc->last_step]);
|
*data = g_variant_new_uint64(buffersizes[devc->last_step]);
|
||||||
break;
|
break;
|
||||||
case SR_CONF_VDIV:
|
case SR_CONF_VDIV:
|
||||||
if (!cg) {
|
if (!cg)
|
||||||
return SR_ERR_CHANNEL_GROUP;
|
return SR_ERR_CHANNEL_GROUP;
|
||||||
} else {
|
if ((idx = std_u8_idx_s(devc->cctl[ch] & 0x33, ARRAY_AND_SIZE(vdivs_map))) < 0)
|
||||||
if ((idx = std_u8_idx_s(devc->cctl[ch] & 0x33, ARRAY_AND_SIZE(vdivs_map))) < 0)
|
return SR_ERR_BUG;
|
||||||
return SR_ERR_BUG;
|
*data = g_variant_new("(tt)", vdivs[idx][0], vdivs[idx][1]);
|
||||||
*data = g_variant_new("(tt)", vdivs[idx][0], vdivs[idx][1]);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case SR_CONF_COUPLING:
|
case SR_CONF_COUPLING:
|
||||||
if (!cg) {
|
if (!cg)
|
||||||
return SR_ERR_CHANNEL_GROUP;
|
return SR_ERR_CHANNEL_GROUP;
|
||||||
} else {
|
if ((idx = std_u8_idx_s(devc->cctl[ch] & 0x0C, ARRAY_AND_SIZE(coupling_map))) < 0)
|
||||||
if ((idx = std_u8_idx_s(devc->cctl[ch] & 0x0C, ARRAY_AND_SIZE(coupling_map))) < 0)
|
return SR_ERR_BUG;
|
||||||
return SR_ERR_BUG;
|
*data = g_variant_new_string(coupling[idx]);
|
||||||
*data = g_variant_new_string(coupling[idx]);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case SR_CONF_PROBE_FACTOR:
|
case SR_CONF_PROBE_FACTOR:
|
||||||
if (!cg)
|
if (!cg)
|
||||||
return SR_ERR_CHANNEL_GROUP;
|
return SR_ERR_CHANNEL_GROUP;
|
||||||
else
|
*data = g_variant_new_uint64(devc->probe[ch]);
|
||||||
*data = g_variant_new_uint64(devc->probe[ch]);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return SR_ERR_NA;
|
return SR_ERR_NA;
|
||||||
|
@ -384,35 +378,28 @@ static int config_set(uint32_t key, GVariant *data,
|
||||||
devc->last_step = idx;
|
devc->last_step = idx;
|
||||||
break;
|
break;
|
||||||
case SR_CONF_VDIV:
|
case SR_CONF_VDIV:
|
||||||
if (!cg) {
|
if (!cg)
|
||||||
return SR_ERR_CHANNEL_GROUP;
|
return SR_ERR_CHANNEL_GROUP;
|
||||||
} else if (!g_variant_is_of_type(data, G_VARIANT_TYPE("(tt)"))) {
|
if (!g_variant_is_of_type(data, G_VARIANT_TYPE("(tt)")))
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
} else {
|
if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(vdivs))) < 0)
|
||||||
if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(vdivs))) < 0)
|
return SR_ERR_ARG;
|
||||||
return SR_ERR_ARG;
|
devc->cctl[ch] = (devc->cctl[ch] & 0xCC) | vdivs_map[idx];
|
||||||
devc->cctl[ch] = (devc->cctl[ch] & 0xCC) | vdivs_map[idx];
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case SR_CONF_COUPLING:
|
case SR_CONF_COUPLING:
|
||||||
if (!cg) {
|
if (!cg)
|
||||||
return SR_ERR_CHANNEL_GROUP;
|
return SR_ERR_CHANNEL_GROUP;
|
||||||
} else {
|
if ((idx = std_str_idx(data, ARRAY_AND_SIZE(coupling))) < 0)
|
||||||
if ((idx = std_str_idx(data, ARRAY_AND_SIZE(coupling))) < 0)
|
return SR_ERR_ARG;
|
||||||
return SR_ERR_ARG;
|
devc->cctl[ch] = (devc->cctl[ch] & 0xF3) | coupling_map[idx];
|
||||||
devc->cctl[ch] = (devc->cctl[ch] & 0xF3) | coupling_map[idx];
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case SR_CONF_PROBE_FACTOR:
|
case SR_CONF_PROBE_FACTOR:
|
||||||
if (!cg) {
|
if (!cg)
|
||||||
return SR_ERR_CHANNEL_GROUP;
|
return SR_ERR_CHANNEL_GROUP;
|
||||||
} else {
|
u = g_variant_get_uint64(data);
|
||||||
u = g_variant_get_uint64(data);
|
if (!u)
|
||||||
if (!u)
|
return SR_ERR_ARG;
|
||||||
return SR_ERR_ARG;
|
devc->probe[ch] = u;
|
||||||
else
|
|
||||||
devc->probe[ch] = u;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return SR_ERR_NA;
|
return SR_ERR_NA;
|
||||||
|
@ -427,17 +414,19 @@ static int config_channel_set(const struct sr_dev_inst *sdi,
|
||||||
struct dev_context *devc = sdi->priv;
|
struct dev_context *devc = sdi->priv;
|
||||||
uint8_t v;
|
uint8_t v;
|
||||||
|
|
||||||
if (changes & SR_CHANNEL_SET_ENABLED) {
|
if (!(changes & SR_CHANNEL_SET_ENABLED))
|
||||||
if (ch->enabled) {
|
return SR_OK;
|
||||||
v = devc->channel | (1 << ch->index);
|
|
||||||
if (v & (v - 1))
|
if (ch->enabled) {
|
||||||
return SR_ERR;
|
v = devc->channel | (1 << ch->index);
|
||||||
devc->channel = v;
|
if (v & (v - 1))
|
||||||
devc->enabled_channel->data = ch;
|
return SR_ERR;
|
||||||
} else {
|
devc->channel = v;
|
||||||
devc->channel &= ~(1 << ch->index);
|
devc->enabled_channel->data = ch;
|
||||||
}
|
} else {
|
||||||
|
devc->channel &= ~(1 << ch->index);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -298,50 +298,52 @@ static struct sr_dev_inst *lascar_identify(unsigned char *config)
|
||||||
|
|
||||||
modelid = config[0];
|
modelid = config[0];
|
||||||
sdi = NULL;
|
sdi = NULL;
|
||||||
if (modelid) {
|
|
||||||
profile = NULL;
|
if (!modelid)
|
||||||
for (i = 0; profiles[i].modelid; i++) {
|
return sdi;
|
||||||
if (profiles[i].modelid == modelid) {
|
|
||||||
profile = &profiles[i];
|
profile = NULL;
|
||||||
break;
|
for (i = 0; profiles[i].modelid; i++) {
|
||||||
}
|
if (profiles[i].modelid == modelid) {
|
||||||
|
profile = &profiles[i];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!profile) {
|
|
||||||
sr_dbg("unknown EL-USB modelid %d", modelid);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
i = config[52] | (config[53] << 8);
|
|
||||||
memcpy(firmware, config + 0x30, 4);
|
|
||||||
firmware[4] = '\0';
|
|
||||||
sr_dbg("found %s with firmware version %s serial %d",
|
|
||||||
profile->modelname, firmware, i);
|
|
||||||
|
|
||||||
if (profile->logformat == LOG_UNSUPPORTED) {
|
|
||||||
sr_dbg("unsupported EL-USB logformat for %s", profile->modelname);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
sdi = g_malloc0(sizeof(struct sr_dev_inst));
|
|
||||||
sdi->status = SR_ST_INACTIVE;
|
|
||||||
sdi->vendor = g_strdup("Lascar");
|
|
||||||
sdi->model = g_strdup(profile->modelname);
|
|
||||||
sdi->version = g_strdup(firmware);
|
|
||||||
|
|
||||||
if (profile->logformat == LOG_TEMP_RH) {
|
|
||||||
/* Model this as two channels: temperature and humidity. */
|
|
||||||
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "Temp");
|
|
||||||
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "Hum");
|
|
||||||
} else if (profile->logformat == LOG_CO) {
|
|
||||||
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CO");
|
|
||||||
} else {
|
|
||||||
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
|
|
||||||
}
|
|
||||||
|
|
||||||
devc = g_malloc0(sizeof(struct dev_context));
|
|
||||||
sdi->priv = devc;
|
|
||||||
devc->profile = profile;
|
|
||||||
}
|
}
|
||||||
|
if (!profile) {
|
||||||
|
sr_dbg("unknown EL-USB modelid %d", modelid);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = config[52] | (config[53] << 8);
|
||||||
|
memcpy(firmware, config + 0x30, 4);
|
||||||
|
firmware[4] = '\0';
|
||||||
|
sr_dbg("found %s with firmware version %s serial %d",
|
||||||
|
profile->modelname, firmware, i);
|
||||||
|
|
||||||
|
if (profile->logformat == LOG_UNSUPPORTED) {
|
||||||
|
sr_dbg("unsupported EL-USB logformat for %s", profile->modelname);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
sdi = g_malloc0(sizeof(struct sr_dev_inst));
|
||||||
|
sdi->status = SR_ST_INACTIVE;
|
||||||
|
sdi->vendor = g_strdup("Lascar");
|
||||||
|
sdi->model = g_strdup(profile->modelname);
|
||||||
|
sdi->version = g_strdup(firmware);
|
||||||
|
|
||||||
|
if (profile->logformat == LOG_TEMP_RH) {
|
||||||
|
/* Model this as two channels: temperature and humidity. */
|
||||||
|
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "Temp");
|
||||||
|
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "Hum");
|
||||||
|
} else if (profile->logformat == LOG_CO) {
|
||||||
|
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CO");
|
||||||
|
} else {
|
||||||
|
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
|
||||||
|
}
|
||||||
|
|
||||||
|
devc = g_malloc0(sizeof(struct dev_context));
|
||||||
|
sdi->priv = devc;
|
||||||
|
devc->profile = profile;
|
||||||
|
|
||||||
return sdi;
|
return sdi;
|
||||||
}
|
}
|
||||||
|
|
|
@ -913,46 +913,50 @@ SR_PRIV void LIBUSB_CALL logic16_receive_transfer(struct libusb_transfer *transf
|
||||||
new_samples = convert_sample_data(devc, devc->convbuffer,
|
new_samples = convert_sample_data(devc, devc->convbuffer,
|
||||||
devc->convbuffer_size, transfer->buffer, transfer->actual_length);
|
devc->convbuffer_size, transfer->buffer, transfer->actual_length);
|
||||||
|
|
||||||
if (new_samples > 0) {
|
if (new_samples <= 0) {
|
||||||
if (devc->trigger_fired) {
|
resubmit_transfer(transfer);
|
||||||
/* Send the incoming transfer to the session bus. */
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* At least one new sample. */
|
||||||
|
if (devc->trigger_fired) {
|
||||||
|
/* Send the incoming transfer to the session bus. */
|
||||||
|
packet.type = SR_DF_LOGIC;
|
||||||
|
packet.payload = &logic;
|
||||||
|
if (devc->limit_samples &&
|
||||||
|
new_samples > devc->limit_samples - devc->sent_samples)
|
||||||
|
new_samples = devc->limit_samples - devc->sent_samples;
|
||||||
|
logic.length = new_samples * 2;
|
||||||
|
logic.unitsize = 2;
|
||||||
|
logic.data = devc->convbuffer;
|
||||||
|
sr_session_send(sdi, &packet);
|
||||||
|
devc->sent_samples += new_samples;
|
||||||
|
} else {
|
||||||
|
trigger_offset = soft_trigger_logic_check(devc->stl,
|
||||||
|
devc->convbuffer, new_samples * 2, &pre_trigger_samples);
|
||||||
|
if (trigger_offset > -1) {
|
||||||
|
devc->sent_samples += pre_trigger_samples;
|
||||||
packet.type = SR_DF_LOGIC;
|
packet.type = SR_DF_LOGIC;
|
||||||
packet.payload = &logic;
|
packet.payload = &logic;
|
||||||
|
num_samples = new_samples - trigger_offset;
|
||||||
if (devc->limit_samples &&
|
if (devc->limit_samples &&
|
||||||
new_samples > devc->limit_samples - devc->sent_samples)
|
num_samples > devc->limit_samples - devc->sent_samples)
|
||||||
new_samples = devc->limit_samples - devc->sent_samples;
|
num_samples = devc->limit_samples - devc->sent_samples;
|
||||||
logic.length = new_samples * 2;
|
logic.length = num_samples * 2;
|
||||||
logic.unitsize = 2;
|
logic.unitsize = 2;
|
||||||
logic.data = devc->convbuffer;
|
logic.data = devc->convbuffer + trigger_offset * 2;
|
||||||
sr_session_send(sdi, &packet);
|
sr_session_send(sdi, &packet);
|
||||||
devc->sent_samples += new_samples;
|
devc->sent_samples += num_samples;
|
||||||
} else {
|
|
||||||
trigger_offset = soft_trigger_logic_check(devc->stl,
|
|
||||||
devc->convbuffer, new_samples * 2, &pre_trigger_samples);
|
|
||||||
if (trigger_offset > -1) {
|
|
||||||
devc->sent_samples += pre_trigger_samples;
|
|
||||||
packet.type = SR_DF_LOGIC;
|
|
||||||
packet.payload = &logic;
|
|
||||||
num_samples = new_samples - trigger_offset;
|
|
||||||
if (devc->limit_samples &&
|
|
||||||
num_samples > devc->limit_samples - devc->sent_samples)
|
|
||||||
num_samples = devc->limit_samples - devc->sent_samples;
|
|
||||||
logic.length = num_samples * 2;
|
|
||||||
logic.unitsize = 2;
|
|
||||||
logic.data = devc->convbuffer + trigger_offset * 2;
|
|
||||||
sr_session_send(sdi, &packet);
|
|
||||||
devc->sent_samples += num_samples;
|
|
||||||
|
|
||||||
devc->trigger_fired = TRUE;
|
devc->trigger_fired = TRUE;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (devc->limit_samples &&
|
if (devc->limit_samples &&
|
||||||
(uint64_t)devc->sent_samples >= devc->limit_samples) {
|
(uint64_t)devc->sent_samples >= devc->limit_samples) {
|
||||||
devc->sent_samples = -2;
|
devc->sent_samples = -2;
|
||||||
free_transfer(transfer);
|
free_transfer(transfer);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resubmit_transfer(transfer);
|
resubmit_transfer(transfer);
|
||||||
|
|
|
@ -211,22 +211,18 @@ static int config_get(uint32_t key, GVariant **data,
|
||||||
ret = SR_OK;
|
ret = SR_OK;
|
||||||
break;
|
break;
|
||||||
case SR_CONF_NUM_VDIV:
|
case SR_CONF_NUM_VDIV:
|
||||||
if (!cg) {
|
if (!cg)
|
||||||
return SR_ERR_CHANNEL_GROUP;
|
return SR_ERR_CHANNEL_GROUP;
|
||||||
} else if (cg_type == CG_ANALOG) {
|
if (cg_type != CG_ANALOG)
|
||||||
*data = g_variant_new_int32(model->num_ydivs);
|
return SR_ERR_NA;
|
||||||
ret = SR_OK;
|
*data = g_variant_new_int32(model->num_ydivs);
|
||||||
break;
|
ret = SR_OK;
|
||||||
} else {
|
|
||||||
ret = SR_ERR_NA;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case SR_CONF_VDIV:
|
case SR_CONF_VDIV:
|
||||||
ret = SR_ERR_NA;
|
if (!cg)
|
||||||
if (!cg) {
|
|
||||||
return SR_ERR_CHANNEL_GROUP;
|
return SR_ERR_CHANNEL_GROUP;
|
||||||
} else if (cg_type != CG_ANALOG)
|
if (cg_type != CG_ANALOG)
|
||||||
break;
|
return SR_ERR_NA;
|
||||||
if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
|
if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
*data = g_variant_new("(tt)",
|
*data = g_variant_new("(tt)",
|
||||||
|
@ -247,11 +243,10 @@ static int config_get(uint32_t key, GVariant **data,
|
||||||
ret = SR_OK;
|
ret = SR_OK;
|
||||||
break;
|
break;
|
||||||
case SR_CONF_COUPLING:
|
case SR_CONF_COUPLING:
|
||||||
ret = SR_ERR_NA;
|
if (!cg)
|
||||||
if (!cg) {
|
|
||||||
return SR_ERR_CHANNEL_GROUP;
|
return SR_ERR_CHANNEL_GROUP;
|
||||||
} else if (cg_type != CG_ANALOG)
|
if (cg_type != CG_ANALOG)
|
||||||
break;
|
return SR_ERR_NA;
|
||||||
if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
|
if ((idx = std_cg_idx(cg, devc->analog_groups, model->analog_channels)) < 0)
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
*data = g_variant_new_string((*model->coupling_options)[state->analog_states[idx].coupling]);
|
*data = g_variant_new_string((*model->coupling_options)[state->analog_states[idx].coupling]);
|
||||||
|
|
Loading…
Reference in New Issue