69 lines
2.3 KiB
Lua
69 lines
2.3 KiB
Lua
local target = peripheral.find("create_target")
|
|
|
|
if not target then
|
|
print("Error: Target block not found! Please check if Wired Modem is connected and activated (red ring).")
|
|
return
|
|
end
|
|
|
|
pcall(target.resize, 80, 10)
|
|
|
|
-- A helper function to parse the Create station summary line
|
|
-- Example input: "1 ?? [Local]1123 HC-02 2"
|
|
local function parseTrainLine(line)
|
|
-- Format we are parsing:
|
|
-- "<Time_Number> <Time_Unit> <Train_Name> <Destination>"
|
|
-- Example: "1 ?? [Local]1123 HC-02 2"
|
|
-- Example: "现在 ?? [Local]1123 HC-02 2" (assuming "现在" might replace the number and unit)
|
|
|
|
local timeValue, timeUnit, trainName, destination
|
|
|
|
-- Try parsing format with a number first (e.g., "1 ?? ...")
|
|
timeValue, timeUnit, trainName, destination = string.match(line, "^(%d+)%s+(.-)%s+(%[.-%][^%s]*)%s+(.*)$")
|
|
|
|
-- If that fails, it might be the "Now" (现在) format which might not have digits at the start
|
|
if not trainName then
|
|
timeValue, timeUnit, trainName, destination = string.match(line, "^([^%s]+)%s+(.-)%s+(%[.-%][^%s]*)%s+(.*)$")
|
|
end
|
|
|
|
-- Fallback for extremely weird formatting
|
|
if not trainName then
|
|
timeValue, timeUnit, trainName, destination = string.match(line, "^([^%s]+)%s+(.-)%s+([^%s]+)%s+(.*)$")
|
|
end
|
|
|
|
return {
|
|
eta_value = timeValue or "N/A",
|
|
eta_unit = timeUnit or "N/A",
|
|
trainName = trainName or "N/A",
|
|
destination = destination or "N/A",
|
|
raw = line
|
|
}
|
|
end
|
|
|
|
while true do
|
|
term.clear()
|
|
term.setCursorPos(1,1)
|
|
print("=== Receiving Station Data ===")
|
|
|
|
local lines = target.dump()
|
|
local hasData = false
|
|
|
|
for i, lineText in pairs(lines) do
|
|
if lineText and lineText ~= "" and lineText:match("[%w%?%[]") then
|
|
print("--- Line " .. i .. " ---")
|
|
print("Raw: " .. lineText)
|
|
|
|
local parsed = parseTrainLine(lineText)
|
|
print(" Train Name : " .. parsed.trainName)
|
|
print(" Destination: " .. parsed.destination)
|
|
print(" ETA Value : " .. parsed.eta_value)
|
|
print(" ETA Unit : " .. parsed.eta_unit)
|
|
hasData = true
|
|
end
|
|
end
|
|
|
|
if not hasData then
|
|
print("No active trains incoming/departing...")
|
|
end
|
|
|
|
os.sleep(1)
|
|
end |