X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fgwinstek-gds-800%2Fprotocol.c;h=604ec54f9d0a881465f0da3b63c64cf54dec8cf0;hb=176d785d33a28a1bb24f2ee483595ec54f7b52b6;hp=77058577e44d8584805f623dca855354617f1b38;hpb=695dc859c15ba4190f5c1aa2e1a6e2dc6a6e5845;p=libsigrok.git diff --git a/src/hardware/gwinstek-gds-800/protocol.c b/src/hardware/gwinstek-gds-800/protocol.c index 77058577..604ec54f 100644 --- a/src/hardware/gwinstek-gds-800/protocol.c +++ b/src/hardware/gwinstek-gds-800/protocol.c @@ -18,6 +18,7 @@ */ #include "protocol.h" +#include #include #define ANALOG_CHANNELS 2 @@ -66,7 +67,10 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data) struct sr_scpi_dev_inst *scpi; struct dev_context *devc; struct sr_datafeed_packet packet; - struct sr_datafeed_analog_old analog; + struct sr_datafeed_analog analog; + struct sr_analog_encoding encoding; + struct sr_analog_meaning meaning; + struct sr_analog_spec spec; char command[32]; char *response; float volts_per_division; @@ -131,7 +135,7 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data) if (devc->cur_acq_frame == devc->frame_limit - 1) { /* All frames accquired. */ sr_spew("All frames acquired."); - + sdi->driver->dev_acquisition_stop(sdi); return TRUE; } else { @@ -139,7 +143,7 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data) 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); } @@ -196,7 +200,7 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data) devc->state = WAIT_FOR_TRANSFER_OF_CHANNEL_INDICATOR_COMPLETE; if (!devc->df_started) { - std_session_send_df_header(sdi, LOG_PREFIX); + std_session_send_df_header(sdi); packet.type = SR_DF_FRAME_BEGIN; sr_session_send(sdi, &packet); @@ -232,21 +236,26 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data) 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])))) / 256. * VERTICAL_DIVISIONS * volts_per_division; + samples[i] = ((float) ((int16_t) (RB16(&devc->rcv_buffer[i*2])))) * vbit; /* Fill frame. */ - analog.channels = g_slist_append(NULL, g_slist_nth_data(sdi->channels, devc->cur_acq_channel)); + 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.mq = SR_MQ_VOLTAGE; - analog.unit = SR_UNIT_VOLT; - analog.mqflags = 0; - packet.type = SR_DF_ANALOG_OLD; + 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.channels); + g_slist_free(analog.meaning->channels); /* All channels acquired. */ if (devc->cur_acq_channel == ANALOG_CHANNELS - 1) { @@ -262,7 +271,7 @@ SR_PRIV int gwinstek_gds_800_receive_data(int fd, int revents, void *cb_data) 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); }