2 * This file is part of the PulseView project.
4 * Copyright (C) 2012-14 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, see <http://www.gnu.org/licenses/>.
21 // Windows: Avoid boost/thread namespace pollution (which includes windows.h).
25 #include <boost/thread/locks.hpp>
26 #include <boost/thread/shared_mutex.hpp>
36 #include "session.hpp"
37 #include "devicemanager.hpp"
39 #include "data/analog.hpp"
40 #include "data/analogsegment.hpp"
41 #include "data/decoderstack.hpp"
42 #include "data/logic.hpp"
43 #include "data/logicsegment.hpp"
44 #include "data/signalbase.hpp"
45 #include "data/decode/decoder.hpp"
47 #include "devices/hardwaredevice.hpp"
48 #include "devices/inputfile.hpp"
49 #include "devices/sessionfile.hpp"
51 #include "toolbars/mainbar.hpp"
53 #include "view/analogsignal.hpp"
54 #include "view/decodetrace.hpp"
55 #include "view/logicsignal.hpp"
56 #include "view/signal.hpp"
57 #include "view/view.hpp"
59 #include <libsigrokcxx/libsigrokcxx.hpp>
62 #include <libsigrokdecode/libsigrokdecode.h>
65 using boost::shared_lock
;
66 using boost::shared_mutex
;
67 using boost::unique_lock
;
69 using std::dynamic_pointer_cast
;
71 using std::lock_guard
;
76 using std::recursive_mutex
;
78 using std::shared_ptr
;
80 using std::unordered_set
;
84 using sigrok::Channel
;
85 using sigrok::ChannelType
;
86 using sigrok::ConfigKey
;
87 using sigrok::DatafeedCallbackFunction
;
90 using sigrok::InputFormat
;
93 using sigrok::OutputFormat
;
95 using sigrok::PacketPayload
;
96 using sigrok::Session
;
97 using sigrok::SessionDevice
;
99 using Glib::VariantBase
;
103 Session::Session(DeviceManager
&device_manager
, QString name
) :
104 device_manager_(device_manager
),
107 capture_state_(Stopped
),
115 // Stop and join to the thread
119 DeviceManager
& Session::device_manager()
121 return device_manager_
;
124 const DeviceManager
& Session::device_manager() const
126 return device_manager_
;
129 shared_ptr
<sigrok::Session
> Session::session() const
132 return shared_ptr
<sigrok::Session
>();
133 return device_
->session();
136 shared_ptr
<devices::Device
> Session::device() const
141 QString
Session::name() const
146 void Session::set_name(QString name
)
148 if (default_name_
.isEmpty())
149 default_name_
= name
;
156 const std::list
< std::shared_ptr
<views::ViewBase
> > Session::views() const
161 std::shared_ptr
<views::ViewBase
> Session::main_view() const
166 void Session::set_main_bar(std::shared_ptr
<pv::toolbars::MainBar
> main_bar
)
168 main_bar_
= main_bar
;
171 shared_ptr
<pv::toolbars::MainBar
> Session::main_bar() const
176 bool Session::data_saved() const
181 void Session::save_settings(QSettings
&settings
) const
183 map
<string
, string
> dev_info
;
184 list
<string
> key_list
;
185 int stacks
= 0, views
= 0;
188 shared_ptr
<devices::HardwareDevice
> hw_device
=
189 dynamic_pointer_cast
< devices::HardwareDevice
>(device_
);
192 settings
.setValue("device_type", "hardware");
193 settings
.beginGroup("device");
195 key_list
.push_back("vendor");
196 key_list
.push_back("model");
197 key_list
.push_back("version");
198 key_list
.push_back("serial_num");
199 key_list
.push_back("connection_id");
201 dev_info
= device_manager_
.get_device_info(device_
);
203 for (string key
: key_list
) {
204 if (dev_info
.count(key
))
205 settings
.setValue(QString::fromUtf8(key
.c_str()),
206 QString::fromUtf8(dev_info
.at(key
).c_str()));
208 settings
.remove(QString::fromUtf8(key
.c_str()));
214 shared_ptr
<devices::SessionFile
> sessionfile_device
=
215 dynamic_pointer_cast
< devices::SessionFile
>(device_
);
217 if (sessionfile_device
) {
218 settings
.setValue("device_type", "sessionfile");
219 settings
.beginGroup("device");
220 settings
.setValue("filename", QString::fromStdString(
221 sessionfile_device
->full_name()));
225 // Save channels and decoders
226 for (shared_ptr
<data::SignalBase
> base
: signalbases_
) {
228 if (base
->is_decode_signal()) {
229 shared_ptr
<pv::data::DecoderStack
> decoder_stack
=
230 base
->decoder_stack();
231 std::shared_ptr
<data::decode::Decoder
> top_decoder
=
232 decoder_stack
->stack().front();
234 settings
.beginGroup("decoder_stack" + QString::number(stacks
++));
235 settings
.setValue("id", top_decoder
->decoder()->id
);
236 settings
.setValue("name", top_decoder
->decoder()->name
);
241 settings
.beginGroup(base
->internal_name());
242 base
->save_settings(settings
);
247 settings
.setValue("decoder_stacks", stacks
);
249 // Save view states and their signal settings
250 // Note: main_view must be saved as view0
251 settings
.beginGroup("view" + QString::number(views
++));
252 main_view_
->save_settings(settings
);
255 for (shared_ptr
<views::ViewBase
> view
: views_
) {
256 if (view
!= main_view_
) {
257 settings
.beginGroup("view" + QString::number(views
++));
258 view
->save_settings(settings
);
263 settings
.setValue("views", views
);
267 void Session::restore_settings(QSettings
&settings
)
269 shared_ptr
<devices::Device
> device
;
271 QString device_type
= settings
.value("device_type").toString();
273 if (device_type
== "hardware") {
274 map
<string
, string
> dev_info
;
275 list
<string
> key_list
;
277 // Re-select last used device if possible but only if it's not demo
278 settings
.beginGroup("device");
279 key_list
.push_back("vendor");
280 key_list
.push_back("model");
281 key_list
.push_back("version");
282 key_list
.push_back("serial_num");
283 key_list
.push_back("connection_id");
285 for (string key
: key_list
) {
286 const QString k
= QString::fromStdString(key
);
287 if (!settings
.contains(k
))
290 const string value
= settings
.value(k
).toString().toStdString();
292 dev_info
.insert(std::make_pair(key
, value
));
295 if (dev_info
.count("model") > 0)
296 device
= device_manager_
.find_device_from_info(dev_info
);
304 if (device_type
== "sessionfile") {
305 settings
.beginGroup("device");
306 QString filename
= settings
.value("filename").toString();
309 if (QFileInfo(filename
).isReadable()) {
310 device
= std::make_shared
<devices::SessionFile
>(device_manager_
.context(),
311 filename
.toStdString());
314 // TODO Perform error handling
315 start_capture([](QString infoMessage
) { (void)infoMessage
; });
317 set_name(QFileInfo(filename
).fileName());
323 for (shared_ptr
<data::SignalBase
> base
: signalbases_
) {
324 settings
.beginGroup(base
->internal_name());
325 base
->restore_settings(settings
);
331 int stacks
= settings
.value("decoder_stacks").toInt();
333 for (int i
= 0; i
< stacks
; i
++) {
334 settings
.beginGroup("decoder_stack" + QString::number(i
++));
336 QString id
= settings
.value("id").toString();
337 add_decoder(srd_decoder_get_by_id(id
.toStdString().c_str()));
344 int views
= settings
.value("views").toInt();
346 for (int i
= 0; i
< views
; i
++) {
347 settings
.beginGroup("view" + QString::number(i
));
350 views::ViewType type
= (views::ViewType
)settings
.value("type").toInt();
351 add_view(name_
, type
, this);
352 views_
.back()->restore_settings(settings
);
354 main_view_
->restore_settings(settings
);
361 void Session::select_device(shared_ptr
<devices::Device
> device
)
367 set_default_device();
368 } catch (const QString
&e
) {
369 main_bar_
->session_error(tr("Failed to Select Device"),
370 tr("Failed to Select Device"));
374 void Session::set_device(shared_ptr
<devices::Device
> device
)
378 // Ensure we are not capturing before setting the device
386 // Revert name back to default name (e.g. "Session 1") as the data is gone
387 name_
= default_name_
;
390 // Remove all stored data
391 for (std::shared_ptr
<views::ViewBase
> view
: views_
) {
392 view
->clear_signals();
394 view
->clear_decode_signals();
397 for (const shared_ptr
<data::SignalData
> d
: all_signal_data_
)
399 all_signal_data_
.clear();
400 signalbases_
.clear();
401 cur_logic_segment_
.reset();
403 for (auto entry
: cur_analog_segments_
) {
404 shared_ptr
<sigrok::Channel
>(entry
.first
).reset();
405 shared_ptr
<data::AnalogSegment
>(entry
.second
).reset();
412 device_
= std::move(device
);
416 } catch (const QString
&e
) {
422 device_
->session()->add_datafeed_callback([=]
423 (shared_ptr
<sigrok::Device
> device
, shared_ptr
<Packet
> packet
) {
424 data_feed_in(device
, packet
);
431 void Session::set_default_device()
433 const list
< shared_ptr
<devices::HardwareDevice
> > &devices
=
434 device_manager_
.devices();
439 // Try and find the demo device and select that by default
440 const auto iter
= std::find_if(devices
.begin(), devices
.end(),
441 [] (const shared_ptr
<devices::HardwareDevice
> &d
) {
442 return d
->hardware_device()->driver()->name() ==
444 set_device((iter
== devices
.end()) ? devices
.front() : *iter
);
447 void Session::load_init_file(const std::string
&file_name
,
448 const std::string
&format
)
450 shared_ptr
<InputFormat
> input_format
;
452 if (!format
.empty()) {
453 const map
<string
, shared_ptr
<InputFormat
> > formats
=
454 device_manager_
.context()->input_formats();
455 const auto iter
= find_if(formats
.begin(), formats
.end(),
456 [&](const pair
<string
, shared_ptr
<InputFormat
> > f
) {
457 return f
.first
== format
; });
458 if (iter
== formats
.end()) {
459 main_bar_
->session_error(tr("Error"),
460 tr("Unexpected input format: %s").arg(QString::fromStdString(format
)));
464 input_format
= (*iter
).second
;
467 load_file(QString::fromStdString(file_name
), input_format
);
470 void Session::load_file(QString file_name
,
471 std::shared_ptr
<sigrok::InputFormat
> format
,
472 const std::map
<std::string
, Glib::VariantBase
> &options
)
474 const QString
errorMessage(
475 QString("Failed to load file %1").arg(file_name
));
479 set_device(shared_ptr
<devices::Device
>(
480 new devices::InputFile(
481 device_manager_
.context(),
482 file_name
.toStdString(),
485 set_device(shared_ptr
<devices::Device
>(
486 new devices::SessionFile(
487 device_manager_
.context(),
488 file_name
.toStdString())));
490 main_bar_
->session_error(tr("Failed to load ") + file_name
, e
.what());
491 set_default_device();
492 main_bar_
->update_device_list();
496 main_bar_
->update_device_list();
498 start_capture([&, errorMessage
](QString infoMessage
) {
499 main_bar_
->session_error(errorMessage
, infoMessage
); });
501 set_name(QFileInfo(file_name
).fileName());
504 Session::capture_state
Session::get_capture_state() const
506 lock_guard
<mutex
> lock(sampling_mutex_
);
507 return capture_state_
;
510 void Session::start_capture(function
<void (const QString
)> error_handler
)
513 error_handler(tr("No active device set, can't start acquisition."));
519 // Check that at least one channel is enabled
520 const shared_ptr
<sigrok::Device
> sr_dev
= device_
->device();
522 const auto channels
= sr_dev
->channels();
523 if (!std::any_of(channels
.begin(), channels
.end(),
524 [](shared_ptr
<Channel
> channel
) {
525 return channel
->enabled(); })) {
526 error_handler(tr("No channels enabled."));
532 for (const shared_ptr
<data::SignalData
> d
: all_signal_data_
)
535 // Revert name back to default name (e.g. "Session 1") as the data is gone
536 name_
= default_name_
;
540 sampling_thread_
= std::thread(
541 &Session::sample_thread_proc
, this, error_handler
);
544 void Session::stop_capture()
546 if (get_capture_state() != Stopped
)
549 // Check that sampling stopped
550 if (sampling_thread_
.joinable())
551 sampling_thread_
.join();
554 void Session::register_view(std::shared_ptr
<views::ViewBase
> view
)
556 if (views_
.empty()) {
560 views_
.push_back(view
);
565 void Session::deregister_view(std::shared_ptr
<views::ViewBase
> view
)
567 views_
.remove_if([&](std::shared_ptr
<views::ViewBase
> v
) {
568 return v
== view
; });
570 if (views_
.empty()) {
573 // Without a view there can be no main bar
578 bool Session::has_view(std::shared_ptr
<views::ViewBase
> view
)
580 for (std::shared_ptr
<views::ViewBase
> v
: views_
)
587 double Session::get_samplerate() const
589 double samplerate
= 0.0;
591 for (const shared_ptr
<pv::data::SignalData
> d
: all_signal_data_
) {
593 const vector
< shared_ptr
<pv::data::Segment
> > segments
=
595 for (const shared_ptr
<pv::data::Segment
> &s
: segments
)
596 samplerate
= std::max(samplerate
, s
->samplerate());
598 // If there is no sample rate given we use samples as unit
599 if (samplerate
== 0.0)
605 const std::unordered_set
< std::shared_ptr
<data::SignalBase
> >
606 Session::signalbases() const
612 bool Session::add_decoder(srd_decoder
*const dec
)
614 map
<const srd_channel
*, shared_ptr
<data::SignalBase
> > channels
;
615 shared_ptr
<data::DecoderStack
> decoder_stack
;
618 // Create the decoder
619 decoder_stack
= shared_ptr
<data::DecoderStack
>(
620 new data::DecoderStack(*this, dec
));
622 // Make a list of all the channels
623 std::vector
<const srd_channel
*> all_channels
;
624 for (const GSList
*i
= dec
->channels
; i
; i
= i
->next
)
625 all_channels
.push_back((const srd_channel
*)i
->data
);
626 for (const GSList
*i
= dec
->opt_channels
; i
; i
= i
->next
)
627 all_channels
.push_back((const srd_channel
*)i
->data
);
629 // Auto select the initial channels
630 for (const srd_channel
*pdch
: all_channels
)
631 for (shared_ptr
<data::SignalBase
> b
: signalbases_
) {
632 if (b
->type() == ChannelType::LOGIC
) {
633 if (QString::fromUtf8(pdch
->name
).toLower().
634 contains(b
->name().toLower()))
639 assert(decoder_stack
);
640 assert(!decoder_stack
->stack().empty());
641 assert(decoder_stack
->stack().front());
642 decoder_stack
->stack().front()->set_channels(channels
);
644 // Create the decode signal
645 shared_ptr
<data::SignalBase
> signalbase
=
646 shared_ptr
<data::SignalBase
>(new data::SignalBase(nullptr));
648 signalbase
->set_decoder_stack(decoder_stack
);
649 signalbases_
.insert(signalbase
);
651 for (std::shared_ptr
<views::ViewBase
> view
: views_
)
652 view
->add_decode_signal(signalbase
);
653 } catch (std::runtime_error e
) {
659 // Do an initial decode
660 decoder_stack
->begin_decode();
665 void Session::remove_decode_signal(shared_ptr
<data::SignalBase
> signalbase
)
667 signalbases_
.erase(signalbase
);
669 for (std::shared_ptr
<views::ViewBase
> view
: views_
)
670 view
->remove_decode_signal(signalbase
);
676 void Session::set_capture_state(capture_state state
)
681 lock_guard
<mutex
> lock(sampling_mutex_
);
682 changed
= capture_state_
!= state
;
683 capture_state_
= state
;
687 capture_state_changed(state
);
690 void Session::update_signals()
693 signalbases_
.clear();
695 for (std::shared_ptr
<views::ViewBase
> view
: views_
) {
696 view
->clear_signals();
698 view
->clear_decode_signals();
704 lock_guard
<recursive_mutex
> lock(data_mutex_
);
706 const shared_ptr
<sigrok::Device
> sr_dev
= device_
->device();
708 signalbases_
.clear();
710 for (std::shared_ptr
<views::ViewBase
> view
: views_
) {
711 view
->clear_signals();
713 view
->clear_decode_signals();
719 // Detect what data types we will receive
720 auto channels
= sr_dev
->channels();
721 unsigned int logic_channel_count
= std::count_if(
722 channels
.begin(), channels
.end(),
723 [] (shared_ptr
<Channel
> channel
) {
724 return channel
->type() == ChannelType::LOGIC
; });
726 // Create data containers for the logic data segments
728 lock_guard
<recursive_mutex
> data_lock(data_mutex_
);
730 if (logic_channel_count
== 0) {
732 } else if (!logic_data_
||
733 logic_data_
->num_channels() != logic_channel_count
) {
734 logic_data_
.reset(new data::Logic(
735 logic_channel_count
));
740 // Make the signals list
741 for (std::shared_ptr
<views::ViewBase
> viewbase
: views_
) {
742 views::TraceView::View
*trace_view
=
743 qobject_cast
<views::TraceView::View
*>(viewbase
.get());
746 unordered_set
< shared_ptr
<views::TraceView::Signal
> >
747 prev_sigs(trace_view
->signals());
748 trace_view
->clear_signals();
750 for (auto channel
: sr_dev
->channels()) {
751 shared_ptr
<data::SignalBase
> signalbase
;
752 shared_ptr
<views::TraceView::Signal
> signal
;
754 // Find the channel in the old signals
755 const auto iter
= std::find_if(
756 prev_sigs
.cbegin(), prev_sigs
.cend(),
757 [&](const shared_ptr
<views::TraceView::Signal
> &s
) {
758 return s
->base()->channel() == channel
;
760 if (iter
!= prev_sigs
.end()) {
761 // Copy the signal from the old set to the new
763 trace_view
->add_signal(signal
);
765 // Find the signalbase for this channel if possible
767 for (const shared_ptr
<data::SignalBase
> b
: signalbases_
)
768 if (b
->channel() == channel
)
771 switch(channel
->type()->id()) {
772 case SR_CHANNEL_LOGIC
:
774 signalbase
= shared_ptr
<data::SignalBase
>(
775 new data::SignalBase(channel
));
776 signalbases_
.insert(signalbase
);
778 all_signal_data_
.insert(logic_data_
);
779 signalbase
->set_data(logic_data_
);
782 signal
= shared_ptr
<views::TraceView::Signal
>(
783 new views::TraceView::LogicSignal(*this,
784 device_
, signalbase
));
785 trace_view
->add_signal(signal
);
788 case SR_CHANNEL_ANALOG
:
791 signalbase
= shared_ptr
<data::SignalBase
>(
792 new data::SignalBase(channel
));
793 signalbases_
.insert(signalbase
);
795 shared_ptr
<data::Analog
> data(new data::Analog());
796 all_signal_data_
.insert(data
);
797 signalbase
->set_data(data
);
800 signal
= shared_ptr
<views::TraceView::Signal
>(
801 new views::TraceView::AnalogSignal(
803 trace_view
->add_signal(signal
);
819 shared_ptr
<data::SignalBase
> Session::signalbase_from_channel(
820 shared_ptr
<sigrok::Channel
> channel
) const
822 for (shared_ptr
<data::SignalBase
> sig
: signalbases_
) {
824 if (sig
->channel() == channel
)
827 return shared_ptr
<data::SignalBase
>();
830 void Session::sample_thread_proc(function
<void (const QString
)> error_handler
)
832 assert(error_handler
);
837 cur_samplerate_
= device_
->read_config
<uint64_t>(ConfigKey::SAMPLERATE
);
839 out_of_memory_
= false;
844 error_handler(e
.what());
848 set_capture_state(device_
->session()->trigger() ?
849 AwaitingTrigger
: Running
);
852 set_capture_state(Stopped
);
854 // Confirm that SR_DF_END was received
855 if (cur_logic_segment_
) {
856 qDebug("SR_DF_END was not received.");
860 // Optimize memory usage
861 free_unused_memory();
863 // We now have unsaved data unless we just "captured" from a file
864 shared_ptr
<devices::File
> file_device
=
865 dynamic_pointer_cast
<devices::File
>(device_
);
871 error_handler(tr("Out of memory, acquisition stopped."));
874 void Session::free_unused_memory()
876 for (shared_ptr
<data::SignalData
> data
: all_signal_data_
) {
877 const vector
< shared_ptr
<data::Segment
> > segments
= data
->segments();
879 for (shared_ptr
<data::Segment
> segment
: segments
) {
880 segment
->free_unused_memory();
885 void Session::feed_in_header()
887 cur_samplerate_
= device_
->read_config
<uint64_t>(ConfigKey::SAMPLERATE
);
890 void Session::feed_in_meta(shared_ptr
<Meta
> meta
)
892 for (auto entry
: meta
->config()) {
893 switch (entry
.first
->id()) {
894 case SR_CONF_SAMPLERATE
:
895 // We can't rely on the header to always contain the sample rate,
896 // so in case it's supplied via a meta packet, we use it.
897 if (!cur_samplerate_
)
898 cur_samplerate_
= g_variant_get_uint64(entry
.second
.gobj());
900 /// @todo handle samplerate changes
903 // Unknown metadata is not an error.
911 void Session::feed_in_trigger()
913 // The channel containing most samples should be most accurate
914 uint64_t sample_count
= 0;
917 for (const shared_ptr
<pv::data::SignalData
> d
: all_signal_data_
) {
919 uint64_t temp_count
= 0;
921 const vector
< shared_ptr
<pv::data::Segment
> > segments
=
923 for (const shared_ptr
<pv::data::Segment
> &s
: segments
)
924 temp_count
+= s
->get_sample_count();
926 if (temp_count
> sample_count
)
927 sample_count
= temp_count
;
931 trigger_event(sample_count
/ get_samplerate());
934 void Session::feed_in_frame_begin()
936 if (cur_logic_segment_
|| !cur_analog_segments_
.empty())
940 void Session::feed_in_logic(shared_ptr
<Logic
> logic
)
942 lock_guard
<recursive_mutex
> lock(data_mutex_
);
945 // The only reason logic_data_ would not have been created is
946 // if it was not possible to determine the signals when the
947 // device was created.
951 if (!cur_logic_segment_
) {
952 // This could be the first packet after a trigger
953 set_capture_state(Running
);
955 // Create a new data segment
956 cur_logic_segment_
= shared_ptr
<data::LogicSegment
>(
957 new data::LogicSegment(*logic_data_
, logic
, cur_samplerate_
));
958 logic_data_
->push_segment(cur_logic_segment_
);
960 // @todo Putting this here means that only listeners querying
961 // for logic will be notified. Currently the only user of
962 // frame_began is DecoderStack, but in future we need to signal
963 // this after both analog and logic sweeps have begun.
966 // Append to the existing data segment
967 cur_logic_segment_
->append_payload(logic
);
973 void Session::feed_in_analog(shared_ptr
<Analog
> analog
)
975 lock_guard
<recursive_mutex
> lock(data_mutex_
);
977 const vector
<shared_ptr
<Channel
>> channels
= analog
->channels();
978 const unsigned int channel_count
= channels
.size();
979 const size_t sample_count
= analog
->num_samples() / channel_count
;
980 const float *data
= static_cast<const float *>(analog
->data_pointer());
981 bool sweep_beginning
= false;
983 if (signalbases_
.empty())
986 for (auto channel
: channels
) {
987 shared_ptr
<data::AnalogSegment
> segment
;
989 // Try to get the segment of the channel
990 const map
< shared_ptr
<Channel
>, shared_ptr
<data::AnalogSegment
> >::
991 iterator iter
= cur_analog_segments_
.find(channel
);
992 if (iter
!= cur_analog_segments_
.end())
993 segment
= (*iter
).second
;
995 // If no segment was found, this means we haven't
996 // created one yet. i.e. this is the first packet
997 // in the sweep containing this segment.
998 sweep_beginning
= true;
1000 // Find the analog data associated with the channel
1001 shared_ptr
<data::SignalBase
> base
= signalbase_from_channel(channel
);
1004 shared_ptr
<data::Analog
> data(base
->analog_data());
1007 // Create a segment, keep it in the maps of channels
1008 segment
= shared_ptr
<data::AnalogSegment
>(
1009 new data::AnalogSegment(*data
, cur_samplerate_
));
1010 cur_analog_segments_
[channel
] = segment
;
1012 // Push the segment into the analog data.
1013 data
->push_segment(segment
);
1018 // Append the samples in the segment
1019 segment
->append_interleaved_samples(data
++, sample_count
,
1023 if (sweep_beginning
) {
1024 // This could be the first packet after a trigger
1025 set_capture_state(Running
);
1031 void Session::data_feed_in(shared_ptr
<sigrok::Device
> device
,
1032 shared_ptr
<Packet
> packet
)
1034 static bool frame_began
=false;
1039 assert(device
== device_
->device());
1042 switch (packet
->type()->id()) {
1048 feed_in_meta(dynamic_pointer_cast
<Meta
>(packet
->payload()));
1055 case SR_DF_FRAME_BEGIN
:
1056 feed_in_frame_begin();
1062 feed_in_logic(dynamic_pointer_cast
<Logic
>(packet
->payload()));
1063 } catch (std::bad_alloc
) {
1064 out_of_memory_
= true;
1071 feed_in_analog(dynamic_pointer_cast
<Analog
>(packet
->payload()));
1072 } catch (std::bad_alloc
) {
1073 out_of_memory_
= true;
1078 case SR_DF_FRAME_END
:
1082 lock_guard
<recursive_mutex
> lock(data_mutex_
);
1083 cur_logic_segment_
.reset();
1084 cur_analog_segments_
.clear();
1087 frame_began
= false;
1097 void Session::on_data_saved()