]>
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 "logicdatasnapshot.h" | |
22 | ||
23 | #include <assert.h> | |
24 | ||
25 | using namespace std; | |
26 | ||
27 | LogicDataSnapshot::LogicDataSnapshot( | |
28 | const sr_datafeed_logic &logic) : | |
29 | DataSnapshot(logic.unitsize) | |
30 | { | |
31 | append_payload(logic); | |
32 | } | |
33 | ||
34 | void LogicDataSnapshot::append_payload( | |
35 | const sr_datafeed_logic &logic) | |
36 | { | |
37 | assert(_unit_size == logic.unitsize); | |
38 | ||
39 | append_data(logic.data, logic.length); | |
40 | } | |
41 | ||
42 | uint64_t LogicDataSnapshot::get_sample(uint64_t index) const | |
43 | { | |
44 | assert(_data); | |
45 | assert(index >= 0 && index < _data_length); | |
46 | ||
47 | return *(uint64_t*)((uint8_t*)_data + index * _unit_size); | |
48 | } | |
49 | ||
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) | |
54 | { | |
55 | assert(start >= 0); | |
56 | assert(end < get_sample_count()); | |
57 | assert(start <= end); | |
58 | assert(quantization_length > 0); | |
59 | assert(sig_index >= 0); | |
60 | assert(sig_index < SR_MAX_NUM_PROBES); | |
61 | ||
62 | const uint64_t sig_mask = 1 << sig_index; | |
63 | ||
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)); | |
67 | ||
68 | for(int64_t i = start + 1; i < end; i++) | |
69 | { | |
70 | const bool sample = get_sample(i) & sig_mask; | |
71 | ||
72 | // Check if we hit an edge | |
73 | if(sample != last_sample) | |
74 | { | |
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); | |
79 | ||
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)); | |
84 | ||
85 | // Continue to sampling | |
86 | i = final_index; | |
87 | last_sample = final_sample; | |
88 | } | |
89 | } | |
90 | ||
91 | // Add the final state | |
92 | edges.push_back(pair<int64_t, bool>(end, | |
93 | get_sample(end) & sig_mask)); | |
94 | } |