X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fscpi-pps%2Fprotocol.c;h=5afaa5e9743d20fc87f108a6d6eee25d28fc9ccf;hb=dd7a72ea697a172032f5473b0ddff5e8d47222f4;hp=fcf3f21b6cbf1ae5ca5837b6105de3633f5a5094;hpb=9c24d16a1d01a01f88f254fbd5f5e413e796f3cf;p=libsigrok.git diff --git a/src/hardware/scpi-pps/protocol.c b/src/hardware/scpi-pps/protocol.c index fcf3f21b..5afaa5e9 100644 --- a/src/hardware/scpi-pps/protocol.c +++ b/src/hardware/scpi-pps/protocol.c @@ -17,6 +17,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -58,11 +59,15 @@ SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data) struct dev_context *devc; struct sr_datafeed_packet packet; struct sr_datafeed_analog analog; + struct sr_analog_encoding encoding; + struct sr_analog_meaning meaning; + struct sr_analog_spec spec; const struct sr_dev_inst *sdi; struct sr_channel *next_channel; struct sr_scpi_dev_inst *scpi; struct pps_channel *pch; - float f; + const struct channel_spec *ch_spec; + double d; int cmd; (void)fd; @@ -77,23 +82,33 @@ SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data) scpi = sdi->conn; /* Retrieve requested value for this state. */ - if (sr_scpi_get_float(scpi, NULL, &f) == SR_OK) { + if (sr_scpi_get_double(scpi, NULL, &d) == SR_OK) { pch = devc->cur_channel->priv; + ch_spec = &devc->device->channels[pch->hw_output_idx]; packet.type = SR_DF_ANALOG; packet.payload = &analog; - analog.channels = g_slist_append(NULL, devc->cur_channel); + /* Note: digits/spec_digits will be overridden later. */ + sr_analog_init(&analog, &encoding, &meaning, &spec, 0); + analog.meaning->channels = g_slist_append(NULL, devc->cur_channel); analog.num_samples = 1; - analog.mq = pch->mq; - if (pch->mq == SR_MQ_VOLTAGE) - analog.unit = SR_UNIT_VOLT; - else if (pch->mq == SR_MQ_CURRENT) - analog.unit = SR_UNIT_AMPERE; - else if (pch->mq == SR_MQ_POWER) - analog.unit = SR_UNIT_WATT; - analog.mqflags = SR_MQFLAG_DC; - analog.data = &f; + analog.meaning->mq = pch->mq; + if (pch->mq == SR_MQ_VOLTAGE) { + analog.meaning->unit = SR_UNIT_VOLT; + analog.encoding->digits = ch_spec->voltage[4]; + analog.spec->spec_digits = ch_spec->voltage[3]; + } else if (pch->mq == SR_MQ_CURRENT) { + analog.meaning->unit = SR_UNIT_AMPERE; + analog.encoding->digits = ch_spec->current[4]; + analog.spec->spec_digits = ch_spec->current[3]; + } else if (pch->mq == SR_MQ_POWER) { + analog.meaning->unit = SR_UNIT_WATT; + analog.encoding->digits = ch_spec->power[4]; + analog.spec->spec_digits = ch_spec->power[3]; + } + analog.meaning->mqflags = SR_MQFLAG_DC; + analog.data = &d; sr_session_send(sdi, &packet); - g_slist_free(analog.channels); + g_slist_free(analog.meaning->channels); } if (g_slist_length(sdi->channels) > 1) {