-- 23.07.23/AH Learjet 35A FMS Synchronize "Digital Transponder" to P3D internal transponder -- -- Flysimware Learjet 35A FMS Expansion Pack delivers a new "Digital Transponder" that synchronizes in a one-way fashion -- the P3D internal transponder. This leads to a conflict with Pilot2ATC's "Copilot sets Squawk" option (overwriting the latter) -- -- This script starts by FSUIPC.ini [Auto] or [Auto.] Section, it could be started manually by FSUIPC button definition. -- [Profile.Flysimware_Learjet35A_FMS] -- 1=Learjet 35A FMS N548PA -- [Auto.Flysimware_Learjet35A_FMS] -- 1=LUA Lear35A_SyncXPDR -- The Script's main procedure starts the sync function every 10.000 ms (or another value in variable cycletime) -- -- The function LearSyncXpndr reads Digital Transponders LVARs and, if not existing, terminates itself (no Lear FMS aircraft) -- The P3D internal transponder Squawk (2 bytes BCD coded at offset 0x0354) is divided into its nibbles (halfbytes) -- They have to be combined digit by digit to a decimal number to compare (BCD x01200 = decimal 4608 <> decimal 1200) -- If the Squawks are different, the Digital Transponder Squawk is set according to P3D internal Squawk. -- -- It's a compromise: -- On one site, manual setting of Digital Transponder is possible: -- even if P3D internal transponder changes, there's a 10 seconds gap until the function runs again -- On the other site if a tool like Pilot2ATC sets the P3D internal transponder and there's no focus in VC on the Digital Transponder -- (knobs not activated by clicking on them), this script sets Digital Transponder accordingly after max. 10 seconds. -- -- Sync function, called by main entry's event.timer every 10 seconds -- function LearSyncXpndr(CurrentTime) -- Get "Digital Transponder" Squawk Code DIGSQ1=ipc.readLvar("L:Digit1") DIGSQ2=ipc.readLvar("L:Digit2") DIGSQ3=ipc.readLvar("L:Digit3") DIGSQ4=ipc.readLvar("L:Digit4") -- Check if "L:Digit..." LVARs were returned, if not: no Lear FMS - end timer procedure if DIGSQ1 == nil or DIGSQ2 == nil or DIGSQ3 == nil or DIGSQ4 == nil then ipc.display("LUA only for Flysimware Learjet 35A with FMS (L:Digit... undefined)") ipc.sleep(2000) ipc.exit() end -- Combine Digital Transponder Squawk digits to decimal number DIGSQ=(DIGSQ1 * 1000) + (DIGSQ2 * 100) + (DIGSQ3 * 10) + DIGSQ4 -- Get P3D BCD-coded Squawk Code and extract nibbles (halfbytes) -- we need them to build a decimal compare number and to set Digital Transponder if not equal XPNDR=ipc.readUW(0x0354) XPNDR1=logic.Shr(XPNDR,12) -- get first nibble by shift right 12 bits XPNDR1=logic.And(XPNDR1,15) -- and leave only rightmost four bits XPNDR2=logic.Shr(XPNDR,8) -- get second nibble by shift right 8 bits XPNDR2=logic.And(XPNDR2,15) -- and leave only rightmost four bits XPNDR3=logic.Shr(XPNDR,4) -- get third nibble by shift right 4 bits XPNDR3=logic.And(XPNDR3,15) -- and leave only rightmost four bits XPNDR4=logic.And(XPNDR,15) -- get fourth nibble: leave only rightmost four bits -- Combine P3D internal transponder digits to decimal number XPNDRDEC=(XPNDR1 * 1000) + (XPNDR2 * 100) + (XPNDR3 * 10) + XPNDR4 -- If Digital Transponder Squawk and P3D-internal Squawk are not equal: set "Digital Transponder" if DIGSQ ~= XPNDRDEC then -- Set Digital Transponder Squawk to P3D Squawk ipc.WriteLvar("L:Digit1", XPNDR1) ipc.WriteLvar("L:Digit2", XPNDR2) ipc.WriteLvar("L:Digit3", XPNDR3) ipc.WriteLvar("L:Digit4", XPNDR4) end -- just for debugging: show nibbles in hex -- XPNDR1X=string.format("%x", XPNDR1) -- XPNDR2X=string.format("%x", XPNDR2) -- XPNDR3X=string.format("%x", XPNDR3) -- XPNDR4X=string.format("%x", XPNDR4) -- ipc.display("P3D XPD: " .. XPNDR1 .. "-" .. XPNDR2 .. "-" .. XPNDR3 .. "-" .. XPNDR4 .. ".") -- ipc.sleep(1000) -- XPNDRX=string.format("%x", XPNDR) -- ipc.display("P3D XPX: " .. XPNDR1X .. "-" .. XPNDR2X .. "-" .. XPNDR3X .. "-" .. XPNDR4X .. ".") -- ipc.sleep(1000) -- ipc.display("P3D XP: " .. XPNDRX .. " (BCD !) DigXP: " .. DIGSQ) end -- -- Main Entry, called by FSUIPC.ini LUA entry in Section "[Auto]" or "[Auto.]" -- cycletime=10000 -- Display in P3D before starting cyclic function to prevent msg removal by function's own msgs ipc.display("Starting Lear 35A Digital Transponder sync every " .. cycletime .. "ms") ipc.sleep(8000) ipc.display("") -- clear display -- Now start cyclic function for XPDR Sync event.timer(cycletime, "LearSyncXpndr") --