]> sigrok.org Git - libsigrok.git/blame_incremental - src/hardware/demo/protocol.h
demo: Get/Set measurement quantity for the analog channels.
[libsigrok.git] / src / hardware / demo / protocol.h
... / ...
CommitLineData
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 * Copyright (C) 2019 Frank Stettner <frank-stettner@gmx.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 */
23
24#ifndef LIBSIGROK_HARDWARE_DEMO_PROTOCOL_H
25#define LIBSIGROK_HARDWARE_DEMO_PROTOCOL_H
26
27#include <stdint.h>
28#include <libsigrok/libsigrok.h>
29#include "libsigrok-internal.h"
30
31#define LOG_PREFIX "demo"
32
33/* The size in bytes of chunks to send through the session bus. */
34#define LOGIC_BUFSIZE 4096
35/* Size of the analog pattern space per channel. */
36#define ANALOG_BUFSIZE 4096
37/* This is a development feature: it starts a new frame every n samples. */
38#define SAMPLES_PER_FRAME 1000UL
39#define DEFAULT_LIMIT_FRAMES 0
40
41/* Logic patterns we can generate. */
42enum logic_pattern_type {
43 /**
44 * Spells "sigrok" across 8 channels using '0's (with '1's as
45 * "background") when displayed using the 'bits' output format.
46 * The pattern is repeated every 8 channels, shifted to the right
47 * in time by one bit.
48 */
49 PATTERN_SIGROK,
50
51 /** Pseudo-random values on all channels. */
52 PATTERN_RANDOM,
53
54 /**
55 * Incrementing number across 8 channels. The pattern is repeated
56 * every 8 channels, shifted to the right in time by one bit.
57 */
58 PATTERN_INC,
59
60 /**
61 * Single bit "walking" across all logic channels by being
62 * shifted across data lines, restarting after the last line
63 * was used. An all-zero (all-one) state is inserted to prevent
64 * repetitive patterns (e.g. with 8 data lines, every 8th state
65 * would show the same line state)
66 */
67 PATTERN_WALKING_ONE,
68 PATTERN_WALKING_ZERO,
69
70 /** All channels have a low logic state. */
71 PATTERN_ALL_LOW,
72
73 /** All channels have a high logic state. */
74 PATTERN_ALL_HIGH,
75
76 /**
77 * Mimics a cable squid. Derived from the "works with" logo
78 * to occupy a larger number of channels yet "painting"
79 * something that can get recognized.
80 */
81 PATTERN_SQUID,
82
83 /** Gray encoded data, like rotary encoder signals. */
84 PATTERN_GRAYCODE,
85};
86
87/* Analog patterns we can generate. */
88enum analog_pattern_type {
89 PATTERN_SQUARE,
90 PATTERN_SINE,
91 PATTERN_TRIANGLE,
92 PATTERN_SAWTOOTH,
93};
94
95struct dev_context {
96 uint64_t cur_samplerate;
97 uint64_t limit_samples;
98 uint64_t limit_msec;
99 uint64_t limit_frames;
100 uint64_t sent_samples;
101 uint64_t sent_frame_samples; /* Number of samples that were sent for current frame. */
102 int64_t start_us;
103 int64_t spent_us;
104 uint64_t step;
105 /* Logic */
106 int32_t num_logic_channels;
107 size_t logic_unitsize;
108 uint64_t all_logic_channels_mask;
109 /* There is only ever one logic channel group, so its pattern goes here. */
110 enum logic_pattern_type logic_pattern;
111 uint8_t logic_data[LOGIC_BUFSIZE];
112 /* Analog */
113 int32_t num_analog_channels;
114 GHashTable *ch_ag;
115 gboolean avg; /* True if averaging is enabled */
116 uint64_t avg_samples;
117 size_t enabled_logic_channels;
118 size_t enabled_analog_channels;
119 size_t first_partial_logic_index;
120 uint8_t first_partial_logic_mask;
121 /* Triggers */
122 uint64_t capture_ratio;
123 gboolean trigger_fired;
124 struct soft_trigger_logic *stl;
125};
126
127static const char *analog_pattern_str[] = {
128 "square",
129 "sine",
130 "triangle",
131 "sawtooth",
132};
133
134struct analog_gen {
135 struct sr_channel *ch;
136 enum sr_mq mq;
137 enum sr_mqflag mq_flags;
138 enum sr_unit unit;
139 enum analog_pattern_type pattern;
140 float amplitude;
141 float pattern_data[ANALOG_BUFSIZE];
142 unsigned int num_samples;
143 struct sr_datafeed_analog packet;
144 struct sr_analog_encoding encoding;
145 struct sr_analog_meaning meaning;
146 struct sr_analog_spec spec;
147 float avg_val; /* Average value */
148 unsigned int num_avgs; /* Number of samples averaged */
149};
150
151SR_PRIV void demo_generate_analog_pattern(struct analog_gen *ag, uint64_t sample_rate);
152SR_PRIV int demo_prepare_data(int fd, int revents, void *cb_data);
153
154#endif