cabana: add comparision operator for CanEvent (#29864)
old-commit-hash: ef4c963c60276a62d64a89c158a1a1ff1dbe8a10
This commit is contained in:
@@ -286,9 +286,7 @@ void ChartView::updateSeries(const cabana::Signal *sig, bool clear) {
|
||||
s.vals.reserve(msgs.capacity());
|
||||
s.step_vals.reserve(msgs.capacity() * 2);
|
||||
|
||||
auto first = std::upper_bound(msgs.cbegin(), msgs.cend(), s.last_value_mono_time, [](uint64_t ts, auto e) {
|
||||
return ts < e->mono_time;
|
||||
});
|
||||
auto first = std::upper_bound(msgs.cbegin(), msgs.cend(), s.last_value_mono_time, CompareCanEvent());
|
||||
const double route_start_time = can->routeStartTime();
|
||||
for (auto end = msgs.cend(); first != end; ++first) {
|
||||
const CanEvent *e = *first;
|
||||
|
||||
@@ -9,12 +9,8 @@ void Sparkline::update(const MessageId &msg_id, const cabana::Signal *sig, doubl
|
||||
const auto &msgs = can->events(msg_id);
|
||||
uint64_t ts = (last_msg_ts + can->routeStartTime()) * 1e9;
|
||||
uint64_t first_ts = (ts > range * 1e9) ? ts - range * 1e9 : 0;
|
||||
auto first = std::lower_bound(msgs.cbegin(), msgs.cend(), first_ts, [](auto e, uint64_t ts) {
|
||||
return e->mono_time < ts;
|
||||
});
|
||||
auto last = std::upper_bound(first, msgs.cend(), ts, [](uint64_t ts, auto e) {
|
||||
return ts < e->mono_time;
|
||||
});
|
||||
auto first = std::lower_bound(msgs.cbegin(), msgs.cend(), first_ts, CompareCanEvent());
|
||||
auto last = std::upper_bound(first, msgs.cend(), ts, CompareCanEvent());
|
||||
|
||||
bool update_values = last_ts != last_msg_ts || time_range != range;
|
||||
last_ts = last_msg_ts;
|
||||
|
||||
@@ -162,9 +162,7 @@ std::deque<HistoryLogModel::Message> HistoryLogModel::fetchData(uint64_t from_ti
|
||||
return msgs;
|
||||
} else {
|
||||
assert(min_time == 0);
|
||||
auto first = std::upper_bound(events.cbegin(), events.cend(), from_time, [](uint64_t ts, auto e) {
|
||||
return ts < e->mono_time;
|
||||
});
|
||||
auto first = std::upper_bound(events.cbegin(), events.cend(), from_time, CompareCanEvent());
|
||||
auto msgs = fetchData(first, events.cend(), 0);
|
||||
if (update_colors) {
|
||||
for (auto it = msgs.begin(); it != msgs.end(); ++it) {
|
||||
|
||||
@@ -162,18 +162,14 @@ void AbstractStream::mergeEvents(std::vector<Event *>::const_iterator first, std
|
||||
}
|
||||
}
|
||||
|
||||
auto compare = [](const CanEvent *l, const CanEvent *r) {
|
||||
return l->mono_time < r->mono_time;
|
||||
};
|
||||
|
||||
for (auto &[id, new_e] : new_events_map) {
|
||||
auto &e = events_[id];
|
||||
auto insert_pos = std::upper_bound(e.cbegin(), e.cend(), new_e.front(), compare);
|
||||
auto insert_pos = std::upper_bound(e.cbegin(), e.cend(), new_e.front()->mono_time, CompareCanEvent());
|
||||
e.insert(insert_pos, new_e.cbegin(), new_e.cend());
|
||||
}
|
||||
|
||||
if (!new_events.empty()) {
|
||||
auto insert_pos = std::upper_bound(all_events_.cbegin(), all_events_.cend(), new_events.front(), compare);
|
||||
auto insert_pos = std::upper_bound(all_events_.cbegin(), all_events_.cend(), new_events.front()->mono_time, CompareCanEvent());
|
||||
all_events_.insert(insert_pos, new_events.cbegin(), new_events.cend());
|
||||
}
|
||||
|
||||
@@ -201,15 +197,11 @@ inline QColor blend(const QColor &a, const QColor &b) {
|
||||
|
||||
// Calculate the frequency of the past minute.
|
||||
double calc_freq(const MessageId &msg_id, double current_sec) {
|
||||
auto compare = [](const CanEvent *e, uint64_t mono_time) {
|
||||
return e->mono_time < mono_time;
|
||||
};
|
||||
|
||||
const auto &events = can->events(msg_id);
|
||||
uint64_t cur_mono_time = (can->routeStartTime() + current_sec) * 1e9;
|
||||
uint64_t first_mono_time = std::max<int64_t>(0, cur_mono_time - 59 * 1e9);
|
||||
auto first = std::lower_bound(events.begin(), events.end(), first_mono_time, compare);
|
||||
auto second = std::lower_bound(first, events.end(), cur_mono_time, compare);
|
||||
auto first = std::lower_bound(events.begin(), events.end(), first_mono_time, CompareCanEvent());
|
||||
auto second = std::lower_bound(first, events.end(), cur_mono_time, CompareCanEvent());
|
||||
if (first != events.end() && second != events.end()) {
|
||||
double duration = ((*second)->mono_time - (*first)->mono_time) / 1e9;
|
||||
uint32_t count = std::distance(first, second);
|
||||
|
||||
@@ -41,6 +41,11 @@ struct CanEvent {
|
||||
uint8_t dat[];
|
||||
};
|
||||
|
||||
struct CompareCanEvent {
|
||||
constexpr bool operator()(const CanEvent *const e, uint64_t ts) const { return e->mono_time < ts; }
|
||||
constexpr bool operator()(uint64_t ts, const CanEvent *const e) const { return ts < e->mono_time; }
|
||||
};
|
||||
|
||||
struct BusConfig {
|
||||
int can_speed_kbps = 500;
|
||||
int data_speed_kbps = 2000;
|
||||
|
||||
@@ -102,12 +102,8 @@ void LiveStream::updateEvents() {
|
||||
uint64_t last_ts = post_last_event && speed_ == 1.0
|
||||
? all_events_.back()->mono_time
|
||||
: first_event_ts + (nanos_since_boot() - first_update_ts) * speed_;
|
||||
auto first = std::upper_bound(all_events_.cbegin(), all_events_.cend(), current_event_ts, [](uint64_t ts, auto e) {
|
||||
return ts < e->mono_time;
|
||||
});
|
||||
auto last = std::upper_bound(first, all_events_.cend(), last_ts, [](uint64_t ts, auto e) {
|
||||
return ts < e->mono_time;
|
||||
});
|
||||
auto first = std::upper_bound(all_events_.cbegin(), all_events_.cend(), current_event_ts, CompareCanEvent());
|
||||
auto last = std::upper_bound(first, all_events_.cend(), last_ts, CompareCanEvent());
|
||||
|
||||
for (auto it = first; it != last; ++it) {
|
||||
const CanEvent *e = *it;
|
||||
|
||||
@@ -37,10 +37,10 @@ void FindSignalModel::search(std::function<bool(double)> cmp) {
|
||||
filtered_signals.reserve(prev_sigs.size());
|
||||
QtConcurrent::blockingMap(prev_sigs, [&](auto &s) {
|
||||
const auto &events = can->events(s.id);
|
||||
auto first = std::upper_bound(events.cbegin(), events.cend(), s.mono_time, [](uint64_t ts, auto &e) { return ts < e->mono_time; });
|
||||
auto first = std::upper_bound(events.cbegin(), events.cend(), s.mono_time, CompareCanEvent());
|
||||
auto last = events.cend();
|
||||
if (last_time < std::numeric_limits<uint64_t>::max()) {
|
||||
last = std::upper_bound(events.cbegin(), events.cend(), last_time, [](uint64_t ts, auto &e) { return ts < e->mono_time; });
|
||||
last = std::upper_bound(events.cbegin(), events.cend(), last_time, CompareCanEvent());
|
||||
}
|
||||
|
||||
auto it = std::find_if(first, last, [&](const CanEvent *e) { return cmp(get_raw_value(e->dat, e->size, s.sig)); });
|
||||
@@ -225,7 +225,7 @@ void FindSignalDlg::setInitialSignals() {
|
||||
for (auto it = can->last_msgs.cbegin(); it != can->last_msgs.cend(); ++it) {
|
||||
if (buses.isEmpty() || buses.contains(it.key().source) && (addresses.isEmpty() || addresses.contains(it.key().address))) {
|
||||
const auto &events = can->events(it.key());
|
||||
auto e = std::lower_bound(events.cbegin(), events.cend(), first_time, [](auto e, uint64_t ts) { return e->mono_time < ts; });
|
||||
auto e = std::lower_bound(events.cbegin(), events.cend(), first_time, CompareCanEvent());
|
||||
if (e != events.cend()) {
|
||||
const int total_size = it.value().dat.size() * 8;
|
||||
for (int size = min_size->value(); size <= max_size->value(); ++size) {
|
||||
|
||||
Reference in New Issue
Block a user