From: Frank Stettner Date: Sat, 6 Apr 2019 22:03:49 +0000 (+0200) Subject: korad-kaxxxxp: Send META packet when states have changed. X-Git-Url: https://sigrok.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=2e129b8b25dc18d6fff17e7f0b572dec3a7c0c3c;hp=8da30037cf8cf0fedb8e87cba9ca56189ed7df5f;p=libsigrok.git korad-kaxxxxp: Send META packet when states have changed. --- diff --git a/src/hardware/korad-kaxxxxp/api.c b/src/hardware/korad-kaxxxxp/api.c index 268de9f6..297da9ad 100644 --- a/src/hardware/korad-kaxxxxp/api.c +++ b/src/hardware/korad-kaxxxxp/api.c @@ -2,7 +2,7 @@ * This file is part of the libsigrok project. * * Copyright (C) 2015 Hannu Vuolasaho - * Copyright (C) 2018 Frank Stettner + * Copyright (C) 2018-2019 Frank Stettner * * 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. */ diff --git a/src/hardware/korad-kaxxxxp/protocol.c b/src/hardware/korad-kaxxxxp/protocol.c index bcda4633..9bd548e4 100644 --- a/src/hardware/korad-kaxxxxp/protocol.c +++ b/src/hardware/korad-kaxxxxp/protocol.c @@ -2,7 +2,7 @@ * This file is part of the libsigrok project. * * Copyright (C) 2015 Hannu Vuolasaho - * Copyright (C) 2018 Frank Stettner + * Copyright (C) 2018-2019 Frank Stettner * * 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); diff --git a/src/hardware/korad-kaxxxxp/protocol.h b/src/hardware/korad-kaxxxxp/protocol.h index f2f13570..8c86c901 100644 --- a/src/hardware/korad-kaxxxxp/protocol.h +++ b/src/hardware/korad-kaxxxxp/protocol.h @@ -2,7 +2,7 @@ * This file is part of the libsigrok project. * * Copyright (C) 2015 Hannu Vuolasaho - * Copyright (C) 2018 Frank Stettner + * Copyright (C) 2018-2019 Frank Stettner * * 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. */