2 * This file is part of the sigrok project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
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
21 #include "sigsession.h"
23 #include "logicdata.h"
24 #include "logicdatasnapshot.h"
25 #include "logicsignal.h"
31 using namespace boost;
34 // TODO: This should not be necessary
35 SigSession* SigSession::_session = NULL;
37 SigSession::SigSession()
39 // TODO: This should not be necessary
43 SigSession::~SigSession()
45 // TODO: This should not be necessary
49 void SigSession::load_file(const std::string &name)
51 if (sr_session_load(name.c_str()) == SR_OK) {
52 /* sigrok session file */
53 sr_session_datafeed_callback_add(data_feed_in_proc);
60 void SigSession::start_capture(struct sr_dev_inst *sdi,
61 uint64_t record_length, uint64_t sample_rate)
64 sr_session_datafeed_callback_add(data_feed_in_proc);
66 if (sr_session_dev_add(sdi) != SR_OK) {
67 qDebug() << "Failed to use device.";
72 if (sr_dev_config_set(sdi, SR_HWCAP_LIMIT_SAMPLES,
73 &record_length) != SR_OK) {
74 qDebug() << "Failed to configure time-based sample limit.";
79 if (sr_dev_config_set(sdi, SR_HWCAP_SAMPLERATE,
80 &sample_rate) != SR_OK) {
81 qDebug() << "Failed to configure samplerate.";
86 if (sr_session_start() != SR_OK) {
87 qDebug() << "Failed to start session.";
95 vector< shared_ptr<Signal> >& SigSession::get_signals()
100 void SigSession::data_feed_in(const struct sr_dev_inst *sdi,
101 struct sr_datafeed_packet *packet)
106 switch (packet->type) {
111 case SR_DF_META_LOGIC:
113 assert(packet->payload);
115 const sr_datafeed_meta_logic &meta_logic =
116 *(sr_datafeed_meta_logic*)packet->payload;
118 // Create an empty LogiData for coming data snapshots
119 _logic_data.reset(new LogicData(meta_logic));
125 for (int i = 0; i < meta_logic.num_probes; i++)
127 const sr_probe *const probe =
128 (const sr_probe*)g_slist_nth_data(
132 boost::shared_ptr<LogicSignal> signal(
133 new LogicSignal(probe->name,
136 _signals.push_back(signal);
145 assert(packet->payload);
146 if(!_cur_logic_snapshot)
148 // Create a new data snapshot
149 _cur_logic_snapshot = shared_ptr<LogicDataSnapshot>(
150 new LogicDataSnapshot(
151 *(sr_datafeed_logic*)packet->payload));
152 _logic_data->push_snapshot(_cur_logic_snapshot);
156 // Append to the existing data snapshot
157 _cur_logic_snapshot->append_payload(
158 *(sr_datafeed_logic*)packet->payload);
164 _cur_logic_snapshot.reset();
170 void SigSession::data_feed_in_proc(const struct sr_dev_inst *sdi,
171 struct sr_datafeed_packet *packet)
174 _session->data_feed_in(sdi, packet);