]> sigrok.org Git - pulseview.git/blame - pv/sigsession.h
Use libsigrok C++ bindings (patch version 7).
[pulseview.git] / pv / sigsession.h
CommitLineData
2953961c 1/*
b3f22de0 2 * This file is part of the PulseView project.
2953961c 3 *
1bc6525b 4 * Copyright (C) 2012-14 Joel Holdsworth <joel@airwebreathe.org.uk>
2953961c
JH
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
640d091b
UH
21#ifndef PULSEVIEW_PV_SIGSESSION_H
22#define PULSEVIEW_PV_SIGSESSION_H
2953961c 23
708c5523 24#include <map>
f9abf97e 25#include <memory>
3b68d03d 26#include <mutex>
bfc9f61e 27#include <set>
28a4c9c5 28#include <string>
3b68d03d 29#include <thread>
e3f65ace 30#include <vector>
28a4c9c5 31
009e1503 32#include <QObject>
f2edb557 33#include <QString>
009e1503 34
82c7f640 35struct srd_decoder;
8bd26d8b 36struct srd_channel;
82c7f640 37
e8d00928
ML
38namespace sigrok {
39 class Analog;
40 class Channel;
41 class Device;
42 class Logic;
43 class Meta;
44 class Packet;
45 class Session;
46}
47
51e77110
JH
48namespace pv {
49
dc0867ff
JH
50class DeviceManager;
51
1b1ec774
JH
52namespace data {
53class Analog;
54class AnalogSnapshot;
55class Logic;
56class LogicSnapshot;
02412f0b 57class SignalData;
1b1ec774 58}
8d634081
JH
59
60namespace view {
b9329558 61class DecodeTrace;
3045c869 62class LogicSignal;
28a4c9c5 63class Signal;
8d634081 64}
2953961c 65
009e1503 66class SigSession : public QObject
2953961c 67{
009e1503
JH
68 Q_OBJECT
69
5b7cf66c
JH
70public:
71 enum capture_state {
72 Stopped,
2b49eeb0 73 AwaitingTrigger,
5b7cf66c
JH
74 Running
75 };
76
2953961c 77public:
dc0867ff 78 SigSession(DeviceManager &device_manager);
2953961c
JH
79
80 ~SigSession();
81
e8d00928 82 std::shared_ptr<sigrok::Device> get_device() const;
dc0867ff 83
d64d1596
JH
84 /**
85 * Sets device instance that will be used in the next capture session.
86 */
e8d00928 87 void set_device(std::shared_ptr<sigrok::Device> device);
d64d1596 88
e8d00928 89 void set_file(const std::string &name);
dc0867ff 90
6fd0b639
JH
91 void set_default_device();
92
5b7cf66c
JH
93 capture_state get_capture_state() const;
94
d2344534 95 void start_capture(std::function<void (const QString)> error_handler);
274d4f13 96
5b7cf66c
JH
97 void stop_capture();
98
f9abf97e 99 std::set< std::shared_ptr<data::SignalData> > get_data() const;
02412f0b 100
f9abf97e 101 std::vector< std::shared_ptr<view::Signal> >
38eeddea 102 get_signals() const;
e3f65ace 103
269528f5 104#ifdef ENABLE_DECODE
4e5a4405 105 bool add_decoder(srd_decoder *const dec);
82c7f640 106
f9abf97e 107 std::vector< std::shared_ptr<view::DecodeTrace> >
38eeddea
JH
108 get_decode_signals() const;
109
b9329558 110 void remove_decode_signal(view::DecodeTrace *signal);
269528f5 111#endif
c51482b3 112
6ac96c2e
JH
113private:
114 void set_capture_state(capture_state state);
115
e8d00928 116 void update_signals(std::shared_ptr<sigrok::Device> device);
b087ba7f 117
6ac6242b 118 std::shared_ptr<view::Signal> signal_from_channel(
e8d00928 119 std::shared_ptr<sigrok::Channel> channel) const;
3ddcc083 120
e8d00928 121 void read_sample_rate(std::shared_ptr<sigrok::Device>);
deef291c 122
2953961c 123private:
e8d00928 124 void sample_thread_proc(std::shared_ptr<sigrok::Device> device,
d2344534 125 std::function<void (const QString)> error_handler);
2e2946fe 126
e8d00928 127 void feed_in_header(std::shared_ptr<sigrok::Device> device);
eec446e1 128
e8d00928
ML
129 void feed_in_meta(std::shared_ptr<sigrok::Device> device,
130 std::shared_ptr<sigrok::Meta> meta);
aba1dd16 131
82f50b10
JH
132 void feed_in_frame_begin();
133
e8d00928 134 void feed_in_logic(std::shared_ptr<sigrok::Logic> logic);
aba1dd16 135
e8d00928 136 void feed_in_analog(std::shared_ptr<sigrok::Analog> analog);
2953961c 137
e8d00928
ML
138 void data_feed_in(std::shared_ptr<sigrok::Device> device,
139 std::shared_ptr<sigrok::Packet> packet);
2953961c
JH
140
141private:
dc0867ff 142 DeviceManager &_device_manager;
d64d1596
JH
143
144 /**
145 * The device instance that will be used in the next capture session.
146 */
e8d00928 147 std::shared_ptr<sigrok::Device> _device;
d64d1596 148
f9abf97e 149 std::vector< std::shared_ptr<view::DecodeTrace> > _decode_traces;
82c7f640 150
3b68d03d 151 mutable std::mutex _sampling_mutex;
5b7cf66c
JH
152 capture_state _capture_state;
153
3b68d03d 154 mutable std::mutex _signals_mutex;
f9abf97e 155 std::vector< std::shared_ptr<view::Signal> > _signals;
3868e5fa 156
3b68d03d 157 mutable std::mutex _data_mutex;
f9abf97e
JH
158 std::shared_ptr<data::Logic> _logic_data;
159 std::shared_ptr<data::LogicSnapshot> _cur_logic_snapshot;
e8d00928 160 std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSnapshot> >
bb2cdfff 161 _cur_analog_snapshots;
009e1503 162
3b68d03d 163 std::thread _sampling_thread;
2e2946fe 164
e9213170 165Q_SIGNALS:
6ac96c2e
JH
166 void capture_state_changed(int state);
167
69dd2b03
JH
168 void signals_changed();
169
82f50b10
JH
170 void frame_began();
171
1f374035
JH
172 void data_received();
173
174 void frame_ended();
2953961c 175
bb3030b3 176public:
e8d00928
ML
177 // Hack. The libsigrok API now allows for multiple sessions. However,
178 // sigrok::Session calls are scattered around the PV architecture and a
179 // single SigSession object is being used across multiple sequential
180 // sessions. This is a mess. For now just keep a single sigrok::Session
181 // pointer here which we can use for all those scattered calls.
182 static std::shared_ptr<sigrok::Session> _sr_session;
2953961c
JH
183};
184
51e77110
JH
185} // namespace pv
186
640d091b 187#endif // PULSEVIEW_PV_SIGSESSION_H