]> sigrok.org Git - libsigrok.git/commitdiff
korad-kaxxxxp: Send META packet when states have changed.
authorFrank Stettner <redacted>
Sat, 6 Apr 2019 22:03:49 +0000 (00:03 +0200)
committerUwe Hermann <redacted>
Mon, 16 Dec 2019 14:42:49 +0000 (15:42 +0100)
src/hardware/korad-kaxxxxp/api.c
src/hardware/korad-kaxxxxp/protocol.c
src/hardware/korad-kaxxxxp/protocol.h

index 268de9f6b934e25ed6eec5e90a738170f588c8ec..297da9ad078b3635c9d73e22e5c39b6e090aac8d 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the libsigrok project.
  *
  * Copyright (C) 2015 Hannu Vuolasaho <vuokkosetae@gmail.com>
- * Copyright (C) 2018 Frank Stettner <frank-stettner@gmx.net>
+ * Copyright (C) 2018-2019 Frank Stettner <frank-stettner@gmx.net>
  *
  * 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
@@ -160,6 +160,11 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        g_mutex_init(&devc->rw_mutex);
        devc->model = &models[model_id];
        devc->req_sent_at = 0;
+       devc->cc_mode_1_changed = FALSE;
+       devc->cc_mode_2_changed = FALSE;
+       devc->output_enabled_changed = FALSE;
+       devc->ocp_enabled_changed = FALSE;
+       devc->ovp_enabled_changed = FALSE;
        sdi->priv = devc;
 
        /* Get current status of device. */
index bcda463379f4d2030ba9a9e5c05f68ab2c77da45..9bd548e4900936bfba901181c343781c63444f0f 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the libsigrok project.
  *
  * Copyright (C) 2015 Hannu Vuolasaho <vuokkosetae@gmail.com>
- * Copyright (C) 2018 Frank Stettner <frank-stettner@gmx.net>
+ * Copyright (C) 2018-2019 Frank Stettner <frank-stettner@gmx.net>
  *
  * 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
@@ -172,6 +172,7 @@ SR_PRIV int korad_kaxxxxp_get_value(struct sr_serial_dev_inst *serial,
        char reply[6];
        float *value;
        char status_byte;
+       gboolean prev_status;
 
        g_mutex_lock(&devc->rw_mutex);
        give_device_time_to_process(devc);
@@ -229,20 +230,42 @@ SR_PRIV int korad_kaxxxxp_get_value(struct sr_serial_dev_inst *serial,
        } else {
                /* We have status reply. */
                status_byte = reply[0];
-               /* Constant current */
-               devc->cc_mode[0] = !(status_byte & (1 << 0)); /* Channel one */
-               devc->cc_mode[1] = !(status_byte & (1 << 1)); /* Channel two */
+
+               /* Constant current channel one. */
+               prev_status = devc->cc_mode[0];
+               devc->cc_mode[0] = !(status_byte & (1 << 0));
+               devc->cc_mode_1_changed = devc->cc_mode[0] != prev_status;
+               /* Constant current channel two. */
+               prev_status = devc->cc_mode[1];
+               devc->cc_mode[1] = !(status_byte & (1 << 1));
+               devc->cc_mode_2_changed = devc->cc_mode[1] != prev_status;
+
                /*
-                * Tracking
+                * Tracking:
                 * status_byte & ((1 << 2) | (1 << 3))
                 * 00 independent 01 series 11 parallel
                 */
-               devc->beep_enabled = (1 << 4);
-               devc->ocp_enabled = (status_byte & (1 << 5));
-               devc->output_enabled = (status_byte & (1 << 6));
-               /* Velleman LABPS3005 quirk */
-               if (devc->output_enabled)
-                       devc->ovp_enabled = (status_byte & (1 << 7));
+               devc->beep_enabled = status_byte & (1 << 4);
+
+               /* OCP enabled. */
+               prev_status = devc->ocp_enabled;
+               devc->ocp_enabled = status_byte & (1 << 5);
+               devc->ocp_enabled_changed = devc->ocp_enabled != prev_status;
+
+               /* Output status. */
+               prev_status = devc->output_enabled;
+               devc->output_enabled = status_byte & (1 << 6);
+               devc->output_enabled_changed = devc->output_enabled != prev_status;
+
+               /* OVP enabled, special handling for Velleman LABPS3005 quirk. */
+               if ((devc->model->model_id == VELLEMAN_LABPS3005D && devc->output_enabled) ||
+                       devc->model->model_id != VELLEMAN_LABPS3005D) {
+
+                       prev_status = devc->ovp_enabled;
+                       devc->ovp_enabled = status_byte & (1 << 7);
+                       devc->ovp_enabled_changed = devc->ovp_enabled != prev_status;
+               }
+
                sr_dbg("Status: 0x%02x", status_byte);
                sr_spew("Status: CH1: constant %s CH2: constant %s. "
                        "Tracking would be %s. Device is "
@@ -354,6 +377,32 @@ SR_PRIV int korad_kaxxxxp_receive_data(int fd, int revents, void *cb_data)
                analog.data = &devc->voltage;
                sr_session_send(sdi, &packet);
                sr_sw_limits_update_samples_read(&devc->limits, 1);
+       } else if (devc->acquisition_target == KAXXXXP_STATUS) {
+               if (devc->cc_mode_1_changed) {
+                       sr_session_send_meta(sdi, SR_CONF_REGULATION,
+                               g_variant_new_string((devc->cc_mode[0]) ? "CC" : "CV"));
+                       devc->cc_mode_1_changed = FALSE;
+               }
+               if (devc->cc_mode_2_changed) {
+                       sr_session_send_meta(sdi, SR_CONF_REGULATION,
+                               g_variant_new_string((devc->cc_mode[1]) ? "CC" : "CV"));
+                       devc->cc_mode_2_changed = FALSE;
+               }
+               if (devc->output_enabled_changed) {
+                       sr_session_send_meta(sdi, SR_CONF_ENABLED,
+                               g_variant_new_boolean(devc->output_enabled));
+                       devc->output_enabled_changed = FALSE;
+               }
+               if (devc->ocp_enabled_changed) {
+                       sr_session_send_meta(sdi, SR_CONF_OVER_CURRENT_PROTECTION_ENABLED,
+                               g_variant_new_boolean(devc->ocp_enabled));
+                       devc->ocp_enabled_changed = FALSE;
+               }
+               if (devc->ovp_enabled_changed) {
+                       sr_session_send_meta(sdi, SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED,
+                               g_variant_new_boolean(devc->ovp_enabled));
+                       devc->ovp_enabled_changed = FALSE;
+               }
        }
        next_measurement(devc);
 
index f2f135707f156fa6088b1fd7ee34267d20866073..8c86c901f89041659d936883282e41f5b8e0bb16 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the libsigrok project.
  *
  * Copyright (C) 2015 Hannu Vuolasaho <vuokkosetae@gmail.com>
- * Copyright (C) 2018 Frank Stettner <frank-stettner@gmx.net>
+ * Copyright (C) 2018-2019 Frank Stettner <frank-stettner@gmx.net>
  *
  * 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
@@ -92,6 +92,12 @@ struct dev_context {
        gboolean ocp_enabled;    /**< Output current protection enabled. */
        gboolean ovp_enabled;    /**< Output voltage protection enabled. */
 
+       gboolean cc_mode_1_changed;      /**< CC mode of channel 1 has changed. */
+       gboolean cc_mode_2_changed;      /**< CC mode of channel 2 has changed. */
+       gboolean output_enabled_changed; /**< Output enabled state has changed. */
+       gboolean ocp_enabled_changed;    /**< OCP enabled state has changed. */
+       gboolean ovp_enabled_changed;    /**< OVP enabled state has changed. */
+
        int acquisition_target;  /**< What reply to expect. */
        int program;             /**< Program to store or recall. */