2 * This file is part of the libsigrok project.
4 * Copyright (C) 2019 Derek Hageman <hageman@inthat.cloud>
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.
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.
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/>.
23 static struct sr_dev_driver mooshimeter_dmm_driver_info;
25 static const uint32_t scanopts[] = {
29 static const uint32_t drvopts[] = {
33 static const uint32_t devopts[] = {
35 SR_CONF_LIMIT_SAMPLES | SR_CONF_SET | SR_CONF_LIST,
36 SR_CONF_LIMIT_MSEC | SR_CONF_SET | SR_CONF_LIST,
37 SR_CONF_AVG_SAMPLES | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
38 SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
39 SR_CONF_CHANNEL_CONFIG | SR_CONF_SET,
42 static void init_dev(struct sr_dev_inst *sdi)
44 struct dev_context *devc;
45 struct sr_channel *chan;
47 devc = g_new0(struct dev_context, 1);
49 sdi->status = SR_ST_INITIALIZING;
50 sdi->vendor = g_strdup("Mooshim Engineering");
51 sdi->model = g_strdup("Mooshimeter");
53 sr_sw_limits_init(&devc->limits);
55 chan = sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
56 devc->channel_meaning[0].mq = SR_MQ_CURRENT;
57 devc->channel_meaning[0].unit = SR_UNIT_AMPERE;
58 devc->channel_meaning[0].mqflags = SR_MQFLAG_DC;
59 devc->channel_meaning[0].channels = g_slist_prepend(NULL, chan);
61 chan = sr_channel_new(sdi, 1, SR_CHANNEL_ANALOG, TRUE, "CH2");
62 devc->channel_meaning[1].mq = SR_MQ_VOLTAGE;
63 devc->channel_meaning[1].unit = SR_UNIT_VOLT;
64 devc->channel_meaning[1].mqflags = SR_MQFLAG_DC;
65 devc->channel_meaning[1].channels = g_slist_prepend(NULL, chan);
67 chan = sr_channel_new(sdi, 2, SR_CHANNEL_ANALOG, FALSE, "P");
68 devc->channel_meaning[2].mq = SR_MQ_POWER;
69 devc->channel_meaning[2].unit = SR_UNIT_WATT;
70 devc->channel_meaning[2].mqflags = SR_MQFLAG_RMS;
71 devc->channel_meaning[2].channels = g_slist_prepend(NULL, chan);
74 static GSList *scan(struct sr_dev_driver *di, GSList *options)
76 struct sr_bt_desc *desc;
78 struct sr_config *src;
83 for (l = options; l; l = l->next) {
87 conn = g_variant_get_string(src->data, NULL);
95 desc = sr_bt_desc_new();
99 ret = sr_bt_config_addr_remote(desc, conn);
104 * These handles where queried with btgatt-client, since the
105 * documentation specifies them in terms of UUIDs.
107 * service - start: 0x0010, end: 0xffff, type: primary, uuid: 1bc5ffa0-0200-62ab-e411-f254e005dbd4
108 * charac - start: 0x0011, value: 0x0012, props: 0x08, ext_props: 0x0000, uuid: 1bc5ffa1-0200-62ab-e411-f254e005dbd4
109 * descr - handle: 0x0013, uuid: 00002901-0000-1000-8000-00805f9b34fb
110 * charac - start: 0x0014, value: 0x0015, props: 0x10, ext_props: 0x0000, uuid: 1bc5ffa2-0200-62ab-e411-f254e005dbd4
111 * descr - handle: 0x0016, uuid: 00002902-0000-1000-8000-00805f9b34fb
112 * descr - handle: 0x0017, uuid: 00002901-0000-1000-8000-00805f9b34fb
114 ret = sr_bt_config_notify(desc, 0x0015, 0x0012, 0x0016, 0x0001);
118 struct sr_dev_inst *sdi = g_malloc0(sizeof(struct sr_dev_inst));
119 struct dev_context *devc = g_malloc0(sizeof(struct dev_context));
122 sdi->inst_type = SR_INST_USER;
123 sdi->connection_id = g_strdup(conn);
128 return std_scan_complete(di, g_slist_prepend(NULL, sdi));
131 sr_bt_desc_free(desc);
135 static int dev_clear(const struct sr_dev_driver *di)
137 struct drv_context *drvc = di->context;
138 struct sr_dev_inst *sdi;
142 for (l = drvc->instances; l; l = l->next) {
144 struct sr_bt_desc *desc = sdi->conn;
146 sr_bt_desc_free(desc);
151 return std_dev_clear(di);
154 static int set_channel1_mean(const struct sr_dev_inst *sdi)
156 struct dev_context *devc = sdi->priv;
157 devc->channel_meaning[0].mqflags &= ~SR_MQFLAG_RMS;
158 devc->channel_meaning[0].mqflags |= SR_MQFLAG_DC;
160 return mooshimeter_dmm_set_chooser(sdi, "CH1:ANALYSIS",
161 "CH1:ANALYSIS:MEAN");
164 static int set_channel1_rms(const struct sr_dev_inst *sdi)
166 struct dev_context *devc = sdi->priv;
167 devc->channel_meaning[0].mqflags &= ~SR_MQFLAG_DC;
168 devc->channel_meaning[0].mqflags |= SR_MQFLAG_RMS;
170 return mooshimeter_dmm_set_chooser(sdi, "CH1:ANALYSIS",
174 static int set_channel1_buffer(const struct sr_dev_inst *sdi)
176 struct dev_context *devc = sdi->priv;
177 devc->channel_meaning[0].mqflags &= ~(SR_MQFLAG_DC | SR_MQFLAG_RMS);
179 return mooshimeter_dmm_set_chooser(sdi, "CH1:ANALYSIS",
180 "CH1:ANALYSIS:BUFFER");
183 static int set_channel2_mean(const struct sr_dev_inst *sdi)
185 struct dev_context *devc = sdi->priv;
186 devc->channel_meaning[1].mqflags &= ~SR_MQFLAG_RMS;
187 devc->channel_meaning[1].mqflags |= SR_MQFLAG_DC;
189 return mooshimeter_dmm_set_chooser(sdi, "CH2:ANALYSIS",
190 "CH2:ANALYSIS:MEAN");
193 static int set_channel2_rms(const struct sr_dev_inst *sdi)
195 struct dev_context *devc = sdi->priv;
196 devc->channel_meaning[1].mqflags &= ~SR_MQFLAG_DC;
197 devc->channel_meaning[1].mqflags |= SR_MQFLAG_RMS;
199 return mooshimeter_dmm_set_chooser(sdi, "CH2:ANALYSIS",
203 static int set_channel2_buffer(const struct sr_dev_inst *sdi)
205 struct dev_context *devc = sdi->priv;
207 devc->channel_meaning[1].mqflags &= ~(SR_MQFLAG_DC | SR_MQFLAG_RMS);
209 return mooshimeter_dmm_set_chooser(sdi, "CH2:ANALYSIS",
210 "CH2:ANALYSIS:BUFFER");
213 static void autorange_channel1_current(const struct sr_dev_inst *sdi,
216 mooshimeter_dmm_set_autorange(sdi, "CH1:RANGE_I",
217 "CH1:MAPPING:CURRENT", value);
220 static int configure_channel1_current(const struct sr_dev_inst *sdi,
223 struct dev_context *devc = sdi->priv;
226 ret = mooshimeter_dmm_set_chooser(sdi, "CH1:MAPPING",
227 "CH1:MAPPING:CURRENT");
231 ret = mooshimeter_dmm_set_larger_number(sdi, "CH1:RANGE_I",
232 "CH1:MAPPING:CURRENT", range);
237 devc->channel_autorange[0] = autorange_channel1_current;
238 devc->channel_meaning[0].mqflags |= SR_MQFLAG_AUTORANGE;
240 devc->channel_autorange[0] = NULL;
241 devc->channel_meaning[0].mqflags &= ~SR_MQFLAG_AUTORANGE;
244 devc->channel_meaning[0].mqflags &= ~SR_MQFLAG_DIODE;
245 devc->channel_meaning[0].mq = SR_MQ_CURRENT;
246 devc->channel_meaning[0].unit = SR_UNIT_AMPERE;
251 static void autorange_channel1_temperature(const struct sr_dev_inst *sdi,
254 mooshimeter_dmm_set_autorange(sdi, "CH1:RANGE_I",
255 "CH1:MAPPING:TEMP", value);
258 static int configure_channel1_temperature(const struct sr_dev_inst *sdi,
261 struct dev_context *devc = sdi->priv;
264 ret = mooshimeter_dmm_set_chooser(sdi, "CH1:MAPPING",
269 ret = mooshimeter_dmm_set_larger_number(sdi, "CH1:RANGE_I",
270 "CH1:MAPPING:TEMP", range);
275 devc->channel_autorange[0] = autorange_channel1_temperature;
276 devc->channel_meaning[0].mqflags |= SR_MQFLAG_AUTORANGE;
278 devc->channel_autorange[0] = NULL;
279 devc->channel_meaning[0].mqflags &= ~SR_MQFLAG_AUTORANGE;
282 devc->channel_meaning[0].mqflags &= ~SR_MQFLAG_DIODE;
283 devc->channel_meaning[0].mq = SR_MQ_TEMPERATURE;
284 devc->channel_meaning[0].unit = SR_UNIT_KELVIN;
289 static void autorange_channel1_auxv(const struct sr_dev_inst *sdi,
292 mooshimeter_dmm_set_autorange(sdi, "CH1:RANGE_I",
293 "SHARED:AUX_V", value);
296 static int configure_channel1_auxv(const struct sr_dev_inst *sdi,
299 struct dev_context *devc = sdi->priv;
302 ret = mooshimeter_dmm_set_chooser(sdi, "SHARED", "SHARED:AUX_V");
306 ret = mooshimeter_dmm_set_chooser(sdi, "CH1:MAPPING",
307 "CH1:MAPPING:SHARED");
311 ret = mooshimeter_dmm_set_larger_number(sdi, "CH1:RANGE_I",
312 "SHARED:AUX_V", range);
317 devc->channel_autorange[0] = autorange_channel1_auxv;
318 devc->channel_meaning[0].mqflags |= SR_MQFLAG_AUTORANGE;
320 devc->channel_autorange[0] = NULL;
321 devc->channel_meaning[0].mqflags &= ~SR_MQFLAG_AUTORANGE;
324 devc->channel_meaning[0].mqflags &= ~SR_MQFLAG_DIODE;
325 devc->channel_meaning[0].mq = SR_MQ_VOLTAGE;
326 devc->channel_meaning[0].unit = SR_UNIT_VOLT;
331 static void autorange_channel1_resistance(const struct sr_dev_inst *sdi,
334 mooshimeter_dmm_set_autorange(sdi, "CH1:RANGE_I",
335 "SHARED:RESISTANCE", value);
338 static int configure_channel1_resistance(const struct sr_dev_inst *sdi,
341 struct dev_context *devc = sdi->priv;
344 ret = mooshimeter_dmm_set_chooser(sdi, "SHARED", "SHARED:RESISTANCE");
348 ret = mooshimeter_dmm_set_chooser(sdi, "CH1:MAPPING",
349 "CH1:MAPPING:SHARED");
353 ret = mooshimeter_dmm_set_larger_number(sdi, "CH1:RANGE_I",
354 "SHARED:RESISTANCE", range);
359 devc->channel_autorange[0] = autorange_channel1_resistance;
360 devc->channel_meaning[0].mqflags |= SR_MQFLAG_AUTORANGE;
362 devc->channel_autorange[0] = NULL;
363 devc->channel_meaning[0].mqflags &= ~SR_MQFLAG_AUTORANGE;
366 devc->channel_meaning[0].mqflags &= ~SR_MQFLAG_DIODE;
367 devc->channel_meaning[0].mq = SR_MQ_RESISTANCE;
368 devc->channel_meaning[0].unit = SR_UNIT_OHM;
373 static void autorange_channel1_diode(const struct sr_dev_inst *sdi,
376 mooshimeter_dmm_set_autorange(sdi, "CH1:RANGE_I",
377 "SHARED:DIODE", value);
380 static int configure_channel1_diode(const struct sr_dev_inst *sdi,
383 struct dev_context *devc = sdi->priv;
386 ret = mooshimeter_dmm_set_chooser(sdi, "SHARED", "SHARED:DIODE");
390 ret = mooshimeter_dmm_set_chooser(sdi, "CH1:MAPPING",
391 "CH1:MAPPING:SHARED");
395 ret = mooshimeter_dmm_set_larger_number(sdi, "CH1:RANGE_I",
396 "SHARED:DIODE", range);
401 devc->channel_autorange[0] = autorange_channel1_diode;
402 devc->channel_meaning[0].mqflags |= SR_MQFLAG_AUTORANGE;
404 devc->channel_autorange[0] = NULL;
405 devc->channel_meaning[0].mqflags &= ~SR_MQFLAG_AUTORANGE;
408 devc->channel_meaning[0].mqflags |= SR_MQFLAG_DIODE;
409 devc->channel_meaning[0].mq = SR_MQ_VOLTAGE;
410 devc->channel_meaning[0].unit = SR_UNIT_VOLT;
415 static void autorange_channel2_voltage(const struct sr_dev_inst *sdi,
418 mooshimeter_dmm_set_autorange(sdi, "CH2:RANGE_I",
419 "CH2:MAPPING:VOLTAGE", value);
422 static int configure_channel2_voltage(const struct sr_dev_inst *sdi,
425 struct dev_context *devc = sdi->priv;
428 ret = mooshimeter_dmm_set_chooser(sdi, "CH2:MAPPING",
429 "CH2:MAPPING:VOLTAGE");
433 ret = mooshimeter_dmm_set_larger_number(sdi, "CH2:RANGE_I",
434 "CH2:MAPPING:VOLTAGE", range);
439 devc->channel_autorange[1] = autorange_channel2_voltage;
440 devc->channel_meaning[1].mqflags |= SR_MQFLAG_AUTORANGE;
442 devc->channel_autorange[1] = NULL;
443 devc->channel_meaning[1].mqflags &= ~SR_MQFLAG_AUTORANGE;
446 devc->channel_meaning[1].mqflags &= ~SR_MQFLAG_DIODE;
447 devc->channel_meaning[1].mq = SR_MQ_VOLTAGE;
448 devc->channel_meaning[1].unit = SR_UNIT_VOLT;
453 static void autorange_channel2_temperature(const struct sr_dev_inst *sdi,
456 mooshimeter_dmm_set_autorange(sdi, "CH2:RANGE_I",
457 "CH2:MAPPING:TEMP", value);
460 static int configure_channel2_temperature(const struct sr_dev_inst *sdi,
463 struct dev_context *devc = sdi->priv;
466 ret = mooshimeter_dmm_set_chooser(sdi, "CH2:MAPPING",
471 ret = mooshimeter_dmm_set_larger_number(sdi, "CH2:RANGE_I",
472 "CH2:MAPPING:TEMP", range);
477 devc->channel_autorange[1] = autorange_channel2_temperature;
478 devc->channel_meaning[1].mqflags |= SR_MQFLAG_AUTORANGE;
480 devc->channel_autorange[1] = NULL;
481 devc->channel_meaning[1].mqflags &= ~SR_MQFLAG_AUTORANGE;
484 devc->channel_meaning[1].mqflags &= ~SR_MQFLAG_DIODE;
485 devc->channel_meaning[1].mq = SR_MQ_TEMPERATURE;
486 devc->channel_meaning[1].unit = SR_UNIT_CELSIUS;
491 static void autorange_channel2_auxv(const struct sr_dev_inst *sdi,
494 mooshimeter_dmm_set_autorange(sdi, "CH2:RANGE_I",
495 "SHARED:AUX_V", value);
498 static int configure_channel2_auxv(const struct sr_dev_inst *sdi,
501 struct dev_context *devc = sdi->priv;
504 ret = mooshimeter_dmm_set_chooser(sdi, "SHARED", "SHARED:AUX_V");
508 ret = mooshimeter_dmm_set_chooser(sdi, "CH2:MAPPING",
509 "CH2:MAPPING:SHARED");
513 ret = mooshimeter_dmm_set_larger_number(sdi, "CH2:RANGE_I",
514 "SHARED:AUX_V", range);
519 devc->channel_autorange[1] = autorange_channel2_auxv;
520 devc->channel_meaning[1].mqflags |= SR_MQFLAG_AUTORANGE;
522 devc->channel_autorange[1] = NULL;
523 devc->channel_meaning[1].mqflags &= ~SR_MQFLAG_AUTORANGE;
526 devc->channel_meaning[1].mqflags &= ~SR_MQFLAG_DIODE;
527 devc->channel_meaning[1].mq = SR_MQ_VOLTAGE;
528 devc->channel_meaning[1].unit = SR_UNIT_VOLT;
533 static void autorange_channel2_resistance(const struct sr_dev_inst *sdi,
536 mooshimeter_dmm_set_autorange(sdi, "CH2:RANGE_I",
537 "SHARED:RESISTANCE", value);
540 static int configure_channel2_resistance(const struct sr_dev_inst *sdi,
543 struct dev_context *devc = sdi->priv;
546 ret = mooshimeter_dmm_set_chooser(sdi, "SHARED", "SHARED:RESISTANCE");
550 ret = mooshimeter_dmm_set_chooser(sdi, "CH2:MAPPING",
551 "CH2:MAPPING:SHARED");
555 ret = mooshimeter_dmm_set_larger_number(sdi, "CH2:RANGE_I",
556 "SHARED:RESISTANCE", range);
561 devc->channel_autorange[1] = autorange_channel2_resistance;
562 devc->channel_meaning[1].mqflags |= SR_MQFLAG_AUTORANGE;
564 devc->channel_autorange[1] = NULL;
565 devc->channel_meaning[1].mqflags &= ~SR_MQFLAG_AUTORANGE;
568 devc->channel_meaning[1].mqflags &= ~SR_MQFLAG_DIODE;
569 devc->channel_meaning[1].mq = SR_MQ_RESISTANCE;
570 devc->channel_meaning[1].unit = SR_UNIT_OHM;
575 static void autorange_channel2_diode(const struct sr_dev_inst *sdi,
578 mooshimeter_dmm_set_autorange(sdi, "CH2:RANGE_I",
579 "SHARED:DIODE", value);
582 static int configure_channel2_diode(const struct sr_dev_inst *sdi,
585 struct dev_context *devc = sdi->priv;
588 ret = mooshimeter_dmm_set_chooser(sdi, "SHARED", "SHARED:DIODE");
592 ret = mooshimeter_dmm_set_chooser(sdi, "CH2:MAPPING",
593 "CH2:MAPPING:SHARED");
597 ret = mooshimeter_dmm_set_larger_number(sdi, "CH2:RANGE_I",
598 "SHARED:DIODE", range);
603 devc->channel_autorange[1] = autorange_channel2_diode;
604 devc->channel_meaning[1].mqflags |= SR_MQFLAG_AUTORANGE;
606 devc->channel_autorange[1] = NULL;
607 devc->channel_meaning[1].mqflags &= ~SR_MQFLAG_AUTORANGE;
610 devc->channel_meaning[1].mqflags |= SR_MQFLAG_DIODE;
611 devc->channel_meaning[1].mq = SR_MQ_VOLTAGE;
612 devc->channel_meaning[1].unit = SR_UNIT_VOLT;
618 * Full string: CH1,CH2
619 * Each channel: MODE[:RANGE[:ANALYSIS]]
632 * Range is the upper bound of the range (e.g. 60 for 0-60 V or 600 for 0-600),
633 * zero or absent for autoranging
639 static int apply_channel_config(const struct sr_dev_inst *sdi,
642 gchar **channel_config;
647 gboolean shared_in_use = FALSE;
649 channel_config = g_strsplit_set(config, ",/", -1);
650 if (!channel_config[0])
651 goto err_free_channel_config;
653 parameters = g_strsplit_set(channel_config[0], ":;", -1);
654 if (parameters[0] && parameters[0][0]) {
657 range = g_ascii_strtod(parameters[1], NULL);
659 param = parameters[0];
660 if (!g_ascii_strncasecmp(param, "Resistance", 10) ||
661 !g_ascii_strncasecmp(param, "Ohm", 3) ||
662 !g_ascii_strncasecmp(param, "W", 1) ||
663 !g_ascii_strncasecmp(param, "R", 1)) {
664 ret = configure_channel1_resistance(sdi, range);
666 goto err_free_parameters;
667 shared_in_use = TRUE;
668 } else if (!g_ascii_strncasecmp(param, "Diode", 5) ||
669 !g_ascii_strncasecmp(param, "D", 1)) {
670 ret = configure_channel1_diode(sdi, range);
672 goto err_free_parameters;
673 shared_in_use = TRUE;
674 } else if (!g_ascii_strncasecmp(param, "Aux", 3) ||
675 !g_ascii_strncasecmp(param, "LV", 2)) {
676 ret = configure_channel1_auxv(sdi, range);
678 goto err_free_parameters;
679 shared_in_use = TRUE;
680 } else if (!g_ascii_strncasecmp(param, "T", 1) ||
681 !g_ascii_strncasecmp(param, "K", 1)) {
682 ret = configure_channel1_temperature(sdi, range);
684 goto err_free_parameters;
685 } else if (!g_ascii_strncasecmp(param, "Current", 7) ||
686 !g_ascii_strncasecmp(param, "A", 1) ||
688 ret = configure_channel1_current(sdi, range);
690 goto err_free_parameters;
692 sr_info("Unrecognized mode for CH1: %s.", param);
693 ret = configure_channel1_current(sdi, range);
695 goto err_free_parameters;
698 if (parameters[1] && parameters[2]) {
699 param = parameters[2];
700 if (!g_ascii_strcasecmp(param, "RMS") ||
701 !g_ascii_strcasecmp(param, "AC")) {
702 ret = set_channel1_rms(sdi);
704 goto err_free_parameters;
705 } else if (!g_ascii_strcasecmp(param, "Buffer") ||
706 !g_ascii_strcasecmp(param, "Samples")) {
707 ret = set_channel1_buffer(sdi);
709 goto err_free_parameters;
711 ret = set_channel1_mean(sdi);
713 goto err_free_parameters;
717 g_strfreev(parameters);
719 if (!channel_config[1]) {
720 g_strfreev(channel_config);
724 parameters = g_strsplit_set(channel_config[1], ":;", -1);
725 if (parameters[0] && parameters[0][0]) {
728 range = g_ascii_strtod(parameters[1], NULL);
730 param = parameters[0];
731 if (!g_ascii_strncasecmp(param, "Resistance", 10) ||
732 !g_ascii_strncasecmp(param, "Ohm", 3) ||
733 !g_ascii_strncasecmp(param, "W", 1) ||
734 !g_ascii_strncasecmp(param, "R", 1)) {
737 goto err_free_parameters;
739 ret = configure_channel2_resistance(sdi, range);
741 goto err_free_parameters;
742 } else if (!g_ascii_strncasecmp(param, "Diode", 5) ||
743 !g_ascii_strncasecmp(param, "D", 1)) {
746 goto err_free_parameters;
748 ret = configure_channel2_diode(sdi, range);
750 goto err_free_parameters;
751 } else if (!g_ascii_strncasecmp(param, "Aux", 3) ||
752 !g_ascii_strncasecmp(param, "LV", 2)) {
755 goto err_free_parameters;
757 ret = configure_channel2_auxv(sdi, range);
759 goto err_free_parameters;
760 } else if (!g_ascii_strncasecmp(param, "T", 1) ||
761 !g_ascii_strncasecmp(param, "K", 1)) {
762 ret = configure_channel2_temperature(sdi, range);
764 goto err_free_parameters;
765 } else if (!g_ascii_strncasecmp(param, "V", 1) ||
767 ret = configure_channel2_voltage(sdi, range);
769 goto err_free_parameters;
771 sr_info("Unrecognized mode for CH2: %s.", param);
772 ret = configure_channel2_voltage(sdi, range);
774 goto err_free_parameters;
777 if (parameters[1] && parameters[2]) {
778 param = parameters[2];
779 if (!g_ascii_strcasecmp(param, "RMS") ||
780 !g_ascii_strcasecmp(param, "AC")) {
781 ret = set_channel2_rms(sdi);
783 goto err_free_parameters;
784 } else if (!g_ascii_strcasecmp(param, "Buffer") ||
785 !g_ascii_strcasecmp(param, "Samples")) {
786 ret = set_channel2_buffer(sdi);
788 goto err_free_parameters;
790 ret = set_channel2_mean(sdi);
792 goto err_free_parameters;
796 g_strfreev(parameters);
798 g_strfreev(channel_config);
802 g_strfreev(parameters);
803 err_free_channel_config:
804 g_strfreev(channel_config);
808 static int dev_open(struct sr_dev_inst *sdi)
812 ret = mooshimeter_dmm_open(sdi);
816 sdi->status = SR_ST_INACTIVE;
818 ret = mooshimeter_dmm_set_chooser(sdi, "SAMPLING:TRIGGER",
819 "SAMPLING:TRIGGER:OFF");
823 ret = mooshimeter_dmm_set_larger_number(sdi, "SAMPLING:RATE",
824 "SAMPLING:RATE", 125);
828 ret = mooshimeter_dmm_set_larger_number(sdi, "SAMPLING:DEPTH",
829 "SAMPLING:DEPTH", 64);
833 /* Looks like these sometimes get set to 8, somehow? */
834 ret = mooshimeter_dmm_set_integer(sdi, "CH1:BUF_BPS", 24);
838 ret = mooshimeter_dmm_set_integer(sdi, "CH2:BUF_BPS", 24);
842 ret = configure_channel1_current(sdi, 0);
846 ret = set_channel1_mean(sdi);
850 ret = configure_channel2_voltage(sdi, 0);
854 ret = set_channel2_mean(sdi);
858 sdi->status = SR_ST_ACTIVE;
863 static int dev_close(struct sr_dev_inst *sdi)
865 struct dev_context *devc = sdi->priv;
867 sdi->status = SR_ST_INACTIVE;
869 g_slist_free(devc->channel_meaning[0].channels);
870 devc->channel_meaning[0].channels = NULL;
872 g_slist_free(devc->channel_meaning[1].channels);
873 devc->channel_meaning[1].channels = NULL;
875 g_slist_free(devc->channel_meaning[2].channels);
876 devc->channel_meaning[2].channels = NULL;
878 return mooshimeter_dmm_close(sdi);
881 static int config_get(uint32_t key, GVariant **data,
882 const struct sr_dev_inst *sdi,
883 const struct sr_channel_group *cg)
885 struct dev_context *devc = sdi->priv;
892 case SR_CONF_SAMPLERATE:
893 ret = mooshimeter_dmm_get_chosen_number(sdi, "SAMPLING:RATE",
894 "SAMPLING:RATE", &value);
897 *data = g_variant_new_uint64((guint64)value);
899 case SR_CONF_AVG_SAMPLES:
900 ret = mooshimeter_dmm_get_chosen_number(sdi, "SAMPLING:DEPTH",
901 "SAMPLING:DEPTH", &value);
904 *data = g_variant_new_uint64((guint64)value);
906 case SR_CONF_CHANNEL_CONFIG:
912 return sr_sw_limits_config_get(&devc->limits, key, data);
915 static int config_set(uint32_t key, GVariant *data,
916 const struct sr_dev_inst *sdi,
917 const struct sr_channel_group *cg)
919 struct dev_context *devc = sdi->priv;
924 case SR_CONF_SAMPLERATE:
925 return mooshimeter_dmm_set_larger_number(sdi, "SAMPLING:RATE",
926 "SAMPLING:RATE", g_variant_get_uint64(data));
927 case SR_CONF_AVG_SAMPLES:
928 return mooshimeter_dmm_set_larger_number(sdi, "SAMPLING:DEPTH",
929 "SAMPLING:DEPTH", g_variant_get_uint64(data));
930 case SR_CONF_CHANNEL_CONFIG:
931 return apply_channel_config(sdi, g_variant_get_string(data, NULL));
936 return sr_sw_limits_config_set(&devc->limits, key, data);
939 static int config_list(uint32_t key, GVariant **data,
940 const struct sr_dev_inst *sdi,
941 const struct sr_channel_group *cg)
949 case SR_CONF_SAMPLERATE:
950 ret = mooshimeter_dmm_get_available_number_choices(sdi,
951 "SAMPLING:RATE", &values, &count);
954 integers = g_malloc(sizeof(uint64_t) * count);
955 for (size_t i = 0; i < count; i++)
956 integers[i] = (uint64_t)values[i];
958 *data = std_gvar_samplerates(integers, count);
961 case SR_CONF_AVG_SAMPLES:
962 ret = mooshimeter_dmm_get_available_number_choices(sdi,
963 "SAMPLING:DEPTH", &values, &count);
966 integers = g_malloc(sizeof(uint64_t) * count);
967 for (size_t i = 0; i < count; i++)
968 integers[i] = (uint64_t)values[i];
970 *data = std_gvar_array_u64(integers, count);
973 case SR_CONF_CHANNEL_CONFIG:
979 return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
982 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
984 struct dev_context *devc = sdi->priv;
987 ret = mooshimeter_dmm_set_chooser(sdi, "SAMPLING:TRIGGER",
988 "SAMPLING:TRIGGER:CONTINUOUS");
992 sr_sw_limits_acquisition_start(&devc->limits);
993 std_session_send_df_header(sdi);
995 sr_session_source_add(sdi->session, -1, 0, 10000,
996 mooshimeter_dmm_heartbeat, (void *)sdi);
998 /* The Bluetooth socket isn't exposed, so just poll for data. */
999 sr_session_source_add(sdi->session, -2, 0, 50,
1000 mooshimeter_dmm_poll, (void *)sdi);
1002 devc->enable_value_stream = TRUE;
1007 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
1009 struct dev_context *devc = sdi->priv;
1011 sr_session_source_remove(sdi->session, -1);
1012 sr_session_source_remove(sdi->session, -2);
1013 devc->enable_value_stream = FALSE;
1015 mooshimeter_dmm_set_chooser(sdi, "SAMPLING:TRIGGER",
1016 "SAMPLING:TRIGGER:OFF");
1021 static struct sr_dev_driver mooshimeter_dmm_driver_info = {
1022 .name = "mooshimeter-dmm",
1023 .longname = "Mooshimeter DMM",
1026 .cleanup = std_cleanup,
1028 .dev_list = std_dev_list,
1029 .dev_clear = dev_clear,
1030 .config_get = config_get,
1031 .config_set = config_set,
1032 .config_list = config_list,
1033 .dev_open = dev_open,
1034 .dev_close = dev_close,
1035 .dev_acquisition_start = dev_acquisition_start,
1036 .dev_acquisition_stop = dev_acquisition_stop,
1039 SR_REGISTER_DEV_DRIVER(mooshimeter_dmm_driver_info);