feat: Implement exact 45s pre-arrival broadcast by delaying 1min signal
This commit is contained in:
+41
-9
@@ -2,7 +2,7 @@
|
|||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
-- 1. Configuration & Constants
|
-- 1. Configuration & Constants
|
||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
local APP_VERSION_TEXT = "v1.0.25"
|
local APP_VERSION_TEXT = "v1.0.26"
|
||||||
|
|
||||||
local CONFIG = {
|
local CONFIG = {
|
||||||
CLOUD_URL = "ws://stabadmin.fse-media.group",
|
CLOUD_URL = "ws://stabadmin.fse-media.group",
|
||||||
@@ -2235,6 +2235,7 @@ end
|
|||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
local Main = {}
|
local Main = {}
|
||||||
State.announcedApproaching = {}
|
State.announcedApproaching = {}
|
||||||
|
State.pendingApproaching = {}
|
||||||
|
|
||||||
function Main.loop()
|
function Main.loop()
|
||||||
while true do
|
while true do
|
||||||
@@ -2252,15 +2253,27 @@ function Main.loop()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if tName and etaVal then
|
if tName and etaVal then
|
||||||
-- 恢复当ETA为“1”时也触发广播(满足提前预告的需求)
|
local announceKey = tName .. "_" .. dest
|
||||||
if etaVal == "现在" or etaVal == "0" or etaVal == "1" then
|
local now = os.epoch("utc")
|
||||||
local announceKey = tName .. "_" .. dest
|
|
||||||
local now = os.epoch("utc")
|
-- 45秒预告逻辑:当读取到1分钟时,延迟15秒再播报
|
||||||
-- Prevent spamming: CRN's "1 min" can be fuzzy and stay for a while.
|
if etaVal == "1" then
|
||||||
-- We set the cooldown to 1 minute (60000 ms) per train per destination.
|
if not State.announcedApproaching[announceKey] or (now - State.announcedApproaching[announceKey] > 120000) then
|
||||||
if not State.announcedApproaching[announceKey] or (now - State.announcedApproaching[announceKey] > 60000) then
|
if not State.pendingApproaching[announceKey] then
|
||||||
|
State.pendingApproaching[announceKey] = {
|
||||||
|
triggerTime = now + 15000, -- 延迟15秒
|
||||||
|
tName = tName,
|
||||||
|
dest = dest,
|
||||||
|
etaVal = etaVal
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif etaVal == "现在" or etaVal == "0" then
|
||||||
|
-- 如果列车已经进站(0或现在),并且没有被播报过,立即播报
|
||||||
|
if not State.announcedApproaching[announceKey] or (now - State.announcedApproaching[announceKey] > 120000) then
|
||||||
State.announcedApproaching[announceKey] = now
|
State.announcedApproaching[announceKey] = now
|
||||||
Utils.log("INFO", "Train Approaching: " .. tName)
|
State.pendingApproaching[announceKey] = nil
|
||||||
|
Utils.log("INFO", "Train Approaching (Now): " .. tName)
|
||||||
Network.send({
|
Network.send({
|
||||||
type = "train_approaching",
|
type = "train_approaching",
|
||||||
stationName = State.stationName,
|
stationName = State.stationName,
|
||||||
@@ -2275,6 +2288,25 @@ function Main.loop()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- 检查是否有到期的延迟播报(45秒预告)
|
||||||
|
local now = os.epoch("utc")
|
||||||
|
for key, info in pairs(State.pendingApproaching) do
|
||||||
|
if now >= info.triggerTime then
|
||||||
|
State.announcedApproaching[key] = now
|
||||||
|
State.pendingApproaching[key] = nil
|
||||||
|
Utils.log("INFO", "Train Approaching (45s mark): " .. info.tName)
|
||||||
|
Network.send({
|
||||||
|
type = "train_approaching",
|
||||||
|
stationName = State.stationName,
|
||||||
|
stationCode = State.stationCode,
|
||||||
|
stationPlatform = State.stationPlatform or "1",
|
||||||
|
trainId = info.tName,
|
||||||
|
destination = info.dest,
|
||||||
|
eta = info.etaVal
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not Peripherals.station then
|
if not Peripherals.station then
|
||||||
|
|||||||
Reference in New Issue
Block a user