Bert Vermeulen | ca1a7cb | 2014-08-31 17:20:39 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of the libsigrok project. |
| 3 | * |
| 4 | * Copyright (C) 2014 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 "protocol.h" |
| 21 | |
| 22 | SR_PRIV struct sr_dev_driver scpi_pps_driver_info; |
| 23 | static struct sr_dev_driver *di = &scpi_pps_driver_info; |
| 24 | |
| 25 | static int init(struct sr_context *sr_ctx) |
| 26 | { |
| 27 | return std_init(sr_ctx, di, LOG_PREFIX); |
| 28 | } |
| 29 | |
| 30 | static GSList *scan(GSList *options) |
| 31 | { |
| 32 | struct drv_context *drvc; |
| 33 | GSList *devices; |
| 34 | |
| 35 | (void)options; |
| 36 | |
| 37 | devices = NULL; |
| 38 | drvc = di->priv; |
| 39 | drvc->instances = NULL; |
| 40 | |
| 41 | /* TODO: scan for devices, either based on a SR_CONF_CONN option |
| 42 | * or on a USB scan. */ |
| 43 | |
| 44 | return devices; |
| 45 | } |
| 46 | |
| 47 | static GSList *dev_list(void) |
| 48 | { |
| 49 | return ((struct drv_context *)(di->priv))->instances; |
| 50 | } |
| 51 | |
| 52 | static int dev_clear(void) |
| 53 | { |
| 54 | return std_dev_clear(di, NULL); |
| 55 | } |
| 56 | |
| 57 | static int dev_open(struct sr_dev_inst *sdi) |
| 58 | { |
| 59 | (void)sdi; |
| 60 | |
| 61 | /* TODO: get handle from sdi->conn and open it. */ |
| 62 | |
| 63 | sdi->status = SR_ST_ACTIVE; |
| 64 | |
| 65 | return SR_OK; |
| 66 | } |
| 67 | |
| 68 | static int dev_close(struct sr_dev_inst *sdi) |
| 69 | { |
| 70 | (void)sdi; |
| 71 | |
| 72 | /* TODO: get handle from sdi->conn and close it. */ |
| 73 | |
| 74 | sdi->status = SR_ST_INACTIVE; |
| 75 | |
| 76 | return SR_OK; |
| 77 | } |
| 78 | |
| 79 | static int cleanup(void) |
| 80 | { |
| 81 | dev_clear(); |
| 82 | |
| 83 | /* TODO: free other driver resources, if any. */ |
| 84 | |
| 85 | return SR_OK; |
| 86 | } |
| 87 | |
| 88 | static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi, |
| 89 | const struct sr_channel_group *cg) |
| 90 | { |
| 91 | int ret; |
| 92 | |
| 93 | (void)sdi; |
| 94 | (void)data; |
| 95 | (void)cg; |
| 96 | |
| 97 | ret = SR_OK; |
| 98 | switch (key) { |
| 99 | /* TODO */ |
| 100 | default: |
| 101 | return SR_ERR_NA; |
| 102 | } |
| 103 | |
| 104 | return ret; |
| 105 | } |
| 106 | |
| 107 | static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi, |
| 108 | const struct sr_channel_group *cg) |
| 109 | { |
| 110 | int ret; |
| 111 | |
| 112 | (void)data; |
| 113 | (void)cg; |
| 114 | |
| 115 | if (sdi->status != SR_ST_ACTIVE) |
| 116 | return SR_ERR_DEV_CLOSED; |
| 117 | |
| 118 | ret = SR_OK; |
| 119 | switch (key) { |
| 120 | /* TODO */ |
| 121 | default: |
| 122 | ret = SR_ERR_NA; |
| 123 | } |
| 124 | |
| 125 | return ret; |
| 126 | } |
| 127 | |
| 128 | static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, |
| 129 | const struct sr_channel_group *cg) |
| 130 | { |
| 131 | int ret; |
| 132 | |
| 133 | (void)sdi; |
| 134 | (void)data; |
| 135 | (void)cg; |
| 136 | |
| 137 | ret = SR_OK; |
| 138 | switch (key) { |
| 139 | /* TODO */ |
| 140 | default: |
| 141 | return SR_ERR_NA; |
| 142 | } |
| 143 | |
| 144 | return ret; |
| 145 | } |
| 146 | |
| 147 | static int dev_acquisition_start(const struct sr_dev_inst *sdi, |
| 148 | void *cb_data) |
| 149 | { |
| 150 | (void)sdi; |
| 151 | (void)cb_data; |
| 152 | |
| 153 | if (sdi->status != SR_ST_ACTIVE) |
| 154 | return SR_ERR_DEV_CLOSED; |
| 155 | |
| 156 | /* TODO: configure hardware, reset acquisition state, set up |
| 157 | * callbacks and send header packet. */ |
| 158 | |
| 159 | return SR_OK; |
| 160 | } |
| 161 | |
| 162 | static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) |
| 163 | { |
| 164 | (void)cb_data; |
| 165 | |
| 166 | if (sdi->status != SR_ST_ACTIVE) |
| 167 | return SR_ERR_DEV_CLOSED; |
| 168 | |
| 169 | /* TODO: stop acquisition. */ |
| 170 | |
| 171 | return SR_OK; |
| 172 | } |
| 173 | |
| 174 | SR_PRIV struct sr_dev_driver scpi_pps_driver_info = { |
| 175 | .name = "scpi-pps", |
| 176 | .longname = "SCPI PPS", |
| 177 | .api_version = 1, |
| 178 | .init = init, |
| 179 | .cleanup = cleanup, |
| 180 | .scan = scan, |
| 181 | .dev_list = dev_list, |
| 182 | .dev_clear = dev_clear, |
| 183 | .config_get = config_get, |
| 184 | .config_set = config_set, |
| 185 | .config_list = config_list, |
| 186 | .dev_open = dev_open, |
| 187 | .dev_close = dev_close, |
| 188 | .dev_acquisition_start = dev_acquisition_start, |
| 189 | .dev_acquisition_stop = dev_acquisition_stop, |
| 190 | .priv = NULL, |
| 191 | }; |