]>
Commit | Line | Data |
---|---|---|
ca1a7cb5 BV |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2014 Bert Vermeulen <bert@biot.com> | |
5 | * | |
6 | * This program is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
6ec6c43b | 20 | #include <config.h> |
9e45cd41 | 21 | #include <string.h> |
ba464a12 | 22 | #include <strings.h> |
9e45cd41 | 23 | #include <stdarg.h> |
91ef511d | 24 | #include "scpi.h" |
ca1a7cb5 BV |
25 | #include "protocol.h" |
26 | ||
27 | SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data) | |
28 | { | |
ca1a7cb5 | 29 | struct dev_context *devc; |
9e45cd41 | 30 | struct sr_datafeed_packet packet; |
0de290a5 UH |
31 | struct sr_datafeed_analog analog; |
32 | struct sr_analog_encoding encoding; | |
33 | struct sr_analog_meaning meaning; | |
34 | struct sr_analog_spec spec; | |
8cd15dd4 UH |
35 | struct sr_dev_inst *sdi; |
36 | int channel_group_cmd; | |
37 | const char *channel_group_name; | |
01b0257a | 38 | struct pps_channel *pch; |
6ed709fe | 39 | const struct channel_spec *ch_spec; |
8cd15dd4 | 40 | int ret; |
9e45cd41 | 41 | float f; |
8cd15dd4 UH |
42 | GVariant *gvdata; |
43 | const GVariantType *gvtype; | |
01b0257a | 44 | int cmd; |
ca1a7cb5 BV |
45 | |
46 | (void)fd; | |
9e45cd41 | 47 | (void)revents; |
ca1a7cb5 BV |
48 | |
49 | if (!(sdi = cb_data)) | |
50 | return TRUE; | |
51 | ||
52 | if (!(devc = sdi->priv)) | |
53 | return TRUE; | |
54 | ||
8cd15dd4 | 55 | pch = devc->cur_acquisition_channel->priv; |
9e45cd41 | 56 | |
8cd15dd4 UH |
57 | channel_group_cmd = 0; |
58 | channel_group_name = NULL; | |
59 | if (g_slist_length(sdi->channel_groups) > 1) { | |
60 | channel_group_cmd = SCPI_CMD_SELECT_CHANNEL; | |
61 | channel_group_name = pch->hwname; | |
60475cd7 | 62 | } |
01b0257a | 63 | |
8cd15dd4 UH |
64 | if (pch->mq == SR_MQ_VOLTAGE) { |
65 | gvtype = G_VARIANT_TYPE_DOUBLE; | |
01b0257a | 66 | cmd = SCPI_CMD_GET_MEAS_VOLTAGE; |
8cd15dd4 UH |
67 | } else if (pch->mq == SR_MQ_FREQUENCY) { |
68 | gvtype = G_VARIANT_TYPE_DOUBLE; | |
4264f1c0 | 69 | cmd = SCPI_CMD_GET_MEAS_FREQUENCY; |
8cd15dd4 UH |
70 | } else if (pch->mq == SR_MQ_CURRENT) { |
71 | gvtype = G_VARIANT_TYPE_DOUBLE; | |
01b0257a | 72 | cmd = SCPI_CMD_GET_MEAS_CURRENT; |
8cd15dd4 UH |
73 | } else if (pch->mq == SR_MQ_POWER) { |
74 | gvtype = G_VARIANT_TYPE_DOUBLE; | |
01b0257a | 75 | cmd = SCPI_CMD_GET_MEAS_POWER; |
8cd15dd4 | 76 | } else { |
01b0257a | 77 | return SR_ERR; |
8cd15dd4 UH |
78 | } |
79 | ||
80 | ret = sr_scpi_cmd_resp(sdi, devc->device->commands, | |
81 | channel_group_cmd, channel_group_name, &gvdata, gvtype, cmd); | |
82 | ||
83 | if (ret != SR_OK) | |
84 | return ret; | |
85 | ||
86 | ch_spec = &devc->device->channels[pch->hw_output_idx]; | |
87 | packet.type = SR_DF_ANALOG; | |
88 | packet.payload = &analog; | |
89 | /* Note: digits/spec_digits will be overridden later. */ | |
90 | sr_analog_init(&analog, &encoding, &meaning, &spec, 0); | |
91 | analog.meaning->channels = g_slist_append(NULL, devc->cur_acquisition_channel); | |
92 | analog.num_samples = 1; | |
93 | analog.meaning->mq = pch->mq; | |
94 | if (pch->mq == SR_MQ_VOLTAGE) { | |
95 | analog.meaning->unit = SR_UNIT_VOLT; | |
96 | analog.encoding->digits = ch_spec->voltage[4]; | |
97 | analog.spec->spec_digits = ch_spec->voltage[3]; | |
98 | } else if (pch->mq == SR_MQ_CURRENT) { | |
99 | analog.meaning->unit = SR_UNIT_AMPERE; | |
100 | analog.encoding->digits = ch_spec->current[4]; | |
101 | analog.spec->spec_digits = ch_spec->current[3]; | |
102 | } else if (pch->mq == SR_MQ_POWER) { | |
103 | analog.meaning->unit = SR_UNIT_WATT; | |
104 | analog.encoding->digits = ch_spec->power[4]; | |
105 | analog.spec->spec_digits = ch_spec->power[3]; | |
106 | } | |
107 | analog.meaning->mqflags = SR_MQFLAG_DC; | |
108 | f = (float)g_variant_get_double(gvdata); | |
109 | g_variant_unref(gvdata); | |
110 | analog.data = &f; | |
111 | sr_session_send(sdi, &packet); | |
112 | g_slist_free(analog.meaning->channels); | |
113 | ||
114 | /* Next channel. */ | |
115 | if (g_slist_length(sdi->channels) > 1) { | |
116 | devc->cur_acquisition_channel = | |
117 | sr_next_enabled_channel(sdi, devc->cur_acquisition_channel); | |
118 | } | |
119 | ||
120 | if (devc->cur_acquisition_channel == sr_next_enabled_channel(sdi, NULL)) | |
121 | /* First enabled channel, so each channel has been sampled */ | |
122 | sr_sw_limits_update_samples_read(&devc->limits, 1); | |
123 | ||
124 | /* Stop if limits have been hit. */ | |
125 | if (sr_sw_limits_check(&devc->limits)) | |
126 | sr_dev_acquisition_stop(sdi); | |
ca1a7cb5 BV |
127 | |
128 | return TRUE; | |
129 | } |