This patch let you run protocol decoders.
This is a preliminary support, which don't support protocol decoder's
chaining.
ex:
/cli/sigrok-cli -d demo --samples 100 -a transitioncounter
Details:
- Renamed command-line options : analyzer* to protocol-decoder*
- Added PDPLUGINS_PATH in Makefiles so we can use protocol decoder
plugin path in code.
- Command-line option "-A" returns list of installed protocol
decoders.
- Command-line option "-a" let you specify a protocol decoder
--
Olivier Fauchon
www.oflabs.com
diff --git a/cli/Makefile.am b/cli/Makefile.am
index a38459f..06c6304 100644
--- a/cli/Makefile.am
+++ b/cli/Makefile.am
@@ -23,6 +23,7 @@ sigrok_cli_SOURCES = sigrok-cli.c parsers.c
sigrok_cli_CPPFLAGS = -I$(top_srcdir)/libsigrok \
-I$(top_srcdir)/libsigrokdecode \
+ -DPDPLUGINS_DIR='"$(PDPLUGINS_DIR)"' \
$(CPPFLAGS_PYTHON)
sigrok_cli_LDADD = $(LIBOBJS) \
diff --git a/cli/sigrok-cli.c b/cli/sigrok-cli.c
index 39949e7..4725e11 100644
--- a/cli/sigrok-cli.c
+++ b/cli/sigrok-cli.c
@@ -34,7 +34,6 @@
#include "sigrok-cli.h"
#include "config.h"
-
#define SIGROK_CLI_VERSION "0.1pre2"
#define DEFAULT_OUTPUT_FORMAT "bits64"
@@ -47,6 +46,10 @@ struct output_format *output_format = NULL;
char *output_format_param = NULL;
char *input_format_param = NULL;
+/* decoder */
+struct sigrokdecode_decoder *dec;
+char* current_decoder;
+
/* These live in hwplugin.c, for the frontend to override. */
extern source_callback_add source_cb_add;
extern source_callback_remove source_cb_remove;
@@ -66,7 +69,7 @@ int source_timeout = -1;
static gboolean opt_version = FALSE;
static gboolean opt_list_hwdrivers = FALSE;
static gboolean opt_list_devices = FALSE;
-static gboolean opt_list_analyzers = FALSE;
+static gboolean opt_list_dp = FALSE;
static gboolean opt_list_output = FALSE;
static gboolean opt_wait_trigger = FALSE;
static gchar *opt_input_file = NULL;
@@ -86,7 +89,7 @@ static GOptionEntry optargs[] = {
{"version", 'V', 0, G_OPTION_ARG_NONE, &opt_version, "Show version", NULL},
{"list-hardware-drivers", 'H', 0, G_OPTION_ARG_NONE, &opt_list_hwdrivers, "List hardware drivers", NULL},
{"list-devices", 'D', 0, G_OPTION_ARG_NONE, &opt_list_devices, "List devices", NULL},
- {"list-analyzer-plugins", 'A', 0, G_OPTION_ARG_NONE, &opt_list_analyzers, "List analyzer plugins", NULL},
+ {"list-protocol-decoder-plugins", 'A', 0, G_OPTION_ARG_NONE, &opt_list_dp, "List protocol-decoders plugins", NULL},
{"list-output-modules", 0, 0, G_OPTION_ARG_NONE, &opt_list_output, "list output modules", NULL},
{"input-file", 'I', 0, G_OPTION_ARG_FILENAME, &opt_input_file, "Load input from file", NULL},
{"load-file", 'L', 0, G_OPTION_ARG_FILENAME, &opt_load_filename, "Load session from file", NULL},
@@ -96,7 +99,7 @@ static GOptionEntry optargs[] = {
{"triggers", 't', 0, G_OPTION_ARG_STRING, &opt_triggers, "Trigger configuration", NULL},
{"wait-trigger", 'w', 0, G_OPTION_ARG_NONE, &opt_wait_trigger, "Wait for trigger", NULL},
{"device-option", 'o', 0, G_OPTION_ARG_STRING_ARRAY, &opt_devoption, "Device-specific option", NULL},
- {"analyzers", 'a', 0, G_OPTION_ARG_STRING, &opt_pds, "Protocol analyzer sequence", NULL},
+ {"protocol-decoder", 'a', 0, G_OPTION_ARG_STRING, &opt_pds, "Protocol decoder sequence", NULL},
{"format", 'f', 0, G_OPTION_ARG_STRING, &opt_format, "Output format", NULL},
{"time", 0, 0, G_OPTION_ARG_STRING, &opt_time, "How long to sample (ms)", NULL},
{"samples", 0, 0, G_OPTION_ARG_STRING, &opt_samples, "Number of samples to acquire", NULL},
@@ -235,9 +238,15 @@ void show_device_detail(void)
}
}
-void show_analyzer_list(void)
+void show_pd_list(void)
{
- /* TODO: Implement. */
+ GSList *l;
+
+ printf("Available protocol decoders : \n");
+ for (l = list_pdplugins; l; l = l->next)
+ printf("- %s\n", (char*) l->data);
+ printf("\n");
+
}
void show_output_list(void)
@@ -374,6 +383,14 @@ void datafeed_in(struct device *device, struct datafeed_packet *packet)
datastore_put(device->datastore, filter_out,
filter_out_len, sample_size, probelist);
+ if (current_decoder){
+ uint8_t* decod_out;
+ uint64_t decod_out_size;
+ // TODO Handle errors
+ sigrokdecode_run_decoder(dec, packet->payload, packet->length, &decod_out, &decod_out_size);
+ printf(">>>> Protocol decoder output:\n%s\n",decod_out);
+ }
+
/* Don't dump samples on stdout when also saving the session. */
output_len = 0;
if (!opt_save_filename) {
@@ -451,35 +468,21 @@ void add_source(int fd, int events, int timeout, receive_data_callback callback,
/* TODO: Only register here, run in streaming fashion later/elsewhere. */
static int register_pds(struct device *device, const char *pdstring)
{
- int i, ret;
char **tokens;
- uint8_t *inbuf = NULL, *outbuf = NULL;
- uint64_t outbuflen = 0;
- struct sigrokdecode_decoder *dec;
/* Avoid compiler warnings. */
device = device;
- /* FIXME: Just for testing... */
-#define BUFLEN 50
- inbuf = calloc(BUFLEN, 1);
- for (i = 0; i < BUFLEN; i++) /* Fill array with some values. */
- inbuf[i] = (uint8_t) (rand() % 256);
-
- /* TODO: Error handling. */
tokens = g_strsplit(pdstring, ",", 10 /* FIXME */);
-
- /* Run specified PDs serially on the data, in the given order. */
- for (i = 0; tokens[i]; i++) {
- printf("Running protocol decoder %d (%s).\n", i, tokens[i]);
- sigrokdecode_init();
- ret = sigrokdecode_load_decoder(tokens[i], &dec);
- ret = sigrokdecode_run_decoder(dec, inbuf, BUFLEN, &outbuf,
- &outbuflen);
- printf("outbuf (%" PRIu64 " bytes):\n%s\n", outbuflen, outbuf);
- sigrokdecode_shutdown();
+
+ if ( tokens[0] && strlen(tokens[0])>0 ) {
+ current_decoder = tokens[0];
+ // TODO: Handle errors.
+ sigrokdecode_load_decoder(current_decoder, &dec);
+
}
+
return 0;
}
@@ -588,10 +591,6 @@ void run_session(void)
uint64_t tmp_u64;
char **probelist, *val;
- /* FIXME: Wrong location, just for testing... */
- if (opt_pds)
- register_pds(NULL, opt_pds);
-
device_scan();
num_devices = num_real_devices();
@@ -723,9 +722,6 @@ void run_session(void)
HWCAP_LIMIT_SAMPLES, &limit_samples);
}
- if (opt_pds)
- register_pds(NULL, opt_pds);
-
if (device->plugin->set_configuration(device->plugin_index,
HWCAP_PROBECONFIG, (char *)device->probes) != SIGROK_OK) {
printf("Failed to configure probes.\n");
@@ -804,36 +800,20 @@ int main(int argc, char **argv)
int i;
GOptionContext *context;
GError *error;
-#if 0
- int ret;
- uint8_t *inbuf = NULL, *outbuf = NULL;
- uint64_t outbuflen = 0;
- struct sigrokdecode_decoder *dec;
-#endif
+
+ // Get protocol decoders list
+ if (load_pdplugins() < 0){
+ printf("Error opening protocol decoders directory: '%s'\n", PDPLUGINS_DIR );
+ return 1;
+ }
+
+ // No decoder at the moment
+ current_decoder = NULL;
g_log_set_default_handler(logger, NULL);
if (getenv("SIGROK_DEBUG"))
debug = strtol(getenv("SIGROK_DEBUG"), NULL, 10);
-#if 0
-#define BUFLEN 50
- sigrokdecode_init();
-
- inbuf = calloc(BUFLEN, 1);
- for (i = 0; i < BUFLEN; i++) /* Fill array with some values. */
- // inbuf[i] = i % 256;
- inbuf[i] = (uint8_t) (rand() % 256);
-
- ret = sigrokdecode_load_decoder("i2c", &dec);
- ret = sigrokdecode_run_decoder(dec, inbuf, BUFLEN, &outbuf, &outbuflen);
- printf("outbuf (%" PRIu64 " bytes):\n%s\n", outbuflen, outbuf);
-
- ret = sigrokdecode_load_decoder("transitioncounter", &dec);
- ret = sigrokdecode_run_decoder(dec, inbuf, BUFLEN, &outbuf, &outbuflen);
- printf("outbuf (%" PRIu64 " bytes):\n%s\n", outbuflen, outbuf);
-
- sigrokdecode_shutdown();
-#endif
error = NULL;
context = g_option_context_new(NULL);
@@ -847,6 +827,11 @@ int main(int argc, char **argv)
if (sigrok_init() != SIGROK_OK)
return 1;
+ if (opt_pds){
+ sigrokdecode_init();
+ register_pds(NULL, opt_pds);
+ }
+
if (!opt_format)
opt_format = DEFAULT_OUTPUT_FORMAT;
outputs = output_list();
@@ -870,19 +855,22 @@ int main(int argc, char **argv)
show_hwdriver_list();
else if (opt_list_devices)
show_device_list();
- else if (opt_list_analyzers)
- show_analyzer_list();
+ else if (opt_list_dp)
+ show_pd_list();
else if (opt_list_output)
show_output_list();
else if (opt_input_file)
load_input_file();
- else if (opt_samples || opt_time || opt_continuous)
+ else if (opt_samples || opt_time || opt_continuous )
run_session();
else if (opt_device)
show_device_detail();
else
printf("%s", g_option_context_get_help(context, TRUE, NULL));
+ if (opt_pds)
+ sigrokdecode_shutdown();
+
g_option_context_free(context);
sigrok_cleanup();
diff --git a/configure.ac b/configure.ac
index b537142..b77b6f2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -198,6 +198,7 @@ AC_CONFIG_FILES([Makefile
])
AC_SUBST(FIRMWARE_DIR, '$(datadir)/sigrok/firmware')
+AC_SUBST(PDPLUGINS_DIR, '$(prefix)/share/sigrok')
AC_SUBST(MAKEFLAGS, '--no-print-directory --silent')
AC_SUBST(AM_LIBTOOLFLAGS, '--silent')
diff --git a/libsigrok/Makefile.am b/libsigrok/Makefile.am
index 4d532e0..2f2de88 100644
--- a/libsigrok/Makefile.am
+++ b/libsigrok/Makefile.am
@@ -18,7 +18,8 @@
##
AM_CPPFLAGS = -I $(top_srcdir)/libsigrok \
- -DFIRMWARE_DIR='"$(FIRMWARE_DIR)"'
+ -DFIRMWARE_DIR='"$(FIRMWARE_DIR)"' \
+ -DPDPLUGINS_DIR='"$(PDPLUGINS_DIR)"'
SUBDIRS = hardware input output
@@ -30,6 +31,7 @@ libsigrok_la_SOURCES = \
device.c \
session.c \
hwplugin.c \
+ pdplugin.c \
filter.c
libsigrok_la_LIBADD = \
diff --git a/libsigrok/pdplugin.c b/libsigrok/pdplugin.c
new file mode 100644
index 0000000..9173fba
--- /dev/null
+++ b/libsigrok/pdplugin.c
@@ -0,0 +1,50 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2010 Bert Vermeulen <[email protected]>
+ * Copyright (C) 2011 Olivier Fauchon <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <string.h>
+#include <glib.h>
+#include <sigrok.h>
+#include "config.h"
+
+/* The list of loaded plugins lives here. */
+GSList *list_pdplugins;
+
+int load_pdplugins(void)
+{
+ DIR *dir;
+ if (! (dir=opendir(PDPLUGINS_DIR)) )
+ return SIGROK_INVALID_PDPLUGINS_DIR;
+
+ struct dirent *dp;
+ char *tmp;
+ while ((dp=readdir(dir)) != NULL) {
+ if ( strstr(dp->d_name, ".py"))
+ if ( (tmp = strdup (dp->d_name)) )
+ list_pdplugins = g_slist_append(list_pdplugins, tmp);
+ }
+ closedir(dir);
+
+ return SIGROK_OK;
+}
+
diff --git a/libsigrok/sigrok-proto.h b/libsigrok/sigrok-proto.h
index ed06bd0..02c0533 100644
--- a/libsigrok/sigrok-proto.h
+++ b/libsigrok/sigrok-proto.h
@@ -59,6 +59,12 @@ void device_trigger_set(struct device *device, int probenum, char *trigger);
int load_hwplugins(void);
GSList *list_hwplugins(void);
+
+/* Protocol decoders */
+int load_pdplugins(void);
+GSList *list_pdplugins;
+
+
/* Generic device instances */
struct sigrok_device_instance *sigrok_device_instance_new(int index,
int status, const char *vendor, const char *model, const char *version);
diff --git a/libsigrok/sigrok.h b/libsigrok/sigrok.h
index 9a22cb0..210193f 100644
--- a/libsigrok/sigrok.h
+++ b/libsigrok/sigrok.h
@@ -49,6 +49,7 @@
#define SIGROK_ERR -1 /* Generic/unspecified error */
#define SIGROK_ERR_MALLOC -2 /* Malloc/calloc/realloc error */
#define SIGROK_ERR_SAMPLERATE -3 /* Incorrect samplerate */
+#define SIGROK_INVALID_PDPLUGINS_DIR -4 /* Plugin decoder path invalid */
/* limited by uint64_t */
#define MAX_NUM_PROBES 64
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel