]> sigrok.org Git - pulseview.git/blame - pv/sigsession.cpp
Don't highlight when dragging
[pulseview.git] / pv / sigsession.cpp
CommitLineData
2953961c 1/*
b3f22de0 2 * This file is part of the PulseView project.
2953961c
JH
3 *
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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
21#include "sigsession.h"
22
28a4c9c5
JH
23#include "logicdata.h"
24#include "logicdatasnapshot.h"
8d634081 25#include "view/logicsignal.h"
28a4c9c5 26
009e1503
JH
27#include <QDebug>
28
2953961c
JH
29#include <assert.h>
30
28a4c9c5 31using namespace boost;
e3f65ace 32using namespace std;
28a4c9c5 33
51e77110
JH
34namespace pv {
35
2953961c 36// TODO: This should not be necessary
04abfae9 37SigSession* SigSession::_session = NULL;
2953961c 38
28a4c9c5 39SigSession::SigSession()
2953961c
JH
40{
41 // TODO: This should not be necessary
04abfae9 42 _session = this;
2953961c
JH
43}
44
45SigSession::~SigSession()
46{
47 // TODO: This should not be necessary
04abfae9 48 _session = NULL;
2953961c
JH
49}
50
04abfae9 51void SigSession::load_file(const std::string &name)
2953961c
JH
52{
53 if (sr_session_load(name.c_str()) == SR_OK) {
54 /* sigrok session file */
04abfae9 55 sr_session_datafeed_callback_add(data_feed_in_proc);
2953961c
JH
56 sr_session_start();
57 sr_session_run();
58 sr_session_stop();
59 }
60}
61
274d4f13 62void SigSession::start_capture(struct sr_dev_inst *sdi,
215f9499 63 uint64_t record_length, uint64_t sample_rate)
274d4f13
JH
64{
65 sr_session_new();
04abfae9 66 sr_session_datafeed_callback_add(data_feed_in_proc);
274d4f13
JH
67
68 if (sr_session_dev_add(sdi) != SR_OK) {
69 qDebug() << "Failed to use device.";
70 sr_session_destroy();
71 return;
72 }
73
274d4f13 74 if (sr_dev_config_set(sdi, SR_HWCAP_LIMIT_SAMPLES,
215f9499 75 &record_length) != SR_OK) {
274d4f13
JH
76 qDebug() << "Failed to configure time-based sample limit.";
77 sr_session_destroy();
78 return;
79 }
80
81 if (sr_dev_config_set(sdi, SR_HWCAP_SAMPLERATE,
82 &sample_rate) != SR_OK) {
83 qDebug() << "Failed to configure samplerate.";
84 sr_session_destroy();
85 return;
86 }
87
88 if (sr_session_start() != SR_OK) {
89 qDebug() << "Failed to start session.";
90 return;
91 }
92
93 sr_session_run();
94 sr_session_destroy();
95}
96
8d634081 97vector< shared_ptr<view::Signal> >& SigSession::get_signals()
e3f65ace
JH
98{
99 return _signals;
100}
101
adb4b10c
JH
102boost::shared_ptr<LogicData> SigSession::get_data()
103{
104 return _logic_data;
105}
106
04abfae9 107void SigSession::data_feed_in(const struct sr_dev_inst *sdi,
2953961c
JH
108 struct sr_datafeed_packet *packet)
109{
8d634081
JH
110 using view::LogicSignal;
111
2953961c
JH
112 assert(sdi);
113 assert(packet);
114
115 switch (packet->type) {
28a4c9c5 116 case SR_DF_HEADER:
e3f65ace 117 _signals.clear();
009e1503
JH
118 break;
119
28a4c9c5 120 case SR_DF_META_LOGIC:
009e1503 121 {
28a4c9c5 122 assert(packet->payload);
009e1503 123
e3f65ace
JH
124 const sr_datafeed_meta_logic &meta_logic =
125 *(sr_datafeed_meta_logic*)packet->payload;
009e1503 126
e3f65ace
JH
127 // Create an empty LogiData for coming data snapshots
128 _logic_data.reset(new LogicData(meta_logic));
28a4c9c5
JH
129 assert(_logic_data);
130 if(!_logic_data)
131 break;
009e1503 132
e3f65ace
JH
133 // Add the signals
134 for (int i = 0; i < meta_logic.num_probes; i++)
135 {
136 const sr_probe *const probe =
137 (const sr_probe*)g_slist_nth_data(
138 sdi->probes, i);
139 if(probe->enabled)
140 {
8d634081 141 shared_ptr<LogicSignal> signal(
e3f65ace
JH
142 new LogicSignal(probe->name,
143 _logic_data,
144 probe->index));
145 _signals.push_back(signal);
146 }
147 }
148
28a4c9c5 149 break;
2953961c 150 }
28a4c9c5
JH
151
152 case SR_DF_LOGIC:
f556bc6a 153
28a4c9c5 154 assert(packet->payload);
f556bc6a
JH
155 if(!_cur_logic_snapshot)
156 {
157 // Create a new data snapshot
158 _cur_logic_snapshot = shared_ptr<LogicDataSnapshot>(
159 new LogicDataSnapshot(
160 *(sr_datafeed_logic*)packet->payload));
161 _logic_data->push_snapshot(_cur_logic_snapshot);
162 }
163 else
164 {
165 // Append to the existing data snapshot
28a4c9c5
JH
166 _cur_logic_snapshot->append_payload(
167 *(sr_datafeed_logic*)packet->payload);
f556bc6a
JH
168 }
169
2953961c
JH
170 break;
171
172 case SR_DF_END:
28a4c9c5 173 _cur_logic_snapshot.reset();
04abfae9 174 data_updated();
2953961c
JH
175 break;
176 }
177}
178
04abfae9 179void SigSession::data_feed_in_proc(const struct sr_dev_inst *sdi,
2953961c
JH
180 struct sr_datafeed_packet *packet)
181{
04abfae9
JH
182 assert(_session);
183 _session->data_feed_in(sdi, packet);
2953961c 184}
51e77110
JH
185
186} // namespace pv