Author Topic: Proxy plugin  (Read 5276 times)

PiBoSo

  • Administrator
  • Hero Member
  • *****
  • Posts: 2237
    • View Profile
Proxy plugin
« on: June 06, 2013, 08:32:42 PM »
Opening the memory-mapped file GPBProxyObject
Code: [Select]
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.

To install it, copy the DLO in "gpbikes\plugins" folder in GP Bikes installation directory

The source code and data structure is available here: http://www.gp-bikes.com/downloads/gpb_proxy.c
« Last Edit: June 21, 2014, 08:38:24 AM by PiBoSo »

PiBoSo

  • Administrator
  • Hero Member
  • *****
  • Posts: 2237
    • View Profile
Re: Proxy plugin
« Reply #1 on: December 15, 2013, 10:34:22 AM »
Proxy plugin updated to the latest interface.
« Last Edit: December 15, 2013, 10:38:37 AM by PiBoSo »

HornetMaX

  • Hero Member
  • *****
  • Posts: 5616
    • View Profile
Re: Proxy plugin
« Reply #2 on: May 13, 2014, 11:18:31 AM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 2237
    • View Profile
Re: Proxy plugin
« Reply #3 on: June 21, 2014, 08:38:30 AM »

Proxy plugin updated to the latest interface.

PiBoSo

  • Administrator
  • Hero Member
  • *****
  • Posts: 2237
    • View Profile
Re: Proxy plugin
« Reply #4 on: October 29, 2014, 07:36:40 PM »

Proxy plugin updated to the latest interface.

Obelix90

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Proxy plugin
« Reply #5 on: November 20, 2014, 08:54:54 PM »
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:
Code: [Select]
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

  • Hero Member
  • *****
  • Posts: 5616
    • View Profile
Re: Proxy plugin
« Reply #6 on: November 20, 2014, 10:01:03 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:
Code: [Select]
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

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Proxy plugin
« Reply #7 on: November 21, 2014, 08:51:19 AM »
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

  • Hero Member
  • *****
  • Posts: 5616
    • View Profile
Re: Proxy plugin
« Reply #8 on: November 21, 2014, 09:03:04 AM »
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

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Proxy plugin
« Reply #9 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 line
Code: [Select]
SProxyData_t *p = (SProxyData_t *) pBuf;and now it works perfect.
Thank you.

HornetMaX

  • Hero Member
  • *****
  • Posts: 5616
    • View Profile
Re: Proxy plugin
« Reply #10 on: November 21, 2014, 08:17:27 PM »
The memcpy is not working for me, also when I put it in the while loop. So I use your line
Code: [Select]
SProxyData_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

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Proxy plugin
« Reply #11 on: November 21, 2014, 09:24:44 PM »
Ah yes, because pBuf is already a pointer, you're right.

PiBoSo

  • Administrator
  • Hero Member
  • *****
  • Posts: 2237
    • View Profile
Re: Proxy plugin
« Reply #12 on: October 27, 2015, 11:34:07 PM »

Source code updated to the latest interface.

HornetMaX

  • Hero Member
  • *****
  • Posts: 5616
    • View Profile
Re: Proxy plugin
« Reply #13 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 ?

PiBoSo

  • Administrator
  • Hero Member
  • *****
  • Posts: 2237
    • View Profile
Re: Proxy plugin
« Reply #14 on: March 12, 2016, 09:32:43 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.