From 9f5d20cc8f55279807e3c2cf682a11afcec060fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B4=9B=E5=B8=8C=E9=9B=85?= Date: Fri, 10 May 2024 18:04:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=B7=E5=8D=B4=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/mqtt.ts | 5 +++- src/views/mqtt/index.vue | 57 ++++++++++++++++++++++++++++++---------- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/store/mqtt.ts b/src/store/mqtt.ts index fd2ba78..edbeed7 100644 --- a/src/store/mqtt.ts +++ b/src/store/mqtt.ts @@ -7,7 +7,10 @@ export const useMqttStore = defineStore('mqtt', { url: 'mqtt://localhost:15675/mqtt', username: 'root', password: '123456', - clientId: 'R328328' + clientId: 'R328328', + forceRawTime: false, + normalizedTime: false, + coolDownTime: 0 } }, persist: { diff --git a/src/views/mqtt/index.vue b/src/views/mqtt/index.vue index e699558..7ce0f7a 100644 --- a/src/views/mqtt/index.vue +++ b/src/views/mqtt/index.vue @@ -18,6 +18,9 @@ const url = $toRef(mqttStore, 'url') const username = $toRef(mqttStore, 'username') const password = $toRef(mqttStore, 'password') const clientId = $toRef(mqttStore, 'clientId') +let forceRawTime = $toRef(mqttStore, 'forceRawTime') +let normalizedTime = $toRef(mqttStore, 'normalizedTime') +let coolDownTime = $toRef(mqttStore, 'coolDownTime') let loading = $ref(false) const dataLib = reactive(dataLib0) @@ -43,8 +46,7 @@ const publish = reactive({ percentage: 0, pause: false, rawTime: true, - forceRawTime: false, - normalizedTime: false, + coolDownTime: 0, range: { start: 0, end: 0 @@ -135,11 +137,31 @@ async function doPublish() { publish.rawTime = true // 发送数据的定时器 const interval = setInterval(() => { + // 判断定时器被关闭 if (exit) { clearInterval(interval) publish.cars = [] return } + + // 判断启用冷却时间 + if (coolDownTime > 0) { + // 判断处于冷却状态 + if (publish.coolDownTime > 0) { + publish.coolDownTime -= 100 + // 操作后小于0时重置发布时间 + if (publish.coolDownTime <= 0) { + publish.index = 0 + } + return + } + // 判断进入冷却状态 + if (publish.index == list.length - 1) { + publish.coolDownTime = coolDownTime + return + } + } + // if (publishing.pause) return publish.lastTime = Date.now() const perStartTime = performance.now() @@ -156,14 +178,14 @@ async function doPublish() { publish.startSecMark = item[0].content[0].secMark } - if (!publish.rawTime || publish.normalizedTime) { + if (!publish.rawTime || normalizedTime) { // 由于时间发生变化,对所有车辆进行复制,避免污染原始数据 item = JSON.parse(JSON.stringify(item)) list = item[0].content } // 时间归一化,将所有车辆的时间对其索引 * 100 ms - if (publish.normalizedTime) { + if (normalizedTime) { for (const it of list) { it.timeStamp = publish.startTimestamp + publish.index * 100 it.secMark = (publish.startSecMark + publish.index * 100) % 60000 @@ -200,7 +222,7 @@ async function doPublish() { } /** 尝试关闭原始时间模式,这在强制使用原始时间模式开关打开时不生效 */ function triggerDisableRawTime() { - if (publish.forceRawTime) return + if (forceRawTime) return publish.rawTime = false } @@ -221,7 +243,7 @@ function move(tick: number) { } watch( - () => publish.forceRawTime, + () => mqttStore.forceRawTime, (it) => { if (it) { publish.rawTime = true @@ -276,7 +298,7 @@ watch( -
+
连接 断开 @@ -288,14 +310,21 @@ watch( 暂停 继续 - + 原始时间模式:开 - 原始时间模式:关 - + 原始时间模式:关 + 时间归一化:开 - 时间归一化:关 + 时间归一化:关 +
+
+ + +
+ +
倒带 @@ -312,11 +341,11 @@ watch(
-
+
原始时间模式已关闭,这可能导致需要绝对时间的功能出现异常,例如红绿灯与车流可能不再同步
原始时间模式已开启,这可能导致修改进度时画面出现闪烁,暂停时画面不显示车辆的问题
-
+
时间归一化已开启,可以修复原始数据可能存在的时间戳不一致问题,减少V2X系统内时间跳跃问题发生的概率。
@@ -332,7 +361,7 @@ watch( - +