[simpits-tech] Lua example for David...

Gene Buckle geneb at deltasoft.com
Thu Jul 24 15:13:05 PDT 2008


Ok, given this information:


5600 .0 APUMasterFault
5600 .1 APUStartAvail
5600 .2 APUFlap
5600 .3 APUMaint
5600 .3 APUStarter // CRJ ????
5600 .4 APULowPress
5600 .5 APUPumpFault
5600 .6 APUFault
5600 .7 APUGenBus

Offset at 5600 hex is a single byte that is broken into 8 1 bit fields.

Interesting note - they're showing Bit # 3 as two different things...Bug?
I'll only use APUMaint for this example...

Here's how you work those in Lua:

require "bit";  -- this is the bit field library you'll use.
                 -- you can download it from
 		--http://luaforge.net/projects/bit/

-- Define our error constants
APUMasterFault = 1;
APUStartAvail = 2;
APUFlap = 3;
APUMaint = 4;
APULowPress = 5;
APUPumpFault = 6;
APUFault = 7;
APUGenBus = 8;

APUError = bit.tobits(CIM:GetNumericValue("APU_ERROR"));
-- APU_ERROR points to offset 5600
if APUError[APUMasterFault] == 1 then
   if CIM:GetOutputState("APU_MASTER_FAULT_LAMP") != 1 then
     CIM:SetOutputChannel("APU_MASTER_FAULT_LAMP", 1)
   end
else
   if CIM:GetOutputState("APU_MASTER_FAULT_LAMP") == 1 then
     CIM:SetOutputChannel("APU_MASTER_FAULT_LAMP", 0)
   end
end

Now this example shows just a single test - but what it does is this:
If the APUMasterFault bit is set, it checks to see if the corresponding 
lamp is already lit.  If it is, it does nothing, otherwise it lights it.
If the APUMasterFault bit is NOT set, it makes sure the lamp is off and 
turns it off if it isn't.

g.




-- 
Proud owner of F-15C 80-0007
http://www.f15sim.com - The only one of its kind.


More information about the Simpits-tech mailing list