libsigrok: More coding style fixes.
This commit is contained in:
parent
1b452b8510
commit
62c8202582
28
filter.c
28
filter.c
|
@ -20,14 +20,16 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "sigrok.h"
|
#include <sigrok.h>
|
||||||
|
|
||||||
/* convert sample from maximum probes -- the way the hardware driver sent
|
/*
|
||||||
|
* Convert sample from maximum probes -- the way the hardware driver sent
|
||||||
* it -- to a sample taking up only as much space as required, with
|
* it -- to a sample taking up only as much space as required, with
|
||||||
* unused probes removed.
|
* unused probes removed.
|
||||||
*/
|
*/
|
||||||
int filter_probes(int in_unitsize, int out_unitsize, int *probelist,
|
int filter_probes(int in_unitsize, int out_unitsize, int *probelist,
|
||||||
char *data_in, uint64_t length_in, char **data_out, uint64_t *length_out)
|
char *data_in, uint64_t length_in, char **data_out,
|
||||||
|
uint64_t * length_out)
|
||||||
{
|
{
|
||||||
unsigned int in_offset, out_offset;
|
unsigned int in_offset, out_offset;
|
||||||
int num_enabled_probes, out_bit, i;
|
int num_enabled_probes, out_bit, i;
|
||||||
|
@ -35,33 +37,31 @@ int filter_probes(int in_unitsize, int out_unitsize, int *probelist,
|
||||||
|
|
||||||
*data_out = malloc(length_in);
|
*data_out = malloc(length_in);
|
||||||
num_enabled_probes = 0;
|
num_enabled_probes = 0;
|
||||||
for(i = 0; probelist[i]; i++)
|
for (i = 0; probelist[i]; i++)
|
||||||
num_enabled_probes++;
|
num_enabled_probes++;
|
||||||
|
|
||||||
if(num_enabled_probes != in_unitsize * 8) {
|
if (num_enabled_probes != in_unitsize * 8) {
|
||||||
in_offset = out_offset = 0;
|
in_offset = out_offset = 0;
|
||||||
while(in_offset <= length_in - in_unitsize) {
|
while (in_offset <= length_in - in_unitsize) {
|
||||||
memcpy(&sample_in, data_in + in_offset, in_unitsize);
|
memcpy(&sample_in, data_in + in_offset, in_unitsize);
|
||||||
sample_out = 0;
|
sample_out = 0;
|
||||||
out_bit = 0;
|
out_bit = 0;
|
||||||
for(i = 0; probelist[i]; i++) {
|
for (i = 0; probelist[i]; i++) {
|
||||||
if(sample_in & (1 << (probelist[i]-1)))
|
if (sample_in & (1 << (probelist[i] - 1)))
|
||||||
sample_out |= 1 << out_bit;
|
sample_out |= 1 << out_bit;
|
||||||
out_bit++;
|
out_bit++;
|
||||||
}
|
}
|
||||||
memcpy((*data_out) + out_offset, &sample_out, out_unitsize);
|
memcpy((*data_out) + out_offset, &sample_out,
|
||||||
|
out_unitsize);
|
||||||
in_offset += in_unitsize;
|
in_offset += in_unitsize;
|
||||||
out_offset += out_unitsize;
|
out_offset += out_unitsize;
|
||||||
}
|
}
|
||||||
*length_out = out_offset;
|
*length_out = out_offset;
|
||||||
}
|
} else {
|
||||||
else {
|
/* All probes are used -- no need to compress anything. */
|
||||||
/* all probes are used -- no need to compress anything */
|
|
||||||
memcpy(*data_out, data_in, length_in);
|
memcpy(*data_out, data_in, length_in);
|
||||||
*length_out = length_in;
|
*length_out = length_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
return SIGROK_OK;
|
return SIGROK_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
89
hwplugin.c
89
hwplugin.c
|
@ -24,18 +24,21 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <gmodule.h>
|
#include <gmodule.h>
|
||||||
#include "sigrok.h"
|
#include <sigrok.h>
|
||||||
|
|
||||||
source_callback_add source_cb_add = NULL;
|
source_callback_add source_cb_add = NULL;
|
||||||
source_callback_remove source_cb_remove = NULL;
|
source_callback_remove source_cb_remove = NULL;
|
||||||
|
|
||||||
/* the list of loaded plugins lives here */
|
/* The list of loaded plugins lives here. */
|
||||||
GSList *plugins;
|
GSList *plugins;
|
||||||
|
|
||||||
/* this enumerates which plugin capabilities correspond to user-settable options */
|
/*
|
||||||
|
* This enumerates which plugin capabilities correspond to user-settable
|
||||||
|
* options.
|
||||||
|
*/
|
||||||
struct hwcap_option hwcap_options[] = {
|
struct hwcap_option hwcap_options[] = {
|
||||||
{ HWCAP_SAMPLERATE, T_UINT64, "Sample rate", "samplerate" },
|
{HWCAP_SAMPLERATE, T_UINT64, "Sample rate", "samplerate"},
|
||||||
{ 0, 0, NULL, NULL }
|
{0, 0, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct device_plugin saleae_logic_plugin_info;
|
extern struct device_plugin saleae_logic_plugin_info;
|
||||||
|
@ -44,28 +47,27 @@ extern struct device_plugin zeroplus_logic_cube_plugin_info;
|
||||||
|
|
||||||
int load_hwplugins(void)
|
int load_hwplugins(void)
|
||||||
{
|
{
|
||||||
plugins = g_slist_append(plugins, (gpointer *)&saleae_logic_plugin_info);
|
plugins =
|
||||||
plugins = g_slist_append(plugins, (gpointer *)&ols_plugin_info);
|
g_slist_append(plugins, (gpointer *) &saleae_logic_plugin_info);
|
||||||
plugins = g_slist_append(plugins, (gpointer *)&zeroplus_logic_cube_plugin_info);
|
plugins = g_slist_append(plugins, (gpointer *) &ols_plugin_info);
|
||||||
|
plugins = g_slist_append(plugins,
|
||||||
|
(gpointer *) &zeroplus_logic_cube_plugin_info);
|
||||||
|
|
||||||
return SIGROK_OK;
|
return SIGROK_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GSList *list_hwplugins(void)
|
GSList *list_hwplugins(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
return plugins;
|
return plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct sigrok_device_instance *sigrok_device_instance_new(int index, int status,
|
struct sigrok_device_instance *sigrok_device_instance_new(int index, int status,
|
||||||
char *vendor, char *model, char *version)
|
char *vendor, char *model, char *version)
|
||||||
{
|
{
|
||||||
struct sigrok_device_instance *sdi;
|
struct sigrok_device_instance *sdi;
|
||||||
|
|
||||||
sdi = malloc(sizeof(struct sigrok_device_instance));
|
sdi = malloc(sizeof(struct sigrok_device_instance));
|
||||||
if(!sdi)
|
if (!sdi)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
sdi->index = index;
|
sdi->index = index;
|
||||||
|
@ -79,16 +81,16 @@ struct sigrok_device_instance *sigrok_device_instance_new(int index, int status,
|
||||||
return sdi;
|
return sdi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct sigrok_device_instance *get_sigrok_device_instance(
|
||||||
struct sigrok_device_instance *get_sigrok_device_instance(GSList *device_instances, int device_index)
|
GSList *device_instances, int device_index)
|
||||||
{
|
{
|
||||||
struct sigrok_device_instance *sdi;
|
struct sigrok_device_instance *sdi;
|
||||||
GSList *l;
|
GSList *l;
|
||||||
|
|
||||||
sdi = NULL;
|
sdi = NULL;
|
||||||
for(l = device_instances; l; l = l->next) {
|
for (l = device_instances; l; l = l->next) {
|
||||||
sdi = (struct sigrok_device_instance *) (l->data);
|
sdi = (struct sigrok_device_instance *)(l->data);
|
||||||
if(sdi->index == device_index)
|
if (sdi->index == device_index)
|
||||||
return sdi;
|
return sdi;
|
||||||
}
|
}
|
||||||
g_warning("could not find device index %d instance", device_index);
|
g_warning("could not find device index %d instance", device_index);
|
||||||
|
@ -96,35 +98,31 @@ struct sigrok_device_instance *get_sigrok_device_instance(GSList *device_instanc
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void sigrok_device_instance_free(struct sigrok_device_instance *sdi)
|
void sigrok_device_instance_free(struct sigrok_device_instance *sdi)
|
||||||
{
|
{
|
||||||
|
switch (sdi->instance_type) {
|
||||||
switch(sdi->instance_type) {
|
|
||||||
case USB_INSTANCE:
|
case USB_INSTANCE:
|
||||||
usb_device_instance_free(sdi->usb);
|
usb_device_instance_free(sdi->usb);
|
||||||
break;
|
break;
|
||||||
case SERIAL_INSTANCE:
|
case SERIAL_INSTANCE:
|
||||||
serial_device_instance_free(sdi->serial);
|
serial_device_instance_free(sdi->serial);
|
||||||
break;
|
break;
|
||||||
/* no specific type, nothing extra to free */
|
/* No specific type, nothing extra to free. */
|
||||||
}
|
}
|
||||||
|
|
||||||
free(sdi->vendor);
|
free(sdi->vendor);
|
||||||
free(sdi->model);
|
free(sdi->model);
|
||||||
free(sdi->version);
|
free(sdi->version);
|
||||||
free(sdi);
|
free(sdi);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct usb_device_instance *usb_device_instance_new(uint8_t bus,
|
||||||
struct usb_device_instance *usb_device_instance_new(uint8_t bus, uint8_t address,
|
uint8_t address, struct libusb_device_handle *hdl)
|
||||||
struct libusb_device_handle *hdl)
|
|
||||||
{
|
{
|
||||||
struct usb_device_instance *udi;
|
struct usb_device_instance *udi;
|
||||||
|
|
||||||
udi = malloc(sizeof(struct usb_device_instance));
|
udi = malloc(sizeof(struct usb_device_instance));
|
||||||
if(!udi)
|
if (!udi)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
udi->bus = bus;
|
udi->bus = bus;
|
||||||
|
@ -134,23 +132,20 @@ struct usb_device_instance *usb_device_instance_new(uint8_t bus, uint8_t address
|
||||||
return udi;
|
return udi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void usb_device_instance_free(struct usb_device_instance *usb)
|
void usb_device_instance_free(struct usb_device_instance *usb)
|
||||||
{
|
{
|
||||||
/* QUICK HACK */
|
/* QUICK HACK */
|
||||||
usb = usb;
|
usb = usb;
|
||||||
|
|
||||||
/* nothing to do for this device instance type */
|
/* Nothing to do for this device instance type. */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct serial_device_instance *serial_device_instance_new(char *port, int fd)
|
struct serial_device_instance *serial_device_instance_new(char *port, int fd)
|
||||||
{
|
{
|
||||||
struct serial_device_instance *serial;
|
struct serial_device_instance *serial;
|
||||||
|
|
||||||
serial = malloc(sizeof(struct serial_device_instance));
|
serial = malloc(sizeof(struct serial_device_instance));
|
||||||
if(!serial)
|
if (!serial)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
serial->port = strdup(port);
|
serial->port = strdup(port);
|
||||||
|
@ -159,37 +154,30 @@ struct serial_device_instance *serial_device_instance_new(char *port, int fd)
|
||||||
return serial;
|
return serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void serial_device_instance_free(struct serial_device_instance *serial)
|
void serial_device_instance_free(struct serial_device_instance *serial)
|
||||||
{
|
{
|
||||||
|
|
||||||
free(serial->port);
|
free(serial->port);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int find_hwcap(int *capabilities, int hwcap)
|
int find_hwcap(int *capabilities, int hwcap)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; capabilities[i]; i++)
|
for (i = 0; capabilities[i]; i++)
|
||||||
if(capabilities[i] == hwcap)
|
if (capabilities[i] == hwcap)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct hwcap_option *find_hwcap_option(int hwcap)
|
struct hwcap_option *find_hwcap_option(int hwcap)
|
||||||
{
|
{
|
||||||
struct hwcap_option *hwo;
|
struct hwcap_option *hwo;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
hwo = NULL;
|
hwo = NULL;
|
||||||
for(i = 0; hwcap_options[i].capability; i++)
|
for (i = 0; hwcap_options[i].capability; i++) {
|
||||||
{
|
if (hwcap_options[i].capability == hwcap) {
|
||||||
if(hwcap_options[i].capability == hwcap)
|
|
||||||
{
|
|
||||||
hwo = &hwcap_options[i];
|
hwo = &hwcap_options[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -198,24 +186,15 @@ struct hwcap_option *find_hwcap_option(int hwcap)
|
||||||
return hwo;
|
return hwo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void source_remove(int fd)
|
void source_remove(int fd)
|
||||||
{
|
{
|
||||||
|
if (source_cb_remove)
|
||||||
if(source_cb_remove)
|
|
||||||
source_cb_remove(fd);
|
source_cb_remove(fd);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void source_add(int fd, int events, int timeout, receive_data_callback rcv_cb,
|
||||||
void source_add(int fd, int events, int timeout, receive_data_callback rcv_cb, void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
|
if (source_cb_add)
|
||||||
if(source_cb_add)
|
|
||||||
source_cb_add(fd, events, timeout, rcv_cb, user_data);
|
source_cb_add(fd, events, timeout, rcv_cb, user_data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
132
session.c
132
session.c
|
@ -22,17 +22,16 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <zip.h>
|
#include <zip.h>
|
||||||
#include "sigrok.h"
|
#include <sigrok.h>
|
||||||
|
|
||||||
/* there can only be one session at a time */
|
/* There can only be one session at a time. */
|
||||||
struct session *session;
|
struct session *session;
|
||||||
|
|
||||||
|
|
||||||
struct session *session_load(const char *filename)
|
struct session *session_load(const char *filename)
|
||||||
{
|
{
|
||||||
struct session *session;
|
struct session *session;
|
||||||
|
|
||||||
/* TODO: implement */
|
/* TODO: Implement. */
|
||||||
session = NULL;
|
session = NULL;
|
||||||
|
|
||||||
/* QUICK HACK */
|
/* QUICK HACK */
|
||||||
|
@ -41,84 +40,66 @@ struct session *session_load(const char *filename)
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct session *session_new(void)
|
struct session *session_new(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
session = calloc(1, sizeof(struct session));
|
session = calloc(1, sizeof(struct session));
|
||||||
|
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void session_destroy(void)
|
void session_destroy(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
g_slist_free(session->devices);
|
g_slist_free(session->devices);
|
||||||
|
|
||||||
/* TODO: loop over protocols and free them */
|
/* TODO: Loop over protocols and free them. */
|
||||||
|
|
||||||
g_free(session);
|
g_free(session);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void session_device_clear(void)
|
void session_device_clear(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
g_slist_free(session->devices);
|
g_slist_free(session->devices);
|
||||||
session->devices = NULL;
|
session->devices = NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int session_device_add(struct device *device)
|
int session_device_add(struct device *device)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = device->plugin->open(device->plugin_index);
|
ret = device->plugin->open(device->plugin_index);
|
||||||
if(ret == SIGROK_OK)
|
if (ret == SIGROK_OK)
|
||||||
session->devices = g_slist_append(session->devices, device);
|
session->devices = g_slist_append(session->devices, device);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void session_pa_clear(void)
|
void session_pa_clear(void)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
/* the protocols are pointers to the global set of PA plugins, so don't free them */
|
* The protocols are pointers to the global set of PA plugins,
|
||||||
|
* so don't free them.
|
||||||
|
*/
|
||||||
g_slist_free(session->analyzers);
|
g_slist_free(session->analyzers);
|
||||||
session->analyzers = NULL;
|
session->analyzers = NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void session_pa_add(struct analyzer *an)
|
void session_pa_add(struct analyzer *an)
|
||||||
{
|
{
|
||||||
|
|
||||||
session->analyzers = g_slist_append(session->analyzers, an);
|
session->analyzers = g_slist_append(session->analyzers, an);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void session_datafeed_callback_clear(void)
|
void session_datafeed_callback_clear(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
g_slist_free(session->datafeed_callbacks);
|
g_slist_free(session->datafeed_callbacks);
|
||||||
session->datafeed_callbacks = NULL;
|
session->datafeed_callbacks = NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void session_datafeed_callback_add(datafeed_callback callback)
|
void session_datafeed_callback_add(datafeed_callback callback)
|
||||||
{
|
{
|
||||||
|
session->datafeed_callbacks =
|
||||||
session->datafeed_callbacks = g_slist_append(session->datafeed_callbacks, callback);
|
g_slist_append(session->datafeed_callbacks, callback);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int session_start(void)
|
int session_start(void)
|
||||||
{
|
{
|
||||||
struct device *device;
|
struct device *device;
|
||||||
|
@ -126,50 +107,43 @@ int session_start(void)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
g_message("starting acquisition");
|
g_message("starting acquisition");
|
||||||
for(l = session->devices; l; l = l->next)
|
for (l = session->devices; l; l = l->next) {
|
||||||
{
|
|
||||||
device = l->data;
|
device = l->data;
|
||||||
if( (ret = device->plugin->start_acquisition(device->plugin_index, device)) != SIGROK_OK)
|
if ((ret = device->plugin->start_acquisition(
|
||||||
|
device->plugin_index, device)) != SIGROK_OK)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void session_stop(void)
|
void session_stop(void)
|
||||||
{
|
{
|
||||||
struct device *device;
|
struct device *device;
|
||||||
GSList *l;
|
GSList *l;
|
||||||
|
|
||||||
g_message("stopping acquisition");
|
g_message("stopping acquisition");
|
||||||
for(l = session->devices; l; l = l->next)
|
for (l = session->devices; l; l = l->next) {
|
||||||
{
|
|
||||||
device = l->data;
|
device = l->data;
|
||||||
device->plugin->stop_acquisition(device->plugin_index, device);
|
device->plugin->stop_acquisition(device->plugin_index, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void session_bus(struct device *device, struct datafeed_packet *packet)
|
void session_bus(struct device *device, struct datafeed_packet *packet)
|
||||||
{
|
{
|
||||||
GSList *l;
|
GSList *l;
|
||||||
datafeed_callback cb;
|
datafeed_callback cb;
|
||||||
|
|
||||||
/* TODO: send packet through PA pipe, and send the output of that to
|
/*
|
||||||
* the callbacks as well
|
* TODO: Send packet through PA pipe, and send the output of that to
|
||||||
|
* the callbacks as well.
|
||||||
*/
|
*/
|
||||||
|
for (l = session->datafeed_callbacks; l; l = l->next) {
|
||||||
for(l = session->datafeed_callbacks; l; l = l->next)
|
|
||||||
{
|
|
||||||
cb = l->data;
|
cb = l->data;
|
||||||
cb(device, packet);
|
cb(device, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void make_metadata(char *filename)
|
void make_metadata(char *filename)
|
||||||
{
|
{
|
||||||
GSList *l, *p;
|
GSList *l, *p;
|
||||||
|
@ -180,38 +154,38 @@ void make_metadata(char *filename)
|
||||||
|
|
||||||
f = fopen(filename, "wb");
|
f = fopen(filename, "wb");
|
||||||
|
|
||||||
/* general */
|
/* General */
|
||||||
|
|
||||||
/* devices */
|
/* Devices */
|
||||||
devcnt = 1;
|
devcnt = 1;
|
||||||
for(l = session->devices; l; l = l->next) {
|
for (l = session->devices; l; l = l->next) {
|
||||||
device = l->data;
|
device = l->data;
|
||||||
fprintf(f, "[device]\n");
|
fprintf(f, "[device]\n");
|
||||||
fprintf(f, "driver = %s\n", device->plugin->name);
|
fprintf(f, "driver = %s\n", device->plugin->name);
|
||||||
if(device->datastore)
|
|
||||||
|
if (device->datastore)
|
||||||
fprintf(f, "capturefile = raw-%d\n", devcnt);
|
fprintf(f, "capturefile = raw-%d\n", devcnt);
|
||||||
for(p = device->probes; p; p = p->next) {
|
|
||||||
|
for (p = device->probes; p; p = p->next) {
|
||||||
probe = p->data;
|
probe = p->data;
|
||||||
if(probe->enabled)
|
if (probe->enabled) {
|
||||||
{
|
|
||||||
fprintf(f, "probe %d", probe->index);
|
fprintf(f, "probe %d", probe->index);
|
||||||
if(probe->name)
|
if (probe->name)
|
||||||
fprintf(f, " name \"%s\"", probe->name);
|
fprintf(f, " name \"%s\"", probe->name);
|
||||||
if(probe->trigger)
|
if (probe->trigger)
|
||||||
fprintf(f, " trigger \"%s\"", probe->trigger);
|
fprintf(f, " trigger \"%s\"",
|
||||||
|
probe->trigger);
|
||||||
fprintf(f, "\n");
|
fprintf(f, "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
devcnt++;
|
devcnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: protocol analyzers */
|
/* TODO: Protocol analyzers */
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int session_save(char *filename)
|
int session_save(char *filename)
|
||||||
{
|
{
|
||||||
GSList *l, *d;
|
GSList *l, *d;
|
||||||
|
@ -222,55 +196,59 @@ int session_save(char *filename)
|
||||||
int bufcnt, devcnt, tmpfile, ret, error;
|
int bufcnt, devcnt, tmpfile, ret, error;
|
||||||
char version[1], rawname[16], metafile[32], *buf;
|
char version[1], rawname[16], metafile[32], *buf;
|
||||||
|
|
||||||
/* quietly delete it first, libzip wants replace ops otherwise */
|
/* Quietly delete it first, libzip wants replace ops otherwise. */
|
||||||
unlink(filename);
|
unlink(filename);
|
||||||
|
|
||||||
if( !(zipfile = zip_open(filename, ZIP_CREATE, &error)) )
|
if (!(zipfile = zip_open(filename, ZIP_CREATE, &error)))
|
||||||
return SIGROK_ERR;
|
return SIGROK_ERR;
|
||||||
|
|
||||||
/* version */
|
/* Version */
|
||||||
version[0] = '1';
|
version[0] = '1';
|
||||||
if( !(src = zip_source_buffer(zipfile, version, 1, 0)) )
|
if (!(src = zip_source_buffer(zipfile, version, 1, 0)))
|
||||||
return SIGROK_ERR;
|
return SIGROK_ERR;
|
||||||
if(zip_add(zipfile, "version", src) == -1) {
|
if (zip_add(zipfile, "version", src) == -1) {
|
||||||
g_message("error saving version into zipfile: %s", zip_strerror(zipfile));
|
g_message("error saving version into zipfile: %s",
|
||||||
|
zip_strerror(zipfile));
|
||||||
return SIGROK_ERR;
|
return SIGROK_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* metadata */
|
/* Metadata */
|
||||||
strcpy(metafile, "sigrok-meta-XXXXXX");
|
strcpy(metafile, "sigrok-meta-XXXXXX");
|
||||||
if( (tmpfile = g_mkstemp(metafile)) == -1)
|
if ((tmpfile = g_mkstemp(metafile)) == -1)
|
||||||
return SIGROK_ERR;
|
return SIGROK_ERR;
|
||||||
close(tmpfile);
|
close(tmpfile);
|
||||||
make_metadata(metafile);
|
make_metadata(metafile);
|
||||||
if( !(src = zip_source_file(zipfile, metafile, 0, -1)) )
|
if (!(src = zip_source_file(zipfile, metafile, 0, -1)))
|
||||||
return SIGROK_ERR;
|
return SIGROK_ERR;
|
||||||
if(zip_add(zipfile, "metadata", src) == -1)
|
if (zip_add(zipfile, "metadata", src) == -1)
|
||||||
return SIGROK_ERR;
|
return SIGROK_ERR;
|
||||||
unlink(metafile);
|
unlink(metafile);
|
||||||
|
|
||||||
/* raw */
|
/* Raw */
|
||||||
devcnt = 1;
|
devcnt = 1;
|
||||||
for(l = session->devices; l; l = l->next) {
|
for (l = session->devices; l; l = l->next) {
|
||||||
device = l->data;
|
device = l->data;
|
||||||
ds = device->datastore;
|
ds = device->datastore;
|
||||||
if(ds) {
|
if (ds) {
|
||||||
buf = malloc(ds->num_units * ds->ds_unitsize + DATASTORE_CHUNKSIZE);
|
buf = malloc(ds->num_units * ds->ds_unitsize +
|
||||||
|
DATASTORE_CHUNKSIZE);
|
||||||
bufcnt = 0;
|
bufcnt = 0;
|
||||||
for(d = ds->chunklist; d; d = d->next) {
|
for (d = ds->chunklist; d; d = d->next) {
|
||||||
memcpy(buf + bufcnt, d->data, DATASTORE_CHUNKSIZE);
|
memcpy(buf + bufcnt, d->data,
|
||||||
|
DATASTORE_CHUNKSIZE);
|
||||||
bufcnt += DATASTORE_CHUNKSIZE;
|
bufcnt += DATASTORE_CHUNKSIZE;
|
||||||
}
|
}
|
||||||
if( !(src = zip_source_buffer(zipfile, buf, ds->num_units * ds->ds_unitsize, TRUE)) )
|
if (!(src = zip_source_buffer(zipfile, buf,
|
||||||
|
ds->num_units * ds->ds_unitsize, TRUE)))
|
||||||
return SIGROK_ERR;
|
return SIGROK_ERR;
|
||||||
snprintf(rawname, 15, "raw-%d", devcnt);
|
snprintf(rawname, 15, "raw-%d", devcnt);
|
||||||
if(zip_add(zipfile, rawname, src) == -1)
|
if (zip_add(zipfile, rawname, src) == -1)
|
||||||
return SIGROK_ERR;
|
return SIGROK_ERR;
|
||||||
}
|
}
|
||||||
devcnt++;
|
devcnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (ret = zip_close(zipfile)) == -1) {
|
if ((ret = zip_close(zipfile)) == -1) {
|
||||||
g_message("error saving zipfile: %s", zip_strerror(zipfile));
|
g_message("error saving zipfile: %s", zip_strerror(zipfile));
|
||||||
return SIGROK_ERR;
|
return SIGROK_ERR;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue