]> sigrok.org Git - libsigrok.git/commitdiff
rdtech-dps: Send META package when states have changed.
authorFrank Stettner <redacted>
Wed, 22 May 2019 13:40:08 +0000 (15:40 +0200)
committerUwe Hermann <redacted>
Mon, 16 Dec 2019 14:38:58 +0000 (15:38 +0100)
src/hardware/rdtech-dps/api.c
src/hardware/rdtech-dps/protocol.c
src/hardware/rdtech-dps/protocol.h

index 50025e6de3ca3eeb27e8a8948bd53f11df9a1267..9a08c792a35cd4fc6ab8f838bd8a0a519b78b275 100644 (file)
@@ -298,11 +298,21 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
        struct sr_modbus_dev_inst *modbus;
+       uint16_t registers[3];
        int ret;
 
        modbus = sdi->conn;
        devc = sdi->priv;
 
+       /* Prefill actual states */
+       ret = rdtech_dps_read_holding_registers(modbus, REG_PROTECT, 3, registers);
+       if (ret != SR_OK)
+               return ret;
+       devc->actual_ovp_state = RB16(registers + 0) == STATE_OVP;
+       devc->actual_ocp_state = RB16(registers + 0) == STATE_OCP;
+       devc->actual_regulation_state = RB16(registers + 1);
+       devc->actual_output_state = RB16(registers + 2);
+
        if ((ret = sr_modbus_source_add(sdi->session, modbus, G_IO_IN, 10,
                        rdtech_dps_receive_data, (void *)sdi)) != SR_OK)
                return ret;
index 6f1d48670b62b87288e601e5c99b5dab4b0cdc44..77cc0a0851070608dd847dc02dd9640647a38ebf 100644 (file)
@@ -121,7 +121,7 @@ SR_PRIV int rdtech_dps_receive_data(int fd, int revents, void *cb_data)
        struct dev_context *devc;
        struct sr_modbus_dev_inst *modbus;
        struct sr_datafeed_packet packet;
-       uint16_t registers[3];
+       uint16_t registers[8];
        int ret;
 
        (void)fd;
@@ -138,10 +138,11 @@ SR_PRIV int rdtech_dps_receive_data(int fd, int revents, void *cb_data)
         * Using the libsigrok function here, because it doesn't matter if the
         * reading fails. It will be done again in the next acquision cycle anyways.
         */
-       ret = sr_modbus_read_holding_registers(modbus, REG_UOUT, 3, registers);
+       ret = sr_modbus_read_holding_registers(modbus, REG_UOUT, 8, registers);
        g_mutex_unlock(&devc->rw_mutex);
 
        if (ret == SR_OK) {
+               /* Send channel values */
                packet.type = SR_DF_FRAME_BEGIN;
                sr_session_send(sdi, &packet);
 
@@ -159,6 +160,30 @@ SR_PRIV int rdtech_dps_receive_data(int fd, int revents, void *cb_data)
 
                packet.type = SR_DF_FRAME_END;
                sr_session_send(sdi, &packet);
+
+               /* Check for state changes */
+               if (devc->actual_ovp_state != (RB16(registers + 5) == STATE_OVP)) {
+                       devc->actual_ovp_state = RB16(registers + 5) == STATE_OVP;
+                       sr_session_send_meta(sdi, SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE,
+                               g_variant_new_boolean(devc->actual_ovp_state));
+               }
+               if (devc->actual_ocp_state != (RB16(registers + 5) == STATE_OCP)) {
+                       devc->actual_ocp_state = RB16(registers + 5) == STATE_OCP;
+                       sr_session_send_meta(sdi, SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE,
+                               g_variant_new_boolean(devc->actual_ocp_state));
+               }
+               if (devc->actual_regulation_state != RB16(registers + 6)) {
+                       devc->actual_regulation_state = RB16(registers + 6);
+                       sr_session_send_meta(sdi, SR_CONF_REGULATION,
+                               g_variant_new_string(
+                                       devc->actual_regulation_state == MODE_CC ? "CC" : "CV"));
+               }
+               if (devc->actual_output_state != RB16(registers + 7)) {
+                       devc->actual_output_state = RB16(registers + 7);
+                       sr_session_send_meta(sdi, SR_CONF_ENABLED,
+                               g_variant_new_boolean(devc->actual_output_state));
+               }
+
                sr_sw_limits_update_samples_read(&devc->limits, 1);
        }
 
index 266ec582580c5854da94fce1a33914ea8fa6c553..d6619e5301321d109b68e3daa5156697a134e3d4 100644 (file)
@@ -44,6 +44,10 @@ struct dev_context {
        GMutex rw_mutex;
        double current_multiplier;
        double voltage_multiplier;
+       gboolean actual_ovp_state;
+       gboolean actual_ocp_state;
+       uint16_t actual_regulation_state;
+       uint16_t actual_output_state;
 };
 
 enum rdtech_dps_register {