]> sigrok.org Git - pulseview.git/blame - sigsession.cpp
Implemented initial data model
[pulseview.git] / sigsession.cpp
CommitLineData
2953961c
JH
1/*
2 * This file is part of the sigrok project.
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
009e1503
JH
23#include <QDebug>
24
2953961c
JH
25#include <assert.h>
26
27// TODO: This should not be necessary
28SigSession* SigSession::session = NULL;
29
009e1503
JH
30SigSession::SigSession() :
31 unitSize(0),
32 sigData(NULL)
2953961c
JH
33{
34 // TODO: This should not be necessary
35 session = this;
36}
37
38SigSession::~SigSession()
39{
009e1503
JH
40 g_array_free(sigData, TRUE);
41
2953961c
JH
42 // TODO: This should not be necessary
43 session = NULL;
44}
45
46void SigSession::loadFile(const std::string &name)
47{
48 if (sr_session_load(name.c_str()) == SR_OK) {
49 /* sigrok session file */
50 sr_session_datafeed_callback_add(dataFeedInProc);
51 sr_session_start();
52 sr_session_run();
53 sr_session_stop();
54 }
55}
56
57void SigSession::dataFeedIn(const struct sr_dev_inst *sdi,
58 struct sr_datafeed_packet *packet)
59{
60 assert(sdi);
61 assert(packet);
62
63 switch (packet->type) {
64 case SR_DF_META_LOGIC:
65 {
66 const sr_datafeed_meta_logic *meta_logic =
67 (sr_datafeed_meta_logic*)packet->payload;
68 int num_enabled_probes = 0;
69
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);
73 if (probe->enabled) {
74 probeList[num_enabled_probes++] = probe->index;
75 }
76 }
009e1503
JH
77
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);
81 }
82 break;
83
84 case SR_DF_LOGIC:
85 {
86 uint64_t filter_out_len;
87 uint8_t *filter_out;
88
89 const struct sr_datafeed_logic *const logic =
90 (sr_datafeed_logic*)packet->payload;
91
92 qDebug() << "SR_DF_LOGIC (length =" << logic->length
93 << ", unitsize = " << logic->unitsize << ")";
94
95 if (sr_filter_probes(logic->unitsize, unitSize,
96 probeList, (uint8_t*)logic->data, logic->length,
97 &filter_out, &filter_out_len) != SR_OK)
98 return;
99
100 assert(sigData);
101 g_array_append_vals(sigData, filter_out, filter_out_len / unitSize);
102
103 g_free(filter_out);
2953961c
JH
104 }
105 break;
106
107 case SR_DF_END:
009e1503 108 dataUpdated();
2953961c
JH
109 break;
110 }
111}
112
113void SigSession::dataFeedInProc(const struct sr_dev_inst *sdi,
114 struct sr_datafeed_packet *packet)
115{
116 assert(session);
117 session->dataFeedIn(sdi, packet);
118}