cc-rail-router/station.lua

38 lines
969 B
Lua
Raw Normal View History

2023-09-07 19:38:39 +00:00
--[[
Stations are kiosks where users can configure their portable computer for a
particular route to another station.
2023-09-08 14:49:17 +00:00
You should add a "station_config.tbl" file containing:
{
2023-09-12 18:11:57 +00:00
name = "stationname",
displayName = "Station Name",
range = 8
2023-09-08 14:49:17 +00:00
}
2023-09-07 19:38:39 +00:00
]]--
local modem = peripheral.wrap("top") or error("Missing top modem")
2023-09-08 14:49:17 +00:00
local BROADCAST_CHANNEL = 45451
2023-09-07 19:38:39 +00:00
2023-09-08 14:49:17 +00:00
local function readConfig()
local f = io.open("station_config.tbl", "r")
if not f then error("Missing station_config.tbl") end
local cfg = textutils.unserialize(f:read("*a"))
f:close()
return cfg
end
2023-09-14 15:09:26 +00:00
local function broadcast(config)
2023-09-07 19:38:39 +00:00
while true do
2023-09-14 15:09:26 +00:00
modem.transmit(BROADCAST_CHANNEL, BROADCAST_CHANNEL, config)
2023-09-07 19:38:39 +00:00
os.sleep(1)
end
end
2023-09-08 14:49:17 +00:00
local config = readConfig()
term.clear()
term.setCursorPos(1, 1)
print("Running station transponder for \""..config.name.."\".")
2023-09-12 18:11:57 +00:00
print(" Display Name: "..config.displayName)
2023-09-08 14:49:17 +00:00
print(" Range: "..config.range.." blocks")
2023-09-14 15:09:26 +00:00
broadcast(config)