From 0d130bb262f25f089d2633479afa0ecee24256e6 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Fri, 3 Aug 2018 19:20:10 +0200 Subject: Uncommitted route handling (update_route function) --- advtrains_interlocking/routesetting.lua | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'advtrains_interlocking/routesetting.lua') 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 = ], rsn = , [origin = ] } -- } 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 -- cgit v1.2.3