-------------------------------------------------------------------------------------- -- PZB 2000Hz Speed Warning Inductor -- (goes next to Hp Signal) -- Modified from Default KUJU PZB Script to make compatible with Default & vR Stock -- SSD 5 Aug 2012 -- Also modified by HRQ 18 Aug 2012 -- Rev 1.0 -------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------- -- GLOBAL DEFINITIONS -- Enable/Disable Script Debug Messages DEBUG = false -- Signal States CLEAR = 0 WARNING = 1 BLOCKED = 2 -- Signal Messages SIGNAL_BLOCKED = 12; SIGNAL_CLEARED = 13; SIGNAL_WARNING = 14; SIGNAL_WARNING2 = 15; -- Consist Messages -- Default Stock MSG_DF_PZB1000 = "1000" MSG_DF_PZB2000 = "2000" -- vR Expert Line Stock CUSTOM_MESSAGE = 15; MSG_VR_PZB1000 = "PZB1000"; MSG_VR_PZB500 = "PZB500"; MSG_VR_PZB2000 = "PZB2000"; -------------------------------------------------------------------------------------- -- INITIALISE -- function Initialise () DebugPrint( ("DEBUG: Initialise") ) trainPassedSignal = false nextSignalMessageState = false end -------------------------------------------------------------------------------------- -- ON CONSIST PASS -- function OnConsistPass ( prevFrontDist, prevBackDist, frontDist, backDist, linkIndex ) -- if the consist is crossing the inductor now if ( frontDist > 0 and backDist < 0 ) or ( frontDist < 0 and backDist > 0 ) then DebugPrint( ("DEBUG: PZB 2000Hz OnConsistPass ( pfd " .. prevFrontDist .. ", pbd " .. prevBackDist .. ", fd " .. frontDist .. ", bd " .. backDist .. ", li " .. linkIndex .. ")" )) -- if the consist was previously before siganl then the crossing has just started if (prevFrontDist > 0 and prevBackDist > 0) then if ( trainPassedSignal ~= true ) then trainPassedSignal = true if ( nextSignalMessageState == false ) then -- Request state of next signal local nextSignalState = Call( "GetNextSignalState", "", 1, 1, 0 ) local nextDistantState = Call( "GetNextDistantState", "", 1, 1, 0 ) DebugPrint( ("DEBUG: PZB 2000Hz OnConsistPass: Crossing started, next signal anim is " .. nextSignalState) ) DebugPrint( ("DEBUG: PZB 2000Hz OnConsistPass: Crossing started, next distant anim is " .. nextDistantState) ) -- If the signal ahead isn't clear... if ( nextSignalState == BLOCKED ) then --Call( "SendConsistMessage", CUSTOM_MESSAGE, MSG_VR_PZB2000 ) Call( "SendConsistMessage", CUSTOM_MESSAGE, MSG_DF_PZB2000 ) elseif ( nextDistantState ~= CLEAR ) then --Call( "SendConsistMessage", CUSTOM_MESSAGE, MSG_VR_PZB1000 ) Call( "SendConsistMessage", CUSTOM_MESSAGE, MSG_DF_PZB1000 ) end else if ( nextSignalMessageState == SIGNAL_BLOCKED ) then --Call( "SendConsistMessage", CUSTOM_MESSAGE, MSG_VR_PZB1000 ) Call( "SendConsistMessage", CUSTOM_MESSAGE, MSG_DF_PZB1000 ) end end end end else -- Reset once train has passed if ( trainPassedSignal ~= false ) then DebugPrint( ("DEBUG: PZB 2000Hz OnConsistPass: Crossing finished") ) trainPassedSignal = false end end end -------------------------------------------------------------------------------------- -- ON SIGNAL MESSAGE -- function OnSignalMessage( message, parameter, direction, linkIndex ) -- Forward every message unchanged, unless it's from a train straddling our link if ( parameter ~= "DoNotForward" ) then Call( "SendSignalMessage", message, parameter, -direction, 1, linkIndex ) end end -------------------------------------------------------------------------------------- -- JUNCTION STATE CHANGE -- Left blank - PZB inductors only have one link -- function OnJunctionStateChange( junction_state, parameter, direction, linkIndex ) end function DebugPrint( message ) if (DEBUG) then Print( message ) end end