]>
Commit | Line | Data |
---|---|---|
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 | #ifndef LIBSIGROK_HARDWARE_MOTECH_LPS_30X_PROTOCOL_H |
22 | #define LIBSIGROK_HARDWARE_MOTECH_LPS_30X_PROTOCOL_H | |
41b7bd01 MH |
23 | |
24 | #include <stdint.h> | |
25 | #include <glib.h> | |
c1aae900 | 26 | #include <libsigrok/libsigrok.h> |
41b7bd01 MH |
27 | #include "libsigrok-internal.h" |
28 | ||
f272d7dd UH |
29 | #define LOG_PREFIX "motech-lps-30x" |
30 | ||
c442ffda UH |
31 | SR_PRIV int lps_process_status(struct sr_dev_inst *sdi, int stat); |
32 | SR_PRIV int lps_send_req(struct sr_serial_dev_inst *serial, const char *fmt, ...); | |
1c3d002b | 33 | |
1c3d002b MH |
34 | #define LINELEN_MAX 50 /**< Max. line length for requests */ |
35 | ||
36 | #define REQ_TIMEOUT_MS 250 /**< Timeout [ms] for single request. */ | |
37 | ||
38 | #define MAX_CHANNELS 3 | |
39 | ||
40 | typedef enum { | |
41 | LPS_UNKNOWN = 0,/**< Unknown model (used during detection process) */ | |
42 | LPS_301, /**< Motech/Amrel LPS-301, 1 output */ | |
43 | LPS_302, /**< Motech/Amrel LPS-302, 1 output */ | |
44 | LPS_303, /**< Motech/Amrel LPS-303, 1 output */ | |
45 | LPS_304, /**< Motech/Amrel LPS-304, 3 outputs */ | |
46 | LPS_305, /**< Motech/Amrel LPS-305, 3 outputs */ | |
47 | } lps_modelid; | |
48 | ||
49 | /** Channel specification */ | |
50 | struct channel_spec { | |
51 | /* Min, max, step. */ | |
52 | gdouble voltage[3]; | |
53 | gdouble current[3]; | |
54 | }; | |
55 | ||
56 | /** Model properties specification */ | |
57 | struct lps_modelspec { | |
58 | lps_modelid modelid; | |
c442ffda | 59 | const char *modelstr; |
1c3d002b MH |
60 | uint8_t num_channels; |
61 | struct channel_spec channels[3]; | |
62 | }; | |
63 | ||
64 | /** Used to implement a little state machine to query all required values in a row. */ | |
65 | typedef enum { | |
66 | AQ_NONE, | |
67 | AQ_U1, | |
68 | AQ_I1, | |
69 | AQ_I2, | |
70 | AQ_U2, | |
71 | AQ_STATUS, | |
72 | } acquisition_req; | |
73 | ||
74 | /** Status of a single channel. */ | |
75 | struct channel_status { | |
76 | /* Channel information (struct channel_info*). data (struct) owned by sdi, just a reference to address a single channel. */ | |
c442ffda | 77 | GSList *info; |
1c3d002b MH |
78 | /* Received from device. */ |
79 | gdouble output_voltage_last; | |
80 | gdouble output_current_last; | |
81 | gboolean output_enabled; /**< Also used when set. */ | |
82 | gboolean cc_mode; /**< Constant current mode. If false, constant voltage mode. */ | |
83 | /* Set by frontend. */ | |
84 | gdouble output_voltage_max; | |
85 | gdouble output_current_max; | |
86 | }; | |
41b7bd01 | 87 | |
41b7bd01 | 88 | struct dev_context { |
c442ffda | 89 | const struct lps_modelspec *model; |
41b7bd01 | 90 | |
f3f19d11 | 91 | gboolean acq_running; /**< Acquisition is running. */ |
8aafc5e6 | 92 | struct sr_sw_limits limits; |
1c3d002b MH |
93 | acquisition_req acq_req; /**< Current request. */ |
94 | uint8_t acq_req_pending; /**< Request pending. 0=none, 1=reply, 2=OK */ | |
41b7bd01 | 95 | |
1c3d002b MH |
96 | struct channel_status channel_status[MAX_CHANNELS]; |
97 | guint8 tracking_mode; /**< 0=off, 1=Tracking from CH1, 2=Tracking from CH2. */ | |
41b7bd01 | 98 | |
1c3d002b | 99 | int64_t req_sent_at; /**< Request sent. */ |
1c3d002b MH |
100 | gchar buf[LINELEN_MAX]; /**< Buffer for read callback */ |
101 | int buflen; /**< Data len in buf */ | |
41b7bd01 MH |
102 | }; |
103 | ||
1c3d002b | 104 | SR_PRIV int motech_lps_30x_receive_data(int fd, int revents, void *cb_data); |
41b7bd01 MH |
105 | |
106 | #endif |