hey bert & all,
i did quick hack (don't trust my code - i don't have an overview yet
of how things really work) -- it works for me in cli mode
but not in the gui -- seems 'source_cb_add' is not implemented in the
gui ? am i right, or is there another way to get the data in ?
cu
ptr_
On Wed, Apr 14, 2010 at 12:03 PM, Bert Vermeulen <[email protected]> wrote:
> pieter.heremans wrote:
>
>> i don't own a logic alnalyzer (yet) - but want to have a look at
>> sigrok to test the basic functionalities
>>
>> is there a 'dummy' interface -- a device spitting out random bits --
>> or maybe more useful, reading a capture file and replayng it?
>
> Hey Pieter,
>
> We don't have a dummy interface yet, but it is an item on the TODO list
> (feel free to take it on). As for taking input from a capture (or other)
> file, that's being worked on right now. We're also going to be making
> available sample captures, to test protocol decoders etc.
>
>
> --
> Bert Vermeulen [email protected] email/xmpp
>
--
http://www.L45.be/voidpointer
0493 52 5009
diff --git a/libsigrok/Makefile.am b/libsigrok/Makefile.am
index 3c2236a..46de2f3 100644
--- a/libsigrok/Makefile.am
+++ b/libsigrok/Makefile.am
@@ -38,6 +38,7 @@ libsigrok_la_SOURCES = \
hardware/zeroplus-logic-cube/gl_usb.c \
hardware/zeroplus-logic-cube/gl_usb.h \
hardware/zeroplus-logic-cube/zeroplus.c \
+ hardware/dummy/dummy.c \
output/output_binary.c \
output/output_text.c \
output/output_vcd.c \
diff --git a/libsigrok/hardware/dummy/dummy.c b/libsigrok/hardware/dummy/dummy.c
new file mode 100644
index 0000000..18da71e
--- /dev/null
+++ b/libsigrok/hardware/dummy/dummy.c
@@ -0,0 +1,355 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2010 Bert Vermeulen <[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 <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <termios.h>
+#include <string.h>
+#include <poll.h>
+#include <sys/time.h>
+
+#include <glib.h>
+
+#include "sigrok.h"
+
+#define NUM_PROBES 32
+#define TRIGGER_TYPES "01"
+
+
+int capabilities[] = {
+ HWCAP_LOGIC_ANALYZER,
+ HWCAP_SAMPLERATE,
+ HWCAP_CAPTURE_RATIO,
+ HWCAP_LIMIT_SAMPLES,
+ 0
+};
+
+float supported_sample_rates[] = {
+ 1,
+ 2,
+ 4,
+ 8,
+ 100,
+ 1000,
+ 0
+};
+
+/* list of struct serial_device_instance */
+GSList *device_instances = NULL;
+
+
+float cur_sample_rate = 0;
+uint64_t limit_samples = 0;
+/* pre/post trigger capture ratio, in percentage. 0 means no pre-trigger data. */
+int capture_ratio = 0;
+
+
+static int hw_init(char *deviceinfo)
+{
+ deviceinfo = deviceinfo;
+
+ struct sigrok_device_instance *sdi;
+
+ sdi = sigrok_device_instance_new(0, ST_INITIALIZING, "dummy", "random generator", "v1.0");
+ device_instances = g_slist_append(device_instances,sdi);
+
+ return 1;
+}
+
+
+static int hw_opendev(int device_index)
+{
+ struct sigrok_device_instance *sdi;
+
+ device_index = device_index;
+
+ if(!(sdi = get_sigrok_device_instance(device_instances, device_index)))
+ return SIGROK_ERR;
+
+ sdi->status = ST_ACTIVE;
+
+ return SIGROK_OK;
+}
+
+
+static void hw_closedev(int device_index)
+{
+ device_index = device_index;
+}
+
+//TODO sigrok never calls cleanup ?
+static void hw_cleanup(void)
+{
+ struct sigrok_device_instance *sdi;
+ GSList *l;
+
+
+ printf("hw_cleanup dummy devices\n");
+
+ /* properly close all devices */
+ for(l = device_instances; l; l = l->next) {
+ sdi = l->data;
+ sigrok_device_instance_free(sdi);
+ }
+ g_slist_free(device_instances);
+ device_instances = NULL;
+}
+
+
+static void*hw_get_device_info(int device_index, int device_info_id)
+{
+ struct sigrok_device_instance *sdi;
+ void *info;
+
+ if( !(sdi = get_sigrok_device_instance(device_instances, device_index)) )
+ return NULL;
+
+ info = NULL;
+ switch(device_info_id)
+ {
+ case DI_INSTANCE:
+ info = sdi;
+ break;
+ case DI_NUM_PROBES:
+ info = GINT_TO_POINTER(NUM_PROBES);
+ break;
+ case DI_SAMPLERATES:
+ info = &supported_sample_rates;
+ break;
+ case DI_TRIGGER_TYPES:
+ info = TRIGGER_TYPES;
+ break;
+ case DI_CUR_SAMPLERATE:
+ info = &cur_sample_rate;
+ break;
+ }
+
+ return info;
+}
+
+
+static int hw_get_status(int device_index)
+{
+ struct sigrok_device_instance *sdi;
+
+ if(!(sdi = get_sigrok_device_instance(device_instances, device_index)))
+ return SIGROK_ERR;
+
+ return sdi->status;
+}
+
+
+int *hw_get_capabilities(void)
+{
+ return capabilities;
+}
+
+
+
+int configure_probes(GSList *probes)
+{
+ // do nothing
+
+ probes = probes;
+ return SIGROK_OK;
+}
+
+static int set_configuration_samplerate(struct sigrok_device_instance *sdi, uint64_t samplerate)
+{
+ if(samplerate < 0.00001 || samplerate > 200)
+ return SIGROK_ERR_SAMPLERATE;
+ sdi = sdi;
+
+ cur_sample_rate = samplerate;
+
+ return SIGROK_OK;
+}
+
+
+
+static int hw_set_configuration(int device_index, int capability, void *value)
+{
+ struct sigrok_device_instance *sdi;
+ int ret;
+
+ if( !(sdi = get_sigrok_device_instance(device_instances, device_index)) )
+ return SIGROK_ERR;
+
+
+ if(capability == HWCAP_SAMPLERATE)
+ ret = set_configuration_samplerate(sdi, atof(value));
+ else if(capability == HWCAP_PROBECONFIG)
+ //ret = configure_probes( (GSList *) value);
+ ret = SIGROK_ERR;
+ else if(capability == HWCAP_LIMIT_SAMPLES)
+ {
+ limit_samples = strtoull(value, NULL, 10);
+ ret = SIGROK_OK;
+ }
+ else if(capability == HWCAP_CAPTURE_RATIO)
+ {
+ capture_ratio = strtol(value, NULL, 10);
+ if(capture_ratio < 0 || capture_ratio > 100)
+ {
+ capture_ratio = 0;
+ ret = SIGROK_ERR;
+ }
+ else
+ ret = SIGROK_OK;
+ }
+ else
+ ret = SIGROK_ERR;
+ return ret;
+}
+
+
+static int receive_data(int fd, int revents, void *user_data)
+{
+
+ static unsigned int num_transfers = 0;
+
+ static char last_sample[4] = {0xff};
+ static int num_bytes = 0;
+ static unsigned char sample[4];
+ struct datafeed_packet packet;
+ unsigned char byte, *buffer;
+ int buflen, num_channels;
+
+ num_channels = 32;
+
+ if(num_transfers++ == 0) {
+ /* first time round, means the device started sending data, and will not
+ * stop until done. if it stops sending for longer than it takes to send
+ * a byte, that means it's finished. we'll double that to 30ms to be sure...
+ */
+ source_remove(fd);
+ source_add(fd, G_IO_IN, 100, receive_data, user_data);
+ }
+
+
+ if(revents == G_IO_IN && num_transfers / num_channels <= limit_samples) {
+
+ byte = 0xff & rand();
+ sample[num_bytes++] = byte;
+ if(num_bytes == 4)
+ {
+ /* no compression */
+ buffer = sample;
+ buflen = 4;
+
+ /* send it all to the session bus */
+ packet.type = DF_LOGIC32;
+ packet.length = buflen;
+ packet.payload = buffer;
+ session_bus(user_data, &packet);
+ if(buffer == sample)
+ memcpy(last_sample, buffer, 4);
+ else
+ g_free(buffer);
+
+ memset(sample, 0, 4);
+ num_bytes = 0;
+ }
+
+ } else {
+ /* this is the main loop telling us a timeout was reached, or we've
+ * acquired all the samples we asked for -- we're done */
+ packet.type = DF_END;
+ packet.length = 0;
+ session_bus(user_data, &packet);
+ }
+
+
+ return TRUE;
+}
+
+
+static int hw_start_acquisition(int device_index, gpointer session_device_id)
+{
+ struct datafeed_packet *packet;
+ struct datafeed_header *header;
+ struct sigrok_device_instance *sdi;
+
+ if(!(sdi = get_sigrok_device_instance(device_instances, device_index)))
+ return SIGROK_ERR;
+
+
+
+ /* start acquisition on the device */
+ source_add(0 , POLLIN,-1, receive_data, session_device_id);
+ //void source_add(int fd, int events, int timeout, receive_data_callback rcv_cb, void *user_data);
+
+
+ /* send header packet to the session bus */
+ packet = g_malloc(sizeof(struct datafeed_packet));
+ header = g_malloc(sizeof(struct datafeed_header));
+ if(!packet || !header)
+ return SIGROK_ERR;
+
+ packet->type = DF_HEADER;
+ packet->length = sizeof(struct datafeed_header);
+ packet->payload = (unsigned char *) header;
+ header->feed_version = 1;
+ gettimeofday(&header->starttime, NULL);
+ header->samplerate = cur_sample_rate;
+ header->protocol_id = PROTO_RAW;
+ header->num_probes = NUM_PROBES;
+ session_bus(session_device_id, packet);
+ g_free(header);
+ g_free(packet);
+
+
+ return SIGROK_OK;
+}
+
+
+static void hw_stop_acquisition(int device_index, gpointer session_device_id)
+{
+ struct datafeed_packet packet;
+
+ device_index = device_index;
+
+ packet.type = DF_END;
+ session_bus(session_device_id, &packet);
+
+}
+
+
+
+struct device_plugin dummy_plugin_info = {
+ "dummy",
+ 1,
+ hw_init,
+ hw_cleanup,
+
+ hw_opendev,
+ hw_closedev,
+ hw_get_device_info,
+ hw_get_status,
+ hw_get_capabilities,
+ hw_set_configuration,
+ hw_start_acquisition,
+ hw_stop_acquisition
+};
+
diff --git a/libsigrok/hwplugin.c b/libsigrok/hwplugin.c
index 3f0e496..f6b9da5 100644
--- a/libsigrok/hwplugin.c
+++ b/libsigrok/hwplugin.c
@@ -41,12 +41,14 @@ struct hwcap_option hwcap_options[] = {
extern struct device_plugin saleae_logic_plugin_info;
extern struct device_plugin ols_plugin_info;
extern struct device_plugin zeroplus_logic_cube_plugin_info;
+extern struct device_plugin dummy_plugin_info;
int load_hwplugins(void)
{
plugins = g_slist_append(plugins, (gpointer *)&saleae_logic_plugin_info);
plugins = g_slist_append(plugins, (gpointer *)&ols_plugin_info);
plugins = g_slist_append(plugins, (gpointer *)&zeroplus_logic_cube_plugin_info);
+ plugins = g_slist_append(plugins, (gpointer *)&dummy_plugin_info);
return SIGROK_OK;
}
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel