]> sigrok.org Git - libsigrok.git/blob - src/hardware/scpi-pps/profiles.c
scpi-pps: Add profile for Agilent N5763A 12.5V 120A supply
[libsigrok.git] / src / hardware / scpi-pps / profiles.c
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2014 Bert Vermeulen <bert@biot.com>
5  * Copyright (C) 2015 Google, Inc.
6  * (Written by Alexandru Gagniuc <mrnuke@google.com> for Google, Inc.)
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 #include <config.h>
23 #include <string.h>
24 #include <strings.h>
25 #include "protocol.h"
26
27 #define CH_IDX(x) (1 << x)
28 #define FREQ_DC_ONLY {0, 0, 0}
29
30 static const uint32_t devopts_none[] = { };
31
32 /* Agilent/Keysight N5700A series */
33 static const uint32_t agilent_n5700a_devopts[] = {
34         SR_CONF_CONTINUOUS | SR_CONF_SET,
35 };
36
37 static const uint32_t agilent_n5700a_devopts_cg[] = {
38         SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
39         SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
40         SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
41         SR_CONF_VOLTAGE | SR_CONF_GET,
42         SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
43         SR_CONF_CURRENT | SR_CONF_GET,
44         SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
45 };
46
47 static const struct channel_group_spec agilent_n5700a_cg[] = {
48         { "1", CH_IDX(0), PPS_OVP | PPS_OCP },
49 };
50
51 static const struct channel_spec agilent_n5767a_ch[] = {
52         { "1", { 0, 60, 0.0001 }, { 0, 25, 0.1 }, FREQ_DC_ONLY },
53 };
54
55 static const struct channel_spec agilent_n5763a_ch[] = {
56         { "1", { 0, 12.5, 0.001 }, { 0, 25, 0.01 }, FREQ_DC_ONLY },
57 };
58
59 /*
60  * TODO: OVER_CURRENT_PROTECTION_ACTIVE status can be determined by the OC bit
61  * in STAT:QUES:EVEN?, but this is not implemented.
62  */
63 static const struct scpi_command agilent_n5700a_cmd[] = {
64         { SCPI_CMD_REMOTE, "SYST:COMM:RLST REM" },
65         { SCPI_CMD_LOCAL, "SYST:COMM:RLST LOC" },
66         { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
67         { SCPI_CMD_GET_MEAS_CURRENT, "MEAS:CURR?" },
68         { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
69         { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" },
70         { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
71         { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
72         { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP:STAT?" },
73         { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" },
74         { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" },
75         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":VOLT:PROT?" },
76         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":VOLT:PROT %.6f" },
77         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, ":CURR:PROT:STAT?" },
78         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, ":CURR:PROT:STAT ON?"},
79         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, ":CURR:PROT:STAT OFF?"},
80         /* Current limit (CC mode) and OCP are set using the same command. */
81         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR?" },
82         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR %.6f" },
83         ALL_ZERO
84 };
85
86 /* Chroma 61600 series AC source */
87 static const uint32_t chroma_61604_devopts[] = {
88         SR_CONF_CONTINUOUS | SR_CONF_SET,
89 };
90
91 static const uint32_t chroma_61604_devopts_cg[] = {
92         SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
93         SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
94         SR_CONF_VOLTAGE | SR_CONF_GET,
95         SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
96         SR_CONF_OUTPUT_FREQUENCY | SR_CONF_GET,
97         SR_CONF_OUTPUT_FREQUENCY_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
98         SR_CONF_CURRENT | SR_CONF_GET,
99         SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
100 };
101
102 static const struct channel_spec chroma_61604_ch[] = {
103         { "1", { 0, 300, 0.1 }, { 0, 16, 0.1 }, { 1.0, 1000.0, 0.01 } },
104 };
105
106 static const struct channel_group_spec chroma_61604_cg[] = {
107         { "1", CH_IDX(0), PPS_OVP | PPS_OCP },
108 };
109
110 static const struct scpi_command chroma_61604_cmd[] = {
111         { SCPI_CMD_REMOTE, "SYST:REM" },
112         { SCPI_CMD_LOCAL, "SYST:LOC" },
113         { SCPI_CMD_GET_MEAS_VOLTAGE, ":FETC:VOLT:ACDC?" },
114         { SCPI_CMD_GET_MEAS_FREQUENCY, ":FETC:FREQ?" },
115         { SCPI_CMD_GET_MEAS_CURRENT, ":FETC:CURR:AC?" },
116         { SCPI_CMD_GET_MEAS_POWER, ":FETC:POW:AC?" },
117         { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT:AC?" },
118         { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT:AC %.1f" },
119         { SCPI_CMD_GET_FREQUENCY_TARGET, ":SOUR:FREQ?" },
120         { SCPI_CMD_SET_FREQUENCY_TARGET, ":SOUR:FREQ %.2f" },
121         { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP?" },
122         { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" },
123         { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" },
124         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:LIM:AC?" },
125         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:LIM:AC %.1f" },
126         /* This is not a current limit mode. It is overcurrent protection. */
127         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR:LIM?" },
128         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR:LIM %.2f" },
129         ALL_ZERO
130 };
131
132 /* Chroma 62000 series DC source */
133
134 static const uint32_t chroma_62000_devopts[] = {
135         SR_CONF_CONTINUOUS | SR_CONF_SET,
136 };
137
138 static const uint32_t chroma_62000_devopts_cg[] = {
139         SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
140         SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
141         SR_CONF_VOLTAGE | SR_CONF_GET,
142         SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
143         SR_CONF_CURRENT | SR_CONF_GET,
144         SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
145         SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
146 };
147
148 static const struct channel_group_spec chroma_62000_cg[] = {
149         { "1", CH_IDX(0), PPS_OVP | PPS_OCP },
150 };
151
152 static const struct scpi_command chroma_62000_cmd[] = {
153         { SCPI_CMD_REMOTE, ":CONF:REM ON" },
154         { SCPI_CMD_LOCAL, ":CONF:REM OFF" },
155         { SCPI_CMD_BEEPER, ":CONF:BEEP?" },
156         { SCPI_CMD_BEEPER_ENABLE, ":CONF:BEEP ON" },
157         { SCPI_CMD_BEEPER_DISABLE, ":CONF:BEEP OFF" },
158         { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
159         { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" },
160         { SCPI_CMD_GET_MEAS_POWER, ":MEAS:POW?" },
161         { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
162         { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.2f" },
163         { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
164         { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
165         { SCPI_CMD_GET_OUTPUT_ENABLED, ":CONF:OUTP?" },
166         { SCPI_CMD_SET_OUTPUT_ENABLE, ":CONF:OUTP ON" },
167         { SCPI_CMD_SET_OUTPUT_DISABLE, ":CONF:OUTP OFF" },
168         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT:HIGH?" },
169         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT:HIGH %.6f" },
170         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR:PROT:HIGH?" },
171         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, ":SOUR:CURR:PROT:HIGH %.6f" },
172         ALL_ZERO
173 };
174
175 static int chroma_62000p_probe_channels(struct sr_dev_inst *sdi,
176                 struct sr_scpi_hw_info *hw_info,
177                 struct channel_spec **channels, unsigned int *num_channels,
178                 struct channel_group_spec **channel_groups,
179                 unsigned int *num_channel_groups)
180 {
181         unsigned int volts, amps;
182         struct channel_spec *channel;
183
184         (void)sdi;
185
186         sscanf(hw_info->model, "%*[^P]P-%u-%u", &volts, &amps);
187         sr_dbg("Found device rated for %d V and %d A", volts, amps);
188
189         if (volts > 600) {
190                 sr_err("Probed max voltage of %u V is out of spec.", volts);
191                 return SR_ERR_BUG;
192         }
193
194         if (volts > 120) {
195                 sr_err("Probed max current of %u A is out of spec.", amps);
196                 return SR_ERR_BUG;
197         }
198
199         channel = g_malloc0(sizeof(struct channel_spec));
200         channel->name = "1";
201         channel->voltage[0] = channel->current[0] = 0.0;
202         channel->voltage[1] = (float)volts;
203         channel->current[1] = (float)amps;
204         channel->voltage[2] = channel->current[2] = 0.01;
205         *channels = channel;
206         *num_channels = 1;
207
208         *channel_groups = g_malloc(sizeof(struct channel_group_spec));
209         **channel_groups = chroma_62000_cg[0];
210         *num_channel_groups = 1;
211
212         return SR_OK;
213 }
214
215 /* Rigol DP800 series */
216 static const uint32_t rigol_dp800_devopts[] = {
217         SR_CONF_CONTINUOUS | SR_CONF_SET,
218         SR_CONF_OVER_TEMPERATURE_PROTECTION | SR_CONF_GET | SR_CONF_SET,
219 };
220
221 static const uint32_t rigol_dp800_devopts_cg[] = {
222         SR_CONF_REGULATION | SR_CONF_GET,
223         SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
224         SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE | SR_CONF_GET,
225         SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
226         SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
227         SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE | SR_CONF_GET,
228         SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
229         SR_CONF_VOLTAGE | SR_CONF_GET,
230         SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
231         SR_CONF_CURRENT | SR_CONF_GET,
232         SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
233         SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
234 };
235
236 static const struct channel_spec rigol_dp821a_ch[] = {
237         { "1", { 0, 60, 0.001 }, { 0, 1, 0.0001 }, FREQ_DC_ONLY },
238         { "2", { 0, 8, 0.001 }, { 0, 10, 0.001 }, FREQ_DC_ONLY },
239 };
240
241 static const struct channel_spec rigol_dp831_ch[] = {
242         { "1", { 0, 8, 0.001 }, { 0, 5, 0.0003 }, FREQ_DC_ONLY },
243         { "2", { 0, 30, 0.001 }, { 0, 2, 0.0001 }, FREQ_DC_ONLY },
244         { "3", { 0, -30, 0.001 }, { 0, 2, 0.0001 }, FREQ_DC_ONLY },
245 };
246
247 static const struct channel_spec rigol_dp832_ch[] = {
248         { "1", { 0, 30, 0.001 }, { 0, 3, 0.001 }, FREQ_DC_ONLY },
249         { "2", { 0, 30, 0.001 }, { 0, 3, 0.001 }, FREQ_DC_ONLY },
250         { "3", { 0, 5, 0.001 }, { 0, 3, 0.001 }, FREQ_DC_ONLY },
251 };
252
253 static const struct channel_group_spec rigol_dp820_cg[] = {
254         { "1", CH_IDX(0), PPS_OVP | PPS_OCP },
255         { "2", CH_IDX(1), PPS_OVP | PPS_OCP },
256 };
257
258 static const struct channel_group_spec rigol_dp830_cg[] = {
259         { "1", CH_IDX(0), PPS_OVP | PPS_OCP },
260         { "2", CH_IDX(1), PPS_OVP | PPS_OCP },
261         { "3", CH_IDX(2), PPS_OVP | PPS_OCP },
262 };
263
264 static const struct scpi_command rigol_dp800_cmd[] = {
265         { SCPI_CMD_REMOTE, "SYST:REMOTE" },
266         { SCPI_CMD_LOCAL, "SYST:LOCAL" },
267         { SCPI_CMD_BEEPER, "SYST:BEEP:STAT?" },
268         { SCPI_CMD_BEEPER_ENABLE, "SYST:BEEP:STAT ON" },
269         { SCPI_CMD_BEEPER_DISABLE, "SYST:BEEP:STAT OFF" },
270         { SCPI_CMD_SELECT_CHANNEL, ":INST:NSEL %s" },
271         { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
272         { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" },
273         { SCPI_CMD_GET_MEAS_POWER, ":MEAS:POWE?" },
274         { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
275         { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" },
276         { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
277         { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
278         { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP?" },
279         { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" },
280         { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" },
281         { SCPI_CMD_GET_OUTPUT_REGULATION, ":OUTP:MODE?" },
282         { SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION, ":SYST:OTP?" },
283         { SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE, ":SYST:OTP ON" },
284         { SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE, ":SYST:OTP OFF" },
285         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED, ":OUTP:OVP?" },
286         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE, ":OUTP:OVP ON" },
287         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE, ":OUTP:OVP OFF" },
288         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE, ":OUTP:OVP:QUES?" },
289         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":OUTP:OVP:VAL?" },
290         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":OUTP:OVP:VAL %.6f" },
291         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, ":OUTP:OCP?" },
292         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, ":OUTP:OCP:STAT ON" },
293         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, ":OUTP:OCP:STAT OFF" },
294         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE, ":OUTP:OCP:QUES?" },
295         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, ":OUTP:OCP:VAL?" },
296         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, ":OUTP:OCP:VAL %.6f" },
297         ALL_ZERO
298 };
299
300 /* HP 663xx series */
301 static const uint32_t hp_6632b_devopts[] = {
302         SR_CONF_CONTINUOUS | SR_CONF_SET,
303         SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
304         SR_CONF_VOLTAGE | SR_CONF_GET,
305         SR_CONF_CURRENT | SR_CONF_GET,
306         SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
307         SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
308 };
309
310 static const struct channel_spec hp_6632b_ch[] = {
311         { "1", { 0, 20.475, 0.005 }, { 0, 5.1188, 0.00132 }, FREQ_DC_ONLY },
312 };
313
314 static const struct channel_group_spec hp_6632b_cg[] = {
315         { "1", CH_IDX(0), 0 },
316 };
317
318 static const struct scpi_command hp_6632b_cmd[] = {
319         { SCPI_CMD_GET_OUTPUT_ENABLED, "OUTP:STAT?" },
320         { SCPI_CMD_SET_OUTPUT_ENABLE, "OUTP:STAT ON" },
321         { SCPI_CMD_SET_OUTPUT_DISABLE, "OUTP:STAT OFF" },
322         { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
323         { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" },
324         { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
325         { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" },
326         { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
327         { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
328         ALL_ZERO
329 };
330
331 /* Philips/Fluke PM2800 series */
332 static const uint32_t philips_pm2800_devopts[] = {
333         SR_CONF_CONTINUOUS | SR_CONF_SET,
334 };
335
336 static const uint32_t philips_pm2800_devopts_cg[] = {
337         SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
338         SR_CONF_VOLTAGE | SR_CONF_GET,
339         SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
340         SR_CONF_CURRENT | SR_CONF_GET,
341         SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
342         SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE | SR_CONF_GET,
343         SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
344         SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
345         SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE | SR_CONF_GET,
346         SR_CONF_REGULATION | SR_CONF_GET,
347 };
348
349 enum philips_pm2800_modules {
350         PM2800_MOD_30V_10A = 1,
351         PM2800_MOD_60V_5A,
352         PM2800_MOD_60V_10A,
353         PM2800_MOD_8V_15A,
354         PM2800_MOD_60V_2A,
355         PM2800_MOD_120V_1A,
356 };
357
358 static const struct philips_pm2800_module_spec {
359         /* Min, max, programming resolution. */
360         float voltage[3];
361         float current[3];
362 } philips_pm2800_module_specs[] = {
363         /* Autoranging modules. */
364         [PM2800_MOD_30V_10A] = { { 0, 30, 0.0075 }, { 0, 10, 0.0025 } },
365         [PM2800_MOD_60V_5A] = { { 0, 60, 0.015 }, { 0, 5, 0.00125 } },
366         [PM2800_MOD_60V_10A] = { { 0, 60, 0.015 }, { 0, 10, 0.0025 } },
367         /* Linear modules. */
368         [PM2800_MOD_8V_15A] = { { 0, 8, 0.002 }, { -15, 15, 0.00375 } },
369         [PM2800_MOD_60V_2A] = { { 0, 60, 0.015 }, { -2, 2, 0.0005 } },
370         [PM2800_MOD_120V_1A] = { { 0, 120, 0.030 }, { -1, 1, 0.00025 } },
371 };
372
373 static const struct philips_pm2800_model {
374         unsigned int chassis;
375         unsigned int num_modules;
376         unsigned int set;
377         unsigned int modules[3];
378 } philips_pm2800_matrix[] = {
379         /* Autoranging chassis. */
380         { 1, 1, 0, { PM2800_MOD_30V_10A, 0, 0 } },
381         { 1, 1, 1, { PM2800_MOD_60V_5A, 0, 0 } },
382         { 1, 2, 0, { PM2800_MOD_30V_10A, PM2800_MOD_30V_10A, 0 } },
383         { 1, 2, 1, { PM2800_MOD_60V_5A, PM2800_MOD_60V_5A, 0 } },
384         { 1, 2, 2, { PM2800_MOD_30V_10A, PM2800_MOD_60V_5A, 0 } },
385         { 1, 2, 3, { PM2800_MOD_30V_10A, PM2800_MOD_60V_10A, 0 } },
386         { 1, 2, 4, { PM2800_MOD_60V_5A, PM2800_MOD_60V_10A, 0 } },
387         { 1, 3, 0, { PM2800_MOD_30V_10A, PM2800_MOD_30V_10A, PM2800_MOD_30V_10A } },
388         { 1, 3, 1, { PM2800_MOD_60V_5A, PM2800_MOD_60V_5A, PM2800_MOD_60V_5A } },
389         { 1, 3, 2, { PM2800_MOD_30V_10A, PM2800_MOD_30V_10A, PM2800_MOD_60V_5A } },
390         { 1, 3, 3, { PM2800_MOD_30V_10A, PM2800_MOD_60V_5A, PM2800_MOD_60V_5A } },
391         /* Linear chassis. */
392         { 3, 1, 0, { PM2800_MOD_60V_2A, 0, 0 } },
393         { 3, 1, 1, { PM2800_MOD_120V_1A, 0, 0 } },
394         { 3, 1, 2, { PM2800_MOD_8V_15A, 0, 0 } },
395         { 3, 2, 0, { PM2800_MOD_60V_2A, 0, 0 } },
396         { 3, 2, 1, { PM2800_MOD_120V_1A, 0, 0 } },
397         { 3, 2, 2, { PM2800_MOD_60V_2A, PM2800_MOD_120V_1A, 0 } },
398         { 3, 2, 3, { PM2800_MOD_8V_15A, PM2800_MOD_8V_15A, 0 } },
399 };
400
401 static const char *philips_pm2800_names[] = { "1", "2", "3" };
402
403 static int philips_pm2800_probe_channels(struct sr_dev_inst *sdi,
404                 struct sr_scpi_hw_info *hw_info,
405                 struct channel_spec **channels, unsigned int *num_channels,
406                 struct channel_group_spec **channel_groups, unsigned int *num_channel_groups)
407 {
408         const struct philips_pm2800_model *model;
409         const struct philips_pm2800_module_spec *spec;
410         unsigned int chassis, num_modules, set, module, m, i;
411
412         (void)sdi;
413
414         /*
415          * The model number as reported by *IDN? looks like e.g. PM2813/11,
416          * Where "PM28" is fixed, followed by the chassis code (1 = autoranging,
417          * 3 = linear series) and the number of modules: 1-3 for autoranging,
418          * 1-2 for linear.
419          * After the slash, the first digit denotes the module set. The
420          * digit after that denotes front (5) or rear (1) binding posts.
421          */
422         chassis = hw_info->model[4] - 0x30;
423         num_modules = hw_info->model[5] - 0x30;
424         set = hw_info->model[7] - 0x30;
425         for (m = 0; m < ARRAY_SIZE(philips_pm2800_matrix); m++) {
426                 model = &philips_pm2800_matrix[m];
427                 if (model->chassis == chassis && model->num_modules == num_modules
428                                 && model->set == set)
429                         break;
430         }
431         if (m == ARRAY_SIZE(philips_pm2800_matrix)) {
432                 sr_dbg("Model %s not found in matrix.", hw_info->model);
433                 return SR_ERR;
434         }
435
436         sr_dbg("Found %d output channel%s:", num_modules, num_modules > 1 ? "s" : "");
437         *channels = g_malloc0(sizeof(struct channel_spec) * num_modules);
438         *channel_groups = g_malloc0(sizeof(struct channel_group_spec) * num_modules);
439         for (i = 0; i < num_modules; i++) {
440                 module = model->modules[i];
441                 spec = &philips_pm2800_module_specs[module];
442                 sr_dbg("output %d: %.0f - %.0fV, %.0f - %.0fA", i + 1,
443                                 spec->voltage[0], spec->voltage[1],
444                                 spec->current[0], spec->current[1]);
445                 (*channels)[i].name = (char *)philips_pm2800_names[i];
446                 memcpy(&((*channels)[i].voltage), spec, sizeof(float) * 6);
447                 (*channel_groups)[i].name = (char *)philips_pm2800_names[i];
448                 (*channel_groups)[i].channel_index_mask = 1 << i;
449                 (*channel_groups)[i].features = PPS_OTP | PPS_OVP | PPS_OCP;
450         }
451         *num_channels = *num_channel_groups = num_modules;
452
453         return SR_OK;
454 }
455
456 static const struct scpi_command philips_pm2800_cmd[] = {
457         { SCPI_CMD_SELECT_CHANNEL, ":INST:NSEL %s" },
458         { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
459         { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" },
460         { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
461         { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" },
462         { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
463         { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
464         { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP?" },
465         { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" },
466         { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" },
467         { SCPI_CMD_GET_OUTPUT_REGULATION, ":SOUR:FUNC:MODE?" },
468         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE, ":SOUR:VOLT:PROT:TRIP?" },
469         { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT:LEV?" },
470         { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT:LEV %.6f" },
471         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, ":SOUR:CURR:PROT:STAT?" },
472         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, ":SOUR:CURR:PROT:STAT ON" },
473         { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, ":SOUR:CURR:PROT:STAT OFF" },
474         { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE, ":SOUR:CURR:PROT:TRIP?" },
475         ALL_ZERO
476 };
477
478 SR_PRIV const struct scpi_pps pps_profiles[] = {
479         /* Agilent N5763A */
480         { "Agilent", "N5763A", 0,
481                 ARRAY_AND_SIZE(agilent_n5700a_devopts),
482                 ARRAY_AND_SIZE(agilent_n5700a_devopts_cg),
483                 ARRAY_AND_SIZE(agilent_n5763a_ch),
484                 ARRAY_AND_SIZE(agilent_n5700a_cg),
485                 agilent_n5700a_cmd,
486                 .probe_channels = NULL,
487         },
488         /* Agilent N5767A */
489         { "Agilent", "N5767A", 0,
490                 ARRAY_AND_SIZE(agilent_n5700a_devopts),
491                 ARRAY_AND_SIZE(agilent_n5700a_devopts_cg),
492                 ARRAY_AND_SIZE(agilent_n5767a_ch),
493                 ARRAY_AND_SIZE(agilent_n5700a_cg),
494                 agilent_n5700a_cmd,
495                 .probe_channels = NULL,
496         },
497         /* Chroma 61604 */
498         { "Chroma", "61604", 0,
499                 ARRAY_AND_SIZE(chroma_61604_devopts),
500                 ARRAY_AND_SIZE(chroma_61604_devopts_cg),
501                 ARRAY_AND_SIZE(chroma_61604_ch),
502                 ARRAY_AND_SIZE(chroma_61604_cg),
503                 chroma_61604_cmd,
504                 .probe_channels = NULL,
505         },
506         /* Chroma 62000 series */
507         { "Chroma", "620[0-9]{2}P-[0-9]{2,3}-[0-9]{1,3}", 0,
508                 ARRAY_AND_SIZE(chroma_62000_devopts),
509                 ARRAY_AND_SIZE(chroma_62000_devopts_cg),
510                 NULL, 0,
511                 NULL, 0,
512                 chroma_62000_cmd,
513                 .probe_channels = chroma_62000p_probe_channels,
514         },
515         /* HP 6632B */
516         { "HP", "6632B", 0,
517                 ARRAY_AND_SIZE(hp_6632b_devopts),
518                 ARRAY_AND_SIZE(devopts_none),
519                 ARRAY_AND_SIZE(hp_6632b_ch),
520                 ARRAY_AND_SIZE(hp_6632b_cg),
521                 hp_6632b_cmd,
522                 .probe_channels = NULL,
523         },
524
525         /* Rigol DP800 series */
526         { "Rigol", "^DP821A$", PPS_OTP,
527                 ARRAY_AND_SIZE(rigol_dp800_devopts),
528                 ARRAY_AND_SIZE(rigol_dp800_devopts_cg),
529                 ARRAY_AND_SIZE(rigol_dp821a_ch),
530                 ARRAY_AND_SIZE(rigol_dp820_cg),
531                 rigol_dp800_cmd,
532                 .probe_channels = NULL,
533         },
534         { "Rigol", "^DP831A$", PPS_OTP,
535                 ARRAY_AND_SIZE(rigol_dp800_devopts),
536                 ARRAY_AND_SIZE(rigol_dp800_devopts_cg),
537                 ARRAY_AND_SIZE(rigol_dp831_ch),
538                 ARRAY_AND_SIZE(rigol_dp830_cg),
539                 rigol_dp800_cmd,
540                 .probe_channels = NULL,
541         },
542         { "Rigol", "^(DP832|DP832A)$", PPS_OTP,
543                 ARRAY_AND_SIZE(rigol_dp800_devopts),
544                 ARRAY_AND_SIZE(rigol_dp800_devopts_cg),
545                 ARRAY_AND_SIZE(rigol_dp832_ch),
546                 ARRAY_AND_SIZE(rigol_dp830_cg),
547                 rigol_dp800_cmd,
548                 .probe_channels = NULL,
549         },
550
551         /* Philips/Fluke PM2800 series */
552         { "Philips", "^PM28[13][123]/[01234]{1,2}$", 0,
553                 ARRAY_AND_SIZE(philips_pm2800_devopts),
554                 ARRAY_AND_SIZE(philips_pm2800_devopts_cg),
555                 NULL, 0,
556                 NULL, 0,
557                 philips_pm2800_cmd,
558                 philips_pm2800_probe_channels,
559         },
560 };
561
562 SR_PRIV unsigned int num_pps_profiles = ARRAY_SIZE(pps_profiles);