PDA

View Full Version : Help with FSbus C++ software



Jan737
01-12-2010, 02:16 PM
Hi all,

I'm busy to transfer my old fsbus software to the latest version, but I need some help with it.

I'm using an offsets of the TSR software of Thomas Richter.

I want to write to offset 0x6DB7 bit 0 ( = below glide slope annunciator).

But what's the format, you write to a specific bit ?

I can't find it in the doc's provided.

Hope someone can help.

Best regards

Jan Geurtsen

sgaert
01-12-2010, 04:26 PM
Hi,
yes that isnt in the Documentation. It is a part of C++.

You have to define the Offset that you are need and every single Bit.
A part of the .h file.

enum _OVERHEADIN {
CI_No_Smoking_on = (GROUP_OVERHEADIN * OBJECTS_PER_GROUP),
FS_LIGHT};

#define FS_LIGHT_NAV 0x01 //01
#define FS_LIGHT_Strobe 0x02 //02

With the 0x01 you assing bit 0.

0x01 = Bit0
0x02 = Bit1
0x04 = Bit2
0x08 = Bit3
0x10 = Bit4
0x20 = Bit5
0x40 = Bit6
0x80 = Bit7

Than you can use the bits in you code.
A Sample Part from my Cockpit.


case CI_SWITCH_Strobe_Stad:
if (val==0)
{
Light |= FS_LIGHT_NAV;
Light |= FS_LIGHT_Strobe;
//printf("Light On \n");
FsWrite (FS_LIGHT,Light);
}
else
{
Light &= ~FS_LIGHT_NAV;
Light &= ~FS_LIGHT_Strobe;
//printf("Light Off \n");
FsWrite (FS_LIGHT,Light);
}
break;
That is an input for one Light Switch.

Stefan

Jan737
01-12-2010, 04:43 PM
Hi,
yes that isnt in the Documentation. It is a part of C++.

You have to define the Offset that you are need and every single Bit.
A part of the .h file.

enum _OVERHEADIN {
CI_No_Smoking_on = (GROUP_OVERHEADIN * OBJECTS_PER_GROUP),
FS_LIGHT};

#define FS_LIGHT_NAV 0x01 //01
#define FS_LIGHT_Strobe 0x02 //02

With the 0x01 you assing bit 0.

0x01 = Bit0
0x02 = Bit1
0x04 = Bit2
0x08 = Bit3
0x10 = Bit4
0x20 = Bit5
0x40 = Bit6
0x80 = Bit7

Than you can use the bits in you code.
A Sample Part from my Cockpit.


case CI_SWITCH_Strobe_Stad:
if (val==0)
{
Light |= FS_LIGHT_NAV;
Light |= FS_LIGHT_Strobe;
//printf("Light On \n");
FsWrite (FS_LIGHT,Light);
}
else
{
Light &= ~FS_LIGHT_NAV;
Light &= ~FS_LIGHT_Strobe;
//printf("Light Off \n");
FsWrite (FS_LIGHT,Light);
}
break;
That is an input for one Light Switch.

Stefan

Thanks Stefan,
I doesn't reconize it as a bit input.

Best regards

Jan Geurtsen

sgaert
01-12-2010, 04:47 PM
Yes that is a Bit Input.

http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
Look to Bitwise operators.

Jan737
02-01-2010, 02:49 PM
Hi

I've made some code (see below) which light my hardware Exec light of the Project magenta CDU.
Will this be work?
I'm not able to test it because I'm abroad.

It's using adress 0x052c bit 1 so I add the following to the .h file

#ifndef _TSR_H
#define _TSR_H

#define FS_CduExecLight 0x01 //01

void BuildTsrObjects();
void cbTsr (int oid, int val, double dval);

enum e_Tsr {

C_CduExecLight = (GROUP_TSR * OBJECTS_PER_GROUP),

};

#endif


And this to the .cpp file:

#include "stdafx.h"
#include "Tsr.h"


extern void TsrBuildObjects()
{

MkFsbusObject(BTP_D_OUT, C_CduExecLight,"OID",cbTsr,17,24);
MkFsObject(FS_CduExecLight, "OID", cbTsr, 0x052c,2, TP_I16, FS_NORMAL);
}
void cbTsr( int oid,int val,double dval)
{
switch(oid)

{
case FS_CduExecLight:
FsbusWrite (C_CduExecLight,val);
}

}



Best regards

Jan Geurtsen

sgaert
02-01-2010, 03:17 PM
Hi Jan,

that is a realy hard question.
First yes it will work, BUT that is fortuity.
It only work i case of that you Value is in Bit0.
You dont readout the bit you read the Value in case on Bit0 it is both the same.

That always work as long you only need Bit0 if you like to use Bit1 or greater you need other code.

In my code a had make 1 funktion how switches all Lights. I was to lame to write always the same code for every output.

As first that is only for Outputs controlled by Bitīs. Im my case the max Number of Bits in a Offset is 8. It is possible to add more.

As First we need an array (http://www.cplusplus.com/doc/tutorial/arrays/) with all our Informations.
I use that Style FS_Objekt, Output_Bit0, Output_Bit1, Output_Bit2,.... and so on. Importend is that you have to fill every "line" of the array complet. I had made an C_non Output to an Output that you dont have connectet on your IO or DOut card.
That you have to write to the cpp file.

int LEDAusgabe[][9]={{FS_APAusgabe1,CO_APDisA,CO_APCmdA,CO_APCmdB,CO_APCwsA,CO_APCwsB,CO_APVS,CO_APALT,CO_APAPP},
{FS_APAusgabe2,CO_APLOC,CO_APLNav,CO_APVNav,CO_APFLCH,CO_APHDGHold,CO_APIAS,CO_APN1,CO_APAT},
{FS_OHLED1,CO_FUEL_PUMP_LEFT_FWD,CO_FUEL_PUMP_LEFT_AFT,CO_FUEL_PUMP_CENTRE_LEFT_LIGHT,CO_FUEL_PUMP_CENTRE_RIGHT_LIGHT,CO_FUEL_PUMP_RIGHT_FWD,CO_FUEL_PUMP_RIGHT_AFT,CO_DOORS_WING_L_AFT,CO_DOORS_WING_R_AFT}
};
int LEDMax =19; // how many lines have your array??????????????

Now there are all Objektbuild funktion.
After that comes the normal Eventfunktion withe the "old" switch call. BUT we dont need any switch.
Here is my complete funktion.

extern void LedausgabeEventHandler (int oid, int val, double dval)
{
int Led;
Led = val;
int arrayPostition=-1;

for(int i=0;i<LEDMax ;i++)
{
if(oid==LEDAusgabe[i][0])
arrayPostition=i;
}

if(arrayPostition!=-1)
{
for (int i=1;i<9;i++)
{
int x=(Led & 0x01);

FsbusWrite (LEDAusgabe[arrayPostition][i], x);
Led = (Led >> 1);
}
}
}

With that i Switch all my LED, btw. it takes 160ms to change all LED (300). That is so fast.

Stefan

Jan737
02-02-2010, 02:16 PM
Hi Jan,

that is a realy hard question.
First yes it will work, BUT that is fortuity.
It only work i case of that you Value is in Bit0.
You dont readout the bit you read the Value in case on Bit0 it is both the same.

That always work as long you only need Bit0 if you like to use Bit1 or greater you need other code.

In my code a had make 1 funktion how switches all Lights. I was to lame to write always the same code for every output.

As first that is only for Outputs controlled by Bitīs. Im my case the max Number of Bits in a Offset is 8. It is possible to add more.

As First we need an array (http://www.cplusplus.com/doc/tutorial/arrays/) with all our Informations.
I use that Style FS_Objekt, Output_Bit0, Output_Bit1, Output_Bit2,.... and so on. Importend is that you have to fill every "line" of the array complet. I had made an C_non Output to an Output that you dont have connectet on your IO or DOut card.
That you have to write to the cpp file.

int LEDAusgabe[][9]={{FS_APAusgabe1,CO_APDisA,CO_APCmdA,CO_APCmdB,CO_APCwsA,CO_APCwsB,CO_APVS,CO_APALT,CO_APAPP},
{FS_APAusgabe2,CO_APLOC,CO_APLNav,CO_APVNav,CO_APFLCH,CO_APHDGHold,CO_APIAS,CO_APN1,CO_APAT},
{FS_OHLED1,CO_FUEL_PUMP_LEFT_FWD,CO_FUEL_PUMP_LEFT_AFT,CO_FUEL_PUMP_CENTRE_LEFT_LIGHT,CO_FUEL_PUMP_CENTRE_RIGHT_LIGHT,CO_FUEL_PUMP_RIGHT_FWD,CO_FUEL_PUMP_RIGHT_AFT,CO_DOORS_WING_L_AFT,CO_DOORS_WING_R_AFT}
};
int LEDMax =19; // how many lines have your array??????????????

Now there are all Objektbuild funktion.
After that comes the normal Eventfunktion withe the "old" switch call. BUT we dont need any switch.
Here is my complete funktion.

extern void LedausgabeEventHandler (int oid, int val, double dval)
{
int Led;
Led = val;
int arrayPostition=-1;

for(int i=0;i<LEDMax ;i++)
{
if(oid==LEDAusgabe[i][0])
arrayPostition=i;
}

if(arrayPostition!=-1)
{
for (int i=1;i<9;i++)
{
int x=(Led & 0x01);

FsbusWrite (LEDAusgabe[arrayPostition][i], x);
Led = (Led >> 1);
}
}
}

With that i Switch all my LED, btw. it takes 160ms to change all LED (300). That is so fast.

Stefan


Hi Stefan.

Have you declared i.e. CO_APDisA as offset 0x0000, bit x in the *.h file?



Best regards

Jan Geurtsen

sgaert
02-02-2010, 02:21 PM
if you read bits you dont need to declare anything in the H file, you only need to build the enum.

Jan737
02-02-2010, 04:10 PM
if you read bits you dont need to declare anything in the H file, you only need to build the enum.

Hi Stefan,

Thanks again for your great help.
Do you have a example piece of the enum code?

Best regards

Jan Geurtsen

sgaert
02-02-2010, 05:35 PM
enum e_LEDOUT{
CO_APDisA = (GROUP_LEDOUT * OBJECTS_PER_GROUP),
CO_APCmdA,
CO_APCmdB,
CO_APCwsA,
CO_APCwsB,
CO_APVS,
CO_APALT,
CO_APAPP,
FS_APAusgabe1,
FS_APAusgabe2,
CO_APLOC,
CO_APLNav,
CO_APVNav,
CO_APFLCH,// and so on
};

Jan737
02-03-2010, 11:36 AM
Hi Stefan,

Thanks again.
I have a question about this:

I use that Style FS_Objekt, Output_Bit0, Output_Bit1, Output_Bit2,.... and so on. Importend is that you have to fill every "line" of the array complet.



I have some offsets who are using 3 bits and other who are using 8 bits.
How to handle these in te array?

Best regards

Jan Geurtsen

sgaert
02-03-2010, 12:53 PM
HI,
in FSUIPC that offset has also 8 bit, but only 3 Bit will be used.
In that case i had make the array line like that

FS_Objekt, Output_Bit0, Output_Bit1, Output_Bit2,Non,Non,Non,Non,Non

With Objects.
{FS_OHLED1,CO_FUEL_PUMP_LEFT_FWD,CO_FUEL_PUMP_LEFT_AFT,CO_FUEL_PUMP_CENTRE_LEFT_LIGHT,CO_non,CO_non,CO_non,CO_non,CO_non,},

the make of my CO-non:
MkFsbusObject (BTP_D_OUT, CO_non,"",EventHandler, 50, 0);

Stefan

Jan737
02-03-2010, 02:46 PM
Hi Stefan,

Ok ,I've done that.
But now I'm getting error messages with i.e:

g:\fsbus2jan\rvdb737ng\tsr.cpp(4) : error C2065: 'CO_non' : undeclared identifier
g:\fsbus2jan\rvdb737ng\tsr.cpp(5) : error C2065: 'FS_FlapIndicators' : undeclared identifier
g:\fsbus2jan\rvdb737ng\tsr.cpp(5) : error C2065: 'CO_SpoilerArmed' : undeclared identifier


I think I missed your point with the FS_object ( couldn't find this in the doc's provided)

How does this work and muss this in the cpp file?

Best regards

Jan Geurtsen

sgaert
02-03-2010, 03:03 PM
The errors are not declared objects in the H file. That is that with the enum.
The FS_object is only a discription.
My array has a wide of 9 "fields". The first one is the FS Objekt (FSUIPC Object), followed by his bits. For the Bits, i write the destination FSBUS Object (LED).
That all is more stuff than written in the FSBUS Docu, you can find that in a C/C++ book.

I will send you my 2 files by EMail.

Stefan