]> sigrok.org Git - pulseview.git/blame - pv/sigsession.h
icons: Renamed probe.svg to channels.svg
[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
2953961c 35#include <libsigrok/libsigrok.h>
2953961c 36
82c7f640 37struct srd_decoder;
8bd26d8b 38struct srd_channel;
82c7f640 39
51e77110
JH
40namespace pv {
41
dc0867ff
JH
42class DeviceManager;
43
1b1ec774
JH
44namespace data {
45class Analog;
46class AnalogSnapshot;
47class Logic;
48class LogicSnapshot;
02412f0b 49class SignalData;
1b1ec774 50}
8d634081 51
94574501
JH
52namespace device {
53class DevInst;
54}
55
8d634081 56namespace view {
b9329558 57class DecodeTrace;
3045c869 58class LogicSignal;
28a4c9c5 59class Signal;
8d634081 60}
2953961c 61
009e1503 62class SigSession : public QObject
2953961c 63{
009e1503
JH
64 Q_OBJECT
65
5b7cf66c
JH
66public:
67 enum capture_state {
68 Stopped,
2b49eeb0 69 AwaitingTrigger,
5b7cf66c
JH
70 Running
71 };
72
2953961c 73public:
dc0867ff 74 SigSession(DeviceManager &device_manager);
2953961c
JH
75
76 ~SigSession();
77
f9abf97e 78 std::shared_ptr<device::DevInst> get_device() const;
dc0867ff 79
d64d1596
JH
80 /**
81 * Sets device instance that will be used in the next capture session.
82 */
f9abf97e 83 void set_device(std::shared_ptr<device::DevInst> dev_inst)
ae2d1bc5 84 throw(QString);
d64d1596 85
ae2d1bc5
JH
86 void set_file(const std::string &name)
87 throw(QString);
dc0867ff 88
6fd0b639
JH
89 void set_default_device();
90
ae2d1bc5 91 void release_device(device::DevInst *dev_inst);
2953961c 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
f9abf97e 116 void update_signals(std::shared_ptr<device::DevInst> dev_inst);
b087ba7f 117
6ac6242b
ML
118 std::shared_ptr<view::Signal> signal_from_channel(
119 const sr_channel *channel) const;
3ddcc083 120
deef291c
JH
121 void read_sample_rate(const sr_dev_inst *const sdi);
122
2953961c 123private:
f9abf97e 124 void sample_thread_proc(std::shared_ptr<device::DevInst> dev_inst,
d2344534 125 std::function<void (const QString)> error_handler);
2e2946fe 126
eec446e1
JH
127 void feed_in_header(const sr_dev_inst *sdi);
128
be73bdfa
JH
129 void feed_in_meta(const sr_dev_inst *sdi,
130 const sr_datafeed_meta &meta);
aba1dd16 131
82f50b10
JH
132 void feed_in_frame_begin();
133
9c112671
JH
134 void feed_in_logic(const sr_datafeed_logic &logic);
135
aba1dd16
JH
136 void feed_in_analog(const sr_datafeed_analog &analog);
137
04abfae9 138 void data_feed_in(const struct sr_dev_inst *sdi,
bc5c1a99 139 const struct sr_datafeed_packet *packet);
2953961c 140
04abfae9 141 static void data_feed_in_proc(const struct sr_dev_inst *sdi,
5045f16d 142 const struct sr_datafeed_packet *packet, void *cb_data);
2953961c
JH
143
144private:
dc0867ff 145 DeviceManager &_device_manager;
d64d1596
JH
146
147 /**
148 * The device instance that will be used in the next capture session.
149 */
f9abf97e 150 std::shared_ptr<device::DevInst> _dev_inst;
d64d1596 151
f9abf97e 152 std::vector< std::shared_ptr<view::DecodeTrace> > _decode_traces;
82c7f640 153
3b68d03d 154 mutable std::mutex _sampling_mutex;
5b7cf66c
JH
155 capture_state _capture_state;
156
3b68d03d 157 mutable std::mutex _signals_mutex;
f9abf97e 158 std::vector< std::shared_ptr<view::Signal> > _signals;
3868e5fa 159
3b68d03d 160 mutable std::mutex _data_mutex;
f9abf97e
JH
161 std::shared_ptr<data::Logic> _logic_data;
162 std::shared_ptr<data::LogicSnapshot> _cur_logic_snapshot;
163 std::map< const sr_channel*, std::shared_ptr<data::AnalogSnapshot> >
bb2cdfff 164 _cur_analog_snapshots;
009e1503 165
3b68d03d 166 std::thread _sampling_thread;
2e2946fe 167
e9213170 168Q_SIGNALS:
6ac96c2e
JH
169 void capture_state_changed(int state);
170
69dd2b03
JH
171 void signals_changed();
172
82f50b10
JH
173 void frame_began();
174
1f374035
JH
175 void data_received();
176
177 void frame_ended();
2953961c
JH
178
179private:
180 // TODO: This should not be necessary. Multiple concurrent
181 // sessions should should be supported and it should be
182 // possible to associate a pointer with a sr_session.
04abfae9 183 static SigSession *_session;
bb3030b3
ML
184
185public:
186 // TODO: Even more of a hack. The libsigrok API now allows for
187 // multiple sessions. However sr_session_* calls are scattered
188 // around the PV architecture and a single SigSession object is
189 // being used across multiple sequential sessions, which are
190 // created and destroyed in other classes in pv::device. This
191 // is a mess. For now just keep a single sr_session pointer here
192 // which we can use for all those scattered calls.
193 static struct sr_session *_sr_session;
2953961c
JH
194};
195
51e77110
JH
196} // namespace pv
197
640d091b 198#endif // PULSEVIEW_PV_SIGSESSION_H