Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cabana: enhance message heatmap visualization #34239

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions tools/cabana/binaryview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,32 +292,52 @@ void BinaryViewModel::updateItem(int row, int col, uint8_t val, const QColor &co
}
}

// TODO:
// 1. Track how long each bit stays in a state and how frequently it flips over time.
// 2. Detect instability through frequent bit flips and highlight stable bits to indicate steady signals.
// 3. Measure the intensity and rate of bit changes, adjusting heatmap visuals based on transition speed.
// 4. Track message sequence and timestamps to understand how patterns evolve.
// 5. Identify time-based or periodic bit state changes to spot recurring patterns.
// 6. Support multiple time windows for short-term and long-term analysis, helping to observe changes in different time frames.
void BinaryViewModel::updateState() {
const auto &last_msg = can->lastMessage(msg_id);
const auto &binary = last_msg.dat;
// data size may changed.
// Handle size changes in binary data
if (binary.size() > row_count) {
beginInsertRows({}, row_count, binary.size() - 1);
row_count = binary.size();
items.resize(row_count * column_count);
endInsertRows();
}

const double max_f = 255.0;
const double factor = 0.25;
const double scaler = max_f / log2(1.0 + factor);
for (int i = 0; i < binary.size(); ++i) {
// Find the maximum bit flip count across the message
uint32_t max_bit_flip_count = 1; // Default to 1 to avoid division by zero
for (const auto &changes : last_msg.last_changes) {
for (uint32_t flip_count : changes.bit_change_counts) {
max_bit_flip_count = std::max(max_bit_flip_count, flip_count);
}
}

const double max_alpha = 255.0;
const double base_alpha = 25.0; // Base alpha for small flip counts
const double log_factor = 1.0 + 0.15; // Factor for logarithmic scaling
const double log_scaler = max_alpha / log2(log_factor * max_bit_flip_count);

for (size_t i = 0; i < binary.size(); ++i) {
for (int j = 0; j < 8; ++j) {
auto &item = items[i * column_count + j];
int val = ((binary[i] >> (7 - j)) & 1) != 0 ? 1 : 0;
// Bit update frequency based highlighting
double offset = !item.sigs.empty() ? 50 : 0;
auto n = last_msg.last_changes[i].bit_change_counts[j];
double min_f = n == 0 ? offset : offset + 25;
double alpha = std::clamp(offset + log2(1.0 + factor * (double)n / (double)last_msg.count) * scaler, min_f, max_f);
int bit_val = (binary[i] >> (7 - j)) & 1;

double alpha = item.sigs.empty() ? 0 : base_alpha;
uint32_t flip_count = last_msg.last_changes[i].bit_change_counts[j];
if (flip_count > 0) {
double normalized_alpha = log2(1.0 + flip_count * log_factor) * log_scaler;
alpha = std::min(base_alpha + normalized_alpha, max_alpha);
}

auto color = item.bg_color;
color.setAlpha(alpha);
updateItem(i, j, val, color);
updateItem(i, j, bit_val, color);
}
updateItem(i, 8, binary[i], last_msg.colors[i]);
}
Expand Down
Loading