2012-12-29 21:22:10 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the libsigrok project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Martin Ling <martin-git@earth.li>
|
2013-04-08 10:01:00 +00:00
|
|
|
* Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
|
2013-11-01 11:05:49 +00:00
|
|
|
* Copyright (C) 2013 Mathias Grimmberger <mgri@zaphod.sax.de>
|
2012-12-29 21:22:10 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-12-30 03:17:56 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-12-29 21:22:10 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include "libsigrok.h"
|
|
|
|
#include "libsigrok-internal.h"
|
|
|
|
#include "protocol.h"
|
|
|
|
|
2013-04-22 13:59:55 +00:00
|
|
|
static const int32_t hwopts[] = {
|
|
|
|
SR_CONF_CONN,
|
2013-12-04 12:49:38 +00:00
|
|
|
SR_CONF_SERIALCOMM
|
2013-04-22 13:59:55 +00:00
|
|
|
};
|
|
|
|
|
2013-03-31 19:25:51 +00:00
|
|
|
static const int32_t hwcaps[] = {
|
2013-01-21 22:22:47 +00:00
|
|
|
SR_CONF_OSCILLOSCOPE,
|
|
|
|
SR_CONF_TIMEBASE,
|
|
|
|
SR_CONF_TRIGGER_SOURCE,
|
|
|
|
SR_CONF_TRIGGER_SLOPE,
|
|
|
|
SR_CONF_HORIZ_TRIGGERPOS,
|
2013-04-07 22:37:12 +00:00
|
|
|
SR_CONF_NUM_TIMEBASE,
|
2013-04-21 13:48:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const int32_t analog_hwcaps[] = {
|
2013-04-07 22:37:12 +00:00
|
|
|
SR_CONF_NUM_VDIV,
|
2013-04-21 13:48:56 +00:00
|
|
|
SR_CONF_VDIV,
|
2013-11-03 13:11:43 +00:00
|
|
|
SR_CONF_COUPLING,
|
2013-11-29 00:14:54 +00:00
|
|
|
SR_CONF_DATA_SOURCE,
|
2012-12-30 03:17:56 +00:00
|
|
|
};
|
|
|
|
|
2013-03-31 19:25:51 +00:00
|
|
|
static const uint64_t timebases[][2] = {
|
2012-12-30 03:17:56 +00:00
|
|
|
/* nanoseconds */
|
|
|
|
{ 2, 1000000000 },
|
|
|
|
{ 5, 1000000000 },
|
|
|
|
{ 10, 1000000000 },
|
|
|
|
{ 20, 1000000000 },
|
|
|
|
{ 50, 1000000000 },
|
|
|
|
{ 100, 1000000000 },
|
|
|
|
{ 500, 1000000000 },
|
|
|
|
/* microseconds */
|
|
|
|
{ 1, 1000000 },
|
|
|
|
{ 2, 1000000 },
|
|
|
|
{ 5, 1000000 },
|
|
|
|
{ 10, 1000000 },
|
|
|
|
{ 20, 1000000 },
|
|
|
|
{ 50, 1000000 },
|
|
|
|
{ 100, 1000000 },
|
|
|
|
{ 200, 1000000 },
|
|
|
|
{ 500, 1000000 },
|
|
|
|
/* milliseconds */
|
|
|
|
{ 1, 1000 },
|
|
|
|
{ 2, 1000 },
|
|
|
|
{ 5, 1000 },
|
|
|
|
{ 10, 1000 },
|
|
|
|
{ 20, 1000 },
|
|
|
|
{ 50, 1000 },
|
|
|
|
{ 100, 1000 },
|
|
|
|
{ 200, 1000 },
|
|
|
|
{ 500, 1000 },
|
|
|
|
/* seconds */
|
|
|
|
{ 1, 1 },
|
|
|
|
{ 2, 1 },
|
|
|
|
{ 5, 1 },
|
|
|
|
{ 10, 1 },
|
|
|
|
{ 20, 1 },
|
|
|
|
{ 50, 1 },
|
2013-11-01 11:05:49 +00:00
|
|
|
{ 100, 1 },
|
|
|
|
{ 200, 1 },
|
|
|
|
{ 500, 1 },
|
|
|
|
/* { 1000, 1 }, Confuses other code? */
|
2012-12-30 03:17:56 +00:00
|
|
|
};
|
|
|
|
|
2013-03-31 19:25:51 +00:00
|
|
|
static const uint64_t vdivs[][2] = {
|
2013-11-01 11:05:49 +00:00
|
|
|
/* microvolts */
|
|
|
|
{ 500, 1000000 },
|
2012-12-30 03:17:56 +00:00
|
|
|
/* millivolts */
|
2013-11-01 11:05:49 +00:00
|
|
|
{ 1, 1000 },
|
2012-12-30 03:17:56 +00:00
|
|
|
{ 2, 1000 },
|
|
|
|
{ 5, 1000 },
|
|
|
|
{ 10, 1000 },
|
|
|
|
{ 20, 1000 },
|
|
|
|
{ 50, 1000 },
|
|
|
|
{ 100, 1000 },
|
|
|
|
{ 200, 1000 },
|
|
|
|
{ 500, 1000 },
|
|
|
|
/* volts */
|
|
|
|
{ 1, 1 },
|
|
|
|
{ 2, 1 },
|
|
|
|
{ 5, 1 },
|
|
|
|
{ 10, 1 },
|
|
|
|
};
|
|
|
|
|
2013-11-01 11:05:49 +00:00
|
|
|
#define NUM_TIMEBASE ARRAY_SIZE(timebases)
|
|
|
|
#define NUM_VDIV ARRAY_SIZE(vdivs)
|
|
|
|
|
2012-12-30 03:17:56 +00:00
|
|
|
static const char *trigger_sources[] = {
|
|
|
|
"CH1",
|
|
|
|
"CH2",
|
|
|
|
"EXT",
|
|
|
|
"AC Line",
|
2013-04-14 01:21:55 +00:00
|
|
|
"D0",
|
|
|
|
"D1",
|
|
|
|
"D2",
|
|
|
|
"D3",
|
|
|
|
"D4",
|
|
|
|
"D5",
|
|
|
|
"D6",
|
|
|
|
"D7",
|
|
|
|
"D8",
|
|
|
|
"D9",
|
|
|
|
"D10",
|
|
|
|
"D11",
|
|
|
|
"D12",
|
|
|
|
"D13",
|
|
|
|
"D14",
|
|
|
|
"D15",
|
2012-12-30 03:17:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *coupling[] = {
|
|
|
|
"AC",
|
|
|
|
"DC",
|
|
|
|
"GND",
|
|
|
|
};
|
|
|
|
|
2013-11-29 00:14:54 +00:00
|
|
|
/* Do not change the order of entries */
|
|
|
|
static const char *data_sources[] = {
|
|
|
|
"Live",
|
|
|
|
"Memory",
|
|
|
|
"Segmented",
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* name, series, protocol flavor, min timebase, max timebase, min vdiv,
|
|
|
|
* digital channels, number of horizontal divs
|
|
|
|
*/
|
2013-11-01 11:05:49 +00:00
|
|
|
static const struct rigol_ds_model supported_models[] = {
|
2013-11-29 00:14:54 +00:00
|
|
|
{"DS1052E", RIGOL_DS1000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, {2, 1000}, false, 12},
|
|
|
|
{"DS1102E", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, false, 12},
|
|
|
|
{"DS1152E", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, false, 12},
|
|
|
|
{"DS1052D", RIGOL_DS1000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, {2, 1000}, true, 12},
|
|
|
|
{"DS1102D", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, true, 12},
|
|
|
|
{"DS1152D", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, true, 12},
|
|
|
|
{"DS2072", RIGOL_DS2000, PROTOCOL_IEEE488_2, {5, 1000000000}, {500, 1}, {500, 1000000}, false, 14},
|
|
|
|
{"DS2102", RIGOL_DS2000, PROTOCOL_IEEE488_2, {5, 1000000000}, {500, 1}, {500, 1000000}, false, 14},
|
|
|
|
{"DS2202", RIGOL_DS2000, PROTOCOL_IEEE488_2, {2, 1000000000}, {500, 1}, {500, 1000000}, false, 14},
|
2013-12-04 21:38:05 +00:00
|
|
|
{"VS5022", RIGOL_VS5000, PROTOCOL_LEGACY, {20, 1000000000}, {50, 1}, {2, 1000}, false, 14},
|
|
|
|
{"VS5022D", RIGOL_VS5000, PROTOCOL_LEGACY, {20, 1000000000}, {50, 1}, {2, 1000}, true, 14},
|
|
|
|
{"VS5042", RIGOL_VS5000, PROTOCOL_LEGACY, {10, 1000000000}, {50, 1}, {2, 1000}, false, 14},
|
|
|
|
{"VS5042D", RIGOL_VS5000, PROTOCOL_LEGACY, {10, 1000000000}, {50, 1}, {2, 1000}, true, 14},
|
|
|
|
{"VS5062", RIGOL_VS5000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, {2, 1000}, false, 14},
|
|
|
|
{"VS5062D", RIGOL_VS5000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, {2, 1000}, true, 14},
|
|
|
|
{"VS5102", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, false, 14},
|
|
|
|
{"VS5102D", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, true, 14},
|
|
|
|
{"VS5202", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, false, 14},
|
|
|
|
{"VS5202D", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, true, 14},
|
2013-01-13 21:42:21 +00:00
|
|
|
};
|
|
|
|
|
2013-10-31 17:31:39 +00:00
|
|
|
SR_PRIV struct sr_dev_driver rigol_ds_driver_info;
|
|
|
|
static struct sr_dev_driver *di = &rigol_ds_driver_info;
|
2012-12-29 21:22:10 +00:00
|
|
|
|
2013-05-31 13:19:53 +00:00
|
|
|
static void clear_helper(void *priv)
|
2012-12-29 21:22:10 +00:00
|
|
|
{
|
|
|
|
struct dev_context *devc;
|
|
|
|
|
2013-10-31 21:53:22 +00:00
|
|
|
devc = priv;
|
2013-11-29 00:14:54 +00:00
|
|
|
g_free(devc->data);
|
|
|
|
g_free(devc->buffer);
|
2013-05-31 13:19:53 +00:00
|
|
|
g_free(devc->coupling[0]);
|
|
|
|
g_free(devc->coupling[1]);
|
|
|
|
g_free(devc->trigger_source);
|
|
|
|
g_free(devc->trigger_slope);
|
2013-10-31 21:53:22 +00:00
|
|
|
g_slist_free(devc->analog_groups[0].probes);
|
|
|
|
g_slist_free(devc->analog_groups[1].probes);
|
|
|
|
g_slist_free(devc->digital_group.probes);
|
2013-05-31 13:19:53 +00:00
|
|
|
}
|
2012-12-29 21:22:10 +00:00
|
|
|
|
2013-05-31 14:09:57 +00:00
|
|
|
static int dev_clear(void)
|
2013-05-31 13:19:53 +00:00
|
|
|
{
|
|
|
|
return std_dev_clear(di, clear_helper);
|
2012-12-29 21:22:10 +00:00
|
|
|
}
|
|
|
|
|
2013-04-11 14:06:55 +00:00
|
|
|
static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
2013-12-04 10:55:32 +00:00
|
|
|
int ret;
|
2013-04-11 14:06:55 +00:00
|
|
|
|
|
|
|
va_start(args, format);
|
2013-12-04 10:55:32 +00:00
|
|
|
ret = sr_scpi_send_variadic(sdi->conn, format, args);
|
2013-04-11 14:06:55 +00:00
|
|
|
va_end(args);
|
2013-12-04 10:55:32 +00:00
|
|
|
|
|
|
|
if (ret != SR_OK)
|
2013-04-11 14:06:55 +00:00
|
|
|
return SR_ERR;
|
|
|
|
|
|
|
|
/* When setting a bunch of parameters in a row, the DS1052E scrambles
|
|
|
|
* some of them unless there is at least 100ms delay in between. */
|
2013-04-12 17:42:44 +00:00
|
|
|
sr_spew("delay %dms", 100);
|
2013-04-21 19:42:22 +00:00
|
|
|
g_usleep(100000);
|
2013-04-11 14:06:55 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int init(struct sr_context *sr_ctx)
|
2012-12-29 21:22:10 +00:00
|
|
|
{
|
2013-05-31 13:46:57 +00:00
|
|
|
return std_init(sr_ctx, di, LOG_PREFIX);
|
2012-12-29 21:22:10 +00:00
|
|
|
}
|
|
|
|
|
2013-12-04 20:42:22 +00:00
|
|
|
static int probe_port(const char *resource, const char *serialcomm, GSList **devices)
|
2012-12-29 21:22:10 +00:00
|
|
|
{
|
2013-04-24 00:09:49 +00:00
|
|
|
struct dev_context *devc;
|
|
|
|
struct sr_dev_inst *sdi;
|
2013-12-04 12:49:38 +00:00
|
|
|
const char *usbtmc_prefix = "/dev/usbtmc";
|
2013-12-04 20:42:22 +00:00
|
|
|
const char *tcp_prefix = "tcp/";
|
|
|
|
gchar **tokens, *address, *port;
|
2013-12-03 23:19:40 +00:00
|
|
|
struct sr_scpi_dev_inst *scpi;
|
|
|
|
struct sr_scpi_hw_info *hw_info;
|
2013-04-24 00:09:49 +00:00
|
|
|
struct sr_probe *probe;
|
2013-03-31 19:25:51 +00:00
|
|
|
unsigned int i;
|
2013-11-01 11:05:49 +00:00
|
|
|
const struct rigol_ds_model *model = NULL;
|
2013-12-03 23:19:40 +00:00
|
|
|
gchar *channel_name;
|
2012-12-30 14:29:00 +00:00
|
|
|
|
2013-04-24 17:07:46 +00:00
|
|
|
*devices = NULL;
|
2013-12-04 12:49:38 +00:00
|
|
|
|
2013-12-04 20:42:22 +00:00
|
|
|
if (strncmp(resource, usbtmc_prefix, strlen(usbtmc_prefix)) == 0) {
|
2013-12-04 23:21:15 +00:00
|
|
|
sr_dbg("Opening USBTMC device %s.", resource);
|
2013-12-04 20:42:22 +00:00
|
|
|
if (!(scpi = scpi_usbtmc_dev_inst_new(resource)))
|
|
|
|
return SR_ERR_MALLOC;
|
|
|
|
} else if (strncmp(resource, tcp_prefix, strlen(tcp_prefix)) == 0) {
|
2013-12-04 23:21:15 +00:00
|
|
|
sr_dbg("Opening TCP connection %s.", resource);
|
2013-12-04 20:42:22 +00:00
|
|
|
tokens = g_strsplit(resource + strlen(tcp_prefix), "/", 0);
|
|
|
|
address = tokens[0];
|
|
|
|
port = tokens[1];
|
|
|
|
if (!address || !port || tokens[2]) {
|
2013-12-04 23:21:15 +00:00
|
|
|
sr_err("Invalid parameters.");
|
2013-12-04 20:42:22 +00:00
|
|
|
g_strfreev(tokens);
|
|
|
|
return SR_ERR_ARG;
|
|
|
|
}
|
|
|
|
scpi = scpi_tcp_dev_inst_new(address, port);
|
|
|
|
g_strfreev(tokens);
|
|
|
|
if (!scpi)
|
2013-12-04 12:49:38 +00:00
|
|
|
return SR_ERR_MALLOC;
|
|
|
|
} else {
|
2013-12-04 23:21:15 +00:00
|
|
|
sr_dbg("Opening serial device %s.", resource);
|
2013-12-04 20:42:22 +00:00
|
|
|
if (!(scpi = scpi_serial_dev_inst_new(resource, serialcomm)))
|
2013-12-04 12:49:38 +00:00
|
|
|
return SR_ERR_MALLOC;
|
|
|
|
}
|
2013-04-22 15:12:06 +00:00
|
|
|
|
2013-12-03 23:19:40 +00:00
|
|
|
if (sr_scpi_open(scpi) != SR_OK) {
|
|
|
|
sr_scpi_free(scpi);
|
2013-04-22 15:12:06 +00:00
|
|
|
return SR_ERR;
|
2013-12-03 23:19:40 +00:00
|
|
|
};
|
2013-04-22 15:12:06 +00:00
|
|
|
|
2013-12-03 23:19:40 +00:00
|
|
|
if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
|
|
|
|
sr_info("Couldn't get IDN response.");
|
|
|
|
sr_scpi_close(scpi);
|
|
|
|
sr_scpi_free(scpi);
|
|
|
|
return SR_ERR;
|
2013-04-22 13:59:55 +00:00
|
|
|
}
|
2012-12-30 03:17:56 +00:00
|
|
|
|
2013-12-03 23:19:40 +00:00
|
|
|
if (strcasecmp(hw_info->manufacturer, "Rigol Technologies")) {
|
|
|
|
sr_scpi_hw_info_free(hw_info);
|
2013-12-07 17:54:33 +00:00
|
|
|
sr_scpi_close(scpi);
|
2013-12-03 23:19:40 +00:00
|
|
|
sr_scpi_free(scpi);
|
2013-04-22 13:59:55 +00:00
|
|
|
return SR_ERR_NA;
|
|
|
|
}
|
2012-12-30 14:29:00 +00:00
|
|
|
|
2013-04-22 13:59:55 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(supported_models); i++) {
|
2013-12-03 23:19:40 +00:00
|
|
|
if (!strcmp(hw_info->model, supported_models[i].name)) {
|
2013-11-01 11:05:49 +00:00
|
|
|
model = &supported_models[i];
|
2013-04-22 13:59:55 +00:00
|
|
|
break;
|
2012-12-30 14:29:00 +00:00
|
|
|
}
|
2013-04-22 13:59:55 +00:00
|
|
|
}
|
2012-12-30 14:29:00 +00:00
|
|
|
|
2013-11-01 11:05:49 +00:00
|
|
|
if (!model || !(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE,
|
2013-12-03 23:19:40 +00:00
|
|
|
hw_info->manufacturer, hw_info->model,
|
|
|
|
hw_info->firmware_version))) {
|
|
|
|
sr_scpi_hw_info_free(hw_info);
|
2013-12-07 17:54:33 +00:00
|
|
|
sr_scpi_close(scpi);
|
2013-12-03 23:19:40 +00:00
|
|
|
sr_scpi_free(scpi);
|
2013-04-22 13:59:55 +00:00
|
|
|
return SR_ERR_NA;
|
|
|
|
}
|
2012-12-30 14:29:00 +00:00
|
|
|
|
2013-12-03 23:19:40 +00:00
|
|
|
sr_scpi_hw_info_free(hw_info);
|
2013-12-07 17:54:33 +00:00
|
|
|
sr_scpi_close(scpi);
|
2013-12-03 23:19:40 +00:00
|
|
|
|
|
|
|
sdi->conn = scpi;
|
2012-12-30 14:29:00 +00:00
|
|
|
|
2013-04-24 00:09:49 +00:00
|
|
|
sdi->driver = di;
|
2013-12-03 23:19:40 +00:00
|
|
|
sdi->inst_type = SR_INST_SCPI;
|
2013-01-13 21:42:21 +00:00
|
|
|
|
2013-04-24 00:09:49 +00:00
|
|
|
if (!(devc = g_try_malloc0(sizeof(struct dev_context))))
|
2013-04-22 13:59:55 +00:00
|
|
|
return SR_ERR_MALLOC;
|
2013-12-03 23:19:40 +00:00
|
|
|
|
2013-04-24 00:09:49 +00:00
|
|
|
devc->limit_frames = 0;
|
2013-11-01 11:05:49 +00:00
|
|
|
devc->model = model;
|
2013-01-13 21:42:21 +00:00
|
|
|
|
2013-04-22 13:59:55 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
2013-04-21 12:44:34 +00:00
|
|
|
channel_name = (i == 0 ? "CH1" : "CH2");
|
|
|
|
if (!(probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE, channel_name)))
|
2013-04-22 13:59:55 +00:00
|
|
|
return SR_ERR_MALLOC;
|
|
|
|
sdi->probes = g_slist_append(sdi->probes, probe);
|
2013-04-21 12:44:34 +00:00
|
|
|
devc->analog_groups[i].name = channel_name;
|
|
|
|
devc->analog_groups[i].probes = g_slist_append(NULL, probe);
|
|
|
|
sdi->probe_groups = g_slist_append(sdi->probe_groups,
|
|
|
|
&devc->analog_groups[i]);
|
2013-04-22 13:59:55 +00:00
|
|
|
}
|
2013-01-13 21:42:21 +00:00
|
|
|
|
2013-11-01 11:05:49 +00:00
|
|
|
if (devc->model->has_digital) {
|
2013-04-22 13:59:55 +00:00
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
if (!(channel_name = g_strdup_printf("D%d", i)))
|
|
|
|
return SR_ERR_MALLOC;
|
|
|
|
probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, channel_name);
|
|
|
|
g_free(channel_name);
|
|
|
|
if (!probe)
|
|
|
|
return SR_ERR_MALLOC;
|
|
|
|
sdi->probes = g_slist_append(sdi->probes, probe);
|
2013-04-21 12:44:34 +00:00
|
|
|
devc->digital_group.probes = g_slist_append(
|
|
|
|
devc->digital_group.probes, probe);
|
2013-01-13 21:42:21 +00:00
|
|
|
}
|
2013-11-29 01:40:50 +00:00
|
|
|
devc->digital_group.name = "LA";
|
|
|
|
sdi->probe_groups = g_slist_append(sdi->probe_groups,
|
|
|
|
&devc->digital_group);
|
2013-04-22 13:59:55 +00:00
|
|
|
}
|
2013-11-01 11:05:49 +00:00
|
|
|
|
|
|
|
for (i = 0; i < NUM_TIMEBASE; i++) {
|
|
|
|
if (!memcmp(&devc->model->min_timebase, &timebases[i], sizeof(uint64_t[2])))
|
|
|
|
devc->timebases = &timebases[i];
|
|
|
|
if (!memcmp(&devc->model->max_timebase, &timebases[i], sizeof(uint64_t[2])))
|
|
|
|
devc->num_timebases = &timebases[i] - devc->timebases + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_VDIV; i++) {
|
|
|
|
if (!memcmp(&devc->model->min_vdiv, &vdivs[i], sizeof(uint64_t[2]))) {
|
2013-11-01 21:49:05 +00:00
|
|
|
devc->vdivs = &vdivs[i];
|
|
|
|
devc->num_vdivs = NUM_VDIV - (&vdivs[i] - &vdivs[0]);
|
2013-11-01 11:05:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-29 00:14:54 +00:00
|
|
|
if (!(devc->buffer = g_try_malloc(ACQ_BUFFER_SIZE)))
|
|
|
|
return SR_ERR_MALLOC;
|
|
|
|
if (!(devc->data = g_try_malloc(ACQ_BUFFER_SIZE * sizeof(float))))
|
|
|
|
return SR_ERR_MALLOC;
|
|
|
|
|
|
|
|
devc->data_source = DATA_SOURCE_LIVE;
|
|
|
|
|
2013-04-24 00:09:49 +00:00
|
|
|
sdi->priv = devc;
|
|
|
|
|
|
|
|
*devices = g_slist_append(NULL, sdi);
|
2013-01-13 21:42:21 +00:00
|
|
|
|
2013-04-22 13:59:55 +00:00
|
|
|
return SR_OK;
|
|
|
|
}
|
2013-01-13 21:42:21 +00:00
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static GSList *scan(GSList *options)
|
2013-04-22 13:59:55 +00:00
|
|
|
{
|
|
|
|
struct drv_context *drvc;
|
|
|
|
struct sr_config *src;
|
2013-04-24 00:09:49 +00:00
|
|
|
GSList *l, *devices;
|
2013-04-22 13:59:55 +00:00
|
|
|
GDir *dir;
|
|
|
|
int ret;
|
2013-04-24 00:09:49 +00:00
|
|
|
const gchar *dev_name;
|
|
|
|
gchar *port = NULL;
|
2013-12-04 12:49:38 +00:00
|
|
|
gchar *serialcomm = NULL;
|
2012-12-30 14:29:00 +00:00
|
|
|
|
2013-04-22 13:59:55 +00:00
|
|
|
drvc = di->priv;
|
2013-04-21 12:17:40 +00:00
|
|
|
|
2013-04-22 13:59:55 +00:00
|
|
|
for (l = options; l; l = l->next) {
|
|
|
|
src = l->data;
|
2013-12-04 12:49:38 +00:00
|
|
|
switch (src->key) {
|
|
|
|
case SR_CONF_CONN:
|
2013-04-24 00:09:49 +00:00
|
|
|
port = (char *)g_variant_get_string(src->data, NULL);
|
2013-04-22 13:59:55 +00:00
|
|
|
break;
|
2013-12-04 12:49:38 +00:00
|
|
|
case SR_CONF_SERIALCOMM:
|
|
|
|
serialcomm = (char *)g_variant_get_string(src->data, NULL);
|
|
|
|
break;
|
2012-12-30 14:29:00 +00:00
|
|
|
}
|
2013-04-22 13:59:55 +00:00
|
|
|
}
|
2012-12-30 14:29:00 +00:00
|
|
|
|
2013-04-24 17:07:46 +00:00
|
|
|
devices = NULL;
|
2013-04-24 00:09:49 +00:00
|
|
|
if (port) {
|
2013-12-04 12:49:38 +00:00
|
|
|
if (probe_port(port, serialcomm, &devices) == SR_ERR_MALLOC) {
|
|
|
|
g_free(port);
|
|
|
|
if (serialcomm)
|
|
|
|
g_free(serialcomm);
|
2013-04-22 13:59:55 +00:00
|
|
|
return NULL;
|
2013-12-04 12:49:38 +00:00
|
|
|
}
|
2013-04-22 13:59:55 +00:00
|
|
|
} else {
|
2013-08-30 11:57:15 +00:00
|
|
|
if (!(dir = g_dir_open("/sys/class/usbmisc/", 0, NULL)))
|
|
|
|
if (!(dir = g_dir_open("/sys/class/usb/", 0, NULL)))
|
|
|
|
return NULL;
|
2013-04-22 13:59:55 +00:00
|
|
|
while ((dev_name = g_dir_read_name(dir))) {
|
2013-04-24 00:09:49 +00:00
|
|
|
if (strncmp(dev_name, "usbtmc", 6))
|
2013-04-22 13:59:55 +00:00
|
|
|
continue;
|
2013-04-24 00:09:49 +00:00
|
|
|
port = g_strconcat("/dev/", dev_name, NULL);
|
2013-12-04 12:49:38 +00:00
|
|
|
ret = probe_port(port, serialcomm, &devices);
|
2013-04-24 00:09:49 +00:00
|
|
|
g_free(port);
|
2013-12-04 12:49:38 +00:00
|
|
|
if (serialcomm)
|
|
|
|
g_free(serialcomm);
|
2013-04-22 13:59:55 +00:00
|
|
|
if (ret == SR_ERR_MALLOC) {
|
|
|
|
g_dir_close(dir);
|
|
|
|
return NULL;
|
2013-04-14 01:21:55 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-22 13:59:55 +00:00
|
|
|
g_dir_close(dir);
|
|
|
|
}
|
2012-12-29 21:22:10 +00:00
|
|
|
|
2013-04-24 17:07:46 +00:00
|
|
|
/* Tack a copy of the newly found devices onto the driver list. */
|
|
|
|
l = g_slist_copy(devices);
|
|
|
|
drvc->instances = g_slist_concat(drvc->instances, l);
|
2013-04-24 00:09:49 +00:00
|
|
|
|
2012-12-29 21:22:10 +00:00
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static GSList *dev_list(void)
|
2012-12-29 21:22:10 +00:00
|
|
|
{
|
2013-02-02 18:52:26 +00:00
|
|
|
return ((struct drv_context *)(di->priv))->instances;
|
2012-12-29 21:22:10 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int dev_open(struct sr_dev_inst *sdi)
|
2012-12-29 21:22:10 +00:00
|
|
|
{
|
2013-12-03 23:19:40 +00:00
|
|
|
struct sr_scpi_dev_inst *scpi = sdi->conn;
|
2013-04-22 15:12:06 +00:00
|
|
|
|
2013-12-03 23:19:40 +00:00
|
|
|
if (sr_scpi_open(scpi) < 0)
|
2012-12-30 03:17:56 +00:00
|
|
|
return SR_ERR;
|
|
|
|
|
2013-10-31 17:31:39 +00:00
|
|
|
if (rigol_ds_get_dev_cfg(sdi) != SR_OK)
|
2013-04-11 14:06:55 +00:00
|
|
|
return SR_ERR;
|
2012-12-29 21:22:10 +00:00
|
|
|
|
2013-04-24 17:07:46 +00:00
|
|
|
sdi->status = SR_ST_ACTIVE;
|
2013-04-24 00:09:49 +00:00
|
|
|
|
2012-12-29 21:22:10 +00:00
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int dev_close(struct sr_dev_inst *sdi)
|
2012-12-29 21:22:10 +00:00
|
|
|
{
|
2013-12-03 23:19:40 +00:00
|
|
|
struct sr_scpi_dev_inst *scpi;
|
|
|
|
|
|
|
|
scpi = sdi->conn;
|
2012-12-30 03:17:56 +00:00
|
|
|
|
2013-12-03 23:19:40 +00:00
|
|
|
if (scpi) {
|
|
|
|
if (sr_scpi_close(scpi) < 0)
|
|
|
|
return SR_ERR;
|
2013-04-24 00:09:49 +00:00
|
|
|
sdi->status = SR_ST_INACTIVE;
|
|
|
|
}
|
2012-12-29 21:22:10 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-10 17:37:54 +00:00
|
|
|
static int cleanup(void)
|
2012-12-29 21:22:10 +00:00
|
|
|
{
|
2013-05-31 14:09:57 +00:00
|
|
|
return dev_clear();
|
2012-12-29 21:22:10 +00:00
|
|
|
}
|
|
|
|
|
2013-04-20 00:00:49 +00:00
|
|
|
static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
|
|
|
|
const struct sr_probe_group *probe_group)
|
2013-04-07 22:37:12 +00:00
|
|
|
{
|
2013-04-28 20:11:43 +00:00
|
|
|
struct dev_context *devc;
|
2013-04-21 13:48:56 +00:00
|
|
|
unsigned int i;
|
2013-04-07 22:37:12 +00:00
|
|
|
|
2013-04-28 20:11:43 +00:00
|
|
|
if (!sdi || !(devc = sdi->priv))
|
|
|
|
return SR_ERR_ARG;
|
|
|
|
|
2013-11-03 13:13:59 +00:00
|
|
|
/* If a probe group is specified, it must be a valid one. */
|
|
|
|
if (probe_group) {
|
|
|
|
if (probe_group != &devc->analog_groups[0]
|
|
|
|
&& probe_group != &devc->analog_groups[1]) {
|
|
|
|
sr_err("Invalid probe group specified.");
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-07 22:37:12 +00:00
|
|
|
switch (id) {
|
|
|
|
case SR_CONF_NUM_TIMEBASE:
|
2013-11-01 11:05:49 +00:00
|
|
|
*data = g_variant_new_int32(devc->num_timebases);
|
2013-04-07 22:37:12 +00:00
|
|
|
break;
|
|
|
|
case SR_CONF_NUM_VDIV:
|
2013-11-03 13:13:59 +00:00
|
|
|
if (!probe_group) {
|
|
|
|
sr_err("No probe group specified.");
|
|
|
|
return SR_ERR_PROBE_GROUP;
|
|
|
|
}
|
2013-04-21 13:48:56 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
2013-04-28 20:11:43 +00:00
|
|
|
if (probe_group == &devc->analog_groups[i]) {
|
2013-11-01 11:05:49 +00:00
|
|
|
*data = g_variant_new_int32(devc->num_vdivs);
|
2013-04-21 13:48:56 +00:00
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SR_ERR_NA;
|
2013-11-29 00:14:54 +00:00
|
|
|
case SR_CONF_DATA_SOURCE:
|
|
|
|
if (devc->data_source == DATA_SOURCE_LIVE)
|
|
|
|
*data = g_variant_new_string("Live");
|
|
|
|
else if (devc->data_source == DATA_SOURCE_MEMORY)
|
|
|
|
*data = g_variant_new_string("Memory");
|
|
|
|
else
|
|
|
|
*data = g_variant_new_string("Segmented");
|
|
|
|
break;
|
2013-04-07 22:37:12 +00:00
|
|
|
default:
|
2013-04-16 00:33:03 +00:00
|
|
|
return SR_ERR_NA;
|
2013-04-07 22:37:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-20 00:00:49 +00:00
|
|
|
static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
|
|
|
|
const struct sr_probe_group *probe_group)
|
2012-12-29 21:22:10 +00:00
|
|
|
{
|
2013-01-03 18:04:11 +00:00
|
|
|
struct dev_context *devc;
|
2013-03-31 19:25:51 +00:00
|
|
|
uint64_t tmp_u64, p, q;
|
2013-04-11 14:06:55 +00:00
|
|
|
double t_dbl;
|
2013-04-21 13:48:56 +00:00
|
|
|
unsigned int i, j;
|
2013-04-11 14:06:55 +00:00
|
|
|
int ret;
|
|
|
|
const char *tmp_str;
|
2012-12-29 21:22:10 +00:00
|
|
|
|
2013-04-28 20:11:43 +00:00
|
|
|
if (!(devc = sdi->priv))
|
|
|
|
return SR_ERR_ARG;
|
2013-01-03 18:04:11 +00:00
|
|
|
|
2013-04-23 13:14:42 +00:00
|
|
|
if (sdi->status != SR_ST_ACTIVE)
|
|
|
|
return SR_ERR_DEV_CLOSED;
|
2012-12-29 21:22:10 +00:00
|
|
|
|
2013-11-03 13:13:59 +00:00
|
|
|
/* If a probe group is specified, it must be a valid one. */
|
|
|
|
if (probe_group) {
|
|
|
|
if (probe_group != &devc->analog_groups[0]
|
|
|
|
&& probe_group != &devc->analog_groups[1]) {
|
|
|
|
sr_err("Invalid probe group specified.");
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-29 21:22:10 +00:00
|
|
|
ret = SR_OK;
|
2013-01-24 18:19:09 +00:00
|
|
|
switch (id) {
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_LIMIT_FRAMES:
|
2013-03-31 19:25:51 +00:00
|
|
|
devc->limit_frames = g_variant_get_uint64(data);
|
2012-12-30 03:17:56 +00:00
|
|
|
break;
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_TRIGGER_SLOPE:
|
2013-03-31 19:25:51 +00:00
|
|
|
tmp_u64 = g_variant_get_uint64(data);
|
2013-04-11 14:06:55 +00:00
|
|
|
if (tmp_u64 != 0 && tmp_u64 != 1)
|
|
|
|
return SR_ERR;
|
|
|
|
g_free(devc->trigger_slope);
|
|
|
|
devc->trigger_slope = g_strdup(tmp_u64 ? "POS" : "NEG");
|
|
|
|
ret = set_cfg(sdi, ":TRIG:EDGE:SLOP %s", devc->trigger_slope);
|
2012-12-30 03:17:56 +00:00
|
|
|
break;
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_HORIZ_TRIGGERPOS:
|
2013-04-11 14:06:55 +00:00
|
|
|
t_dbl = g_variant_get_double(data);
|
|
|
|
if (t_dbl < 0.0 || t_dbl > 1.0)
|
|
|
|
return SR_ERR;
|
|
|
|
devc->horiz_triggerpos = t_dbl;
|
|
|
|
/* We have the trigger offset as a percentage of the frame, but
|
|
|
|
* need to express this in seconds. */
|
2013-11-01 11:05:49 +00:00
|
|
|
t_dbl = -(devc->horiz_triggerpos - 0.5) * devc->timebase * devc->num_timebases;
|
2013-04-11 14:06:55 +00:00
|
|
|
ret = set_cfg(sdi, ":TIM:OFFS %.6f", t_dbl);
|
2012-12-30 03:17:56 +00:00
|
|
|
break;
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_TIMEBASE:
|
2013-03-31 19:25:51 +00:00
|
|
|
g_variant_get(data, "(tt)", &p, &q);
|
2013-11-01 11:05:49 +00:00
|
|
|
for (i = 0; i < devc->num_timebases; i++) {
|
|
|
|
if (devc->timebases[i][0] == p && devc->timebases[i][1] == q) {
|
2013-04-11 14:06:55 +00:00
|
|
|
devc->timebase = (float)p / q;
|
|
|
|
ret = set_cfg(sdi, ":TIM:SCAL %.9f", devc->timebase);
|
2013-03-31 19:25:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-11-01 11:05:49 +00:00
|
|
|
if (i == devc->num_timebases)
|
2013-04-11 14:06:55 +00:00
|
|
|
ret = SR_ERR_ARG;
|
2012-12-30 03:17:56 +00:00
|
|
|
break;
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_TRIGGER_SOURCE:
|
2013-03-31 19:25:51 +00:00
|
|
|
tmp_str = g_variant_get_string(data, NULL);
|
2013-04-11 14:06:55 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(trigger_sources); i++) {
|
|
|
|
if (!strcmp(trigger_sources[i], tmp_str)) {
|
|
|
|
g_free(devc->trigger_source);
|
|
|
|
devc->trigger_source = g_strdup(trigger_sources[i]);
|
|
|
|
if (!strcmp(devc->trigger_source, "AC Line"))
|
|
|
|
tmp_str = "ACL";
|
|
|
|
else if (!strcmp(devc->trigger_source, "CH1"))
|
|
|
|
tmp_str = "CHAN1";
|
|
|
|
else if (!strcmp(devc->trigger_source, "CH2"))
|
|
|
|
tmp_str = "CHAN2";
|
|
|
|
else
|
|
|
|
tmp_str = (char *)devc->trigger_source;
|
|
|
|
ret = set_cfg(sdi, ":TRIG:EDGE:SOUR %s", tmp_str);
|
|
|
|
break;
|
|
|
|
}
|
2012-12-30 13:17:08 +00:00
|
|
|
}
|
2013-04-11 14:06:55 +00:00
|
|
|
if (i == ARRAY_SIZE(trigger_sources))
|
|
|
|
ret = SR_ERR_ARG;
|
2012-12-30 03:17:56 +00:00
|
|
|
break;
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_VDIV:
|
2013-11-03 13:13:59 +00:00
|
|
|
if (!probe_group) {
|
|
|
|
sr_err("No probe group specified.");
|
|
|
|
return SR_ERR_PROBE_GROUP;
|
|
|
|
}
|
2013-03-31 19:25:51 +00:00
|
|
|
g_variant_get(data, "(tt)", &p, &q);
|
2013-04-21 13:48:56 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
2013-11-03 13:11:43 +00:00
|
|
|
if (probe_group == &devc->analog_groups[i]) {
|
|
|
|
for (j = 0; j < ARRAY_SIZE(vdivs); j++) {
|
2013-04-21 13:48:56 +00:00
|
|
|
if (vdivs[j][0] != p || vdivs[j][1] != q)
|
|
|
|
continue;
|
|
|
|
devc->vdiv[i] = (float)p / q;
|
|
|
|
return set_cfg(sdi, ":CHAN%d:SCAL %.3f", i + 1,
|
|
|
|
devc->vdiv[i]);
|
|
|
|
}
|
|
|
|
return SR_ERR_ARG;
|
|
|
|
}
|
2012-12-30 03:17:56 +00:00
|
|
|
}
|
2013-04-21 13:48:56 +00:00
|
|
|
return SR_ERR_NA;
|
2013-01-21 22:22:47 +00:00
|
|
|
case SR_CONF_COUPLING:
|
2013-11-03 13:11:43 +00:00
|
|
|
if (!probe_group) {
|
|
|
|
sr_err("No probe group specified.");
|
|
|
|
return SR_ERR_PROBE_GROUP;
|
|
|
|
}
|
2013-03-31 19:25:51 +00:00
|
|
|
tmp_str = g_variant_get_string(data, NULL);
|
2013-04-21 13:48:56 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
2013-11-03 13:11:43 +00:00
|
|
|
if (probe_group == &devc->analog_groups[i]) {
|
|
|
|
for (j = 0; j < ARRAY_SIZE(coupling); j++) {
|
|
|
|
if (!strcmp(tmp_str, coupling[j])) {
|
2013-04-21 13:48:56 +00:00
|
|
|
g_free(devc->coupling[i]);
|
|
|
|
devc->coupling[i] = g_strdup(coupling[j]);
|
|
|
|
return set_cfg(sdi, ":CHAN%d:COUP %s", i + 1,
|
|
|
|
devc->coupling[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SR_ERR_ARG;
|
2012-12-30 03:17:56 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-21 13:48:56 +00:00
|
|
|
return SR_ERR_NA;
|
2013-11-29 00:14:54 +00:00
|
|
|
case SR_CONF_DATA_SOURCE:
|
|
|
|
tmp_str = g_variant_get_string(data, NULL);
|
|
|
|
if (!strcmp(tmp_str, "Live"))
|
|
|
|
devc->data_source = DATA_SOURCE_LIVE;
|
|
|
|
else if (!strcmp(tmp_str, "Memory"))
|
|
|
|
devc->data_source = DATA_SOURCE_MEMORY;
|
|
|
|
else if (devc->model->protocol == PROTOCOL_IEEE488_2
|
|
|
|
&& !strcmp(tmp_str, "Segmented"))
|
|
|
|
devc->data_source = DATA_SOURCE_SEGMENTED;
|
|
|
|
else
|
|
|
|
return SR_ERR;
|
|
|
|
break;
|
2012-12-29 21:22:10 +00:00
|
|
|
default:
|
2013-04-16 00:33:03 +00:00
|
|
|
ret = SR_ERR_NA;
|
2013-01-03 18:04:11 +00:00
|
|
|
break;
|
2012-12-29 21:22:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-20 00:00:49 +00:00
|
|
|
static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
|
|
|
|
const struct sr_probe_group *probe_group)
|
2013-01-25 01:32:05 +00:00
|
|
|
{
|
2013-04-07 19:51:26 +00:00
|
|
|
GVariant *tuple, *rational[2];
|
|
|
|
GVariantBuilder gvb;
|
|
|
|
unsigned int i;
|
2013-11-01 21:32:33 +00:00
|
|
|
struct dev_context *devc = NULL;
|
|
|
|
|
|
|
|
if (sdi)
|
|
|
|
devc = sdi->priv;
|
2013-04-20 00:00:49 +00:00
|
|
|
|
2013-04-28 20:11:43 +00:00
|
|
|
if (key == SR_CONF_SCAN_OPTIONS) {
|
2013-04-22 13:59:55 +00:00
|
|
|
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
|
|
|
|
hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t));
|
2013-04-28 20:11:43 +00:00
|
|
|
return SR_OK;
|
|
|
|
} else if (key == SR_CONF_DEVICE_OPTIONS && probe_group == NULL) {
|
|
|
|
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
|
|
|
|
hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Every other option requires a valid device instance. */
|
|
|
|
if (!sdi || !(devc = sdi->priv))
|
|
|
|
return SR_ERR_ARG;
|
|
|
|
|
2013-11-03 13:13:59 +00:00
|
|
|
/* If a probe group is specified, it must be a valid one. */
|
|
|
|
if (probe_group) {
|
|
|
|
if (probe_group != &devc->analog_groups[0]
|
|
|
|
&& probe_group != &devc->analog_groups[1]) {
|
|
|
|
sr_err("Invalid probe group specified.");
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-28 20:11:43 +00:00
|
|
|
switch (key) {
|
2013-04-22 13:59:55 +00:00
|
|
|
break;
|
2013-01-25 14:01:49 +00:00
|
|
|
case SR_CONF_DEVICE_OPTIONS:
|
2013-11-03 13:13:59 +00:00
|
|
|
if (!probe_group) {
|
|
|
|
sr_err("No probe group specified.");
|
|
|
|
return SR_ERR_PROBE_GROUP;
|
|
|
|
}
|
2013-04-28 20:11:43 +00:00
|
|
|
if (probe_group == &devc->digital_group) {
|
2013-04-21 13:48:56 +00:00
|
|
|
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
|
|
|
|
NULL, 0, sizeof(int32_t));
|
|
|
|
return SR_OK;
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (probe_group == &devc->analog_groups[i]) {
|
|
|
|
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
|
|
|
|
analog_hwcaps, ARRAY_SIZE(analog_hwcaps), sizeof(int32_t));
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SR_ERR_NA;
|
|
|
|
}
|
2013-11-03 13:15:35 +00:00
|
|
|
break;
|
2013-01-25 10:04:27 +00:00
|
|
|
case SR_CONF_COUPLING:
|
2013-11-03 13:13:59 +00:00
|
|
|
if (!probe_group) {
|
|
|
|
sr_err("No probe group specified.");
|
|
|
|
return SR_ERR_PROBE_GROUP;
|
2013-04-21 13:48:56 +00:00
|
|
|
}
|
2013-11-03 13:16:10 +00:00
|
|
|
*data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling));
|
|
|
|
break;
|
2013-01-25 10:13:49 +00:00
|
|
|
case SR_CONF_VDIV:
|
2013-11-01 21:32:33 +00:00
|
|
|
if (!devc)
|
|
|
|
/* Can't know this until we have the exact model. */
|
|
|
|
return SR_ERR_ARG;
|
2013-11-03 13:13:59 +00:00
|
|
|
if (!probe_group) {
|
|
|
|
sr_err("No probe group specified.");
|
|
|
|
return SR_ERR_PROBE_GROUP;
|
2013-04-07 19:51:26 +00:00
|
|
|
}
|
2013-11-03 13:16:10 +00:00
|
|
|
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
|
2013-11-01 11:05:49 +00:00
|
|
|
for (i = 0; i < devc->num_vdivs; i++) {
|
|
|
|
rational[0] = g_variant_new_uint64(devc->vdivs[i][0]);
|
|
|
|
rational[1] = g_variant_new_uint64(devc->vdivs[i][1]);
|
2013-11-03 13:16:10 +00:00
|
|
|
tuple = g_variant_new_tuple(rational, 2);
|
|
|
|
g_variant_builder_add_value(&gvb, tuple);
|
|
|
|
}
|
|
|
|
*data = g_variant_builder_end(&gvb);
|
|
|
|
break;
|
2013-01-25 10:22:20 +00:00
|
|
|
case SR_CONF_TIMEBASE:
|
2013-11-01 21:32:33 +00:00
|
|
|
if (!devc)
|
|
|
|
/* Can't know this until we have the exact model. */
|
|
|
|
return SR_ERR_ARG;
|
2013-04-07 19:51:26 +00:00
|
|
|
g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
|
2013-11-01 11:05:49 +00:00
|
|
|
for (i = 0; i < devc->num_timebases; i++) {
|
|
|
|
rational[0] = g_variant_new_uint64(devc->timebases[i][0]);
|
|
|
|
rational[1] = g_variant_new_uint64(devc->timebases[i][1]);
|
2013-04-07 19:51:26 +00:00
|
|
|
tuple = g_variant_new_tuple(rational, 2);
|
|
|
|
g_variant_builder_add_value(&gvb, tuple);
|
|
|
|
}
|
|
|
|
*data = g_variant_builder_end(&gvb);
|
2013-01-25 10:22:20 +00:00
|
|
|
break;
|
2013-01-25 10:25:32 +00:00
|
|
|
case SR_CONF_TRIGGER_SOURCE:
|
2013-11-01 21:32:33 +00:00
|
|
|
if (!devc)
|
|
|
|
/* Can't know this until we have the exact model. */
|
|
|
|
return SR_ERR_ARG;
|
2013-03-31 19:25:51 +00:00
|
|
|
*data = g_variant_new_strv(trigger_sources,
|
2013-11-01 11:05:49 +00:00
|
|
|
devc->model->has_digital ? ARRAY_SIZE(trigger_sources) : 4);
|
2013-01-25 10:25:32 +00:00
|
|
|
break;
|
2013-11-29 00:14:54 +00:00
|
|
|
case SR_CONF_DATA_SOURCE:
|
|
|
|
if (!devc)
|
|
|
|
/* Can't know this until we have the exact model. */
|
|
|
|
return SR_ERR_ARG;
|
|
|
|
/* This needs tweaking by series/model! */
|
|
|
|
if (devc->model->series == RIGOL_DS2000)
|
|
|
|
*data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
|
|
|
|
else
|
|
|
|
*data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources) - 1);
|
|
|
|
break;
|
2013-01-25 01:32:05 +00:00
|
|
|
default:
|
2013-04-16 00:33:03 +00:00
|
|
|
return SR_ERR_NA;
|
2013-01-25 01:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-11 14:06:55 +00:00
|
|
|
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
|
2012-12-29 21:22:10 +00:00
|
|
|
{
|
2013-12-03 23:19:40 +00:00
|
|
|
struct sr_scpi_dev_inst *scpi;
|
2013-01-03 18:04:11 +00:00
|
|
|
struct dev_context *devc;
|
2013-04-11 14:06:55 +00:00
|
|
|
struct sr_probe *probe;
|
|
|
|
GSList *l;
|
|
|
|
char cmd[256];
|
2013-01-03 18:04:11 +00:00
|
|
|
|
2013-04-23 13:14:42 +00:00
|
|
|
if (sdi->status != SR_ST_ACTIVE)
|
|
|
|
return SR_ERR_DEV_CLOSED;
|
2012-12-30 03:17:56 +00:00
|
|
|
|
2013-12-03 23:19:40 +00:00
|
|
|
scpi = sdi->conn;
|
2013-01-03 18:04:11 +00:00
|
|
|
devc = sdi->priv;
|
|
|
|
|
2013-11-29 00:14:54 +00:00
|
|
|
if (devc->data_source == DATA_SOURCE_LIVE) {
|
2013-12-04 10:25:15 +00:00
|
|
|
if (sr_scpi_send(sdi->conn, ":RUN") != SR_OK)
|
2013-11-29 00:14:54 +00:00
|
|
|
return SR_ERR;
|
|
|
|
} else if (devc->data_source == DATA_SOURCE_MEMORY) {
|
|
|
|
if (devc->model->series != RIGOL_DS2000) {
|
|
|
|
sr_err("Data source 'Memory' not supported for this device");
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
} else if (devc->data_source == DATA_SOURCE_SEGMENTED) {
|
|
|
|
sr_err("Data source 'Segmented' not yet supported");
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
2013-04-11 14:06:55 +00:00
|
|
|
for (l = sdi->probes; l; l = l->next) {
|
|
|
|
probe = l->data;
|
2013-04-14 01:21:55 +00:00
|
|
|
sr_dbg("handling probe %s", probe->name);
|
|
|
|
if (probe->type == SR_PROBE_ANALOG) {
|
|
|
|
if (probe->enabled)
|
|
|
|
devc->enabled_analog_probes = g_slist_append(
|
|
|
|
devc->enabled_analog_probes, probe);
|
|
|
|
if (probe->enabled != devc->analog_channels[probe->index]) {
|
|
|
|
/* Enabled channel is currently disabled, or vice versa. */
|
|
|
|
sprintf(cmd, ":CHAN%d:DISP %s", probe->index + 1,
|
|
|
|
probe->enabled ? "ON" : "OFF");
|
2013-12-04 10:25:15 +00:00
|
|
|
if (sr_scpi_send(sdi->conn, cmd) != SR_OK)
|
2013-04-14 01:21:55 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
} else if (probe->type == SR_PROBE_LOGIC) {
|
|
|
|
if (probe->enabled)
|
|
|
|
devc->enabled_digital_probes = g_slist_append(
|
|
|
|
devc->enabled_digital_probes, probe);
|
|
|
|
if (probe->enabled != devc->digital_channels[probe->index]) {
|
|
|
|
/* Enabled channel is currently disabled, or vice versa. */
|
|
|
|
sprintf(cmd, ":DIG%d:TURN %s", probe->index,
|
|
|
|
probe->enabled ? "ON" : "OFF");
|
2013-12-04 10:25:15 +00:00
|
|
|
if (sr_scpi_send(sdi->conn, cmd) != SR_OK)
|
2013-04-14 01:21:55 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
2013-04-11 14:06:55 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-14 01:21:55 +00:00
|
|
|
if (!devc->enabled_analog_probes && !devc->enabled_digital_probes)
|
2013-04-11 14:06:55 +00:00
|
|
|
return SR_ERR;
|
2012-12-30 03:17:56 +00:00
|
|
|
|
2013-12-03 23:19:40 +00:00
|
|
|
sr_scpi_source_add(scpi, G_IO_IN, 50, rigol_ds_receive, (void *)sdi);
|
2012-12-30 03:17:56 +00:00
|
|
|
|
|
|
|
/* Send header packet to the session bus. */
|
2013-05-03 19:59:32 +00:00
|
|
|
std_session_send_df_header(cb_data, LOG_PREFIX);
|
2012-12-30 03:17:56 +00:00
|
|
|
|
2013-11-29 00:14:54 +00:00
|
|
|
if (devc->model->protocol == PROTOCOL_LEGACY) {
|
2013-11-01 11:05:49 +00:00
|
|
|
/* Fetch the first frame. */
|
|
|
|
if (devc->enabled_analog_probes) {
|
2013-11-29 00:14:54 +00:00
|
|
|
devc->analog_frame_size = DS1000_ANALOG_LIVE_WAVEFORM_SIZE;
|
2013-11-01 11:05:49 +00:00
|
|
|
devc->channel_frame = devc->enabled_analog_probes->data;
|
2013-12-04 10:25:15 +00:00
|
|
|
if (sr_scpi_send(sdi->conn, ":WAV:DATA? CHAN%d",
|
2013-11-01 11:05:49 +00:00
|
|
|
devc->channel_frame->index + 1) != SR_OK)
|
|
|
|
return SR_ERR;
|
|
|
|
} else {
|
|
|
|
devc->channel_frame = devc->enabled_digital_probes->data;
|
2013-12-04 10:25:15 +00:00
|
|
|
if (sr_scpi_send(sdi->conn, ":WAV:DATA? DIG") != SR_OK)
|
2013-11-01 11:05:49 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
devc->num_frame_bytes = 0;
|
2013-04-14 01:21:55 +00:00
|
|
|
} else {
|
2013-11-01 11:05:49 +00:00
|
|
|
if (devc->enabled_analog_probes) {
|
2013-11-29 00:14:54 +00:00
|
|
|
if (devc->data_source == DATA_SOURCE_MEMORY)
|
|
|
|
{
|
|
|
|
if (g_slist_length(devc->enabled_analog_probes) == 1)
|
|
|
|
devc->analog_frame_size = DS2000_ANALOG_MEM_WAVEFORM_SIZE_1C;
|
|
|
|
else
|
|
|
|
devc->analog_frame_size = DS2000_ANALOG_MEM_WAVEFORM_SIZE_2C;
|
|
|
|
/* Apparently for the DS2000 the memory
|
|
|
|
* depth can only be set in Running state -
|
|
|
|
* this matches the behaviour of the UI. */
|
2013-12-04 10:25:15 +00:00
|
|
|
if (sr_scpi_send(sdi->conn, ":RUN") != SR_OK)
|
2013-11-29 00:14:54 +00:00
|
|
|
return SR_ERR;
|
2013-12-04 10:25:15 +00:00
|
|
|
if (sr_scpi_send(sdi->conn, "ACQ:MDEP %d", devc->analog_frame_size) != SR_OK)
|
2013-11-29 00:14:54 +00:00
|
|
|
return SR_ERR;
|
2013-12-04 10:25:15 +00:00
|
|
|
if (sr_scpi_send(sdi->conn, ":STOP") != SR_OK)
|
2013-11-29 00:14:54 +00:00
|
|
|
return SR_ERR;
|
|
|
|
} else
|
|
|
|
devc->analog_frame_size = DS2000_ANALOG_LIVE_WAVEFORM_SIZE;
|
2013-11-07 23:13:30 +00:00
|
|
|
devc->channel_frame = devc->enabled_analog_probes->data;
|
2013-11-29 00:14:54 +00:00
|
|
|
if (rigol_ds_capture_start(sdi) != SR_OK)
|
2013-11-01 11:05:49 +00:00
|
|
|
return SR_ERR;
|
|
|
|
}
|
2013-04-14 01:21:55 +00:00
|
|
|
}
|
2012-12-29 21:22:10 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-11 14:06:55 +00:00
|
|
|
static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
|
2012-12-29 21:22:10 +00:00
|
|
|
{
|
2013-01-03 18:04:11 +00:00
|
|
|
struct dev_context *devc;
|
2013-12-03 23:19:40 +00:00
|
|
|
struct sr_scpi_dev_inst *scpi;
|
2013-01-03 18:04:11 +00:00
|
|
|
|
2012-12-29 21:22:10 +00:00
|
|
|
(void)cb_data;
|
|
|
|
|
2013-01-03 18:04:11 +00:00
|
|
|
devc = sdi->priv;
|
|
|
|
|
2012-12-29 21:22:10 +00:00
|
|
|
if (sdi->status != SR_ST_ACTIVE) {
|
|
|
|
sr_err("Device inactive, can't stop acquisition.");
|
|
|
|
return SR_ERR;
|
|
|
|
}
|
|
|
|
|
2013-04-14 01:21:55 +00:00
|
|
|
g_slist_free(devc->enabled_analog_probes);
|
|
|
|
g_slist_free(devc->enabled_digital_probes);
|
|
|
|
devc->enabled_analog_probes = NULL;
|
|
|
|
devc->enabled_digital_probes = NULL;
|
2013-12-03 23:19:40 +00:00
|
|
|
scpi = sdi->conn;
|
|
|
|
sr_scpi_source_remove(scpi);
|
2012-12-29 21:22:10 +00:00
|
|
|
|
|
|
|
return SR_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-31 17:31:39 +00:00
|
|
|
SR_PRIV struct sr_dev_driver rigol_ds_driver_info = {
|
|
|
|
.name = "rigol-ds",
|
|
|
|
.longname = "Rigol DS",
|
2012-12-29 21:22:10 +00:00
|
|
|
.api_version = 1,
|
2013-05-10 17:37:54 +00:00
|
|
|
.init = init,
|
|
|
|
.cleanup = cleanup,
|
|
|
|
.scan = scan,
|
|
|
|
.dev_list = dev_list,
|
2013-05-31 14:09:57 +00:00
|
|
|
.dev_clear = dev_clear,
|
2013-04-07 22:37:12 +00:00
|
|
|
.config_get = config_get,
|
2013-01-24 18:19:09 +00:00
|
|
|
.config_set = config_set,
|
2013-01-25 01:32:05 +00:00
|
|
|
.config_list = config_list,
|
2013-05-10 17:37:54 +00:00
|
|
|
.dev_open = dev_open,
|
|
|
|
.dev_close = dev_close,
|
2013-04-11 14:06:55 +00:00
|
|
|
.dev_acquisition_start = dev_acquisition_start,
|
|
|
|
.dev_acquisition_stop = dev_acquisition_stop,
|
2012-12-29 21:22:10 +00:00
|
|
|
.priv = NULL,
|
|
|
|
};
|