PDA

View Full Version : Shared Data returns wrong Data



Paceman
24-10-2015, 14:45
Hi,

I use the shared data to show some informations with my arduino.
Some functions, like read the flagcolours, the carflags and the current gear works fine, but most of the other functions doesn't work, like fuil, rpm, etc.
The returned data looks like this: -0104554351 or 1251215341

I have this problem even with the example.

I allready checked the pCars files.

MikeyTT
24-10-2015, 15:12
What's the programming language you are using to read the data from the API?

If your data types are off in any way that's the likely cause of the odd looking data.

Paceman
24-10-2015, 15:27
Oh sorry, i am using C++

I don't know what you mean with data types off.

I am reading this way:



HANDLE fileHandle;
do
{
fileHandle = OpenFileMapping( PAGE_READONLY, FALSE, MAP_OBJECT_NAME );
printf( "Could not open file mapping object (%d).\nPlease start Project Cars", GetLastError() );
system("cls");
}while (fileHandle == NULL);

// Get the data structure
const SharedMemory* sharedData = (SharedMemory*)MapViewOfFile( fileHandle, PAGE_READONLY, 0, 0, sizeof(SharedMemory) );
while (sharedData == NULL)
{
printf( "Could not map view of file (%d).\n", GetLastError() );

CloseHandle( fileHandle );
system("cls");
}

// Ensure we're sync'd to the correct data version
if ( sharedData->mVersion != SHARED_MEMORY_VERSION )
{
printf( "Data version mismatch\n");
system("cls");
}

printf( "RPM: (%d)\n", sharedData->mRpm);


(I don't know whether it is correct, because this is not the whole script)

LipstickL
25-10-2015, 01:12
Change %d in the printf statement to %f, in short %d represents an int. mRpm in the SharedMemory struct is a float value.

MikeyTT
28-10-2015, 15:21
Oh sorry, i am using C++

I don't know what you mean with data types off.

By "off" I meant if you're data types don't 100% match what the API is producing. In the C# world there were some gotchas around the size of bools if I recall that would then make the data past this point look to be rubbish.

I presume you are using, or are heavily referencing the test app that was produced by SMS (http://forum.projectcarsgame.com/showthread.php?30903-Project-CARS-Shared-Memory-or-how-do-I-make-my-own-app). In theory that should give you everything you need to get up and running in the C++ world.

Can't help much more than that, sorry...

Paceman
07-11-2015, 12:12
Change %d in the printf statement to %f, in short %d represents an int. mRpm in the SharedMemory struct is a float value.

Thx this was the solution.

@MikeyTT Thx for your help