diff --git a/station_broadcast.lua b/station_broadcast.lua index 01f4fb7..788b0df 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -1,6 +1,6 @@ -- 1. Configuration & Constants -local APP_VERSION_TEXT = "v1.0.74" +local APP_VERSION_TEXT = "v1.0.75" local CONFIG = { CLOUD_URL = "ws://stabadmin.fse-media.group", @@ -3401,6 +3401,10 @@ function Main.loop() if Peripherals.blockReader then local ok, data = pcall(Peripherals.blockReader.getBlockData) + if not ok then + Utils.log("WARN", "BlockReader.getBlockData() failed: " .. tostring(data)) + data = nil + end if ok and data and data.TrainStops then if not State.lastRefreshed or State.lastRefreshed ~= data.LastRefreshed then if State.lastRefreshed and State.lastRefreshedEpoch then @@ -3426,6 +3430,7 @@ function Main.loop() cleanupTimestampMap(State.announcedAlerts, now, tonumber(CONFIG.ALERT_COOLDOWN_MS) or 300000) for i, stop in ipairs(data.TrainStops) do + local okStop, err = pcall(function() local st = type(stop.Station) == "table" and stop.Station[1] or stop.Station if st then local trainName = st.TrainName or "Unknown" @@ -3440,11 +3445,8 @@ function Main.loop() local lastStopover = stop.Stopovers[#stop.Stopovers] if looksLikeValidDestinationText(lastStopover) then destination = lastStopover - else - if looksLikeValidDestinationText(destination) then - else - destination = lastStopover or destination - end + elseif not looksLikeValidDestinationText(destination) then + destination = lastStopover or destination end end @@ -3596,6 +3598,10 @@ function Main.loop() end end end + end) + if not okStop then + Utils.log("WARN", "TrainStop[" .. tostring(i) .. "] parse error: " .. tostring(err)) + end end for k, _ in pairs(State.pendingAlerts) do @@ -3612,7 +3618,10 @@ function Main.loop() end if not Peripherals.blockReader and Peripherals.createTarget then - local lines = Peripherals.createTarget.dump() + local okCT, lines = pcall(Peripherals.createTarget.dump) + if not okCT or type(lines) ~= "table" then + lines = {} + end local seenAlertKeys = {} local seenApproachKeys = {}