A wrapper is really just an interface. This particular one interfaces with devicelink. It supplies a function like GearDown(), then carries out all the message handling to make this happen via udp.
There was one typo I found in Sensei's code.
devicelink.cpp:741 err = sscanf (pdest, "16%s", &m_game_ip);
This reads a string beginning with 16
should be
err = sscanf (pdest, "%16s", &m_game_ip);
This reads a string 16 characters long (which is the length of a standard IP address)
As promised here's some example code. I have to confess I couldn't get it to work. It compiles fine, but for some reason WWSensei's wrapper won't connect. I think its more to the fact that I wrote the code on linux, compiled it for win32 using xmingw and then ran the program through wine.
This is the way object oriented programming was explained to me, think of an object like a thing. All things have a collection of traits and functions. An aircraft may be blue, have wings, stabilizers and have the ability to roll, yaw and pitch.
Continuing with the analogy, each object is made up of a collection of others. You, the pilot, pull back on the stick (this is a method). All you know is the stick and that it will move you up and down. However, the aircraft is made up of several objects to complete this, hydraulics, cable linkages, elevator, etc ... You really don't care about the elevator's deflection angle, but it is integral to the aircraft's attitude.
In C++ classes make up the data structure and objects are the realization of the class.
P-51 is a class, Glamorous Glenis (Yeager's -51) is an object
Also there is Inheritance, traits are taken from parent classes
Fighter would be a parent
P-51 and Fw-190 would be child classes that share fighter traits
A quick background in C++ files, the build works in two stages. First, the compiler builds object files (.o, .obj) using the source and header files (.cpp). After this stage there should be one object file for every source file. This is when the linker is used, it collects all the object files and libraries into an executable program.
If you are still using VC express, creating a project and adding all the files into it should do this all automatically. You will have to go into the project properties, there should be a linker tab where there is a textbox for additional libraries. Add -lwsock32 I think, -l (ell) means link to library and wsock32 is the network socket library for windows. You may have to dig around a bit to find the correct syntax. I'm really rusty with MSVC, I've pretty much sworn off Windows except to play games and migrated to Linux.
If you've switched over to a gnu compiler.
compile: g++ -c -o object.o source.cpp (for each file)
link: g++ -o dlc.exe *.o -lwsock32
You can also add the debug flag for Sensei's code in the devicelink.cpp, this will show a lot of useful error messages.
g++ -c -DDEBUG_OUTPUT -o devicelink.o devicelink.cpp
Without further adeiu. Place these files in the same directory as WWSensei's wrapper. The code is commented if you have any questions feel free to ask.
dlconsole.h - DLConsole class definition
- Code: Select all
#ifndef __DLCONSOLE_H_
#define __DLCONSOLE_H_
#include "devicelink.h"
/*! \class DLConsole dlconsole.h "dlconsole.h"
* \brief Console interface to IL-2 Device Link
* \author Chris Guthrie (3./JG51_Specter)
* \version 1.0
*
* Command line prompt like interface to 1c/Maddox's flight simulator IL-2 Sturmovik and
* iterations. This class utilizes WWSensei's C_DeviceLink wrapper.
*/
class DLConsole
{
private:
/// \brief console run status flag
bool _bRunFlag;
/// \brief instance of wrapper class
C_DeviceLink _devlink;
public:
DLConsole();
bool run();
/*! \brief Checks status of console run status
* \return true if running, false otherwise
*/
bool isRunning() {return _bRunFlag;}
protected:
void parse (char cmd);
void printHelp ();
};
#endif //__DLCONSOLE_H_
dlconsole.cpp - All the methods of the DLConsole class
- Code: Select all
#include "dlconsole.h"
#include <iostream>
using namespace std;
/*! \brief Default Constructor
* Sets values for class members
*/
DLConsole :: DLConsole () {
_bRunFlag = false;
}
/*! \brief Starts the console and enters the main loop
* \return true if succesful
*/
bool DLConsole :: run () {
char cmd;
char buffer[32];
//caviot of wrapper, must set the length of the buffer
memset (buffer, ' ', 32);
//initializes devicelink interface
if ( ! (_bRunFlag = _devlink.IsInitialized()) )
_bRunFlag = _devlink.Init();
if (isRunning()) {
//Welcome message
_devlink.GetDLVersion (buffer);
cout << "Connected version " << buffer << "\n";
//console command loop
while (isRunning()) {
cout << "\n>";
cin >> cmd;
parse(cmd);
}
return true;
} else
return false;
}
/*! \brief run entered command
* \param cmd command to run
*/
void DLConsole :: parse (char cmd) {
switch (cmd) {
case 'q':
case 'Q':
_bRunFlag = false;
break;
case 'h':
case 'H':
printHelp();
break;
case '1':
if (_devlink.ToggleEng1Select())
cout << "Engine 1 Toggled\n";
break;
case '2':
if (_devlink.ToggleEng2Select())
cout << "Engine 2 Toggled\n";
break;
case 'n':
case 'N':
if (_devlink.ToggleNavLights())
cout << "Nav Lights Toggled\n";
break;
default:
cout << "Unknown cmd (" << cmd << ")\n";
}
}
/*! \brief prints help message to stdout
*/
void DLConsole :: printHelp() {
cout << "Help --\n";
cout << "\t q \t exit\n";
cout << "\t h \t this help message\n";
cout << "\t 1 \t Switch Engine #1\n";
cout << "\t 2 \t Switch Engine #2\n";
cout << "\t n \t Toggle Nav Lights\n";
}
main.cpp - the infamous main function that starts all
- Code: Select all
#include "dlconsole.h"
#include <iostream>
/*
* File: main.cpp
* Purpose: This is a small c application that serves as a comand console to interface with
* the 1C/Maddox Il-2 series device link.
*
* Req'd: WWSensei's DeviceLink Wrapper
*
* Version: 1.0
* Author: Chris Guthrie (3./JG51_Specter)
*
*Thanks: WWSensei for his work on the devicelink wrapper
*
* Legal Stuff:
* I submit this source code under the BLA (Beer License Agreement). You are free to
* use this code in anyway you like. I only request that I and others receive credit where do.
* Also, if we happen to find ourselves in a pub somewhere, share how you found this
* useful over a round or two.
*
* Use at your own risk, I'm not responsible for any damages or problems that might
* be directly or indirectly caused by this source code. This includes bashing your head
* on the keyboard out of frustration.
*/
using namespace std;
/*! \brief Entry Point
* Standard C/C++ entry function, runs a device link console then exits
*/
int main (int argc, char * argv[]) {
DLConsole dlc;
if (! dlc.run()) {
cout << "Error:\n";
cout << "\t Unable to start Device Link Console\n";
}
return 0;
}