The online racing simulator
OutGaugePack C++ wrong values
(2 posts, started )
OutGaugePack C++ wrong values
Hello. I'm trying to get info from game, but when I do this I have wrong values in packet. What I do wrong? There is my code:

#include "cinsim.h" //Headers for CInsim library
#include <iostream> //Basic C++ streams, needed for console output

CInsim insim; //CInsim object, handles the communication with LFS

int main()
{
int retVal = 0;
struct IS_VER verPack; //LFS can tell us info about it's version and InSim version, store that info in this struct.

//Try to connect to LFS
retVal = insim.init("192.168.0.213", //LFS will run on local machine
(word)33334, //InSim will accept connection on port 33334
"Example app", //Short name for our app, will appear in LFS
"", //No admin password
&verPack, //Pointer to IS_VERSION packet
'!', //InSim command character
ISF_MCI, //We're writing a local InSim app
1000, //Receive updates every 1000 msecs
33334); //UDP Port


//Could we connect to LFS?
if(retVal < 0) //We could not
{
//Tell the user and exit
std::cerr << "Error connecting to LFS!" << std::endl;
return -1;
}

//All OK, report version of LFS and InSim
std::cout << "Connected to LFS " << verPack.Version << ", InSim ver. " << verPack.InSimVer << std::endl << std::endl;


//Now enter the main loop which will receive packets from LFS
int recvErr = 0;
int packetType = 0;
bool canRun = true; //Run the loop as long as this is true


struct IS_SMALL initOutGauge;
initOutGauge.Size = 8;
initOutGauge.Type = ISP_SMALL;
initOutGauge.ReqI = 0;
initOutGauge.SubT = SMALL_SSG;
initOutGauge.UVal = 100;
insim.send_packet(&initOutGauge);

struct OutGaugePack outgaugepacket;
memset( &outgaugepacket, 0, sizeof(outgaugepacket) );

std::cout << "SIZE OF PACKET: " << sizeof(outgaugepacket) << std::endl; // 96 here

while(canRun)
{
//Get the next packet in the buffer
recvErr = insim.udp_next_packet();

if(recvErr < 0) //Something went wrong
{
//Tell the user and exit
std::cerr << "Error receiving packets from LFS!" << std::endl;
return -1;
}

//We have a packet, check it's type
packetType = insim.udp_peek_packet();

std::cout << "PACKET TYPE: " << packetType << std::endl; // ISF_MCI (38)

//Handle each type of packet
struct OutGaugePack* ptr_outgaugepacket = &outgaugepacket;
ptr_outgaugepacket = (struct OutGaugePack*)insim.udp_get_packet();
std::cout << "SIZE OF PTR: " << sizeof(ptr_outgaugepacket) << std::endl; // 8 here

std::cout << "Speed: " << ( (ptr_outgaugepacket->Speed) * 3.6 ) << std::endl;
std::cout << "RMP: " << static_cast<uint16_t>( ptr_outgaugepacket->RPM ) << std::endl;
std::cout << "CAR: " << ptr_outgaugepacket->Car << std::endl;
std::cout << "Gear: " << (ptr_outgaugepacket->Gear) + 1 << std::endl;
std::cout << "Engine Temp: " << ptr_outgaugepacket->EngTemp << std::endl << std::endl;
}


//Successful exit
insim.isclose();
return 0;
}

What is '!' //InSim command character? I didn't found anything about it. Please help me Smile

Output from console:

Connected to LFS 0.6V, InSim ver. 8

SIZE OF PACKET: 96
PACKET TYPE: 38

SIZE OF PTR: 8
Speed: 1.3125e-38
RMP: 0
CAR:
Gear: 193
Engine Temp: 0

You're connecting to InSim but you want OutGauge data. Enable OutGauge in LFS configuration and connect to it directly.

OutGaugePack C++ wrong values
(2 posts, started )
FGED GREDG RDFGDR GSFDG