]>
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; | |
9e45cd41 | 35 | const struct sr_dev_inst *sdi; |
17a82e83 FS |
36 | int channel_group_cmd; |
37 | char *channel_group_name; | |
01b0257a | 38 | struct pps_channel *pch; |
6ed709fe | 39 | const struct channel_spec *ch_spec; |
fa2ce8c7 FS |
40 | int ret; |
41 | float f; | |
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 | ||
17a82e83 FS |
55 | channel_group_cmd = 0; |
56 | channel_group_name = NULL; | |
57 | if (g_slist_length(sdi->channel_groups) > 1) { | |
58 | channel_group_cmd = SCPI_CMD_SELECT_CHANNEL; | |
59 | channel_group_name = g_strdup(devc->cur_acquisition_channel->name); | |
60 | } | |
61 | ||
62 | pch = devc->cur_acquisition_channel->priv; | |
fa2ce8c7 FS |
63 | if (pch->mq == SR_MQ_VOLTAGE) { |
64 | gvtype = G_VARIANT_TYPE_DOUBLE; | |
65 | cmd = SCPI_CMD_GET_MEAS_VOLTAGE; | |
66 | } else if (pch->mq == SR_MQ_FREQUENCY) { | |
67 | gvtype = G_VARIANT_TYPE_DOUBLE; | |
68 | cmd = SCPI_CMD_GET_MEAS_FREQUENCY; | |
69 | } else if (pch->mq == SR_MQ_CURRENT) { | |
70 | gvtype = G_VARIANT_TYPE_DOUBLE; | |
71 | cmd = SCPI_CMD_GET_MEAS_CURRENT; | |
72 | } else if (pch->mq == SR_MQ_POWER) { | |
73 | gvtype = G_VARIANT_TYPE_DOUBLE; | |
74 | cmd = SCPI_CMD_GET_MEAS_POWER; | |
75 | } else { | |
76 | return SR_ERR; | |
9e45cd41 BV |
77 | } |
78 | ||
17a82e83 FS |
79 | ret = sr_scpi_cmd_resp(sdi, devc->device->commands, |
80 | channel_group_cmd, channel_group_name, &gvdata, gvtype, cmd); | |
81 | g_free(channel_group_name); | |
82 | ||
fa2ce8c7 FS |
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); | |
17a82e83 | 91 | analog.meaning->channels = g_slist_append(NULL, devc->cur_acquisition_channel); |
fa2ce8c7 FS |
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 | analog.data = &f; | |
110 | sr_session_send(sdi, &packet); | |
111 | g_slist_free(analog.meaning->channels); | |
112 | ||
17a82e83 | 113 | /* Next channel. */ |
60475cd7 | 114 | if (g_slist_length(sdi->channels) > 1) { |
17a82e83 FS |
115 | devc->cur_acquisition_channel = |
116 | sr_next_enabled_channel(sdi, devc->cur_acquisition_channel); | |
60475cd7 | 117 | } |
01b0257a | 118 | |
ca1a7cb5 BV |
119 | return TRUE; |
120 | } |