1
|
turnouts = {
{1870,11,9122},-- Southern headshunt/Goods Shed
{1863,11,9122},--Southern Roads
{1857,11,9122},
{1851,11,9122},
{1845,11,9122},
{1782,11,9222},--NW Roads
{1782,11,9216},
{1782,11,9210},
{1782,11,9204},
{1868,11,9157}, --Eastern Assembly Roads
{1860,11,9161},
{1817,11,9237},
{1817,11,9231},
{1822,11,9251}, --Northern Wye
{1817,11,9238},
{1806,11,9243},
}
routes = {
-- max# of routes = 32 (1-31 + R0)
--southern headshunt
{['matrix']={"1st"}, ['name']="Goods Shed Headshunt"}, --1
{['matrix']={"1cr"}, ['name']="West Assembly Yard"}, --2
--southern road access
{['matrix']={"2cr"}, ['name']="East S1"}, --3
{['matrix']={"2st","3cr"}, ['name']="East S2"}, --4
{['matrix']={"2st","3st","4cr"}, ['name']="East S3"}, --5
{['matrix']={"2st","3st","4st","5cr"}, ['name']="East S4"}, --6
{['matrix']={"2st","3st","4st","5st"}, ['name']="East S5"}, --7
--NW road access
{['matrix']={"6cr"}, ['name']="East N1"}, --8
{['matrix']={"6st","7cr"}, ['name']="East N2"}, --9
{['matrix']={"6st","7st","8cr"}, ['name']="East N3"}, --10
{['matrix']={"6st","7st","8st","9cr"}, ['name']="East N4"}, --11
{['matrix']={"6st","7st","8st","9st"}, ['name']="East N5"}, --12
--Eastern Assembly Roads
{['matrix']={"10st","12cr"}, ['name']="Assembly East"}, --13
{['matrix']={"10cr","11cr","12st","13cr"}, ['name']="Assembly Central"}, --14
{['matrix']={"10cr","11st","12st","13st"}, ['name']="Assembly West"}, --15
--Norther Wye
{['matrix']={"15st","14cr"}, ['name']="Assembly<->Station"}, --16
{['matrix']={"15cr","16cr"}, ['name']="Yard Loopback"}, --17
{['matrix']={"14st","16st"}, ['name']="Bypass Yard"}, --18
--testing routes
{['matrix']={"1cr","2cr","3cr","4cr","5cr"}, ['name']="[TEST]Southern Cr"}, --19
{['matrix']={"1st","2st","3st","4st","5st"}, ['name']="[TEST]Southern St"}, --20
{['matrix']={"6st","7st","8st","9st"}, ['name']="[TEST]Northern St"}, --21
{['matrix']={"6cr","7cr","8cr","9cr"}, ['name']="[TEST]Northern Cr"}, --22
}
local display = "tl1"
local debug_screen = "tl2"
function tableLength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
if event.type=="digiline" then
if event.channel=="track_control" then
local r = event.msg
if r > tableLength(routes) then
digiline_send(display,"Input ["..r.."] exceeds #routes||"..tableLength(routes))
-- digiline_send(debug_screen,"Input ["..r.."] exceeds #routes ("..tableLength(routes)..")")
return
elseif r == 0 then
digiline_send(display,"Input 0 is not defined")
-- digiline_send(debug_screen,"Input 0 is not defined")
return
end
route = routes[r]
-- a = ""
for _,v in pairs(route.matrix) do
local tid = tonumber(v:match("%d+"))
local tpos = turnouts[tid]
local turnout = {}
turnout.x = tpos[1]
turnout.y = tpos[2]
turnout.z = tpos[3]
local cmd = v:match("%a+")
-- a = a..string.format("%s %d,%d,%d\n",cmd,turnout.x,turnout.y,turnout.z)
setstate(turnout,cmd)
end
local verbose = table.concat(route.matrix," ")
digiline_send(display,"Route "..r.." set||"..verbose.."||"..route.name)
-- digiline_send(debug_screen,a)
return
end
if event.channel=="input" then --show debug info
if event.msg=="rwt_get" then
digiline_send("rwt_get",rwt.now())
elseif event.msg=="debug" then
digiline_send(debug_screen,"#turnouts: "..tableLength(turnouts).."\n#routes: "..tableLength(routes))
elseif event.msg=="occupancy_refresh" then
local m = ""
for k,v in pairs(S.yards.WOA) do
if type(v) == "table" then
m = m..k..": "..tostring(v.car_count).."||"
end
end
digiline_send(debug_screen,m)
end
end
end
|