Upload files to "/"
This commit is contained in:
639
serial_terminal.h
Normal file
639
serial_terminal.h
Normal file
@@ -0,0 +1,639 @@
|
||||
#ifndef SERIAL_TERMINAL_H
|
||||
#define SERIAL_TERMINAL_H
|
||||
|
||||
const char serial_terminal_html[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Serial Terminal - Byun CAN Logger</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 10px;
|
||||
}
|
||||
.container {
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
||||
overflow: hidden;
|
||||
}
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.header h1 { font-size: 1.8em; margin-bottom: 5px; }
|
||||
.header p { opacity: 0.9; font-size: 0.9em; }
|
||||
.nav {
|
||||
background: #2c3e50;
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
.nav a {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
padding: 10px 15px;
|
||||
border-radius: 5px;
|
||||
transition: all 0.3s;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
.nav a:hover { background: #34495e; }
|
||||
.nav a.active { background: #3498db; }
|
||||
.content { padding: 20px; }
|
||||
|
||||
.controls {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 15px;
|
||||
margin-bottom: 20px;
|
||||
background: #f8f9fa;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.control-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.control-group label {
|
||||
font-weight: 600;
|
||||
color: #2c3e50;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.control-group select,
|
||||
.control-group input {
|
||||
padding: 10px;
|
||||
border: 2px solid #ddd;
|
||||
border-radius: 8px;
|
||||
font-size: 1em;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.control-group select:focus,
|
||||
.control-group input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 1em;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-success:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(17, 153, 142, 0.4);
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(255, 107, 107, 0.4);
|
||||
}
|
||||
|
||||
.btn-warning {
|
||||
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #95a5a6;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-group {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.terminal-container {
|
||||
background: #1e1e1e;
|
||||
border-radius: 10px;
|
||||
padding: 15px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
.terminal-output {
|
||||
height: 400px;
|
||||
overflow-y: auto;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 0.9em;
|
||||
color: #0f0;
|
||||
background: #000;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.terminal-output::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
|
||||
.terminal-output::-webkit-scrollbar-track {
|
||||
background: #2c3e50;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.terminal-output::-webkit-scrollbar-thumb {
|
||||
background: #667eea;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.terminal-line {
|
||||
margin-bottom: 2px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.terminal-line.tx {
|
||||
color: #ff6b6b;
|
||||
}
|
||||
|
||||
.terminal-line.rx {
|
||||
color: #38ef7d;
|
||||
}
|
||||
|
||||
.terminal-timestamp {
|
||||
color: #95a5a6;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.input-area {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.input-area input {
|
||||
flex: 1;
|
||||
padding: 12px;
|
||||
border: 2px solid #ddd;
|
||||
border-radius: 8px;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.input-area input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
||||
gap: 15px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 15px;
|
||||
border-radius: 10px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 0.85em;
|
||||
opacity: 0.9;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 1.5em;
|
||||
font-weight: 700;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
|
||||
.status-indicator {
|
||||
display: inline-block;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 50%;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.status-indicator.on {
|
||||
background: #38ef7d;
|
||||
box-shadow: 0 0 8px #38ef7d;
|
||||
}
|
||||
|
||||
.status-indicator.off {
|
||||
background: #95a5a6;
|
||||
}
|
||||
|
||||
.status-text {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-weight: 600;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.controls {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.terminal-output {
|
||||
height: 300px;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>📡 Serial Terminal</h1>
|
||||
<p>RS232 Communication Interface</p>
|
||||
</div>
|
||||
|
||||
<div class="nav">
|
||||
<a href="/">🏠 Monitor</a>
|
||||
<a href="/transmit">📤 Transmit</a>
|
||||
<a href="/graph">📊 Graph</a>
|
||||
<a href="/serial" class="active">📡 Serial</a>
|
||||
<a href="/settings">⚙️ Settings</a>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<!-- 상태 통계 -->
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Received</div>
|
||||
<div class="stat-value" id="rx-count">0</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Transmitted</div>
|
||||
<div class="stat-value" id="tx-count">0</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Logging Size</div>
|
||||
<div class="stat-value" id="log-size">0 KB</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-label">Queue Usage</div>
|
||||
<div class="stat-value" id="queue-usage">0%</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Serial 설정 -->
|
||||
<div class="controls">
|
||||
<div class="control-group">
|
||||
<label>Baud Rate</label>
|
||||
<select id="baudrate">
|
||||
<option value="9600">9600</option>
|
||||
<option value="19200">19200</option>
|
||||
<option value="38400">38400</option>
|
||||
<option value="57600">57600</option>
|
||||
<option value="115200" selected>115200</option>
|
||||
<option value="230400">230400</option>
|
||||
<option value="460800">460800</option>
|
||||
<option value="921600">921600</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label>Data Bits</label>
|
||||
<select id="databits">
|
||||
<option value="5">5</option>
|
||||
<option value="6">6</option>
|
||||
<option value="7">7</option>
|
||||
<option value="8" selected>8</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label>Parity</label>
|
||||
<select id="parity">
|
||||
<option value="0" selected>None</option>
|
||||
<option value="1">Even</option>
|
||||
<option value="2">Odd</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label>Stop Bits</label>
|
||||
<select id="stopbits">
|
||||
<option value="1" selected>1</option>
|
||||
<option value="2">2</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 버튼 그룹 -->
|
||||
<div class="btn-group" style="margin-bottom: 20px;">
|
||||
<button class="btn btn-primary" onclick="applySerialConfig()">Apply Settings</button>
|
||||
<button class="btn btn-success" id="log-btn" onclick="toggleSerialLogging()">
|
||||
<span class="status-indicator off"></span>
|
||||
Start Logging
|
||||
</button>
|
||||
<button class="btn btn-warning" onclick="clearTerminal()">Clear Terminal</button>
|
||||
<button class="btn btn-secondary" onclick="autoScroll = !autoScroll; updateAutoScrollBtn()">
|
||||
<span id="autoscroll-text">Auto-scroll: ON</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 터미널 -->
|
||||
<div class="terminal-container">
|
||||
<div class="status-text">
|
||||
<span class="status-indicator" id="logging-status"></span>
|
||||
<span id="logging-text">Serial Terminal Ready</span>
|
||||
</div>
|
||||
<div class="terminal-output" id="terminal"></div>
|
||||
<div class="input-area">
|
||||
<input type="text" id="serial-input" placeholder="Type command and press Enter..."
|
||||
onkeypress="handleKeyPress(event)">
|
||||
<button class="btn btn-primary" onclick="sendSerialData()">Send</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
<script>
|
||||
let ws;
|
||||
let autoScroll = true;
|
||||
let serialLogging = false;
|
||||
let totalRx = 0;
|
||||
let totalTx = 0;
|
||||
let logSize = 0;
|
||||
let queueUsed = 0;
|
||||
let queueSize = 100; // 200 → 100으로 변경
|
||||
|
||||
function initWebSocket() {
|
||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
const wsUrl = protocol + '//' + window.location.hostname + ':81';
|
||||
|
||||
ws = new WebSocket(wsUrl);
|
||||
|
||||
ws.onopen = function() {
|
||||
console.log('WebSocket 연결됨');
|
||||
requestSerialConfig();
|
||||
};
|
||||
|
||||
ws.onmessage = function(event) {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
|
||||
if (data.type === 'update') {
|
||||
updateStats(data);
|
||||
|
||||
// Serial 메시지 표시
|
||||
if (data.serialMessages && data.serialMessages.length > 0) {
|
||||
data.serialMessages.forEach(msg => {
|
||||
addTerminalLine(msg);
|
||||
});
|
||||
}
|
||||
} else if (data.type === 'serialConfig') {
|
||||
loadSerialConfig(data);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('메시지 파싱 오류:', e);
|
||||
}
|
||||
};
|
||||
|
||||
ws.onerror = function(error) {
|
||||
console.error('WebSocket 오류:', error);
|
||||
};
|
||||
|
||||
ws.onclose = function() {
|
||||
console.log('WebSocket 연결 종료');
|
||||
setTimeout(initWebSocket, 2000);
|
||||
};
|
||||
}
|
||||
|
||||
function requestSerialConfig() {
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({cmd: 'getSerialConfig'}));
|
||||
}
|
||||
}
|
||||
|
||||
function loadSerialConfig(config) {
|
||||
document.getElementById('baudrate').value = config.baudRate || 115200;
|
||||
document.getElementById('databits').value = config.dataBits || 8;
|
||||
document.getElementById('parity').value = config.parity || 0;
|
||||
document.getElementById('stopbits').value = config.stopBits || 1;
|
||||
|
||||
console.log('Serial 설정 로드됨:', config);
|
||||
}
|
||||
|
||||
function applySerialConfig() {
|
||||
const config = {
|
||||
cmd: 'setSerialConfig',
|
||||
baudRate: parseInt(document.getElementById('baudrate').value),
|
||||
dataBits: parseInt(document.getElementById('databits').value),
|
||||
parity: parseInt(document.getElementById('parity').value),
|
||||
stopBits: parseInt(document.getElementById('stopbits').value)
|
||||
};
|
||||
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify(config));
|
||||
console.log('Serial 설정 적용:', config);
|
||||
|
||||
// 성공 피드백
|
||||
const btn = event.target;
|
||||
const originalText = btn.textContent;
|
||||
btn.textContent = '✓ Applied!';
|
||||
btn.style.background = 'linear-gradient(135deg, #11998e 0%, #38ef7d 100%)';
|
||||
|
||||
setTimeout(() => {
|
||||
btn.textContent = originalText;
|
||||
btn.style.background = '';
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleSerialLogging() {
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
if (serialLogging) {
|
||||
ws.send(JSON.stringify({cmd: 'stopSerialLogging'}));
|
||||
} else {
|
||||
ws.send(JSON.stringify({cmd: 'startSerialLogging'}));
|
||||
}
|
||||
serialLogging = !serialLogging;
|
||||
updateLoggingUI();
|
||||
}
|
||||
}
|
||||
|
||||
function updateLoggingUI() {
|
||||
const btn = document.getElementById('log-btn');
|
||||
const indicator = btn.querySelector('.status-indicator');
|
||||
const status = document.getElementById('logging-status');
|
||||
const text = document.getElementById('logging-text');
|
||||
|
||||
if (serialLogging) {
|
||||
btn.innerHTML = '<span class="status-indicator on"></span>Stop Logging';
|
||||
btn.className = 'btn btn-danger';
|
||||
status.className = 'status-indicator on';
|
||||
text.textContent = 'Logging Active';
|
||||
} else {
|
||||
btn.innerHTML = '<span class="status-indicator off"></span>Start Logging';
|
||||
btn.className = 'btn btn-success';
|
||||
status.className = 'status-indicator off';
|
||||
text.textContent = 'Serial Terminal Ready';
|
||||
}
|
||||
}
|
||||
|
||||
function sendSerialData() {
|
||||
const input = document.getElementById('serial-input');
|
||||
const data = input.value.trim();
|
||||
|
||||
if (data.length === 0) return;
|
||||
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({
|
||||
cmd: 'sendSerial',
|
||||
data: data
|
||||
}));
|
||||
|
||||
input.value = '';
|
||||
console.log('전송:', data);
|
||||
}
|
||||
}
|
||||
|
||||
function handleKeyPress(event) {
|
||||
if (event.key === 'Enter') {
|
||||
sendSerialData();
|
||||
}
|
||||
}
|
||||
|
||||
function addTerminalLine(msg) {
|
||||
const terminal = document.getElementById('terminal');
|
||||
const line = document.createElement('div');
|
||||
line.className = 'terminal-line ' + (msg.isTx ? 'tx' : 'rx');
|
||||
|
||||
// 타임스탬프 포맷
|
||||
const date = new Date(msg.timestamp / 1000);
|
||||
const timestamp = date.toLocaleTimeString() + '.' +
|
||||
String(date.getMilliseconds()).padStart(3, '0');
|
||||
|
||||
const direction = msg.isTx ? '[TX]' : '[RX]';
|
||||
line.innerHTML = '<span class="terminal-timestamp">' + timestamp + '</span>' +
|
||||
'<span style="font-weight:bold">' + direction + '</span> ' +
|
||||
escapeHtml(msg.data);
|
||||
|
||||
terminal.appendChild(line);
|
||||
|
||||
// 자동 스크롤
|
||||
if (autoScroll) {
|
||||
terminal.scrollTop = terminal.scrollHeight;
|
||||
}
|
||||
|
||||
// 최대 1000줄로 제한
|
||||
while (terminal.children.length > 1000) {
|
||||
terminal.removeChild(terminal.firstChild);
|
||||
}
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
const map = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": '''
|
||||
};
|
||||
return text.replace(/[&<>"']/g, m => map[m]);
|
||||
}
|
||||
|
||||
function clearTerminal() {
|
||||
document.getElementById('terminal').innerHTML = '';
|
||||
console.log('터미널 초기화');
|
||||
}
|
||||
|
||||
function updateAutoScrollBtn() {
|
||||
const btn = event.target;
|
||||
btn.querySelector('#autoscroll-text').textContent =
|
||||
'Auto-scroll: ' + (autoScroll ? 'ON' : 'OFF');
|
||||
|
||||
if (autoScroll) {
|
||||
btn.className = 'btn btn-secondary';
|
||||
} else {
|
||||
btn.className = 'btn btn-secondary';
|
||||
btn.style.opacity = '0.7';
|
||||
}
|
||||
}
|
||||
|
||||
function updateStats(data) {
|
||||
// RX/TX 카운터 업데이트
|
||||
if (data.totalSerialRx !== undefined) {
|
||||
totalRx = data.totalSerialRx;
|
||||
document.getElementById('rx-count').textContent = totalRx.toLocaleString();
|
||||
}
|
||||
|
||||
if (data.totalSerialTx !== undefined) {
|
||||
totalTx = data.totalSerialTx;
|
||||
document.getElementById('tx-count').textContent = totalTx.toLocaleString();
|
||||
}
|
||||
|
||||
// 로그 파일 크기
|
||||
if (data.serialFileSize !== undefined) {
|
||||
logSize = data.serialFileSize;
|
||||
const sizeKB = (logSize / 1024).toFixed(1);
|
||||
document.getElementById('log-size').textContent = sizeKB + ' KB';
|
||||
}
|
||||
|
||||
// Queue 사용량
|
||||
if (data.serialQueueUsed !== undefined && data.serialQueueSize !== undefined) {
|
||||
queueUsed = data.serialQueueUsed;
|
||||
queueSize = data.serialQueueSize;
|
||||
const percentage = ((queueUsed / queueSize) * 100).toFixed(0);
|
||||
document.getElementById('queue-usage').textContent = percentage + '%';
|
||||
}
|
||||
|
||||
// 로깅 상태 동기화
|
||||
if (data.serialLogging !== undefined && data.serialLogging !== serialLogging) {
|
||||
serialLogging = data.serialLogging;
|
||||
updateLoggingUI();
|
||||
}
|
||||
}
|
||||
|
||||
// 초기화
|
||||
initWebSocket();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
)rawliteral";
|
||||
|
||||
#endif
|
||||
550
settings.h
Normal file
550
settings.h
Normal file
@@ -0,0 +1,550 @@
|
||||
#ifndef SETTINGS_H
|
||||
#define SETTINGS_H
|
||||
|
||||
const char settings_html[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<title>Settings - Byun CAN Logger</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 10px;
|
||||
}
|
||||
.container {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
||||
overflow: hidden;
|
||||
}
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.header h1 { font-size: 1.8em; margin-bottom: 5px; }
|
||||
.header p { opacity: 0.9; font-size: 0.9em; }
|
||||
.nav {
|
||||
background: #2c3e50;
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
.nav a {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
padding: 10px 15px;
|
||||
border-radius: 5px;
|
||||
transition: all 0.3s;
|
||||
font-size: 0.9em;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.nav a:hover { background: #34495e; }
|
||||
.nav a.active { background: #3498db; }
|
||||
.content { padding: 30px; }
|
||||
|
||||
.settings-section {
|
||||
background: #f8f9fa;
|
||||
padding: 25px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
||||
}
|
||||
|
||||
.section-title {
|
||||
color: #333;
|
||||
font-size: 1.3em;
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 3px solid #667eea;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin-bottom: 8px;
|
||||
font-size: 0.95em;
|
||||
}
|
||||
|
||||
.help-text {
|
||||
font-size: 0.85em;
|
||||
color: #666;
|
||||
margin-top: 5px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
input[type="text"],
|
||||
input[type="password"] {
|
||||
width: 100%;
|
||||
padding: 12px 15px;
|
||||
border: 2px solid #e1e8ed;
|
||||
border-radius: 8px;
|
||||
font-size: 0.95em;
|
||||
transition: all 0.3s;
|
||||
background: white;
|
||||
}
|
||||
|
||||
input[type="text"]:focus,
|
||||
input[type="password"]:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
||||
}
|
||||
|
||||
input[type="checkbox"] {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
cursor: pointer;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.checkbox-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.checkbox-group label {
|
||||
margin-bottom: 0;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.sta-settings {
|
||||
background: #f0f4f8;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
margin-top: 15px;
|
||||
border-left: 4px solid #667eea;
|
||||
}
|
||||
|
||||
.sta-settings.disabled {
|
||||
opacity: 0.5;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.button-group {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
margin-top: 30px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
button {
|
||||
flex: 1;
|
||||
min-width: 150px;
|
||||
padding: 14px 28px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 1em;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.btn-save {
|
||||
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
|
||||
color: white;
|
||||
box-shadow: 0 4px 15px rgba(17, 153, 142, 0.3);
|
||||
}
|
||||
|
||||
.btn-save:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px rgba(17, 153, 142, 0.4);
|
||||
}
|
||||
|
||||
.btn-cancel {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
|
||||
}
|
||||
|
||||
.btn-cancel:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
button:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.alert {
|
||||
padding: 15px 20px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
display: none;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
animation: slideDown 0.3s ease-out;
|
||||
}
|
||||
|
||||
@keyframes slideDown {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.alert.show {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.alert-success {
|
||||
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.alert-info {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.alert-warning {
|
||||
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.alert-icon {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.alert-text {
|
||||
flex: 1;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.info-box {
|
||||
background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
|
||||
border-left: 4px solid #667eea;
|
||||
padding: 15px 20px;
|
||||
border-radius: 8px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.info-box-title {
|
||||
font-weight: 700;
|
||||
color: #333;
|
||||
margin-bottom: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.info-box-text {
|
||||
color: #555;
|
||||
font-size: 0.9em;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.content { padding: 20px; }
|
||||
.settings-section { padding: 20px; }
|
||||
.section-title { font-size: 1.1em; }
|
||||
button { min-width: 100%; }
|
||||
.button-group { flex-direction: column; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>⚙️ Settings</h1>
|
||||
<p>Configure WiFi and System Settings</p>
|
||||
</div>
|
||||
|
||||
<div class="nav">
|
||||
<a href="/">📊 Monitor</a>
|
||||
<a href="/transmit">📤 Transmit</a>
|
||||
<a href="/graph">📈 Graph</a>
|
||||
<a href="/graph-view">📊 Graph View</a>
|
||||
<a href="/settings" class="active">⚙️ Settings</a>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<div id="alert-success" class="alert alert-success">
|
||||
<span class="alert-icon">✓</span>
|
||||
<span class="alert-text">Settings saved successfully!</span>
|
||||
</div>
|
||||
|
||||
<div id="alert-loading" class="alert alert-info">
|
||||
<span class="alert-icon">⏳</span>
|
||||
<span class="alert-text">Loading settings...</span>
|
||||
</div>
|
||||
|
||||
<div class="settings-section">
|
||||
<div class="section-title">
|
||||
<span>📶</span>
|
||||
<span>WiFi Configuration</span>
|
||||
</div>
|
||||
|
||||
<h3 style="color: #333; font-size: 1.1em; margin-bottom: 15px;">AP Mode (Access Point)</h3>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="wifi-ssid">AP SSID (네트워크 이름)</label>
|
||||
<input type="text" id="wifi-ssid" placeholder="Byun_CAN_Logger" maxlength="31">
|
||||
<div class="help-text">ESP32가 생성할 WiFi 네트워크 이름입니다 (최대 31자)</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="wifi-password">AP Password (비밀번호)</label>
|
||||
<input type="password" id="wifi-password" placeholder="최소 8자 이상" minlength="8" maxlength="63">
|
||||
<div class="help-text">WiFi 접속 시 필요한 비밀번호입니다 (8-63자)</div>
|
||||
</div>
|
||||
|
||||
<hr style="margin: 25px 0; border: none; border-top: 1px solid #ddd;">
|
||||
|
||||
<h3 style="color: #333; font-size: 1.1em; margin-bottom: 15px;">APSTA Mode (AP + Station)</h3>
|
||||
|
||||
<div class="checkbox-group">
|
||||
<input type="checkbox" id="sta-enable" onchange="toggleSTASettings()">
|
||||
<label for="sta-enable">Station 모드 활성화 (외부 WiFi에 연결)</label>
|
||||
</div>
|
||||
<div class="help-text" style="margin-left: 30px; margin-bottom: 15px;">
|
||||
AP와 Station을 동시에 사용하여 인터넷 접속 가능
|
||||
</div>
|
||||
|
||||
<div id="sta-settings" class="sta-settings disabled">
|
||||
<div class="form-group">
|
||||
<label for="sta-ssid">연결할 WiFi SSID</label>
|
||||
<input type="text" id="sta-ssid" placeholder="공유기 이름 입력" maxlength="31">
|
||||
<div class="help-text">연결할 외부 WiFi 네트워크 이름</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="sta-password">연결할 WiFi Password</label>
|
||||
<input type="password" id="sta-password" placeholder="공유기 비밀번호 입력" maxlength="63">
|
||||
<div class="help-text">외부 WiFi 비밀번호</div>
|
||||
</div>
|
||||
|
||||
<div id="sta-status" style="display: none; margin-top: 15px; padding: 12px; background: #e8f5e9; border-radius: 6px; color: #2e7d32; font-weight: 600;">
|
||||
✓ WiFi 연결됨: <span id="sta-ip"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="button-group">
|
||||
<button class="btn-save" onclick="saveSettings()">💾 Save Settings</button>
|
||||
<button class="btn-cancel" onclick="location.href='/'">← Back to Monitor</button>
|
||||
</div>
|
||||
|
||||
<div class="info-box" style="margin-top: 30px;">
|
||||
<div class="info-box-title">
|
||||
<span>⚠️</span>
|
||||
<span>중요 안내</span>
|
||||
</div>
|
||||
<div class="info-box-text">
|
||||
• WiFi 설정을 변경한 경우, ESP32를 재부팅해야 새 SSID/비밀번호가 적용됩니다.<br>
|
||||
• <strong>APSTA 모드:</strong> Station 모드를 활성화하면 ESP32가 AP와 Station을 동시에 사용합니다.<br>
|
||||
• Station 모드로 외부 WiFi에 연결하면 인터넷 접속이 가능해집니다.<br>
|
||||
• Station 연결 실패 시에도 AP 모드는 정상 동작합니다.<br>
|
||||
• 설정 저장 후 ESP32의 리셋 버튼을 눌러 재부팅하세요.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let ws;
|
||||
|
||||
function initWebSocket() {
|
||||
ws = new WebSocket('ws://' + window.location.hostname + ':81/');
|
||||
|
||||
ws.onopen = function() {
|
||||
console.log('WebSocket connected');
|
||||
loadSettings();
|
||||
};
|
||||
|
||||
ws.onclose = function() {
|
||||
console.log('WebSocket disconnected');
|
||||
showAlert('alert-loading', '연결 끊김. 재연결 시도 중...', 'alert-warning');
|
||||
setTimeout(initWebSocket, 3000);
|
||||
};
|
||||
|
||||
ws.onerror = function(error) {
|
||||
console.error('WebSocket error:', error);
|
||||
};
|
||||
|
||||
ws.onmessage = function(event) {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
|
||||
if (data.type === 'settings') {
|
||||
document.getElementById('wifi-ssid').value = data.ssid || 'Byun_CAN_Logger';
|
||||
document.getElementById('wifi-password').value = data.password || '';
|
||||
|
||||
// STA 모드 설정 로드
|
||||
document.getElementById('sta-enable').checked = data.staEnable || false;
|
||||
document.getElementById('sta-ssid').value = data.staSSID || '';
|
||||
document.getElementById('sta-password').value = data.staPassword || '';
|
||||
|
||||
// STA 설정 표시/숨김
|
||||
toggleSTASettings();
|
||||
|
||||
// STA 연결 상태 표시
|
||||
if (data.staConnected && data.staIP && data.staIP !== '0.0.0.0') {
|
||||
document.getElementById('sta-ip').textContent = data.staIP;
|
||||
document.getElementById('sta-status').style.display = 'block';
|
||||
} else {
|
||||
document.getElementById('sta-status').style.display = 'none';
|
||||
}
|
||||
|
||||
hideAlert('alert-loading');
|
||||
console.log('Settings loaded:', data);
|
||||
} else if (data.type === 'settingsSaved') {
|
||||
if (data.success) {
|
||||
showAlert('alert-success', '설정이 저장되었습니다! 재부팅 후 적용됩니다.', 'alert-success');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Parse error:', e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function loadSettings() {
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({cmd: 'getSettings'}));
|
||||
showAlert('alert-loading', '설정을 불러오는 중...', 'alert-info');
|
||||
}
|
||||
}
|
||||
|
||||
function saveSettings() {
|
||||
const ssid = document.getElementById('wifi-ssid').value.trim();
|
||||
const password = document.getElementById('wifi-password').value;
|
||||
|
||||
// STA 모드 설정
|
||||
const staEnable = document.getElementById('sta-enable').checked;
|
||||
const staSSID = document.getElementById('sta-ssid').value.trim();
|
||||
const staPassword = document.getElementById('sta-password').value;
|
||||
|
||||
// 입력 검증
|
||||
if (ssid.length === 0) {
|
||||
alert('WiFi SSID를 입력하세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (ssid.length > 31) {
|
||||
alert('WiFi SSID는 최대 31자까지 입력 가능합니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.length > 0 && password.length < 8) {
|
||||
alert('WiFi 비밀번호는 최소 8자 이상이어야 합니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.length > 63) {
|
||||
alert('WiFi 비밀번호는 최대 63자까지 입력 가능합니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
// STA 모드 검증
|
||||
if (staEnable) {
|
||||
if (staSSID.length === 0) {
|
||||
alert('Station 모드를 활성화하려면 WiFi SSID를 입력하세요.');
|
||||
return;
|
||||
}
|
||||
if (staSSID.length > 31) {
|
||||
alert('Station WiFi SSID는 최대 31자까지 입력 가능합니다.');
|
||||
return;
|
||||
}
|
||||
if (staPassword.length > 0 && staPassword.length < 8) {
|
||||
alert('Station WiFi 비밀번호는 최소 8자 이상이어야 합니다.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const settings = {
|
||||
cmd: 'saveSettings',
|
||||
ssid: ssid,
|
||||
password: password,
|
||||
staEnable: staEnable,
|
||||
staSSID: staSSID,
|
||||
staPassword: staPassword
|
||||
};
|
||||
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify(settings));
|
||||
console.log('Settings saved:', settings);
|
||||
} else {
|
||||
alert('WebSocket 연결이 끊겼습니다. 페이지를 새로고침하세요.');
|
||||
}
|
||||
}
|
||||
|
||||
function showAlert(alertId, message, className) {
|
||||
const alert = document.getElementById(alertId);
|
||||
if (alert) {
|
||||
const textElement = alert.querySelector('.alert-text');
|
||||
if (textElement && message) {
|
||||
textElement.textContent = message;
|
||||
}
|
||||
|
||||
// 기존 클래스 제거
|
||||
alert.className = 'alert ' + className;
|
||||
alert.classList.add('show');
|
||||
|
||||
// 3초 후 자동 숨김 (success 알림만)
|
||||
if (className === 'alert-success') {
|
||||
setTimeout(() => {
|
||||
hideAlert(alertId);
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function hideAlert(alertId) {
|
||||
const alert = document.getElementById(alertId);
|
||||
if (alert) {
|
||||
alert.classList.remove('show');
|
||||
}
|
||||
}
|
||||
|
||||
function toggleSTASettings() {
|
||||
const staEnable = document.getElementById('sta-enable').checked;
|
||||
const staSettings = document.getElementById('sta-settings');
|
||||
|
||||
if (staEnable) {
|
||||
staSettings.classList.remove('disabled');
|
||||
} else {
|
||||
staSettings.classList.add('disabled');
|
||||
}
|
||||
}
|
||||
|
||||
// 페이지 로드 시 WebSocket 연결
|
||||
window.addEventListener('load', function() {
|
||||
initWebSocket();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
)rawliteral";
|
||||
|
||||
#endif
|
||||
690
transmit.h
Normal file
690
transmit.h
Normal file
@@ -0,0 +1,690 @@
|
||||
#ifndef TRANSMIT_H
|
||||
#define TRANSMIT_H
|
||||
|
||||
const char transmit_html[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>CAN Transmit - Sequence Editor</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 10px;
|
||||
}
|
||||
.container {
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
||||
overflow: hidden;
|
||||
}
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.header h1 { font-size: 1.8em; margin-bottom: 5px; }
|
||||
.header p { opacity: 0.9; font-size: 0.9em; }
|
||||
.nav {
|
||||
background: #2c3e50;
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
.nav a {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
padding: 10px 15px;
|
||||
border-radius: 5px;
|
||||
transition: all 0.3s;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
.nav a:hover { background: #34495e; }
|
||||
.nav a.active { background: #3498db; }
|
||||
.content { padding: 20px; }
|
||||
|
||||
.section {
|
||||
background: #f8f9fa;
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #333;
|
||||
margin-bottom: 15px;
|
||||
font-size: 1.3em;
|
||||
border-bottom: 3px solid #667eea;
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 15px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
label {
|
||||
font-weight: 600;
|
||||
margin-bottom: 5px;
|
||||
color: #333;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
input, select {
|
||||
padding: 10px;
|
||||
border: 2px solid #ddd;
|
||||
border-radius: 5px;
|
||||
font-size: 1em;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
input:focus, select:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.button-group {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
font-size: 1em;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #eb3349 0%, #f45c43 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-warning {
|
||||
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.steps-list {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.step-item {
|
||||
background: #f8f9fa;
|
||||
padding: 12px;
|
||||
margin-bottom: 10px;
|
||||
border-radius: 5px;
|
||||
border-left: 4px solid #667eea;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.step-info {
|
||||
flex: 1;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.step-actions {
|
||||
display: flex;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.btn-small {
|
||||
padding: 5px 10px;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
|
||||
.sequence-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.sequence-card {
|
||||
background: white;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
border: 2px solid #ddd;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.sequence-card:hover {
|
||||
border-color: #667eea;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.sequence-card h3 {
|
||||
color: #667eea;
|
||||
margin-bottom: 10px;
|
||||
font-size: 1.1em;
|
||||
}
|
||||
|
||||
.sequence-info {
|
||||
font-size: 0.9em;
|
||||
color: #666;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: inline-block;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.8em;
|
||||
font-weight: 600;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.badge-once { background: #e3f2fd; color: #1976d2; }
|
||||
.badge-count { background: #fff3e0; color: #f57c00; }
|
||||
.badge-infinite { background: #f3e5f5; color: #7b1fa2; }
|
||||
.badge-running { background: #c8e6c9; color: #388e3c; }
|
||||
|
||||
.connection-status {
|
||||
position: fixed;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
padding: 8px 15px;
|
||||
border-radius: 20px;
|
||||
font-size: 0.85em;
|
||||
font-weight: 600;
|
||||
z-index: 1000;
|
||||
}
|
||||
.connection-status.connected {
|
||||
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
|
||||
color: white;
|
||||
}
|
||||
.connection-status.disconnected {
|
||||
background: linear-gradient(135deg, #eb3349 0%, #f45c43 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.form-row { grid-template-columns: 1fr; }
|
||||
.sequence-list { grid-template-columns: 1fr; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="connection-status" class="connection-status disconnected">🔴 Disconnected</div>
|
||||
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>🚀 CAN Sequence Transmitter</h1>
|
||||
<p>Create and Execute CAN Message Sequences</p>
|
||||
</div>
|
||||
|
||||
<div class="nav">
|
||||
<a href="/">📊 Monitor</a>
|
||||
<a href="/transmit" class="active">📤 Transmit</a>
|
||||
<a href="/graph">📈 Graph</a>
|
||||
<a href="/graph-view">📊 Graph View</a>
|
||||
<a href="/settings">⚙️ Settings</a>
|
||||
<a href="/serial">📟 Serial</a>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<div class="section">
|
||||
<h2>Create New Sequence</h2>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label>Sequence Name</label>
|
||||
<input type="text" id="seq-name" placeholder="My Sequence" maxlength="31">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Repeat Mode</label>
|
||||
<select id="repeat-mode">
|
||||
<option value="0">Once</option>
|
||||
<option value="1">Count</option>
|
||||
<option value="2">Infinite</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Repeat Count</label>
|
||||
<input type="number" id="repeat-count" value="1" min="1" max="1000">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3 style="margin-top: 20px; margin-bottom: 10px; color: #555;">Add Step</h3>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label>CAN ID (Hex)</label>
|
||||
<input type="text" id="step-id" placeholder="0x123" maxlength="8">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>ID Type</label>
|
||||
<select id="step-extended">
|
||||
<option value="0">Standard</option>
|
||||
<option value="1">Extended</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>DLC</label>
|
||||
<select id="step-dlc">
|
||||
<option value="0">0</option>
|
||||
<option value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
<option value="3">3</option>
|
||||
<option value="4">4</option>
|
||||
<option value="5">5</option>
|
||||
<option value="6">6</option>
|
||||
<option value="7">7</option>
|
||||
<option value="8" selected>8</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Delay (ms)</label>
|
||||
<input type="number" id="step-delay" value="100" min="0" max="60000">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="margin-bottom: 15px;">
|
||||
<label>Data (8 bytes, Hex)</label>
|
||||
<input type="text" id="step-data" placeholder="00 11 22 33 44 55 66 77" maxlength="23">
|
||||
</div>
|
||||
|
||||
<div class="button-group">
|
||||
<button class="btn-primary" onclick="addStep()">➕ Add Step</button>
|
||||
<button class="btn-success" onclick="saveSequence()">💾 Save Sequence</button>
|
||||
<button class="btn-danger" onclick="clearSteps()">🗑️ Clear All</button>
|
||||
</div>
|
||||
|
||||
<h3 style="margin-top: 20px; margin-bottom: 10px; color: #555;">Steps (<span id="step-count">0</span>)</h3>
|
||||
<div class="steps-list" id="steps-list">
|
||||
<p style="text-align: center; color: #999;">No steps added yet</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>Saved Sequences</h2>
|
||||
<div class="button-group" style="margin-bottom: 15px;">
|
||||
<button class="btn-primary" onclick="loadSequences()">🔄 Refresh</button>
|
||||
</div>
|
||||
<div class="sequence-list" id="sequence-list">
|
||||
<p style="text-align: center; color: #999;">Loading...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let ws;
|
||||
let currentSteps = [];
|
||||
let sequences = [];
|
||||
|
||||
function updateConnectionStatus(connected) {
|
||||
const status = document.getElementById('connection-status');
|
||||
if (connected) {
|
||||
status.className = 'connection-status connected';
|
||||
status.innerHTML = '🟢 Connected';
|
||||
} else {
|
||||
status.className = 'connection-status disconnected';
|
||||
status.innerHTML = '🔴 Disconnected';
|
||||
}
|
||||
}
|
||||
|
||||
function initWebSocket() {
|
||||
ws = new WebSocket('ws://' + window.location.hostname + ':81/');
|
||||
|
||||
ws.onopen = function() {
|
||||
console.log('WebSocket connected');
|
||||
updateConnectionStatus(true);
|
||||
setTimeout(loadSequences, 500);
|
||||
};
|
||||
|
||||
ws.onclose = function() {
|
||||
console.log('WebSocket disconnected');
|
||||
updateConnectionStatus(false);
|
||||
setTimeout(initWebSocket, 3000);
|
||||
};
|
||||
|
||||
ws.onerror = function(error) {
|
||||
console.error('WebSocket error:', error);
|
||||
updateConnectionStatus(false);
|
||||
};
|
||||
|
||||
ws.onmessage = function(event) {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
console.log('Received:', data.type, data);
|
||||
|
||||
if (data.type === 'sequences') {
|
||||
sequences = data.sequences || data.list || [];
|
||||
sequences = sequences.map((seq, idx) => ({
|
||||
...seq,
|
||||
index: seq.index !== undefined ? seq.index : idx,
|
||||
mode: seq.mode !== undefined ? seq.mode : seq.repeatMode,
|
||||
count: seq.count !== undefined ? seq.count : seq.repeatCount
|
||||
}));
|
||||
updateSequenceList();
|
||||
} else if (data.type === 'sequenceDetail') {
|
||||
handleSequenceDetail(data);
|
||||
} else if (data.type === 'sequenceSaved') {
|
||||
if (data.success) {
|
||||
alert('Sequence saved successfully!');
|
||||
clearSteps();
|
||||
loadSequences();
|
||||
} else {
|
||||
alert('Failed to save sequence (max 10 sequences)');
|
||||
}
|
||||
} else if (data.type === 'sequenceDeleted') {
|
||||
if (data.success) {
|
||||
alert('Sequence deleted!');
|
||||
loadSequences();
|
||||
}
|
||||
} else if (data.type === 'sequenceStarted') {
|
||||
alert('Sequence started!');
|
||||
} else if (data.type === 'sequenceStopped') {
|
||||
alert('Sequence stopped!');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Parse error:', e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function loadSequences() {
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
console.log('Requesting sequences...');
|
||||
ws.send(JSON.stringify({cmd: 'getSequences'}));
|
||||
} else {
|
||||
console.log('WebSocket not connected, retrying...');
|
||||
setTimeout(loadSequences, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
function addStep() {
|
||||
const id = document.getElementById('step-id').value.trim();
|
||||
const extended = parseInt(document.getElementById('step-extended').value);
|
||||
const dlc = parseInt(document.getElementById('step-dlc').value);
|
||||
const dataStr = document.getElementById('step-data').value.trim();
|
||||
const delay = parseInt(document.getElementById('step-delay').value);
|
||||
|
||||
let canId = 0;
|
||||
if (id.startsWith('0x') || id.startsWith('0X')) {
|
||||
canId = parseInt(id.substring(2), 16);
|
||||
} else {
|
||||
canId = parseInt(id, 16);
|
||||
}
|
||||
|
||||
if (isNaN(canId) || id === '') {
|
||||
alert('Invalid CAN ID');
|
||||
return;
|
||||
}
|
||||
|
||||
let dataBytes = [];
|
||||
if (dataStr) {
|
||||
dataBytes = dataStr.split(/[\s,]+/).map(b => parseInt(b, 16));
|
||||
}
|
||||
while (dataBytes.length < 8) {
|
||||
dataBytes.push(0);
|
||||
}
|
||||
|
||||
const step = {
|
||||
canId: canId,
|
||||
extended: extended === 1,
|
||||
dlc: dlc,
|
||||
data: dataBytes.slice(0, 8),
|
||||
delayMs: delay
|
||||
};
|
||||
|
||||
currentSteps.push(step);
|
||||
updateStepsList();
|
||||
|
||||
document.getElementById('step-id').value = '';
|
||||
document.getElementById('step-data').value = '';
|
||||
}
|
||||
|
||||
function removeStep(index) {
|
||||
currentSteps.splice(index, 1);
|
||||
updateStepsList();
|
||||
}
|
||||
|
||||
function clearSteps() {
|
||||
currentSteps = [];
|
||||
updateStepsList();
|
||||
document.getElementById('seq-name').value = '';
|
||||
}
|
||||
|
||||
function updateStepsList() {
|
||||
const list = document.getElementById('steps-list');
|
||||
document.getElementById('step-count').textContent = currentSteps.length;
|
||||
|
||||
if (currentSteps.length === 0) {
|
||||
list.innerHTML = '<p style="text-align: center; color: #999;">No steps added yet</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
list.innerHTML = '';
|
||||
currentSteps.forEach((step, index) => {
|
||||
const item = document.createElement('div');
|
||||
item.className = 'step-item';
|
||||
|
||||
const dataStr = step.data.map(b => b.toString(16).padStart(2, '0').toUpperCase()).join(' ');
|
||||
|
||||
item.innerHTML =
|
||||
'<div class="step-info">' +
|
||||
'<strong>Step ' + (index + 1) + ':</strong> ' +
|
||||
'ID=0x' + step.canId.toString(16).toUpperCase() + ' ' +
|
||||
(step.extended ? '(Ext)' : '(Std)') + ' | ' +
|
||||
'DLC=' + step.dlc + ' | ' +
|
||||
'Data=[' + dataStr + '] | ' +
|
||||
'Delay=' + step.delayMs + 'ms' +
|
||||
'</div>' +
|
||||
'<div class="step-actions">' +
|
||||
'<button class="btn-danger btn-small" onclick="removeStep(' + index + ')">Delete</button>' +
|
||||
'</div>';
|
||||
|
||||
list.appendChild(item);
|
||||
});
|
||||
}
|
||||
|
||||
function saveSequence() {
|
||||
const name = document.getElementById('seq-name').value.trim();
|
||||
const mode = parseInt(document.getElementById('repeat-mode').value);
|
||||
const count = parseInt(document.getElementById('repeat-count').value);
|
||||
|
||||
if (name === '') {
|
||||
alert('Please enter sequence name');
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentSteps.length === 0) {
|
||||
alert('Please add at least one step');
|
||||
return;
|
||||
}
|
||||
|
||||
const sequence = {
|
||||
cmd: 'addSequence',
|
||||
name: name,
|
||||
repeatMode: mode,
|
||||
repeatCount: count,
|
||||
steps: currentSteps.map(step => ({
|
||||
id: '0x' + step.canId.toString(16).toUpperCase(),
|
||||
ext: step.extended,
|
||||
dlc: step.dlc,
|
||||
data: step.data,
|
||||
delay: step.delayMs
|
||||
}))
|
||||
};
|
||||
|
||||
console.log('Saving sequence:', sequence);
|
||||
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify(sequence));
|
||||
}
|
||||
}
|
||||
|
||||
function updateSequenceList() {
|
||||
const list = document.getElementById('sequence-list');
|
||||
|
||||
console.log('Updating sequence list:', sequences);
|
||||
|
||||
if (!sequences || sequences.length === 0) {
|
||||
list.innerHTML = '<p style="text-align: center; color: #999;">No saved sequences</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
list.innerHTML = '';
|
||||
sequences.forEach((seq, idx) => {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'sequence-card';
|
||||
|
||||
const mode = seq.mode !== undefined ? seq.mode : seq.repeatMode;
|
||||
const count = seq.count !== undefined ? seq.count : seq.repeatCount;
|
||||
const index = seq.index !== undefined ? seq.index : idx;
|
||||
|
||||
let modeBadge = '';
|
||||
if (mode === 0) {
|
||||
modeBadge = '<span class="status-badge badge-once">Once</span>';
|
||||
} else if (mode === 1) {
|
||||
modeBadge = '<span class="status-badge badge-count">Count: ' + count + '</span>';
|
||||
} else if (mode === 2) {
|
||||
modeBadge = '<span class="status-badge badge-infinite">Infinite</span>';
|
||||
}
|
||||
|
||||
const stepCount = typeof seq.steps === 'number' ? seq.steps :
|
||||
(Array.isArray(seq.steps) ? seq.steps.length : seq.stepCount || 0);
|
||||
|
||||
card.innerHTML =
|
||||
'<h3>' + seq.name + '</h3>' +
|
||||
'<div class="sequence-info">' +
|
||||
modeBadge +
|
||||
'<span class="status-badge" style="background: #e0e0e0; color: #555;">Steps: ' + stepCount + '</span>' +
|
||||
'</div>' +
|
||||
'<div class="button-group">' +
|
||||
'<button class="btn-primary btn-small" onclick="loadSequenceDetail(' + index + ')">📝 Edit</button>' +
|
||||
'<button class="btn-success btn-small" onclick="startSequence(' + index + ')">▶️ Run</button>' +
|
||||
'<button class="btn-warning btn-small" onclick="stopSequence()">⏹️ Stop</button>' +
|
||||
'<button class="btn-danger btn-small" onclick="deleteSequence(' + index + ')">🗑️ Delete</button>' +
|
||||
'</div>';
|
||||
|
||||
list.appendChild(card);
|
||||
});
|
||||
}
|
||||
|
||||
function loadSequenceDetail(index) {
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({cmd: 'getSequence', index: index}));
|
||||
}
|
||||
}
|
||||
|
||||
function handleSequenceDetail(data) {
|
||||
const seq = data.sequence;
|
||||
|
||||
document.getElementById('seq-name').value = seq.name;
|
||||
document.getElementById('repeat-mode').value = seq.mode !== undefined ? seq.mode : seq.repeatMode;
|
||||
document.getElementById('repeat-count').value = seq.count !== undefined ? seq.count : seq.repeatCount;
|
||||
|
||||
currentSteps = [];
|
||||
if (seq.steps && Array.isArray(seq.steps)) {
|
||||
seq.steps.forEach(step => {
|
||||
let dataBytes = [];
|
||||
if (typeof step.data === 'string') {
|
||||
dataBytes = step.data.split(' ').map(b => parseInt(b, 16));
|
||||
} else if (Array.isArray(step.data)) {
|
||||
dataBytes = step.data;
|
||||
}
|
||||
|
||||
currentSteps.push({
|
||||
canId: typeof step.id === 'string' ? parseInt(step.id, 16) : step.id,
|
||||
extended: step.ext || step.extended || false,
|
||||
dlc: step.dlc,
|
||||
data: dataBytes,
|
||||
delayMs: step.delay || step.delayMs || 0
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
updateStepsList();
|
||||
document.querySelector('.section').scrollIntoView({ behavior: 'smooth' });
|
||||
alert('Sequence loaded! You can now edit and save it.');
|
||||
}
|
||||
|
||||
function startSequence(index) {
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
console.log('Starting sequence:', index);
|
||||
ws.send(JSON.stringify({cmd: 'startSequence', index: index}));
|
||||
}
|
||||
}
|
||||
|
||||
function stopSequence() {
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({cmd: 'stopSequence'}));
|
||||
}
|
||||
}
|
||||
|
||||
// ★★★ 핵심 수정: Arduino는 'removeSequence' 명령어 사용
|
||||
function deleteSequence(index) {
|
||||
if (!confirm('Are you sure you want to delete this sequence?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({cmd: 'removeSequence', index: index}));
|
||||
console.log('Delete sequence command sent (removeSequence):', index);
|
||||
|
||||
// 삭제 후 목록 새로고침
|
||||
setTimeout(loadSequences, 500);
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('repeat-mode').addEventListener('change', function() {
|
||||
const countInput = document.getElementById('repeat-count');
|
||||
if (this.value === '1') {
|
||||
countInput.disabled = false;
|
||||
} else {
|
||||
countInput.disabled = true;
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('load', function() {
|
||||
initWebSocket();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
)rawliteral";
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user