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( 暂停 继续 - + 原始时间模式:开 - 原始时间模式:关 - + 原始时间模式:关 + 时间归一化:开 - 时间归一化:关 + 时间归一化:关 + + + 冷却时间:关闭 + 冷却时间:{{ coolDownTime }} ms + + + 倒带 @@ -312,11 +341,11 @@ watch( - + 原始时间模式已关闭,这可能导致需要绝对时间的功能出现异常,例如红绿灯与车流可能不再同步 原始时间模式已开启,这可能导致修改进度时画面出现闪烁,暂停时画面不显示车辆的问题 - + 时间归一化已开启,可以修复原始数据可能存在的时间戳不一致问题,减少V2X系统内时间跳跃问题发生的概率。 @@ -332,7 +361,7 @@ watch( 已禁用 - 归一化 + 归一化 正常