PDA

View Full Version : DeviceLink C++ Wrapper Class



WWSensei
06-06-2004, 10:33 PM
Writing drivers for my GoFlight equipment. To start with I've started a C++ class library as a wrapper for DeviceLink. It isn't finished as I've only done a few of the functions but I've laid the groundwork so it should be easy to add additional functionality. The few I've done should be a good example. If you come up with more let me know. Most of this was written in a hurry so I apologize for the lack of comments and/or seemingly bad logic. ;-) Currently, it's written for Win32 and only tested on XP and Win2K. I'm using Visual Studio 6.

You can have the config.ini, cpp and h file here:

http://www.wingwalkers.org/sensei/devicelink.zip

Example to create a DeviceLink object, get the DeviceLink version number, get your aircraft type and then lower and raise the landing gear.

The Init() function can take a filename as a debug output file. If none provided it defaults to stderr. Init also takes care of all the socket UDP setup so you don't have to fool with it.:


C_DeviceLink my_dl; //create the object
my_dl.Init(); //initialize
char version[32]; //make a temp string to store the result in.
my_dl.GetDLVersion(version); //make the call to the object function
printf("Device Link version is %s.\n", version);
char ac[32];
my_dl.GetAircraftID(ac);
printf("Aircraft is %s\n", ac);
my_dl.SetGearDown(); //send command to Lower Gear
if (my_dl.Gear_Is_Up() == FALSE)
{
printf("Gear is down.\n");
} else
{
printf("Gear is up.\n");
}
my_dl.SetGearUp(); // raise the gear

WWSensei
06-06-2004, 10:33 PM
Writing drivers for my GoFlight equipment. To start with I've started a C++ class library as a wrapper for DeviceLink. It isn't finished as I've only done a few of the functions but I've laid the groundwork so it should be easy to add additional functionality. The few I've done should be a good example. If you come up with more let me know. Most of this was written in a hurry so I apologize for the lack of comments and/or seemingly bad logic. ;-) Currently, it's written for Win32 and only tested on XP and Win2K. I'm using Visual Studio 6.

You can have the config.ini, cpp and h file here:

http://www.wingwalkers.org/sensei/devicelink.zip

Example to create a DeviceLink object, get the DeviceLink version number, get your aircraft type and then lower and raise the landing gear.

The Init() function can take a filename as a debug output file. If none provided it defaults to stderr. Init also takes care of all the socket UDP setup so you don't have to fool with it.:


C_DeviceLink my_dl; //create the object
my_dl.Init(); //initialize
char version[32]; //make a temp string to store the result in.
my_dl.GetDLVersion(version); //make the call to the object function
printf("Device Link version is %s.\n", version);
char ac[32];
my_dl.GetAircraftID(ac);
printf("Aircraft is %s\n", ac);
my_dl.SetGearDown(); //send command to Lower Gear
if (my_dl.Gear_Is_Up() == FALSE)
{
printf("Gear is down.\n");
} else
{
printf("Gear is up.\n");
}
my_dl.SetGearUp(); // raise the gear

CPS_Shadow
06-07-2004, 02:59 AM
Cool thanks for sharing this with us.

Aaron_GT
06-07-2004, 06:30 AM
There's a GPLed game netcode lib that's been released. I can dig up the details in Linux Developer this evening if you are interested.

WWSensei
06-07-2004, 07:54 AM
"There's a GPLed game netcode lib that's been released. I can dig up the details in Linux Developer this evening if you are interested."

Always interested in cool libs. This code is very specific to IL2 and devicelink. I just did it in order to ease my own development of programs to communicate with FB. In my case it is for using my home cockpit hardware GoFlight modules.

JRH147
06-07-2004, 12:19 PM
Thanks so much for posting this Sensei!

WWSensei
06-08-2004, 11:16 AM
Got a couple of PM's asking about various functionality. There are two primary funtions you can use.

SendMsg() can be used to send any "R" formatted query command that you have placed in the private m_cmd variable and ReadMsg() will read the socket and place the corresponding "A" reply string in the private variable m_buff.

I made a public method of QueryMsg(char* code) which will do the combo of SendMsg and ReadMsg when you expect a response to your query command.

Arguably, QueryMsg could be private but I wanted to provide some flexability.