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 "logicdatasnapshot.h"
27 LogicDataSnapshot::LogicDataSnapshot(
28 const sr_datafeed_logic &logic) :
29 DataSnapshot(logic.unitsize)
31 append_payload(logic);
34 void LogicDataSnapshot::append_payload(
35 const sr_datafeed_logic &logic)
37 assert(_unit_size == logic.unitsize);
39 append_data(logic.data, logic.length);
42 uint64_t LogicDataSnapshot::get_sample(uint64_t index) const
45 assert(index >= 0 && index < _data_length);
47 return *(uint64_t*)((uint8_t*)_data + index * _unit_size);
50 void LogicDataSnapshot::get_subsampled_edges(
51 std::vector<EdgePair> &edges,
52 int64_t start, int64_t end,
53 int64_t quantization_length, int sig_index)
56 assert(end < get_sample_count());
58 assert(quantization_length > 0);
59 assert(sig_index >= 0);
60 assert(sig_index < SR_MAX_NUM_PROBES);
62 const uint64_t sig_mask = 1 << sig_index;
64 // Add the initial state
65 bool last_sample = get_sample(start) & sig_mask;
66 edges.push_back(pair<int64_t, bool>(start, last_sample));
68 for(int64_t i = start + 1; i < end - 1; i++)
70 const bool sample = get_sample(i) & sig_mask;
72 // Check if we hit an edge
73 if(sample != last_sample)
75 // Take the last sample of the quanization block
76 const int64_t final_index =
77 min((i - (i % quantization_length) +
78 quantization_length - 1), end);
80 // Store the final state
81 const bool final_sample = get_sample(final_index) & sig_mask;
82 edges.push_back(pair<int64_t, bool>(
83 final_index, final_sample));
85 // Continue to sampling
87 last_sample = final_sample;
91 // Add the final state
92 edges.push_back(pair<int64_t, bool>(end - 1,
93 get_sample(end - 1) & sig_mask));