]> sigrok.org Git - libsigrok.git/blame - hardware/motech-lps-30x/protocol.h
build: Portability fixes.
[libsigrok.git] / hardware / motech-lps-30x / protocol.h
CommitLineData
41b7bd01
MH
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2014 Matthias Heidbrink <m-sigrok@heidbrink.biz>
1c3d002b 5 * Copyright (C) 2014 Bert Vermeulen <bert@biot.com> (code from atten-pps3xxx)
41b7bd01
MH
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 3 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, see <http://www.gnu.org/licenses/>.
19 */
20
1c3d002b
MH
21/** @file
22 * <em>Motech LPS-30x series</em> power supply driver
23 * @internal
24 */
25
26
27#ifndef LIBSIGROK_HARDWARE_MOTECH_LPS_30X_PROTOCOL_H
28#define LIBSIGROK_HARDWARE_MOTECH_LPS_30X_PROTOCOL_H
41b7bd01
MH
29
30#include <stdint.h>
31#include <glib.h>
32#include "libsigrok.h"
33#include "libsigrok-internal.h"
34
1c3d002b
MH
35
36SR_PRIV int lps_process_status(struct sr_dev_inst* sdi, int stat);
37SR_PRIV int lps_send_req(struct sr_serial_dev_inst *serial, const char* fmt, ...);
38
39#define LOG_PREFIX "motech-lps-30x"
40
41#define LINELEN_MAX 50 /**< Max. line length for requests */
42
43#define REQ_TIMEOUT_MS 250 /**< Timeout [ms] for single request. */
44
45#define MAX_CHANNELS 3
46
47typedef enum {
48 LPS_UNKNOWN = 0,/**< Unknown model (used during detection process) */
49 LPS_301, /**< Motech/Amrel LPS-301, 1 output */
50 LPS_302, /**< Motech/Amrel LPS-302, 1 output */
51 LPS_303, /**< Motech/Amrel LPS-303, 1 output */
52 LPS_304, /**< Motech/Amrel LPS-304, 3 outputs */
53 LPS_305, /**< Motech/Amrel LPS-305, 3 outputs */
54} lps_modelid;
55
56/** Channel specification */
57struct channel_spec {
58 /* Min, max, step. */
59 gdouble voltage[3];
60 gdouble current[3];
61};
62
63/** Model properties specification */
64struct lps_modelspec {
65 lps_modelid modelid;
66 const char* modelstr;
67 uint8_t num_channels;
68 struct channel_spec channels[3];
69};
70
71/** Used to implement a little state machine to query all required values in a row. */
72typedef enum {
73 AQ_NONE,
74 AQ_U1,
75 AQ_I1,
76 AQ_I2,
77 AQ_U2,
78 AQ_STATUS,
79} acquisition_req;
80
81/** Status of a single channel. */
82struct channel_status {
83 /* Channel information (struct channel_info*). data (struct) owned by sdi, just a reference to address a single channel. */
84 GSList* info;
85 /* Received from device. */
86 gdouble output_voltage_last;
87 gdouble output_current_last;
88 gboolean output_enabled; /**< Also used when set. */
89 gboolean cc_mode; /**< Constant current mode. If false, constant voltage mode. */
90 /* Set by frontend. */
91 gdouble output_voltage_max;
92 gdouble output_current_max;
93};
41b7bd01
MH
94
95/** Private, per-device-instance driver context. */
96struct dev_context {
97 /* Model-specific information */
1c3d002b 98 struct lps_modelspec* model;
41b7bd01 99
1c3d002b
MH
100 /* Acquisition status */
101 gboolean acq_running; /**< Aquisition is running. */
102 uint64_t limit_samples; /**< Target number of samples */
103 uint64_t limit_msec; /**< Target sampling time */
104 acquisition_req acq_req; /**< Current request. */
105 uint8_t acq_req_pending; /**< Request pending. 0=none, 1=reply, 2=OK */
41b7bd01
MH
106
107 /* Operational state */
1c3d002b
MH
108 struct channel_status channel_status[MAX_CHANNELS];
109 guint8 tracking_mode; /**< 0=off, 1=Tracking from CH1, 2=Tracking from CH2. */
41b7bd01
MH
110
111 /* Temporary state across callbacks */
1c3d002b
MH
112 int64_t req_sent_at; /**< Request sent. */
113 uint64_t num_samples; /**< Current #samples for limit_samples */
114 GTimer *elapsed_msec; /**< Used for sampling with limit_msec */
115 gchar buf[LINELEN_MAX]; /**< Buffer for read callback */
116 int buflen; /**< Data len in buf */
41b7bd01
MH
117};
118
1c3d002b 119SR_PRIV int motech_lps_30x_receive_data(int fd, int revents, void *cb_data);
41b7bd01
MH
120
121#endif