diff options
author | orwell96 <orwell@bleipb.de> | 2018-08-03 19:20:10 +0200 |
---|---|---|
committer | orwell96 <orwell@bleipb.de> | 2018-08-03 19:20:10 +0200 |
commit | 0d130bb262f25f089d2633479afa0ecee24256e6 (patch) | |
tree | 6606ae962786133ed38f358c860048d0052eda66 /advtrains_interlocking/routesetting.lua | |
parent | c34794e8a1a28826a7e8443b46fa76e0de238978 (diff) | |
download | advtrains-0d130bb262f25f089d2633479afa0ecee24256e6.tar.gz advtrains-0d130bb262f25f089d2633479afa0ecee24256e6.tar.bz2 advtrains-0d130bb262f25f089d2633479afa0ecee24256e6.zip |
Uncommitted route handling (update_route function)
Diffstat (limited to 'advtrains_interlocking/routesetting.lua')
-rw-r--r-- | advtrains_interlocking/routesetting.lua | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/advtrains_interlocking/routesetting.lua b/advtrains_interlocking/routesetting.lua index 181b82d..00ee024 100644 --- a/advtrains_interlocking/routesetting.lua +++ b/advtrains_interlocking/routesetting.lua @@ -15,6 +15,10 @@ local ilrs = {} -- [n] = { [by = <ts_id>], rsn = <human-readable text>, [origin = <sigd>] } -- } ilrs.rte_locks = {} +ilrs.rte_callbacks = { + ts = {}, + lck = {} +} -- Requests the given route -- This function will try to set the designated route. @@ -28,7 +32,7 @@ end -- then (if "try" is not set) actually sets it -- returns: -- true - route can be/was successfully set --- false, message - something went wrong, what is contained in the message. +-- false, message, cbts, cblk - something went wrong, what is contained in the message. function ilrs.set_route(signal, route, try) if not try then atdebug("rteset real-run") @@ -222,5 +226,32 @@ function ilrs.cancel_route_from(sigd) end end + +-- TCBS Routesetting helper: generic update function for +-- route setting + +function ilrs.update_route(sigd, tcbs, newrte, cancel) + if (newrte and tcbs.routeset and tcbs.routeset ~= newrte) or cancel then + if tcbs.route_committed then + atdebug("Cancelling:",tcbs.routeset) + advtrains.interlocking.route.cancel_route_from(sigd) + end + tcbs.route_committed = nil + tcbs.routeset = newrte + end + if newrte or tcbs.routeset then + if newrte then tcbs.routeset = newrte end + atdebug("Setting:",tcbs.routeset) + local succ, rsn, cbts, cblk = ilrs.set_route(sigd, tcbs.routes[tcbs.routeset]) + if not succ then + tcbs.route_rsn = rsn + -- add cbts or cblk to callback table + else + tcbs.route_committed = true + end + end + --TODO callbacks +end + advtrains.interlocking.route = ilrs |