Periodic subscription

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
freedom
Posts: 63
Joined: Wed Jul 29, 2020 2:41 pm

Periodic subscription

#1 Post by freedom »

I am trying to subscribe aircraft location dataref every one second. Is there any way to achieve this?

User avatar
jph
Posts: 2856
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Periodic subscription

#2 Post by jph »

freedom wrote: Sat Oct 09, 2021 11:01 am I am trying to subscribe aircraft location dataref every one second. Is there any way to achieve this?
Please list - sim in use and version - OS in use and version - Your code. Version of AM in use,, etc etc.
Joe. CISSP, MSc.

freedom
Posts: 63
Joined: Wed Jul 29, 2020 2:41 pm

Re: Periodic subscription

#3 Post by freedom »

AM 4.0.2
XP11

I suppose it doesn't matter I am just trying to figure out the coding logic instead of the actual commands itself?

I tried inserting timer() after function recall but it just delay the first recall. Gotta find another way.

User avatar
Keith Baxter
Posts: 4685
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Periodic subscription

#4 Post by Keith Baxter »

freedom wrote: Sat Oct 09, 2021 11:01 am I am trying to subscribe aircraft location dataref every one second. Is there any way to achieve this?
Hi yes.

@Corjan helped with this throttle dataref subscribe. It is somewhere in the abyss in the forum. I use it mostly for large dataref buss's but no reason it could not also be used for what you want.

A simple timer could also be used to just reed the dataref. Depends on your application. If your dataref is not firing due to it not changing then use ...request_callback(callback_function) which will force a dararef fire/read by AM

This should give you a pointer.

NOTE: the Function and dataref subscribe are just extracts. You need to simplify.

Code: Select all

function xpl_dataref_subscribe_trottle(...)
    -- Local variables
    local args = {...}
    local user_callback = args[#args - 1]
    local delta_ms = table.remove(args, #args)
    local data = nil
    
    -- Replace the user callback with our own
    args[#args] = function (...)
        data = {...}
    end
    
    -- Do the actual subscribe
    xpl_dataref_subscribe(table.unpack(args))
    
    -- Start a timer that will fire the callback on requested interval
    timer_start(0, delta_ms, function()
        if data ~= nil then
            user_callback(table.unpack(data))
            data = nil
        end
    end)
end

---The function
function callback_w_cas(batH,fire,EoilT,EoilP,Eout,rpm,fadec,xmsnp,xmsnt,ap,ap_trim,baggage,Echip,oilpH,mgt_ex,float_arm,fuelQ,hydr,xfrL,xfrR,gen,ignit,antiice,wog,Q,nr1,np1,ng1,mgt1,Pstop,igw)++



end

---Dataref subscribe
xpl_dataref_subscribe_trottle("sim/cockpit2/annunciators/battery_charge_hi","INT",
						"sim/cockpit/warnings/annunciators/engine_fires","INT[8]",
						"sim/cockpit/warnings/annunciators/oil_temperature_high","INT[8]",
						"sim/cockpit/warnings/annunciators/oil_pressure_low","INT[8]",
						
						
						"sim/flightmodel/weight/m_total","FLOAT",callback_w_cas,1000)						



Note: that the timer fires the throttle every 1000ms in this case.

Keith

@Corjan I see this not in the API. "xpl_dataref_subscribe_trottle" .
Is this an over site??

Yes one subscribes to the function. Could this not be made simpler for others....
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

Post Reply