]> sigrok.org Git - libsigrok.git/commitdiff
lecroy-xstream: Implement config_channel_set API callback
authorSoeren Apel <redacted>
Tue, 3 Oct 2017 15:07:27 +0000 (17:07 +0200)
committerSoeren Apel <redacted>
Tue, 3 Oct 2017 15:31:48 +0000 (17:31 +0200)
src/hardware/lecroy-xstream/api.c
src/hardware/lecroy-xstream/protocol.c
src/hardware/lecroy-xstream/protocol.h

index 6b4842ba3b6786441b216fea0e5649ec410bda1c..8d4fe0b291eb775189535e9f8124083146d295cd 100644 (file)
@@ -302,6 +302,16 @@ static int config_set(uint32_t key, GVariant *data,
        return ret;
 }
 
+static int config_channel_set(const struct sr_dev_inst *sdi,
+       struct sr_channel *ch, unsigned int changes)
+{
+       /* Currently we only handle SR_CHANNEL_SET_ENABLED. */
+       if (changes != SR_CHANNEL_SET_ENABLED)
+               return SR_ERR_NA;
+
+       return lecroy_xstream_channel_state_set(sdi, ch->index, ch->enabled);
+}
+
 static int config_list(uint32_t key, GVariant **data,
                const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
@@ -497,6 +507,7 @@ static struct sr_dev_driver lecroy_xstream_driver_info = {
        .dev_clear = dev_clear,
        .config_get = config_get,
        .config_set = config_set,
+       .config_channel_set = config_channel_set,
        .config_list = config_list,
        .dev_open = dev_open,
        .dev_close = dev_close,
index 1d0c37e0bcf62da55d61ed127f28e1c83b71f664..f1f69fc5d40e192cbbe3cc4914ec9b73a1fe2910 100644 (file)
@@ -318,6 +318,54 @@ static int analog_channel_state_get(struct sr_scpi_dev_inst *scpi,
        return SR_OK;
 }
 
+SR_PRIV int lecroy_xstream_channel_state_set(const struct sr_dev_inst *sdi,
+               const int ch_index, gboolean ch_state)
+{
+       GSList *l;
+       struct sr_channel *ch;
+       struct dev_context *devc = NULL;
+       struct scope_state *state;
+       char command[MAX_COMMAND_SIZE];
+       gboolean chan_found;
+       int result;
+
+       result = SR_OK;
+
+       devc = sdi->priv;
+       state = devc->model_state;
+       chan_found = FALSE;
+
+       for (l = sdi->channels; l; l = l->next) {
+               ch = l->data;
+
+               switch (ch->type) {
+               case SR_CHANNEL_ANALOG:
+                       if (ch->index == ch_index) {
+                               g_snprintf(command, sizeof(command), "C%d:TRACE %s", ch_index + 1,
+                                               (ch_state ? "ON" : "OFF"));
+                               if ((sr_scpi_send(sdi->conn, command) != SR_OK ||
+                                               sr_scpi_get_opc(sdi->conn) != SR_OK)) {
+                                       result = SR_ERR;
+                                       break;
+                               }
+
+                               ch->enabled = ch_state;
+                               state->analog_channels[ch->index].state = ch_state;
+                               chan_found = TRUE;
+                               break;
+                       }
+                       break;
+               default:
+                       result = SR_ERR_NA;
+               }
+       }
+
+       if ((result == SR_OK) && !chan_found)
+               result = SR_ERR_BUG;
+
+       return result;
+}
+
 SR_PRIV int lecroy_xstream_update_sample_rate(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
index fa68f71f311fdf19a9547df635db2ab08fbbe1e8..0b8d9e59edba9a3fa2ee56ecd5b92d02d710bf81 100644 (file)
@@ -96,6 +96,8 @@ SR_PRIV int lecroy_xstream_receive_data(int fd, int revents, void *cb_data);
 
 SR_PRIV void lecroy_xstream_state_free(struct scope_state *state);
 SR_PRIV int lecroy_xstream_state_get(struct sr_dev_inst *sdi);
+SR_PRIV int lecroy_xstream_channel_state_set(const struct sr_dev_inst *sdi,
+               const int ch_index, gboolean ch_state);
 SR_PRIV int lecroy_xstream_update_sample_rate(const struct sr_dev_inst *sdi);
 
 #endif