]> sigrok.org Git - libsigrok.git/blob - src/hardware/demo/protocol.h
8eb841ce7d2e0b5fc61366a6cb9c4673670890e1
[libsigrok.git] / src / hardware / demo / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
5  * Copyright (C) 2011 Olivier Fauchon <olivier@aixmarseille.com>
6  * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
7  * Copyright (C) 2015 Bartosz Golaszewski <bgolaszewski@baylibre.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, see <http://www.gnu.org/licenses/>.
21  */
22
23 #ifndef LIBSIGROK_HARDWARE_DEMO_PROTOCOL_H
24 #define LIBSIGROK_HARDWARE_DEMO_PROTOCOL_H
25
26 #include <stdint.h>
27 #include <libsigrok/libsigrok.h>
28 #include "libsigrok-internal.h"
29
30 #define LOG_PREFIX "demo"
31
32 /* The size in bytes of chunks to send through the session bus. */
33 #define LOGIC_BUFSIZE                   4096
34 /* Size of the analog pattern space per channel. */
35 #define ANALOG_BUFSIZE                  4096
36
37 /* Private, per-device-instance driver context. */
38 struct dev_context {
39         uint64_t cur_samplerate;
40         uint64_t limit_samples;
41         uint64_t limit_msec;
42         uint64_t sent_samples;
43         int64_t start_us;
44         int64_t spent_us;
45         uint64_t step;
46         /* Logic */
47         int32_t num_logic_channels;
48         unsigned int logic_unitsize;
49         /* There is only ever one logic channel group, so its pattern goes here. */
50         uint8_t logic_pattern;
51         unsigned char logic_data[LOGIC_BUFSIZE];
52         /* Analog */
53         int32_t num_analog_channels;
54         GHashTable *ch_ag;
55         gboolean avg; /* True if averaging is enabled */
56         uint64_t avg_samples;
57 };
58
59 /* Logic patterns we can generate. */
60 enum {
61         /**
62          * Spells "sigrok" across 8 channels using '0's (with '1's as
63          * "background") when displayed using the 'bits' output format.
64          * The pattern is repeated every 8 channels, shifted to the right
65          * in time by one bit.
66          */
67         PATTERN_SIGROK,
68
69         /** Pseudo-random values on all channels. */
70         PATTERN_RANDOM,
71
72         /**
73          * Incrementing number across 8 channels. The pattern is repeated
74          * every 8 channels, shifted to the right in time by one bit.
75          */
76         PATTERN_INC,
77
78         /** All channels have a low logic state. */
79         PATTERN_ALL_LOW,
80
81         /** All channels have a high logic state. */
82         PATTERN_ALL_HIGH,
83
84         /**
85          * Mimics a cable squid. Derived from the "works with" logo
86          * to occupy a larger number of channels yet "painting"
87          * something that can get recognized.
88          */
89         PATTERN_SQUID,
90 };
91
92 /* Analog patterns we can generate. */
93 enum {
94         /**
95          * Square wave.
96          */
97         PATTERN_SQUARE,
98         PATTERN_SINE,
99         PATTERN_TRIANGLE,
100         PATTERN_SAWTOOTH,
101 };
102
103 static const char *analog_pattern_str[] = {
104         "square",
105         "sine",
106         "triangle",
107         "sawtooth",
108 };
109
110 struct analog_gen {
111         int pattern;
112         float amplitude;
113         float pattern_data[ANALOG_BUFSIZE];
114         unsigned int num_samples;
115         struct sr_datafeed_analog packet;
116         struct sr_analog_encoding encoding;
117         struct sr_analog_meaning meaning;
118         struct sr_analog_spec spec;
119         float avg_val; /* Average value */
120         unsigned num_avgs; /* Number of samples averaged */
121 };
122
123 SR_PRIV void demo_generate_analog_pattern(struct analog_gen *ag, uint64_t sample_rate);
124 SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data);
125
126 #endif