그래프 수신 시만 dot, monitor창 수신시만 표현

This commit is contained in:
2025-10-07 17:04:20 +00:00
parent 16e0ba1c85
commit da51fafd5a
2 changed files with 54 additions and 53 deletions

34
index.h
View File

@@ -275,10 +275,11 @@ const char index_html[] PROGMEM = R"rawliteral(
let canMessages = {};
let messageOrder = [];
// CAN 속도 이름 매핑
// 마지막 업데이트 추적용
let lastMessageData = {};
const speedNames = ['125 Kbps', '250 Kbps', '500 Kbps', '1 Mbps'];
// CAN 속도 설정 저장
function saveCanSpeed() {
const speed = document.getElementById('can-speed').value;
try {
@@ -289,7 +290,6 @@ const char index_html[] PROGMEM = R"rawliteral(
}
}
// CAN 속도 설정 복원
function loadCanSpeed() {
try {
const savedSpeed = localStorage.getItem('canSpeed');
@@ -297,7 +297,6 @@ const char index_html[] PROGMEM = R"rawliteral(
document.getElementById('can-speed').value = savedSpeed;
console.log('Restored CAN speed:', speedNames[savedSpeed]);
// 복원되었음을 표시
const statusSpan = document.getElementById('speed-status');
if (statusSpan) {
statusSpan.textContent = '(Restored: ' + speedNames[savedSpeed] + ')';
@@ -423,13 +422,24 @@ const char index_html[] PROGMEM = R"rawliteral(
const msg = canMessages[canId];
let row = existingRows.get(canId);
// 이전 데이터와 비교하여 실제 변경사항 확인
const prevData = lastMessageData[canId];
const hasChanged = !prevData ||
prevData.data !== msg.data ||
prevData.dlc !== msg.dlc ||
prevData.timestamp !== msg.timestamp;
if (row) {
row.cells[1].textContent = msg.dlc;
row.cells[2].textContent = msg.data;
row.cells[3].textContent = msg.updateCount;
row.cells[4].textContent = msg.timestamp;
row.classList.add('flash-row');
setTimeout(() => row.classList.remove('flash-row'), 300);
// 실제로 변경된 경우에만 flash 효과
if (hasChanged) {
row.classList.add('flash-row');
setTimeout(() => row.classList.remove('flash-row'), 300);
}
} else {
row = tbody.insertRow();
row.dataset.canId = canId;
@@ -442,6 +452,14 @@ const char index_html[] PROGMEM = R"rawliteral(
row.classList.add('flash-row');
setTimeout(() => row.classList.remove('flash-row'), 300);
}
// 현재 데이터 저장
lastMessageData[canId] = {
data: msg.data,
dlc: msg.dlc,
timestamp: msg.timestamp,
updateCount: msg.updateCount
};
});
}
@@ -485,10 +503,8 @@ const char index_html[] PROGMEM = R"rawliteral(
ws.send(JSON.stringify({cmd: 'setSpeed', speed: parseInt(speed)}));
// 설정 저장
saveCanSpeed();
// 적용 완료 표시
const statusSpan = document.getElementById('speed-status');
if (statusSpan) {
statusSpan.textContent = ' Applied: ' + speedName;
@@ -511,6 +527,7 @@ const char index_html[] PROGMEM = R"rawliteral(
function clearMessages() {
canMessages = {};
messageOrder = [];
lastMessageData = {};
document.getElementById('can-messages').innerHTML = '';
}
@@ -518,7 +535,6 @@ const char index_html[] PROGMEM = R"rawliteral(
window.location.href = '/download?file=' + encodeURIComponent(filename);
}
// 페이지 로드 시 저장된 CAN speed 복원
window.addEventListener('load', function() {
loadCanSpeed();
});