Shared memory reading
-
Hello,
I want to make my own C++ program to read the data located inside the Falcon shared memory. Then I will make this program communicate with my external devices for cockpit motor, display and led controls.
I have searched this forum and saw that Flight data.h is provided inside the Falcon as a memory map and includes class/function declarations. From where can I read those values dynamically while the sim is running? And where are the implementations of those functions (.cpp file)? There are some functions like that I might use as well, such as:
(quoting from) Flight data.h:
….
// getters for external reader programs
bool UfcTacanIsAA(void) {return ((tacanInfo[UFC] & mode) ? true : false); }
…. -
As I replied to another your post, all you have to do is initialize the shared memory handle and the data will be available automagically when Falcon is running. If you need source code I can provide.
-
That would be great if you can provide me some example. You can share it here or as a PM.
Thanks in advance!
-
Don’t cross post. Use this one only.
Here a little code#include <iostream>#include <windows.h>#include <stdio.h>#include “Flight Data.h”
using namespace std;TCHAR sharedMemoryAreaName[] = TEXT( “FalconSharedMemoryArea” );
int main()
{
const HANDLE hMapFile = OpenFileMapping(FILE_MAP_READ, FALSE, sharedMemoryAreaName);
if (hMapFile != NULL)
{
const FlightData * data = (FlightData *) MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, sizeof(FlightData));
if (data != NULL)
{
while (true)
{
std::cout << data->kias << std::endl;
Sleep(1000);
}
UnmapViewOfFile(data);
}
else
{
cout << “Could not map view of file”;
}
CloseHandle(hMapFile);
}
else
{
DWORD err = GetLastError();
cout << "Could not open file mapping object: " << err;
}
return 0;
}</stdio.h></windows.h></iostream>In the example it will print the speed you are flying to the output console.
-
This worked, big thanks!
-
Your welcome! Show your work when ready!!:)