Moderator: CrazySchmidt
#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_
#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";
}
#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;
}
BaLrOg wrote:Just one question they reference to 16 being the standard length of an ip address. I take it that is in the format xxx.xxx.xxx.xxx wouldn't that mean it was 15 characters instead ?
C++ usese a Null character terminated string. A normal c string is of type (char *).
Users browsing this forum: No registered users and 3 guests