From ea288b6572625f37228549acc4e56b4decd1558b Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sun, 2 Aug 2026 16:41:01 +0800 Subject: [PATCH] feat: show delay reason/status from CRN NBT on monitor --- station_broadcast.lua | 54 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/station_broadcast.lua b/station_broadcast.lua index af31244..27f5cac 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -2,7 +2,7 @@ -- ============================================================================ -- 1. Configuration & Constants -- ============================================================================ -local APP_VERSION_TEXT = "v1.0.28" +local APP_VERSION_TEXT = "v1.0.29" local CONFIG = { CLOUD_URL = "ws://stabadmin.fse-media.group", @@ -2134,7 +2134,7 @@ function Display.render() mon.setTextColor(COLORS.DEBUG) mon.setCursorPos(1, upcomingStartY) mon.write("UPCOMING TRAINS:") - if State.debugUpcoming and upcomingStartY + 1 <= h then + if CONFIG.DEBUG and State.debugUpcoming and upcomingStartY + 1 <= h then mon.setCursorPos(1, upcomingStartY + 1) mon.setTextColor(COLORS.DEBUG) local dbg = State.debugUpcoming @@ -2155,8 +2155,20 @@ function Display.render() for i = 1, visibleCount do local t = State.upcomingTrains[i] mon.setCursorPos(1, upcomingStartY + i) - local delayStr = t.delay > 0 and (" [+" .. t.delay .. "m]") or "" - local lineText = string.format("%s->%s ETA:%ds%s", t.trainName, t.dest, t.eta, delayStr) + local suffix = "" + if t.cancelled then + suffix = " [CANCEL]" + elseif (tonumber(t.delay) or 0) > 0 then + local reason = t.reason and (" " .. tostring(t.reason)) or "" + suffix = " [+" .. tostring(t.delay) .. "m" .. reason .. "]" + elseif t.reason then + suffix = " [" .. tostring(t.reason) .. "]" + end + local pfx = "" + if t.platform and tostring(t.platform) ~= "" then + pfx = "P" .. tostring(t.platform) .. " " + end + local lineText = string.format("%s%s->%s ETA:%ds%s", pfx, t.trainName, t.dest, t.eta, suffix) if #lineText > w then lineText = lineText:sub(1, w) end mon.write(lineText) end @@ -2164,7 +2176,7 @@ function Display.render() else mon.setTextColor(COLORS.WARNING) local msgY = upcomingStartY + 1 - if State.debugUpcoming then msgY = upcomingStartY + 2 end + if CONFIG.DEBUG and State.debugUpcoming then msgY = upcomingStartY + 2 end if msgY <= h then mon.setCursorPos(1, msgY) mon.write("NONE / WAITING DATA") @@ -2355,6 +2367,30 @@ function Main.loop() local trainName = st.TrainName or "Unknown" local destination = st.Destination or "Unknown" local platform = stop.StationInfo and stop.StationInfo.Platform or State.stationPlatform or "1" + local cancelled = false + local reason = nil + local tr = stop.Train + if tr then + cancelled = tr.Cancelled == 1 or tr.Cancelled == true + local status = tr.Status + if type(status) == "table" then + for _, s in ipairs(status) do + if type(s) == "string" then + if string.find(s, "delay_from_previous_journey", 1, true) then + reason = "prev" + elseif string.find(s, "cancel", 1, true) then + reason = "cancel" + else + local tail = string.match(s, ":(.+)$") + reason = tail or s + end + end + end + end + end + if cancelled then + reason = "cancelled" + end -- Calculate ETA in seconds using interpolated currentTick local scheduledArrival = st.ScheduledArrival or 0 @@ -2373,7 +2409,9 @@ function Main.loop() dest = destination, platform = platform, eta = etaSeconds, - delay = delayMinutes + delay = delayMinutes, + cancelled = cancelled, + reason = reason }) if etaSeconds >= 0 and etaSeconds <= 45 then @@ -2453,7 +2491,9 @@ function Main.loop() dest = dest, platform = platform or State.stationPlatform or "1", eta = etaSeconds >= 0 and etaSeconds or 0, - delay = delay + delay = delay, + cancelled = false, + reason = nil }) -- 触发逻辑:当 ETA 已经明确 <= 45秒(包括30秒、15秒、现在等),且之前没有播报过