]> sigrok.org Git - libsigrok.git/blob - hardware/manson-hcs-3xxx/protocol.h
manson-hcs-3xxx: Implemented setting voltage, current and output.
[libsigrok.git] / hardware / manson-hcs-3xxx / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2014 Uwe Hermann <uwe@hermann-uwe.de>
5  * Copyright (C) 2014 Matthias Heidbrink <m-sigrok@heidbrink.biz>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 /** @file
23   *  <em>Manson HCS-3xxx Series</em> power supply driver
24   *  @internal
25   */
26
27 #ifndef LIBSIGROK_HARDWARE_MANSON_HCS_3XXX_PROTOCOL_H
28 #define LIBSIGROK_HARDWARE_MANSON_HCS_3XXX_PROTOCOL_H
29
30 #include <stdint.h>
31 #include <string.h>
32 #include <math.h>
33 #include <glib.h>
34 #include "libsigrok.h"
35 #include "libsigrok-internal.h"
36
37 #define LOG_PREFIX "manson-hcs-3xxx"
38
39 enum {
40         MANSON_HCS_3100,
41         MANSON_HCS_3102,
42         MANSON_HCS_3104,
43         MANSON_HCS_3150,
44         MANSON_HCS_3200,
45         MANSON_HCS_3202,
46         MANSON_HCS_3204,
47         MANSON_HCS_3300,
48         MANSON_HCS_3302,
49         MANSON_HCS_3304,
50         MANSON_HCS_3400,
51         MANSON_HCS_3402,
52         MANSON_HCS_3404,
53         MANSON_HCS_3600,
54         MANSON_HCS_3602,
55         MANSON_HCS_3604,
56 };
57
58 /** Information on a single model. */
59 struct hcs_model {
60         int model_id;      /**< Model info */
61         char *name;        /**< Model name */
62         char *id;          /**< Model ID, like delivered by interface */
63         double voltage[3]; /**< Min, max, step */
64         double current[3]; /**< Min, max, step */
65 };
66
67 /** Private, per-device-instance driver context. */
68 struct dev_context {
69         struct hcs_model *model; /**< Model informaion. */
70
71         uint64_t limit_samples;
72         uint64_t limit_msec;
73         uint64_t num_samples;
74         int64_t starttime;
75         int64_t req_sent_at;
76         gboolean reply_pending;
77
78         void *cb_data;
79
80         float current;          /**< Last current value [A] read from device. */
81         float current_max;      /**< Output current set */
82         float voltage;          /**< Last voltage value [V] read from device. */
83         float voltage_max;      /**< Output voltage set */
84         gboolean cc_mode;       /**< Device is in constant current mode (otherwise constant voltage). */
85
86         gboolean output_enabled; /**< Is the output enabled? */
87
88         char buf[50];
89         int buflen;
90 };
91
92 SR_PRIV int hcs_parse_volt_curr_mode(struct sr_dev_inst *sdi, char **tokens);
93 SR_PRIV int hcs_read_reply(struct sr_serial_dev_inst *serial, int lines, char* buf, int buflen);
94 SR_PRIV int hcs_send_cmd(struct sr_serial_dev_inst *serial, const char *cmd, ...);
95 SR_PRIV int hcs_receive_data(int fd, int revents, void *cb_data);
96
97 #endif