Files
esp32s3-mcp2518FD-logger/canfd_settings.h
2026-02-27 10:02:27 +00:00

564 lines
20 KiB
C
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef CANFD_SETTINGS_H
#define CANFD_SETTINGS_H
const char canfd_settings_html[] PROGMEM = R"rawliteral(
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Settings - ESP32-S3 CAN FD 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: 28px; margin-bottom: 5px; }
.header p { opacity: 0.9; font-size: 14px; }
/* Navigation */
.nav {
background: #f8f9fa;
padding: 0;
border-bottom: 2px solid #e0e0e0;
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.nav a {
padding: 15px 20px;
text-decoration: none;
color: #666;
font-weight: 500;
font-size: 14px;
border-bottom: 3px solid transparent;
transition: all 0.3s;
}
.nav a:hover {
background: #e9ecef;
color: #667eea;
}
.nav a.active {
color: #764ba2;
border-bottom-color: #764ba2;
background: white;
font-weight: 600;
}
.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: 20px;
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 3px solid #667eea;
display: flex;
align-items: center;
gap: 10px;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
font-weight: 600;
color: #333;
margin-bottom: 8px;
font-size: 14px;
}
.help-text {
font-size: 12px;
color: #666;
margin-top: 5px;
line-height: 1.4;
}
input[type="text"],
input[type="password"],
select {
width: 100%;
padding: 12px 15px;
border: 2px solid #e1e8ed;
border-radius: 8px;
font-size: 14px;
transition: all 0.3s;
background: white;
}
input:focus, select: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;
}
.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: 14px;
font-weight: 700;
cursor: pointer;
transition: all 0.3s;
text-transform: uppercase;
}
.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);
}
.alert {
padding: 15px 20px;
border-radius: 8px;
margin-bottom: 20px;
display: none;
align-items: center;
gap: 12px;
}
.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-icon {
font-size: 20px;
}
.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;
}
.info-box-text {
color: #555;
font-size: 13px;
line-height: 1.6;
}
.sta-status {
margin-top: 15px;
padding: 12px;
background: #e8f5e9;
border-radius: 6px;
color: #2e7d32;
font-weight: 600;
display: none;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1> Settings</h1>
<p>Configure WiFi and CAN Settings</p>
</div>
<div class="nav">
<a href="/">📊 Dashboard</a>
<a href="/settings" class="active"> Settings</a>
<a href="/graph">📈 Graph</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>
<!-- WiFi Settings -->
<div class="settings-section">
<div class="section-title">
<span>📶</span>
<span>WiFi Configuration</span>
</div>
<h3 style="color: #333; font-size: 16px; 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" value="Byun_CANFD_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" value="12345678" 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: 16px; 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" class="sta-status">
WiFi : <span id="sta-ip"></span>
</div>
</div>
</div>
<!-- CAN Settings -->
<div class="settings-section">
<div class="section-title">
<span>🚗</span>
<span>CAN Configuration</span>
</div>
<div class="form-group">
<label for="can-mode">CAN Mode</label>
<select id="can-mode" onchange="toggleDataRate()">
<option value="fd">CAN FD Mode</option>
<option value="classic">Classic CAN Mode</option>
</select>
<div class="help-text">CAN FD: 64, Classic CAN: 8</div>
</div>
<div class="form-group">
<label for="bit-rate">Arbitration Bit Rate</label>
<select id="bit-rate">
<option value="125000">125 kbps</option>
<option value="250000">250 kbps</option>
<option value="500000" selected>500 kbps</option>
<option value="1000000">1 Mbps</option>
</select>
<div class="help-text">CAN </div>
</div>
<div class="form-group" id="data-rate-group">
<label for="data-rate">Data Rate Factor (CAN FD만)</label>
<select id="data-rate">
<option value="1">x1</option>
<option value="2">x2</option>
<option value="4" selected>x4 ()</option>
<option value="8">x8</option>
</select>
<div class="help-text">CAN FD </div>
</div>
<div class="form-group">
<label for="controller-mode">Controller Mode</label>
<select id="controller-mode">
<option value="0" selected>Normal</option>
<option value="1">Listen Only</option>
<option value="2">Loopback</option>
</select>
<div class="help-text">Normal: , Listen Only: </div>
</div>
<div class="form-group">
<label for="log-format">Log File Format</label>
<select id="log-format">
<option value="0" selected>CSV (Excel/Python)</option>
<option value="1">PCAP (Wireshark)</option>
</select>
<div class="help-text">CSV: ( ), PCAP: Wireshark로 </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 Dashboard</button>
</div>
<div class="info-box">
<div class="info-box-title">
</div>
<div class="info-box-text">
WiFi , <strong>ESP32를 </strong> SSID/ .<br>
<strong>APSTA :</strong> Station ESP32가 AP와 Station을 .<br>
Station WiFi에 .<br>
Station AP .<br>
CAN <strong>ESP32 </strong> .<br>
ESP32의 <strong>RST </strong> .
</div>
</div>
</div>
</div>
<script>
function loadSettings() {
fetch('/settings/get')
.then(r => r.json())
.then(data => {
// WiFi settings
document.getElementById('wifi-ssid').value = data.wifiSSID || 'Byun_CANFD_Logger';
document.getElementById('wifi-password').value = data.wifiPassword || '12345678';
// STA settings
document.getElementById('sta-enable').checked = data.staEnable || false;
document.getElementById('sta-ssid').value = data.staSSID || '';
document.getElementById('sta-password').value = data.staPassword || '';
// CAN settings
document.getElementById('can-mode').value = data.canMode || 'fd';
document.getElementById('bit-rate').value = data.bitRate || 500000;
document.getElementById('data-rate').value = data.dataRate || 4;
document.getElementById('controller-mode').value = data.controllerMode || 0;
document.getElementById('log-format').value = data.logFormat || 0;
// Update UI
toggleSTASettings();
toggleDataRate();
// STA status
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');
})
.catch(err => {
console.error('Failed to load settings:', err);
hideAlert('alert-loading');
});
}
function saveSettings() {
const settings = {
wifiSSID: document.getElementById('wifi-ssid').value.trim(),
wifiPassword: document.getElementById('wifi-password').value,
staEnable: document.getElementById('sta-enable').checked,
staSSID: document.getElementById('sta-ssid').value.trim(),
staPassword: document.getElementById('sta-password').value,
canMode: document.getElementById('can-mode').value,
bitRate: parseInt(document.getElementById('bit-rate').value),
dataRate: parseInt(document.getElementById('data-rate').value),
controllerMode: parseInt(document.getElementById('controller-mode').value),
logFormat: parseInt(document.getElementById('log-format').value)
};
console.log('Saving settings:', settings);
// Validation - AP SSID가 비어있으면 기본값 사용
if (settings.wifiSSID.length === 0) {
settings.wifiSSID = 'Byun_CANFD_Logger';
console.log('Using default SSID:', settings.wifiSSID);
}
if (settings.wifiPassword.length > 0 && settings.wifiPassword.length < 8) {
alert('WiFi 8 .');
return;
}
if (settings.staEnable && settings.staSSID.length === 0) {
alert('Station WiFi SSID를 .');
return;
}
fetch('/settings/save', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(settings)
})
.then(r => r.json())
.then(data => {
if (data.success) {
showAlert('alert-success', ' ! ESP32를 .', 'alert-success');
} else {
alert(' : ' + data.message);
}
})
.catch(err => {
console.error('Save error:', err);
alert(' : ' + err);
});
}
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');
}
}
function toggleDataRate() {
const canMode = document.getElementById('can-mode').value;
const dataRateGroup = document.getElementById('data-rate-group');
if (canMode === 'classic') {
dataRateGroup.style.display = 'none';
} else {
dataRateGroup.style.display = 'block';
}
}
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');
if (className === 'alert-success') {
setTimeout(() => {
hideAlert(alertId);
}, 5000);
}
}
}
function hideAlert(alertId) {
const alert = document.getElementById(alertId);
if (alert) {
alert.classList.remove('show');
}
}
// Load settings on page load
window.addEventListener('load', function() {
showAlert('alert-loading', ' ...', 'alert-info');
loadSettings();
});
</script>
</body>
</html>
)rawliteral";
#endif