- // Create a new data snapshot
- _cur_analog_snapshot = shared_ptr<data::AnalogSnapshot>(
- new data::AnalogSnapshot(analog));
- _analog_data->push_snapshot(_cur_analog_snapshot);
+ shared_ptr<data::AnalogSnapshot> snapshot;
+
+ // Try to get the snapshot of the channel
+ const map< shared_ptr<Channel>, shared_ptr<data::AnalogSnapshot> >::
+ iterator iter = cur_analog_snapshots_.find(channel);
+ if (iter != cur_analog_snapshots_.end())
+ snapshot = (*iter).second;
+ else
+ {
+ // If no snapshot was found, this means we havn't
+ // created one yet. i.e. this is the first packet
+ // in the sweep containing this snapshot.
+ sweep_beginning = true;
+
+ // Get sample limit.
+ uint64_t sample_limit;
+ try {
+ sample_limit = VariantBase::cast_dynamic<Variant<guint64>>(
+ device_->config_get(ConfigKey::LIMIT_SAMPLES)).get();
+ } catch (Error) {
+ sample_limit = 0;
+ }
+
+ // Create a snapshot, keep it in the maps of channels
+ snapshot = shared_ptr<data::AnalogSnapshot>(
+ new data::AnalogSnapshot(sample_limit));
+ cur_analog_snapshots_[channel] = snapshot;
+
+ // Find the annalog data associated with the channel
+ shared_ptr<view::AnalogSignal> sig =
+ dynamic_pointer_cast<view::AnalogSignal>(
+ signal_from_channel(channel));
+ assert(sig);
+
+ shared_ptr<data::Analog> data(sig->analog_data());
+ assert(data);
+
+ // Push the snapshot into the analog data.
+ data->push_snapshot(snapshot);
+ }
+
+ assert(snapshot);
+
+ // Append the samples in the snapshot
+ snapshot->append_interleaved_samples(data++, sample_count,
+ channel_count);