korad-kaxxxxp: Send META packet when states have changed.
This commit is contained in:
parent
8da30037cf
commit
2e129b8b25
|
@ -2,7 +2,7 @@
|
||||||
* This file is part of the libsigrok project.
|
* This file is part of the libsigrok project.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Hannu Vuolasaho <vuokkosetae@gmail.com>
|
* 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
|
* 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
|
* 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);
|
g_mutex_init(&devc->rw_mutex);
|
||||||
devc->model = &models[model_id];
|
devc->model = &models[model_id];
|
||||||
devc->req_sent_at = 0;
|
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;
|
sdi->priv = devc;
|
||||||
|
|
||||||
/* Get current status of device. */
|
/* Get current status of device. */
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* This file is part of the libsigrok project.
|
* This file is part of the libsigrok project.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Hannu Vuolasaho <vuokkosetae@gmail.com>
|
* 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
|
* 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
|
* 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];
|
char reply[6];
|
||||||
float *value;
|
float *value;
|
||||||
char status_byte;
|
char status_byte;
|
||||||
|
gboolean prev_status;
|
||||||
|
|
||||||
g_mutex_lock(&devc->rw_mutex);
|
g_mutex_lock(&devc->rw_mutex);
|
||||||
give_device_time_to_process(devc);
|
give_device_time_to_process(devc);
|
||||||
|
@ -229,20 +230,42 @@ SR_PRIV int korad_kaxxxxp_get_value(struct sr_serial_dev_inst *serial,
|
||||||
} else {
|
} else {
|
||||||
/* We have status reply. */
|
/* We have status reply. */
|
||||||
status_byte = reply[0];
|
status_byte = reply[0];
|
||||||
/* Constant current */
|
|
||||||
devc->cc_mode[0] = !(status_byte & (1 << 0)); /* Channel one */
|
/* Constant current channel one. */
|
||||||
devc->cc_mode[1] = !(status_byte & (1 << 1)); /* Channel two */
|
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))
|
* status_byte & ((1 << 2) | (1 << 3))
|
||||||
* 00 independent 01 series 11 parallel
|
* 00 independent 01 series 11 parallel
|
||||||
*/
|
*/
|
||||||
devc->beep_enabled = (1 << 4);
|
devc->beep_enabled = status_byte & (1 << 4);
|
||||||
devc->ocp_enabled = (status_byte & (1 << 5));
|
|
||||||
devc->output_enabled = (status_byte & (1 << 6));
|
/* OCP enabled. */
|
||||||
/* Velleman LABPS3005 quirk */
|
prev_status = devc->ocp_enabled;
|
||||||
if (devc->output_enabled)
|
devc->ocp_enabled = status_byte & (1 << 5);
|
||||||
devc->ovp_enabled = (status_byte & (1 << 7));
|
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_dbg("Status: 0x%02x", status_byte);
|
||||||
sr_spew("Status: CH1: constant %s CH2: constant %s. "
|
sr_spew("Status: CH1: constant %s CH2: constant %s. "
|
||||||
"Tracking would be %s. Device is "
|
"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;
|
analog.data = &devc->voltage;
|
||||||
sr_session_send(sdi, &packet);
|
sr_session_send(sdi, &packet);
|
||||||
sr_sw_limits_update_samples_read(&devc->limits, 1);
|
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);
|
next_measurement(devc);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* This file is part of the libsigrok project.
|
* This file is part of the libsigrok project.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Hannu Vuolasaho <vuokkosetae@gmail.com>
|
* 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
|
* 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
|
* 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 ocp_enabled; /**< Output current protection enabled. */
|
||||||
gboolean ovp_enabled; /**< Output voltage 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 acquisition_target; /**< What reply to expect. */
|
||||||
int program; /**< Program to store or recall. */
|
int program; /**< Program to store or recall. */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue