PDA

View Full Version : Sioc,Im Confused,Help



iwik
01-11-2009, 12:11 AM
Hi Guys,
Im struggling with Sioc,everytime i seem to try things,i take for ever and sometimes i completely bomb out.Here is what im trying to achieve.
Want to display my remaining fuel in gallons on a lcd display.However Fsuipc returns the value as a percentage.There is also an offset that holds the max capacity of the tank.So with my maths i would take the
percentage multiply it by tank capacity and divide by 100.
So i set to write some code as follows(i really dont fully inderstand sioc);

// **** Fuel Left *****
var 6030 name fuell Link FSUIPC_IN,offset $0b7c Length 4 // % remaining
{
L0 = v6030 / 0.000011920928955078125
v6032 = L0 / 100
}
var 6034 name fuelmax Link FSUIPC_IN,OFFSET $0b80 Length 4 // Tank Capacity
{
v6033 = v6034
}
Var 6037 name fcalc Value 0
{
CALL &Outfuel
}
Var 6039 name Outfuel Link Subrutine
{
Fuellcd = (here is where im trying to do the maths)
}


Var 6001 name Fuellcd // Output to lcd

Now when i try to say multiply the tank value by the percentage i cant seem to find out how to do this portion.
I dont even know if what i have written above is correct.
Any help would be much appreciated.
Thanks
Les :(

Michael Carter
01-11-2009, 01:12 AM
I wish I could help.

I can't believe I'm going to have to go through this myself in a short time. I dred this.

Kennair
01-11-2009, 01:53 AM
Don't worry Mike, when you know Nico is around, you know there's help. If nothing but to give you a nudge how to figure it out yourself. He is da master of SIOC code!

Les, I won't even try to attempt a correct code for you as I don't know anything about the LCD card but it's coding is different to most other OC cards. However you have a friend in Nico (Kiek) as he has his LevelD767 Fuel display to LCD code available to learn from. Have a look HERE (http://www.lekseecon.nl/iocards.html#USBLCD)and enjoy :)

Ken.

iwik
01-11-2009, 02:11 AM
Hi all,
Thanks for the comments,
Ken i did have a look at nicos article, but i think he just displays it as a
percentage.Ive been able to display percentages but when it comes
something involving multiple processes i get confused.Still im hoping
someone will help.Thats what i like about this site,someone always
is looking.
Rgds
Les

kiek
01-11-2009, 07:17 AM
Hi all,
but i think he just displays it as a percentage.
No, I display in kg-tons (with one decimal), see http://www.lekseecon.nl/news.html#news200831

About your SIOC code:
I'm afraid, you made a mistake in interpreting offset 0x0b7C. It is an offset indicating the fuel level as % * 128 * 65536, not just a percentage (0 -100).

Also note that the max capacity of a tank in your aircraft is fixed (if your script is for a certain type of aircraft). You do not need to read it from a FSUIPC offset.

My approach is to read the level of fuel and to divide it by a value that scales the (default FS tank) to the capacity of a 767 tank, like this:

Var 2923 name FI_FuelL Link FSUIPC_IN Offset $0B7C Length 4
{
L0 = DIV &FI_FuelL 45467
IF (L0 <> &FuelL)
{
&FuelL = L0
}
}
I'll describe the formula behind this scaling factor in a later post.

You can take this code, and replace 45467 by a value that scales the default FS tank to the tannk of your aircraft (in gallons).

If you want to have this script work for various aircraft, then you have to read the max capacity of the tank indeed.

regards,
Nico

kiek
01-11-2009, 01:06 PM
Okay, here the promised calculation:

Offset $0Bc7 gives the fuel level in the left wing tank as a "percentage" * 128 * 65536.

The Level-D left wing tank has a capacity of 18,449 kilo tons.

To map the FSUIPC "percentage" value to a real value we have to multiply the offset by

(18,449 / (128 * 65536))

or (that will give the same result) divide the offset by ((128 * 65536) / 18,449) or 454692

This will give us kg-tons; in my display I use * 100 kg (and I put a decimal point before the last digit to make it kg-tons) so I divide by 45469 (my sioc code is slighty wrong by dividing by 45467...)

You will have to find out the capacity of your tank in gallons. You should divide the offset by ((128 * 65536) / your capacity in gallons) = ?
This will give you gallons.

I'd recommend to make the SIOC script first fit for 7-segment displays using the DispII card, and if your satified change it to be used at a lcd

Cheers,
Nico Kaan
www.lekseecon.nl (http://www.lekseecon.nl)

iwik
01-12-2009, 01:44 PM
Hi Nico,
Thanks for the explanation,i dont think i made myself clear.I had been able
to get my Gallons displayed.But i am wanting to show Fuel remaining on
Any aircraft i am flying and therefore will have to read the offset that stores the Max capacity.This is where im having trouble.What i wanted to do was to multiply the pecentage by the max tank offset value.
How does one take this value and mutiply it by the %.In other words if
the values (% and Max cap) are in two vaiables how is this done.I cant see to find any logic that will do this.
Please bear with me as im really trying to get a handle on Sioc.When you get in your latter years the brain doesnt work well,at least mine doesnt.
Les

kiek
01-12-2009, 04:24 PM
Hi Les,

Okay, no problem.

See Config_sioc, Help, Help, Scripts Language ..

Here is the basic schema, you only may have to do some math.

The basis idea behind SIOC is that the statements in the body (between curly braces) are (only) executed if the value of the Var changes.... (!)

In this example if Var 1 (the percentage) changes, subroutine Calc is called and also if Var 2 changes Calc is called. So you are always up to date.


var 1 Link FSUIPC_IN,offset $0b7c Length 4 // % remaining
{
CALL &Calc
}

var 2 Link FSUIPC_IN,OFFSET $0b80 Length 4 // Tank Capacity
{
Call &Calc
}

Var 3 name Calc Link SUBRUTINE
{
v4 = v1 * v2
}

Var 4 name Fuel
{
CALL &OutFuel
}

Regards,
Nico

iwik
01-14-2009, 05:50 AM
Hi Nico,
Thanks for imfo,i think im slowly getting the hang of it.Been able to display
Gallons,but not parts of gallons.Suppose thats not so important but would be curious how to do this.My tanks have capcity under 100 gallons.Would be good if i could display say 56.7 gallons.
Rgds
Les

kiek
01-14-2009, 07:34 AM
Hi Nico,
My tanks have capcity under 100 gallons.

Do you really mean 100 gallons or 100.000 gallons?

You can only display information that you have available. Suppose you have a value in gallons and you want to display gallons, then you have no info about something to put behind a decimal point.

But if you have available the amount in gallons and you want to display in tons of gallons with one decimal value, you should first divide your gallons by 100 (to get gallons * 100), and then you display this value and you put a decimal point before the least significant digit.

Example:
Suppose you have 56743 gallons
Divide by 100 makes 567 (*100) gallons
Write this to a 4 digit display: 0567
and make sure that the DP of digit 6 is on, so it shows 056.7 (*1000) gallons.
A full tank would show 100.0

Rgrds,
Nico
nico

iwik
01-16-2009, 01:53 PM
Thanks Nico,
Yes i did mean 100.00 gallons.Everything is now working as i want it to.
Much appreciated for your patience.I learnt a lot about sioc with this thread.
Les