• Welcome to PiBoSo Official Forum. Please login or sign up.
 
October 17, 2021, 06:56:24 PM

Proxy plugin

Started by PiBoSo, June 06, 2013, 08:32:42 PM

Previous topic - Next topic

PiBoSo

June 06, 2013, 08:32:42 PM Last Edit: September 28, 2021, 11:57:36 AM by PiBoSo
Opening the memory-mapped file GPBProxyObject
g_hMapFile = OpenFileMapping(FILE_MAP_READ,FALSE,"Local\\GPBProxyObject");
void *pBuf = MapViewOfFile(g_hMapFile,FILE_MAP_READ,0,0,sizeof(SProxyData_t));
external programs can read GP Bikes output data.

The source code and data structure is available here: http://www.gp-bikes.com/downloads/gpb_proxy.c
"La perfezione non è il nostro obiettivo, è la nostra tendenza".

PiBoSo

December 15, 2013, 10:34:22 AM #1 Last Edit: December 15, 2013, 10:38:37 AM by PiBoSo
Proxy plugin updated to the latest interface.
"La perfezione non è il nostro obiettivo, è la nostra tendenza".

HornetMaX

Silly question maybe, I'm not familiar with this shared memory stuff: are there synchronization problems between the writer (the .dlo) and the external reader ?
Could the reader be in the middle of the read operation when the writer starts to write  (or vice versa) ?

MaX.

PiBoSo


Proxy plugin updated to the latest interface.
"La perfezione non è il nostro obiettivo, è la nostra tendenza".

PiBoSo


Proxy plugin updated to the latest interface.
"La perfezione non è il nostro obiettivo, è la nostra tendenza".

Obelix90

Hi PiBoSo,

is there a way to test the output of the plugin. I compiled it as a .dll and copied it as a .dlo in the plugins folder. Then I used the two lines of your first post in another program to read the output. I used the following code lines to copy the *pBuf Data to a SProxyData_t Object:
SProxyData_t data;
memcpy(&data, &pBuf, sizeof(SProxyData_t));
while(1)
{
printf("%f\n", data.m_sData.m_fRPM);
Sleep(500);
}

The problem is, that the m_fRPM field is empty.

Thanks, Obelix90

HornetMaX

Quote from: Obelix90 on November 20, 2014, 08:54:54 PM
Hi PiBoSo,

is there a way to test the output of the plugin.
Works fine for me.

Can you post the totality of your code ?

This is my test code:
int main(int argc, char* argv[])
{

while (true) {
HANDLE g_hMapFile = OpenFileMapping(FILE_MAP_READ,FALSE,"Local\\GPBProxyObject");

if (g_hMapFile) {
void *pBuf = MapViewOfFile(g_hMapFile,FILE_MAP_READ,0,0,sizeof(SProxyData_t));
SProxyData_t *p = (SProxyData_t *) pBuf;

while (true) {
printf("State: %d\n", p->m_iState);
if (p->m_iState == 2) {
// On track, simulator running.
printf("  Speed: %.1f Kmh\n", p->m_sData.m_fSpeedometer * 3.6);
printf("  RPM  : %.0f rpm\n", p->m_sData.m_fRPM);
}
Sleep(1000);
}
} else {
printf("Can't open file mapping, GPB may not be running !\n");
}

Sleep(1000);
}

return 0;
}


MaX.

Obelix90

Hi MaX,

I think I see my mistake. I only copied the pBuf once in the data-field at the beginning of my program, so it isn't updated. I try this when I'm at home. If it's not working I post the rest of my code.
Thank you MaX.

Obelix90

HornetMaX

That should be the reason.
Notice that you may not need to make a copy of the data (e.g. in my example, I don't copy it), just be sure to avoid writing on it (I should probably use a "const *").

MaX.

Obelix90

The memcpy is not working for me, also when I put it in the while loop. So I use your lineSProxyData_t *p = (SProxyData_t *) pBuf;and now it works perfect.
Thank you.

HornetMaX

Quote from: Obelix90 on November 21, 2014, 08:12:45 PM
The memcpy is not working for me, also when I put it in the while loop. So I use your lineSProxyData_t *p = (SProxyData_t *) pBuf;and now it works perfect.
Thank you.

Your memcpy is wrong I think:

   memcpy(&data, &pBuf, sizeof(SProxyData_t));

Should probably be:

   memcpy(&data, pBuf, sizeof(SProxyData_t));

MaX.

Obelix90

Ah yes, because pBuf is already a pointer, you're right.

PiBoSo


Source code updated to the latest interface.
"La perfezione non è il nostro obiettivo, è la nostra tendenza".

HornetMaX

Quick question: at which frequency is the default proxy plugin data updated ?
Custom plugins can specify that at 10/20/50/100 Hz, but what about the default proxy.dlo ?

The sample code you provide (http://www.gp-bikes.com/downloads/gpb_proxy.c) seems to read from a proxy.ini file: is that the case for the default proxy.dlo ?

PiBoSo

Quote from: HornetMaX on March 12, 2016, 06:41:06 PM
Quick question: at which frequency is the default proxy plugin data updated ?
Custom plugins can specify that at 10/20/50/100 Hz, but what about the default proxy.dlo ?

The sample code you provide (http://www.gp-bikes.com/downloads/gpb_proxy.c) seems to read from a proxy.ini file: is that the case for the default proxy.dlo ?

The default is 10hz.
"La perfezione non è il nostro obiettivo, è la nostra tendenza".