-
-
Save severak/235c28c7e146f4a0a6549cbf532be23f to your computer and use it in GitHub Desktop.
Remote train
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Remote train | |
-- (c) Severak 2021 | |
-- place this into LuaAutomation ATC rail code and connect it to microcontroller via digiline | |
if event.digiline and event.channel=="to_atc" then | |
if event.msg.train_id then | |
if atc_id then | |
digiline_send("debug_atc","tid " .. atc_id) | |
digiline_send("from_atc", {train_id=atc_id}) | |
else | |
digiline_send("debug_atc","no train!") | |
digiline_send("from_atc", {train_id=false}) | |
end | |
end | |
if event.msg.panic then | |
digiline_send("debug_atc","panic! " .. event.msg.panic) | |
atc_send_to_train(event.msg.autostop, "BB") | |
end | |
if event.msg.start then | |
digiline_send("debug_atc","start! " .. event.msg.start) | |
atc_send_to_train(event.msg.start, "S5") | |
end | |
if event.msg.stop then | |
digiline_send("debug_atc","stop! " .. event.msg.stop) | |
atc_send_to_train(event.msg.stop, "B0") | |
end | |
if event.msg.reverse then | |
digiline_send("debug_atc","reverse! " .. event.msg.reverse) | |
atc_send_to_train(event.msg.reverse, "B0 W R S5") | |
end | |
if event.msg.couple then | |
digiline_send("debug_atc","couple! " .. event.msg.couple) | |
atc_send_to_train(event.msg.couple, "Cpl") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Remote train | |
-- (c) Severak 2021 | |
-- place this into microcontroller and connect it with Lua ATC via digiline | |
-- use with digiterms monitor with channel "mon" and digiterms keyboard with channel "in" | |
-- handles these commands: | |
-- PAIR - pairs train standing at ATC rail with microcontroller (you should do this first) | |
-- START - starts train engine | |
-- STOP - stops train | |
-- REV - reverses train direction | |
-- CPL - enters coupling mode | |
-- SHUNT - starts train and enter coupling mode | |
-- DEBUG - enables debug | |
-- you can use these aliases | |
-- S - stop | |
-- R - reverse | |
-- C - couple | |
-- however currently if train is stuck there is no help :-( | |
-- program updated, print info | |
if event.type=="program" then | |
for i=1,6 do | |
digiline_send("mon", " ") | |
end | |
digiline_send("mon", "Remote train") | |
digiline_send("mon", "(c) Severak 2021") | |
mem.train_id=false | |
mem.debug = false | |
-- autopairing on restart | |
digiline_send("to_atc",{train_id=true}) | |
end | |
-- ATC debug messages | |
if mem.debug and event.type=="digiline" and event.channel=="debug_atc" then | |
digiline_send("mon", "// " .. event.msg) | |
end | |
-- handle user commands: | |
if event.type=="digiline" and event.channel=="in" then | |
-- expand aliases | |
if event.msg=="s" then event.msg = "stop" end | |
if event.msg=="r" then event.msg = "rev" end | |
if event.msg=="c" then event.msg = "cpl" end | |
-- send typed in command back | |
digiline_send("mon", "> " .. event.msg) | |
if event.msg=="help" then | |
digiline_send("mon", "No help page!") | |
digiline_send("mon", "Please consult program source code.") | |
end | |
if event.msg=="debug" then | |
mem.debug = true | |
digiline_send("mon", "ATC debug enabled.") | |
end | |
-- we asked ATC for train_id | |
if event.msg=="pair" then | |
digiline_send("to_atc",{train_id=true}) | |
end | |
if event.msg=="start" then | |
if not mem.train_id then | |
digiline_send("mon" , "Train not paired!") | |
else | |
digiline_send("to_atc", {start=mem.train_id}) | |
end | |
end | |
if event.msg=="stop" then | |
if not mem.train_id then | |
digiline_send("mon" , "Train not paired!") | |
else | |
digiline_send("to_atc", {stop=mem.train_id}) | |
end | |
end | |
if event.msg=="rev" then | |
if not mem.train_id then | |
digiline_send("mon" , "Train not paired!") | |
else | |
digiline_send("to_atc", {reverse=mem.train_id}) | |
end | |
end | |
if event.msg=="cpl" then | |
if not mem.train_id then | |
digiline_send("mon" , "Train not paired!") | |
else | |
digiline_send("to_atc", {couple=mem.train_id}) | |
end | |
end | |
if event.msg=="shunt" then | |
if not mem.train_id then | |
digiline_send("mon" , "Train not paired!") | |
else | |
digiline_send("to_atc", {start=mem.train_id}) | |
digiline_send("to_atc", {couple=mem.train_id}) | |
end | |
end | |
end | |
-- ATC got our train_id, saving it | |
if event.type=="digiline" and event.channel=="from_atc" then | |
mem.train_id = event.msg.train_id | |
if not event.msg.train_id then | |
digiline_send("mon", "No train present!") | |
else | |
digiline_send("mon", "Pairing OK.") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment