X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fkorad-kaxxxxp%2Fprotocol.h;h=005d94ab15f7757ade08b9fecf05f12079ae549a;hb=HEAD;hp=77c4eb6f7d229a71f58ddb155aa957e743584c07;hpb=a078d3ec527c0a8180f59086e62a8905ae79aa65;p=libsigrok.git diff --git a/src/hardware/korad-kaxxxxp/protocol.h b/src/hardware/korad-kaxxxxp/protocol.h index 77c4eb6f..005d94ab 100644 --- a/src/hardware/korad-kaxxxxp/protocol.h +++ b/src/hardware/korad-kaxxxxp/protocol.h @@ -2,6 +2,7 @@ * This file is part of the libsigrok project. * * Copyright (C) 2015 Hannu Vuolasaho + * 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 @@ -17,12 +18,6 @@ * along with this program. If not, see . */ -/** - * @file - * Korad KAxxxxP power supply driver - * @internal - */ - #ifndef LIBSIGROK_HARDWARE_KORAD_KAXXXXP_PROTOCOL_H #define LIBSIGROK_HARDWARE_KORAD_KAXXXXP_PROTOCOL_H @@ -36,31 +31,33 @@ #define KAXXXXP_POLL_INTERVAL_MS 80 -enum { - VELLEMAN_PS3005D, - VELLEMAN_LABPS3005D, - KORAD_KA3005P, - KORAD_KA3005P_0X01, - /* Support for future devices with this protocol. */ +enum korad_quirks_flag { + KORAD_QUIRK_NONE = 0, + KORAD_QUIRK_LABPS_OVP_EN = 1UL << 0, + KORAD_QUIRK_ID_NO_VENDOR = 1UL << 1, + KORAD_QUIRK_ID_TRAILING = 1UL << 2, + KORAD_QUIRK_ID_OPT_VERSION = 1UL << 3, + KORAD_QUIRK_SLOW_PROCESSING = 1UL << 4, + KORAD_QUIRK_ALL = (1UL << 5) - 1, }; /* Information on single model */ struct korad_kaxxxxp_model { - int model_id; /**< Model info */ const char *vendor; /**< Vendor name */ const char *name; /**< Model name */ const char *id; /**< Model ID, as delivered by interface */ int channels; /**< Number of channels */ - double voltage[3]; /**< Min, max, step */ - double current[3]; /**< Min, max, step */ + const double *voltage; /**< References: Min, max, step */ + const double *current; /**< References: Min, max, step */ + enum korad_quirks_flag quirks; }; /* Reply targets */ enum { KAXXXXP_CURRENT, - KAXXXXP_CURRENT_MAX, + KAXXXXP_CURRENT_LIMIT, KAXXXXP_VOLTAGE, - KAXXXXP_VOLTAGE_MAX, + KAXXXXP_VOLTAGE_TARGET, KAXXXXP_STATUS, KAXXXXP_OUTPUT, KAXXXXP_BEEP, @@ -70,26 +67,17 @@ enum { KAXXXXP_RECALL, }; -/** Private, per-device-instance driver context. */ struct dev_context { - /* Model-specific information */ const struct korad_kaxxxxp_model *model; /**< Model information. */ - /* Acquisition settings */ - uint64_t limit_samples; - uint64_t limit_msec; - uint64_t num_samples; - int64_t starttime; - int64_t req_sent_at; - gboolean reply_pending; + struct sr_sw_limits limits; + int64_t next_req_time; + GMutex rw_mutex; - void *cb_data; - - /* Operational state */ float current; /**< Last current value [A] read from device. */ - float current_max; /**< Output current set. */ + float current_limit; /**< Output current set. */ float voltage; /**< Last voltage value [V] read from device. */ - float voltage_max; /**< Output voltage set. */ + float voltage_target; /**< Output voltage set. */ gboolean cc_mode[2]; /**< Device is in CC mode (otherwise CV). */ gboolean output_enabled; /**< Is the output enabled? */ @@ -97,24 +85,33 @@ struct dev_context { gboolean ocp_enabled; /**< Output current protection enabled. */ gboolean ovp_enabled; /**< Output voltage protection enabled. */ - /* Temporary state across callbacks */ - int target; /**< What reply to expect. */ + 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. */ - char reply[6]; + + float set_current_limit; /**< New output current to set. */ + float set_voltage_target; /**< New output voltage to set. */ + gboolean set_output_enabled; /**< New output enabled to set. */ + gboolean set_beep_enabled; /**< New enable beeper to set. */ + gboolean set_ocp_enabled; /**< New OCP enabled to set. */ + gboolean set_ovp_enabled; /**< New OVP enabled to set. */ }; SR_PRIV int korad_kaxxxxp_send_cmd(struct sr_serial_dev_inst *serial, - const char *cmd); + const char *cmd); SR_PRIV int korad_kaxxxxp_read_chars(struct sr_serial_dev_inst *serial, - int count, char *buf); + size_t count, char *buf); SR_PRIV int korad_kaxxxxp_set_value(struct sr_serial_dev_inst *serial, - struct dev_context *devc); -SR_PRIV int korad_kaxxxxp_query_value(struct sr_serial_dev_inst *serial, - struct dev_context *devc); -SR_PRIV int korad_kaxxxxp_get_reply(struct sr_serial_dev_inst *serial, - struct dev_context *devc); + int target, struct dev_context *devc); +SR_PRIV int korad_kaxxxxp_get_value(struct sr_serial_dev_inst *serial, + int target, struct dev_context *devc); SR_PRIV int korad_kaxxxxp_get_all_values(struct sr_serial_dev_inst *serial, - struct dev_context *devc); + struct dev_context *devc); SR_PRIV int korad_kaxxxxp_receive_data(int fd, int revents, void *cb_data); #endif