]> sigrok.org Git - libsigrok.git/blame - hardware/fluke-dmm/api.c
fluke-dmm: initial driver skeleton
[libsigrok.git] / hardware / fluke-dmm / api.c
CommitLineData
883a2e9e
BV
1/*
2 * This file is part of the sigrok project.
3 *
4 * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
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#include <glib.h>
21#include "libsigrok.h"
22#include "libsigrok-internal.h"
23#include "config.h"
24
25
26SR_PRIV struct sr_dev_driver driver_info;
27static struct sr_dev_driver *di = &driver_info;
28
29/* TODO move to header file */
30struct drv_context { GSList *instances; };
31struct dev_context { };
32
33/* Properly close and free all devices. */
34static int clear_instances(void)
35{
36 struct sr_dev_inst *sdi;
37 struct drv_context *drvc;
38 struct dev_context *devc;
39 GSList *l;
40
41 drvc = di->priv;
42 for (l = drvc->instances; l; l = l->next) {
43 if (!(sdi = l->data)) {
44 /* Log error, but continue cleaning up the rest. */
45 sr_err("TODO: %s: sdi was NULL, continuing", __func__);
46 continue;
47 }
48 if (!(devc = sdi->priv)) {
49 /* Log error, but continue cleaning up the rest. */
50 sr_err("TODO: %s: sdi->priv was NULL, continuing", __func__);
51 continue;
52 }
53
54 /* TODO */
55
56 sr_dev_inst_free(sdi);
57 }
58
59 g_slist_free(drvc->instances);
60 drvc->instances = NULL;
61
62 return SR_OK;
63}
64
65static int hw_init(void)
66{
67 struct drv_context *drvc;
68
69 if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
70 sr_err("TODO: driver context malloc failed.");
71 return SR_ERR;
72 }
73
74 /* TODO */
75
76 di->priv = drvc;
77
78 return SR_OK;
79}
80
81static GSList *hw_scan(GSList *options)
82{
83 struct drv_context *drvc;
84 GSList *devices;
85
86 (void)options;
87 devices = NULL;
88 drvc = di->priv;
89 drvc->instances = NULL;
90
91 /* TODO */
92
93 return devices;
94}
95
96static GSList *hw_dev_list(void)
97{
98 struct drv_context *drvc;
99
100 drvc = di->priv;
101
102 return drvc->instances;
103}
104
105static int hw_dev_open(struct sr_dev_inst *sdi)
106{
107
108 /* TODO */
109
110 return SR_OK;
111}
112
113static int hw_dev_close(struct sr_dev_inst *sdi)
114{
115
116 /* TODO */
117
118 return SR_OK;
119}
120
121static int hw_cleanup(void)
122{
123
124 clear_instances();
125
126 /* TODO */
127
128 return SR_OK;
129}
130
131static int hw_info_get(int info_id, const void **data,
132 const struct sr_dev_inst *sdi)
133{
134
135
136 switch (info_id) {
137 /* TODO */
138 default:
139 return SR_ERR_ARG;
140 }
141
142 return SR_OK;
143}
144
145static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
146 const void *value)
147{
148 int ret;
149
150 if (sdi->status != SR_ST_ACTIVE)
151 return SR_ERR;
152
153 ret = SR_OK;
154 switch (hwcap) {
155 /* TODO */
156 default:
157 ret = SR_ERR_ARG;
158 }
159
160 return ret;
161}
162
163static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
164 void *cb_data)
165{
166
167 /* TODO */
168
169 return SR_OK;
170}
171
172static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi,
173 void *cb_data)
174{
175
176 (void)cb_data;
177
178 if (sdi->status != SR_ST_ACTIVE)
179 return SR_ERR;
180
181 /* TODO */
182
183 return SR_OK;
184}
185
186SR_PRIV struct sr_dev_driver driver_info = {
187 .name = "fluke-dmm",
188 .longname = "Fluke 18x/28x series DMMs",
189 .api_version = 1,
190 .init = hw_init,
191 .cleanup = hw_cleanup,
192 .scan = hw_scan,
193 .dev_list = hw_dev_list,
194 .dev_clear = clear_instances,
195 .dev_open = hw_dev_open,
196 .dev_close = hw_dev_close,
197 .info_get = hw_info_get,
198 .dev_config_set = hw_dev_config_set,
199 .dev_acquisition_start = hw_dev_acquisition_start,
200 .dev_acquisition_stop = hw_dev_acquisition_stop,
201 .priv = NULL,
202};