From 278de7de6b9b5acaec762ccbfe1deff3eaa144d5 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sun, 2 Aug 2026 18:58:54 +0800 Subject: [PATCH] feat: announce delay alerts as soon as they appear --- station_broadcast.lua | 53 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/station_broadcast.lua b/station_broadcast.lua index af80e81..df1b974 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -2,7 +2,7 @@ -- ============================================================================ -- 1. Configuration & Constants -- ============================================================================ -local APP_VERSION_TEXT = "v1.0.37" +local APP_VERSION_TEXT = "v1.0.38" local CONFIG = { CLOUD_URL = "ws://stabadmin.fse-media.group", @@ -2308,6 +2308,7 @@ end -- ============================================================================ local Main = {} State.announcedApproaching = {} +State.announcedAlerts = {} State.pendingApproaching = {} local function parseEtaText(etaStr) @@ -2471,6 +2472,11 @@ function Main.loop() State.announcedApproaching[k] = nil end end + for k, v in pairs(State.announcedAlerts) do + if now - v > 300000 then + State.announcedAlerts[k] = nil + end + end for i, stop in ipairs(data.TrainStops) do local st = stop.Station @@ -2523,6 +2529,27 @@ function Main.loop() cancelled = cancelled, reason = reason }) + + local alertKey = announceKey .. "::delay=" .. tostring(delayMinutes) .. "::reason=" .. tostring(reason or "") .. "::cancel=" .. tostring(cancelled) + if cancelled or delayMinutes > 0 then + if not State.announcedAlerts[alertKey] then + State.announcedAlerts[alertKey] = now + Utils.log("INFO", string.format("Train Alert: %s (ETA: %ds, Delay: %dm, Cancelled: %s, Reason: %s)", trainName, etaSeconds, delayMinutes, tostring(cancelled), tostring(reason or ""))) + Network.send({ + type = "train_approaching", + stationName = State.stationName, + stationCode = State.stationCode, + stationPlatform = platform, + trainId = trainName, + destination = destination, + eta = tostring(etaSeconds) .. "s", + etaSeconds = etaSeconds, + delay = delayMinutes, + cancelled = cancelled, + reason = reason + }) + end + end if etaSeconds >= 0 and etaSeconds < 30 then if not State.announcedApproaching[announceKey] then @@ -2557,6 +2584,11 @@ function Main.loop() State.announcedApproaching[k] = nil end end + for k, v in pairs(State.announcedAlerts) do + if now - v > 300000 then + State.announcedAlerts[k] = nil + end + end for _, lineText in pairs(lines) do if lineText and lineText ~= "" and lineText:match("[%w%?%[]") then @@ -2611,6 +2643,25 @@ function Main.loop() reason = nil }) + local alertKey = announceKey .. "::delay=" .. tostring(delay) + if delay > 0 then + if not State.announcedAlerts[alertKey] then + State.announcedAlerts[alertKey] = now + Utils.log("INFO", string.format("Train Delay Alert: %s (ETA: %ds, Delay: %dm)", tName, etaSeconds, delay)) + Network.send({ + type = "train_approaching", + stationName = State.stationName, + stationCode = State.stationCode, + stationPlatform = platform or State.stationPlatform or "1", + trainId = tName, + destination = dest, + eta = etaStr, + etaSeconds = etaSeconds, + delay = delay + }) + end + end + -- 触发逻辑:当 ETA 已经明确小于30秒(包括15秒、现在等),且之前没有播报过 if etaSeconds >= 0 and etaSeconds < 30 then if not State.announcedApproaching[announceKey] then