20 #include <sys/types.h>
27 #include "sigrok-internal.h"
30 #define CHUNKSIZE (512 * 1024)
42 static char *sessionfile = NULL;
43 static GSList *dev_insts = NULL;
44 static int hwcaps[] = {
55 static struct session_vdev *get_vdev_by_index(
int dev_index)
63 sr_err(
"session driver: %s: device instance with device "
64 "index %d was not found", __func__, dev_index);
84 static int receive_data(
int fd,
int revents,
void *cb_data)
98 sr_dbg(
"session_driver: feed chunk");
101 for (l = dev_insts; l; l = l->next) {
109 sr_err(
"session driver: %s: buf malloc failed",
118 packet.payload = &logic;
142 static int hw_cleanup(
void);
151 static int hw_init(
const char *devinfo)
153 sessionfile = g_strdup(devinfo);
161 static int hw_cleanup(
void)
165 for (l = dev_insts; l; l = l->next)
167 g_slist_free(dev_insts);
177 static int hw_dev_open(
int dev_index)
187 sr_err(
"session driver: %s: sdi->priv malloc failed", __func__);
191 dev_insts = g_slist_append(dev_insts, sdi);
196 static void *hw_dev_info_get(
int dev_index,
int dev_info_id)
204 if (!(vdev = get_vdev_by_index(dev_index)))
212 static int hw_dev_status_get(
int dev_index)
229 static int *hw_hwcap_get_all(
void)
234 static int hw_dev_config_set(
int dev_index,
int hwcap,
void *value)
239 if (!(vdev = get_vdev_by_index(dev_index)))
246 sr_info(
"session driver: setting samplerate to %" PRIu64,
251 sr_info(
"session driver: setting capturefile to %s",
263 sr_err(
"session driver: %s: unknown capability %d requested",
271 static int hw_dev_acquisition_start(
int dev_index,
void *cb_data)
279 if (!(vdev = get_vdev_by_index(dev_index)))
282 sr_info(
"session_driver: opening archive %s file %s", sessionfile,
285 if (!(vdev->
archive = zip_open(sessionfile, 0, &ret))) {
286 sr_err(
"session driver: Failed to open session file '%s': "
287 "zip error %d\n", sessionfile, ret);
292 sr_err(
"session driver: Failed to check capture file '%s' in "
293 "session file '%s'.", vdev->
capturefile, sessionfile);
298 sr_err(
"session driver: Failed to open capture file '%s' in "
299 "session file '%s'.", vdev->
capturefile, sessionfile);
307 sr_err(
"session driver: %s: packet malloc failed", __func__);
312 sr_err(
"session driver: %s: header malloc failed", __func__);
318 packet->
payload = (
unsigned char *)header;
332 .longname =
"Session-emulating driver",
335 .cleanup = hw_cleanup,
336 .dev_open = hw_dev_open,
338 .dev_info_get = hw_dev_info_get,
339 .dev_status_get = hw_dev_status_get,
340 .hwcap_get_all = hw_hwcap_get_all,
341 .dev_config_set = hw_dev_config_set,
342 .dev_acquisition_start = hw_dev_acquisition_start,
343 .dev_acquisition_stop = NULL,