]>
Commit | Line | Data |
---|---|---|
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 | ||
23 | #include "logicdata.h" | |
24 | #include "logicdatasnapshot.h" | |
25 | #include "logicsignal.h" | |
26 | ||
27 | #include <QDebug> | |
28 | ||
29 | #include <assert.h> | |
30 | ||
31 | using namespace boost; | |
32 | using namespace std; | |
33 | ||
34 | // TODO: This should not be necessary | |
35 | SigSession* SigSession::session = NULL; | |
36 | ||
37 | SigSession::SigSession() | |
38 | { | |
39 | // TODO: This should not be necessary | |
40 | session = this; | |
41 | } | |
42 | ||
43 | SigSession::~SigSession() | |
44 | { | |
45 | // TODO: This should not be necessary | |
46 | session = NULL; | |
47 | } | |
48 | ||
49 | void SigSession::loadFile(const std::string &name) | |
50 | { | |
51 | if (sr_session_load(name.c_str()) == SR_OK) { | |
52 | /* sigrok session file */ | |
53 | sr_session_datafeed_callback_add(dataFeedInProc); | |
54 | sr_session_start(); | |
55 | sr_session_run(); | |
56 | sr_session_stop(); | |
57 | } | |
58 | } | |
59 | ||
60 | vector< shared_ptr<Signal> >& SigSession::get_signals() | |
61 | { | |
62 | return _signals; | |
63 | } | |
64 | ||
65 | void SigSession::dataFeedIn(const struct sr_dev_inst *sdi, | |
66 | struct sr_datafeed_packet *packet) | |
67 | { | |
68 | assert(sdi); | |
69 | assert(packet); | |
70 | ||
71 | switch (packet->type) { | |
72 | case SR_DF_HEADER: | |
73 | _signals.clear(); | |
74 | break; | |
75 | ||
76 | case SR_DF_META_LOGIC: | |
77 | { | |
78 | assert(packet->payload); | |
79 | ||
80 | const sr_datafeed_meta_logic &meta_logic = | |
81 | *(sr_datafeed_meta_logic*)packet->payload; | |
82 | ||
83 | // Create an empty LogiData for coming data snapshots | |
84 | _logic_data.reset(new LogicData(meta_logic)); | |
85 | assert(_logic_data); | |
86 | if(!_logic_data) | |
87 | break; | |
88 | ||
89 | // Add the signals | |
90 | for (int i = 0; i < meta_logic.num_probes; i++) | |
91 | { | |
92 | const sr_probe *const probe = | |
93 | (const sr_probe*)g_slist_nth_data( | |
94 | sdi->probes, i); | |
95 | if(probe->enabled) | |
96 | { | |
97 | boost::shared_ptr<LogicSignal> signal( | |
98 | new LogicSignal(probe->name, | |
99 | _logic_data, | |
100 | probe->index)); | |
101 | _signals.push_back(signal); | |
102 | } | |
103 | } | |
104 | ||
105 | break; | |
106 | } | |
107 | ||
108 | case SR_DF_LOGIC: | |
109 | ||
110 | assert(packet->payload); | |
111 | if(!_cur_logic_snapshot) | |
112 | { | |
113 | // Create a new data snapshot | |
114 | _cur_logic_snapshot = shared_ptr<LogicDataSnapshot>( | |
115 | new LogicDataSnapshot( | |
116 | *(sr_datafeed_logic*)packet->payload)); | |
117 | _logic_data->push_snapshot(_cur_logic_snapshot); | |
118 | } | |
119 | else | |
120 | { | |
121 | // Append to the existing data snapshot | |
122 | _cur_logic_snapshot->append_payload( | |
123 | *(sr_datafeed_logic*)packet->payload); | |
124 | } | |
125 | ||
126 | break; | |
127 | ||
128 | case SR_DF_END: | |
129 | _cur_logic_snapshot.reset(); | |
130 | dataUpdated(); | |
131 | break; | |
132 | } | |
133 | } | |
134 | ||
135 | void SigSession::dataFeedInProc(const struct sr_dev_inst *sdi, | |
136 | struct sr_datafeed_packet *packet) | |
137 | { | |
138 | assert(session); | |
139 | session->dataFeedIn(sdi, packet); | |
140 | } |