1 /* 2 * This file is part of the libsigrok project. 3 * 4 * Copyright (C) 2018 Bastian Schmitz <bastian.schmitz@udo.edu> 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef LIBSIGROK_HARDWARE_GWINSTEK_GPD_PROTOCOL_H 21 #define LIBSIGROK_HARDWARE_GWINSTEK_GPD_PROTOCOL_H 22 23 #include <stdint.h> 24 #include <glib.h> 25 #include <libsigrok/libsigrok.h> 26 #include "libsigrok-internal.h" 27 28 #define LOG_PREFIX "gwinstek-gpd" 29 30 enum { 31 GPD_2303S, 32 }; 33 34 /* Maximum number of output channels handled by this driver. */ 35 #define MAX_CHANNELS 2 36 37 #define CHANMODE_INDEPENDENT (1 << 0) 38 #define CHANMODE_SERIES (1 << 1) 39 #define CHANMODE_PARALLEL (1 << 2) 40 41 struct channel_spec { 42 /* Min, max, step. */ 43 gdouble voltage[3]; 44 gdouble current[3]; 45 }; 46 47 struct gpd_model { 48 int modelid; 49 const char *name; 50 int channel_modes; 51 unsigned int num_channels; 52 struct channel_spec channels[MAX_CHANNELS]; 53 }; 54 55 struct per_channel_config { 56 /* Received from device. */ 57 float output_voltage_last; 58 float output_current_last; 59 /* Set by frontend. */ 60 float output_voltage_max; 61 float output_current_max; 62 }; 63 64 struct dev_context { 65 /* Received from device. */ 66 gboolean output_enabled; 67 int64_t req_sent_at; 68 gboolean reply_pending; 69 70 struct sr_sw_limits limits; 71 int channel_mode; 72 struct per_channel_config *config; 73 const struct gpd_model *model; 74 }; 75 76 SR_PRIV int gpd_send_cmd(struct sr_serial_dev_inst *serial, const char *cmd, ...); 77 SR_PRIV int gpd_receive_data(int fd, int revents, void *cb_data); 78 SR_PRIV int gpd_receive_reply(struct sr_serial_dev_inst *serial, char *buf, int buflen); 79 80 #endif 81