The online racing simulator
Insim in C++ and VS 2008 Express
Hi there,

it's likely someone has had this issue before, but I just wasn't able to find anything relevant. I'm making a tiny app which in the end should make the RPM LEDs on G27 work, but I've ran into problems using the insim.h header.
When I try to compile the source, I get a handful of warning like

\include\insim.h(82) : error C2146: syntax error : missing ';' before identifier (some identifier)
\include\insim.h(82) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

I understand that the compiler behavior has changed since VS2005, but I have no idea how to get around this as C++ and Windows programming isn't really my area of expertise... Thanx for any advise.

My code is just a modified OutGauge program by DarkTimes

#include "stdafx.h"
#include <iostream>
#include <winsock2.h> // WinSock2 library (may need to add WS2_32.lib to project dependencies).

#define BUFFER_SIZE 512 // Receive buffer size (basically maximum packet size in UDP).
#define HOST "127.0.0.1" // Host to connect to.
#define PORT 30000 // Port to connect to the host through.

#define FIRST_LEDS_ON 4000.00f
#define REDLINE_LEDS 7000.00f

// Include Logitech headers
#include "LogiWheel.h"
#include "LogiControllerInput.h"

// Include InSim header.
#include "InSim.h"

using namespace LogitechSteeringWheel;
using namespace LogitechControllerInput;
using namespace std;


// Define types used by InSim.
typedef unsigned char byte;
typedef unsigned short word;
typedef struct
{
int X, Y, Z;
} Vec;

typedef struct
{
float X, Y, Z;
} Vector;

// Declare variables for the Logitech Wheel
Wheel* g_wheel;
ControllerInput* g_controllerInput;

// Declare RPM variable too
float inRpm = 0;

// Level of debbuging, passed by external argument
// 0 = Default, no verbosity
// 1 = Print what RPM are we getting from OutGauge
// 2 = Confirm that LED data is being sent te wheel
// 3 = Only output RPM info from OutGauge, don't send anything to wheel
int debugLevel = 0;

// More than one Logitech wheel can be connected. We have to take care of all of them.
int wheelIdx = 0;

//void OutGaugePacketReceived(const OutGaugePack packet);
int initInSimConnection();
void processOutGaugePacket(const OutGaugePack packet);

int _tmain(int argc, char** argv)
{
// Get the debug level
if(argc > 0)
{
debugLevel = atoi(argv[0]);

//Idiot failsafe;)
if((debugLevel > 4) || (debugLevel < 0))
{
debugLevel = 0;
}
}

//Initialize the wheel input
g_controllerInput = new ControllerInput(0, TRUE);
g_wheel = new Wheel(g_controllerInput);

//Connect to InSim

return initInSimConnection();
}

int initInSimConnection()
{

// Initialise WinSock version 2.2.
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
{
WSACleanup();
std::cerr << "Error: Failed to init WinSock" << std::endl;
return EXIT_FAILURE;
}

// Create UDP socket.
SOCKET sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock == INVALID_SOCKET)
{
WSACleanup();
std::cerr << "Error: Could not create socket." << std::endl;
return EXIT_FAILURE;
}

// Bind to receive UDP packets.
sockaddr_in saddr;
saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = inet_addr(HOST);
saddr.sin_port = htons(PORT);
if (bind(sock, (sockaddr *)&saddr, sizeof(sockaddr)) == SOCKET_ERROR)
{
closesocket(sock);
WSACleanup();
std::cerr << "Error: Could not connect to LFS" << std::endl;
return EXIT_FAILURE;
}

// Packet receive loop.
char recvbuf[BUFFER_SIZE];
memset(recvbuf, 0, sizeof(recvbuf)); // Set recvbuf to zero.
int bytes = 0;
do
{
bytes = recv(sock, recvbuf, BUFFER_SIZE, 0);
if (bytes > 0)
processOutGaugePacket((OutGaugePack &)recvbuf);
else if (bytes == 0)
std::cerr << "Error: Lost connection with LFS" << std::endl;
else
std::cerr << "Error: " << WSAGetLastError() << std::endl;
} while (bytes > 0);

// Cleanup and exit.
closesocket(sock);
WSACleanup();
return EXIT_SUCCESS;
}

void processOutGaugePacket(const OutGaugePacket packet)
{
inRpm = packet.RPM;


if (debugLevel > 0)
{
cout << inRpm << std::endl;
}

//We are confident enough to send LED data to the wheel
if(debugLevel < 2)
{
g_controllerInput->Update();
g_wheel->Update();

for(wheelIdx = 0; wheelIdx < LogitechSteeringWheel::LG_MAX_CONTROLLERS; wheelIdx++)
{
if(g_wheel->IsConnected(wheelIdx))
{
g_wheel->PlayLeds(wheelIdx, inRpm, FIRST_LEDS_ON, REDLINE_LEDS);

//Print whether the data has been sent
if (debugLevel == 2)
{
cout << "RPM data sent to device ID = " << wheelIdx << std::endl;
}
}
}
}
}

Hey MadcatX..

If I'm not mistaken.. you should be able to adapt this code to allow wheel rotation to get modified (with a / command)... Can you look into this as it's the Logi SDK that lets this happen.
I guess so, but the first thing I have to sort out is that the VS 2008 compiler just won't accept the "InSim.h" file.
#4 - filur
First google the error codes (C2146, C4430). If that doesn't help post line 82 of your copy of insim.h.
I got it sorted out, I accidentally included insim.h before definitions of the datatypes it uses Now let's see if I can get that Logitech SDK cooperating...

FGED GREDG RDFGDR GSFDG