chore: 提交调试文档与模拟器改动
This commit is contained in:
@@ -13,8 +13,14 @@
|
||||
])
|
||||
const BRIDGE_CONFIG_STORAGE_KEY = 'mock-gps-sim.bridge-config'
|
||||
const BRIDGE_PRESETS_STORAGE_KEY = 'mock-gps-sim.bridge-presets'
|
||||
const SIM_CHANNEL_STORAGE_KEY = 'mock-gps-sim.channel-id'
|
||||
const MAX_DEBUG_LOG_LINES = 400
|
||||
|
||||
function normalizeSimChannelId(rawValue) {
|
||||
const trimmed = String(rawValue || '').trim()
|
||||
return trimmed || 'default'
|
||||
}
|
||||
|
||||
const map = L.map('map').setView(DEFAULT_CENTER, 16)
|
||||
let tileLayer = createTileLayer(DEFAULT_TILE_URL, {
|
||||
maxZoom: 20,
|
||||
@@ -60,6 +66,7 @@
|
||||
lastHeartRateSentText: '--',
|
||||
lastResourceDetailText: '尚未载入资源',
|
||||
lastTrackSourceText: '路径待命',
|
||||
simChannelId: 'default',
|
||||
currentLatLng: L.latLng(DEFAULT_CENTER[0], DEFAULT_CENTER[1]),
|
||||
headingDeg: 0,
|
||||
currentSegmentIndex: 0,
|
||||
@@ -128,6 +135,7 @@
|
||||
trackFileInput: document.getElementById('trackFileInput'),
|
||||
importTrackBtn: document.getElementById('importTrackBtn'),
|
||||
connectBtn: document.getElementById('connectBtn'),
|
||||
simChannelIdInput: document.getElementById('simChannelIdInput'),
|
||||
sendOnceBtn: document.getElementById('sendOnceBtn'),
|
||||
streamBtn: document.getElementById('streamBtn'),
|
||||
stopStreamBtn: document.getElementById('stopStreamBtn'),
|
||||
@@ -164,6 +172,7 @@
|
||||
}
|
||||
|
||||
elements.configUrlInput.value = DEFAULT_CONFIG_URL
|
||||
applySimChannelId(loadSimChannelId(), false)
|
||||
|
||||
function createTileLayer(urlTemplate, extraOptions) {
|
||||
return L.tileLayer(urlTemplate, Object.assign({
|
||||
@@ -177,6 +186,33 @@
|
||||
elements.log.textContent = `[${time}] ${message}\n` + elements.log.textContent
|
||||
}
|
||||
|
||||
function loadSimChannelId() {
|
||||
try {
|
||||
return normalizeSimChannelId(window.localStorage.getItem(SIM_CHANNEL_STORAGE_KEY))
|
||||
} catch (_error) {
|
||||
return 'default'
|
||||
}
|
||||
}
|
||||
|
||||
function saveSimChannelId(channelId) {
|
||||
try {
|
||||
window.localStorage.setItem(SIM_CHANNEL_STORAGE_KEY, normalizeSimChannelId(channelId))
|
||||
} catch (_error) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
|
||||
function applySimChannelId(channelId, persist) {
|
||||
state.simChannelId = normalizeSimChannelId(channelId)
|
||||
if (elements.simChannelIdInput) {
|
||||
elements.simChannelIdInput.value = state.simChannelId
|
||||
}
|
||||
if (persist) {
|
||||
saveSimChannelId(state.simChannelId)
|
||||
}
|
||||
renderDebugLog()
|
||||
}
|
||||
|
||||
function logDebug(entry) {
|
||||
if (!elements.debugLog) {
|
||||
return
|
||||
@@ -184,6 +220,7 @@
|
||||
|
||||
const normalized = {
|
||||
timestamp: entry.timestamp || Date.now(),
|
||||
channelId: normalizeSimChannelId(entry.channelId),
|
||||
scope: String(entry.scope || 'app'),
|
||||
level: String(entry.level || 'info'),
|
||||
message: String(entry.message || ''),
|
||||
@@ -231,12 +268,15 @@
|
||||
}
|
||||
|
||||
const filteredEntries = state.debugLogEntries.filter((entry) => {
|
||||
if (normalizeSimChannelId(entry.channelId) !== state.simChannelId) {
|
||||
return false
|
||||
}
|
||||
return state.debugLogScopeFilter === 'all' || entry.scope === state.debugLogScopeFilter
|
||||
})
|
||||
|
||||
if (elements.debugLogMeta) {
|
||||
const scopeLabel = state.debugLogScopeFilter === 'all' ? '全部' : state.debugLogScopeFilter
|
||||
elements.debugLogMeta.textContent = `${scopeLabel} · ${filteredEntries.length} 条`
|
||||
elements.debugLogMeta.textContent = `通道 ${state.simChannelId} · ${scopeLabel} · ${filteredEntries.length} 条`
|
||||
}
|
||||
|
||||
elements.debugLog.textContent = filteredEntries
|
||||
@@ -244,7 +284,7 @@
|
||||
const time = new Date(entry.timestamp || Date.now()).toLocaleTimeString()
|
||||
const level = String(entry.level || 'info').toUpperCase()
|
||||
const payloadText = entry.payload ? ` ${JSON.stringify(entry.payload)}` : ''
|
||||
return `[${time}] [${entry.scope}] [${level}] ${entry.message}${payloadText}`
|
||||
return `[${time}] [${entry.channelId}] [${entry.scope}] [${level}] ${entry.message}${payloadText}`
|
||||
})
|
||||
.join('\n')
|
||||
}
|
||||
@@ -1389,6 +1429,7 @@
|
||||
const payload = {
|
||||
type: 'mock_gps',
|
||||
timestamp: Date.now(),
|
||||
channelId: state.simChannelId,
|
||||
lat: Number(state.currentLatLng.lat.toFixed(6)),
|
||||
lon: Number(state.currentLatLng.lng.toFixed(6)),
|
||||
accuracyMeters: getAccuracy(),
|
||||
@@ -1409,6 +1450,7 @@
|
||||
const payload = {
|
||||
type: 'mock_heart_rate',
|
||||
timestamp: Date.now(),
|
||||
channelId: state.simChannelId,
|
||||
bpm: state.heartRateSampleMode ? getSampleHeartRateBpm() : getHeartRateBpm(),
|
||||
}
|
||||
state.heartRateSocket.send(JSON.stringify(payload))
|
||||
@@ -1840,6 +1882,12 @@
|
||||
})
|
||||
|
||||
elements.connectBtn.addEventListener('click', connectSocket)
|
||||
if (elements.simChannelIdInput) {
|
||||
elements.simChannelIdInput.addEventListener('change', () => {
|
||||
applySimChannelId(elements.simChannelIdInput.value, true)
|
||||
log(`已切换模拟通道 ${state.simChannelId}`)
|
||||
})
|
||||
}
|
||||
elements.applyGatewayBridgePresetBtn.addEventListener('click', applyBridgePresetToForm)
|
||||
elements.saveGatewayBridgePresetBtn.addEventListener('click', saveCurrentBridgePreset)
|
||||
elements.deleteGatewayBridgePresetBtn.addEventListener('click', deleteSelectedBridgePreset)
|
||||
|
||||
Reference in New Issue
Block a user