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"
27 // TODO: This should not be necessary
28 SigSession* SigSession::session = NULL;
30 SigSession::SigSession() :
34 // TODO: This should not be necessary
38 SigSession::~SigSession()
40 g_array_free(sigData, TRUE);
42 // TODO: This should not be necessary
46 void SigSession::loadFile(const std::string &name)
48 if (sr_session_load(name.c_str()) == SR_OK) {
49 /* sigrok session file */
50 sr_session_datafeed_callback_add(dataFeedInProc);
57 void SigSession::dataFeedIn(const struct sr_dev_inst *sdi,
58 struct sr_datafeed_packet *packet)
63 switch (packet->type) {
64 case SR_DF_META_LOGIC:
66 const sr_datafeed_meta_logic *meta_logic =
67 (sr_datafeed_meta_logic*)packet->payload;
68 int num_enabled_probes = 0;
70 for (int i = 0; i < meta_logic->num_probes; i++) {
71 const sr_probe *probe =
72 (sr_probe *)g_slist_nth_data(sdi->probes, i);
74 probeList[num_enabled_probes++] = probe->index;
78 /* How many bytes we need to store num_enabled_probes bits */
79 unitSize = (num_enabled_probes + 7) / 8;
80 sigData = g_array_new(FALSE, FALSE, unitSize);
86 uint64_t filter_out_len;
89 const struct sr_datafeed_logic *const logic =
90 (sr_datafeed_logic*)packet->payload;
92 qDebug() << "SR_DF_LOGIC (length =" << logic->length
93 << ", unitsize = " << logic->unitsize << ")";
95 if (sr_filter_probes(logic->unitsize, unitSize,
96 probeList, (uint8_t*)logic->data, logic->length,
97 &filter_out, &filter_out_len) != SR_OK)
101 g_array_append_vals(sigData, filter_out, filter_out_len / unitSize);
113 void SigSession::dataFeedInProc(const struct sr_dev_inst *sdi,
114 struct sr_datafeed_packet *packet)
117 session->dataFeedIn(sdi, packet);