• Welcome to PiBoSo Official Forum. Please login or sign up.
 
August 24, 2019, 07:17:32 am

News:

GP Bikes beta15b available! :)


UDP Proxy

Started by PiBoSo, July 18, 2018, 04:01:57 pm

Previous topic - Next topic

PiBoSo

July 18, 2018, 04:01:57 pm Last Edit: May 12, 2019, 08:06:34 am by PiBoSo
Starting with Beta14, GP Bikes integrates a plugin that allows to receive UDP data from the simulated bike in realtime.

To enable it and set the parameters, edit the file "gpbikes/proxy_udp.ini" in the GP Bikes installation folder:
[params]
enable = 1
port = 30000
ip = 127.0.0.1:30001
delay = 1

port: outbound port
ip: inbound address and, optional, port ( if missing, the outbound port is used )
delay: hundredths of second between packets

The packet format:
"data": null-terminated string
"state": integer. 0: software running; 1: on-track, simulation paused; 2: on-track, simulation running
"time": integer, milliseconds.
The rest of the packet follows the "SPluginsBikeData_t" structure of the proxy plugin: https://www.gp-bikes.com/downloads/gpb_proxy.c


In the proxy_udp.ini file, add the line
info = 1
to enable the streaming of the event, session, lap and split data.

Data format of the event packet, sent every second:
"evnt": null-terminated string
The rest of the packet follows the "SPluginsEventData_t" structure of the proxy plugin.

Data format of the session packet, sent every second:
"sesn": null-terminated string
The rest of the packet follows the "SPluginsBikeSession_t" structure of the proxy plugin.

Data format of the lap packet, sent five times a second:
"lap ": null-terminated string
The rest of the packet follows the "SPluginsBikeLap_t" structure of the proxy plugin.

Data format of the split packet, sent five times a second:
"splt": null-terminated string
"split": integer. 0: the latest line crossed is the start / finish one; 1: the latest line crossed is a split one
The rest of the packet follows the "SPluginsBikeSplit_t" structure of the proxy plugin.
"Obviously your ambition outweighs your talent".

maggikk22

Hi Piboso,
first of all I'm a big fan of your work.
i need some assistance concerning UDP proxy.

I wrote a small program in Processing (for Arduino) to read the bikes data that GPB send in UDP proxy.
it works, I get a packet with 218 values.

I was able to identify the gear (data[25]), and the fuel (data[30] and data[31]).
But i can't find the speed.

Below there's 5 output results for different speeds.
Can you help me to identify the speed??


   60km/h-70km/h-120km/h-140km/h-200km/h
               
  •   100   100   100   100   100
    [1]   97   97   97   97   97
    [2]   116   116   116   116   116
    [3]   97   97   97   97   97
    [4]   0   0   0   0   0
    [5]   1   1   1   1   1
    [6]   0   0   0   0   0
    [7]   0   0   0   0   0
    [8]   0   0   0   0   0
    [9]   -116   81   -37   23   -3
    [10]   -67   29   67   -113   88
    [11]   1   1   0   0   0
    [12]   0   0   0   0   0
    [13]   -128   8   -15   99   -3
    [14]   27   32   47   47   53
    [15]   0   0   0   0   0
    [16]   0   0   0   0   0
    [17]   -103   58   -88   -71   -72
    [18]   -102   -117   94   -85   63
    [19]   62   66   78   76   90
    [20]   66   66   66   66   66
    [21]   118   15   67   127   -120
    [22]   78   -126   101   -52   109
    [23]   60   62   67   65   68
    [24]   66   66   66   66   66
    [25]   1   1   2   3   5                  GEAR
    [26]   0   0   0   0   0
    [27]   0   0   0   0   0
    [28]   0   0   0   0   0
    [29]   13   115   108   7   56
    [30]   -69   117   69   37   109     FUEL
    [31]   76   77   79   78   78          FUEL
    [32]   65   65   65   65   65
    [33]   -61   85   18   42   -62
    [34]   -12   28   17   -76   48
    [35]   -123   -100   6   27   95
    [36]   65   65   66   66   66
    [37]   -20   -80   30   50   -121
    [38]   -113   98   8   -90   -44
    [39]   -30   5   -112   15   -106
    [40]   67   68   66   68   67
    [41]   53   -40   114   -60   -82
    [42]   12   98   119   108   30
    [43]   -92   15   7   68   -64
    [44]   -65   -67   64   63   -65
    [45]   28   -48   -101   52   97
    [46]   -80   -66   -103   112   31
    [47]   -78   55   -62   -128   26
    [48]   66   -61   -62   -61   -63
    [49]   127   0   15   127   63
    [50]   -57   112   -110   -29   -122
    [51]   120   20   -3   -96   84
    [52]   -63   65   65   65   66
    [53]   -1   127   127   -81   -81
    [54]   29   -109   92   -88   43
    [55]   -11   87   -11   -25   -25
    [56]   -68   62   -67   62   -66
    [57]   63   64   -1   0   -102
    [58]   -38   84   80   77   75
    [59]   -58   -119   46   5   -120
    [60]   64   -63   65   -62   65
    [61]   -70   1   -53   -33   59
    [62]   -70   56   84   103   -123
    [63]   21   69   -79   58   35
    [64]   61   -68   59   61   61
    [65]   -82   111   -119   -118   117
    [66]   -58   120   -22   -120   10
    [67]   -85   -80   26   -21   -60
    [68]   61   -67   60   61   61
    [69]   48   -96   -37   22   45
    [70]   -1   17   -33   28   -59
    [71]   13   -35   -108   -114   -104
    [72]   -66   -67   -67   -66   62
    [73]   24   99   49   33   -94
    [74]   58   0   -97   64   49
    [75]   -66   97   -90   91   -98
    [76]   62   -65   62   -65   62
    [77]   28   48   33   -87   2
    [78]   33   93   40   42   -71
    [79]   36   -82   -120   80   100
    [80]   -68   -68   60   -69   60
    [81]   69   -6   -6   87   -83
    [82]   -87   -8   6   39   114
    [83]   109   -13   114   4   115
    [84]   -65   62   63   63   63
    [85]   48   -62   -54   43   1
    [86]   1   6   38   107   -10
    [87]   -60   -60   104   100   -115
    [88]   57   -68   -69   -69   -68
    [89]   73   58   -47   -103   122
    [90]   -4   -19   -10   -1   -13
    [91]   127   127   127   127   127
    [92]   63   63   63   63   63
    [93]   49   -32   30   70   -10
    [94]   85   -19   2   73   56
    [95]   46   7   -122   -62   20
    [96]   -68   58   -68   57   -68
    [97]   -49   -120   30   53   11
    [98]    -84   -24   16   39   111
    [99]          109   -13   114   4   115
    [100]   63   -66   -65   -65   -65
    [101]   -69   -117   -38   96   66
    [102]   86   89   103   59   52
    [103]   108   51   1   -62   96
    [104]   59   -68   59   -70   -68
    [105]   -46   67   -18   -126   -102
    [106]   55   17   -96   64   73
    [107]   -66   97   -90   91   -98
    [108]   62   -65   62   -65   62
    [109]   -16   -40   108   -82   88
    [110]   96   -118   2   -21   -5
    [111]   -120   23   -114   20   -113
    [112]   -62   67   66   67   66
    [113]   -30   92   -101   32   -113
    [114]   18   97   -13   -17   -78
    [115]   28   -13   111   -83   4
    [116]   63   -68   63   -68   63
    [117]   -84   61   105   -51   8
    [118]   123   -126   -36   125   52
    [119]   -81   -81   79   76   126
    [120]   60   -65   -66   -66   -65
    [121]   -86   -43   -44   -36   54
    [122]   -45   29   -10   -69   90
    [123]   108   -25   -84   -68   5
    [124]   -65   63   61   62   63
    [125]   -93   78   -44   -89   13
    [126]   -86   105   78   -45   -15
    [127]   -41   7   -47   30   71
    [128]   -65   63   -66   -64   -63
    [129]   111   13   -19   96   99
    [130]   -1   124   -128   -37   -53
    [131]   50   -42   -93   84   17
    [132]   -66   62   -67   -65   62
    [133]   -65   0   -116   10   45
    [134]   -50   -77   100   18   -122
    [135]   -104   -95   -88   -98   -68
    [136]   61   61   61   61   61
    [137]   80   -56   -80   -96   -24
    [138]   0   -28   -35   -93   -59
    [139]   35   47   64   48   95
    [140]   61   61   61   61   61
    [141]   31   39   0   0   -6
    [142]   108   -57   -73   88   95
    [143]   -11   53   -99   -104   2
    [144]   60   61   -70   -69   -66
    [145]   0   32   -1   64   63
    [146]   -66   41   67   30   17
    [147]   7   -104   -59   -110   41
    [148]   -68   61   59   60   61
    [149]   0   0   0   0   0
    [150]   0   0   0   0   0
    [151]   0   0   0   0   0
    [152]   0   0   0   0   0
    [153]   -101   51   19   -106   94
    [154]   34   -73   -19   -67   -127
    [155]   -109   -109   111   -84   58
    [156]   61   59   -68   -68   -66
    [157]   0   0   -89   0   0
    [158]   0   0   -90   0   0
    [159]   0   0   -90   0   -128
    [160]   0   0   62   0   63
    [161]   0   0   0   0   0
    [162]   0   0   0   0   0
    [163]   0   0   0   0   0
    [164]   0   0   0   0   0
    [165]   0   0   0   0   0
    [166]   0   0   0   0   0
    [167]   0   0   0   0   0
    [168]   0   0   0   0   0
    [169]   0   0   0   0   0
    [170]   0   0   0   0   0
    [171]   0   0   0   0   0
    [172]   0   0   0   0   0
    [173]   44   -67   37   19   -11
    [174]   -32   -77   -1   80   20
    [175]   -124   -104   2   26   93
    [176]   65   65   66   66   66
    [177]   59   -27   -9   -117   -85
    [178]   -74   80   -90   -67   -71
    [179]   -124   -104   3   25   98
    [180]   65   65   66   66   66
    [181]   5   1   1   5   5
    [182]   0   0   0   0   0
    [183]   0   0   0   0   0
    [184]   0   0   0   0   0
    [185]   5   1   1   5   5
    [186]   0   0   0   0   0
    [187]   0   0   0   0   0
    [188]   0   0   0   0   0
    [189]   -30   94   102   -110   -101
    [190]   117   62   116   -75   22
    [191]   22   30   106   -97   -114
    [192]   63   63   -65   64   64
    [193]   0   0   0   0   0
    [194]   0   0   0   0   0
    [195]   0   0   0   0   0
    [196]   0   0   0   0   0
    [197]   -1   -1   -1   -1   -1
    [198]   -1   -1   -1   -1   -1
    [199]   -1   -1   -1   -1   -1
    [200]   -1   -1   -1   -1   -1
    [201]   0   0   0   0   0
    [202]   0   0   0   0   0
    [203]   0   0   0   0   0
    [204]   0   0   0   0   0
    [205]   0   0   0   0   0
    [206]   0   0   0   0   0
    [207]   0   0   0   0   0
    [208]   0   0   0   0   0
    [209]   0   0   0   0   0
    [210]   0   0   0   0   0
    [211]   0   0   0   0   0
    [212]   0   0   0   0   0
    [213]   0   0   0   0   0
    [214]   0   0   0   0   0
    [215]   0   0   0   0   0
    [216]   0   0   0   0   0
    [217]   0   0   0   0   0


    Also, here's the code in Processing:

    import hypermedia.net.*;
    int PORT_RX=30001; //port
    String HOST_IP="127.0.0.1"; //
    UDP udp;


    void setup() {
      udp= new UDP(this,PORT_RX,HOST_IP);
      udp.log(true);
      udp.listen(true);
    }


    void draw() {
    }


    void receive(byte[] data, String HOST_IP, int PORT_RX) {
      println(data);
      println("-------");
    }

Gibbon

Hi,

You can create an Excel table as I did, it will be easier to understand.

Keep in mind that each data is coded on 4 bytes.

So the variable m_iGear for example will be in [25],[26],[27] and [28].

Same for the variable m_fFuel --> [29],[30],[31] and [32] (If I recall correctly).

Following that logic, m_fSpeedometer should be [33],[34],[35] and [36]

Then you need to convert those bytes into a integer/float depending on the variable type.

Hope that it helped.

(I will try to post this Excel table.)

PiBoSo

October 26, 2018, 12:24:43 pm #3 Last Edit: October 26, 2018, 12:28:55 pm by PiBoSo

The packets must be parsed as a series of little-endian integers and floats ( except for the first 5 bytes ).
There is a 13 bytes "header", followed by the data in the same order of the "SPluginsBikeData_t" structure: http://www.gp-bikes.com/downloads/gpb_example.c
Therefore, "gear" is a 4 bytes integer at position 25 to 28, and "speed" ( in meters per second ) is a 4 bytes float at position 33 to 36.
"Obviously your ambition outweighs your talent".

maggikk22

Great! thank you so much for your help!

For those who are intersted in using Processing, this is the code I used:

import hypermedia.net.*;
int PORT_RX=30001;
String HOST_IP="127.0.0.1";
UDP udp;

int pos;

void setup() {
  udp= new UDP(this,PORT_RX,HOST_IP);
  //udp.log(true);
  udp.listen(true);
}


void draw() {
}


void receive(byte[] data, String HOST_IP, int PORT_RX) {
   
  pos = 25;
  int gear = (data[pos] & 0xff) | ((data[pos+1] & 0xff) << 8) | ((data[pos+2] & 0xff) << 16) | ((data[pos+3] & 0xff) << 24);
 
  pos = 33;
  int speed = int(Float.intBitsToFloat((data[pos] & 0xff) | ((data[pos+1] & 0xff) << 8) | ((data[pos+2] & 0xff) << 16) | ((data[pos+3] & 0xff) << 24))*3.6);
   
  pos = 29;
  float fuel = Float.intBitsToFloat((data[pos] & 0xff) | ((data[pos+1] & 0xff) << 8) | ((data[pos+2] & 0xff) << 16) | ((data[pos+3] & 0xff) << 24));
 
  pos = 13;
  int rpm = (data[pos] & 0xff) | ((data[pos+1] & 0xff) << 8) | ((data[pos+2] & 0xff) << 16) | ((data[pos+3] & 0xff) << 24);
 
  pos = 133;
  int fsusp = int(Float.intBitsToFloat((data[pos] & 0xff) | ((data[pos+1] & 0xff) << 8) | ((data[pos+2] & 0xff) << 16) | ((data[pos+3] & 0xff) << 24))*1000);   

  pos = 137;
  int rsusp = int(Float.intBitsToFloat((data[pos] & 0xff) | ((data[pos+1] & 0xff) << 8) | ((data[pos+2] & 0xff) << 16) | ((data[pos+3] & 0xff) << 24))*1000);   

  pos = 157;
  int thro = int(Float.intBitsToFloat((data[pos] & 0xff) | ((data[pos+1] & 0xff) << 8) | ((data[pos+2] & 0xff) << 16) | ((data[pos+3] & 0xff) << 24))*100);   

  pos = 161;
  int fBrak = int(Float.intBitsToFloat((data[pos] & 0xff) | ((data[pos+1] & 0xff) << 8) | ((data[pos+2] & 0xff) << 16) | ((data[pos+3] & 0xff) << 24))*100);   

  pos = 17;
  int tempEng = int(Float.intBitsToFloat((data[pos] & 0xff) | ((data[pos+1] & 0xff) << 8) | ((data[pos+2] & 0xff) << 16) | ((data[pos+3] & 0xff) << 24)));   

  pos = 21;
  int tempWat = int(Float.intBitsToFloat((data[pos] & 0xff) | ((data[pos+1] & 0xff) << 8) | ((data[pos+2] & 0xff) << 16) | ((data[pos+3] & 0xff) << 24)));   

  pos = 113;
  int pitch = int(Float.intBitsToFloat((data[pos] & 0xff) | ((data[pos+1] & 0xff) << 8) | ((data[pos+2] & 0xff) << 16) | ((data[pos+3] & 0xff) << 24)));   

  pos = 117;
  int lean = int(Float.intBitsToFloat((data[pos] & 0xff) | ((data[pos+1] & 0xff) << 8) | ((data[pos+2] & 0xff) << 16) | ((data[pos+3] & 0xff) << 24)));   


  println("gear = " +gear);
  println("rpm = " +rpm +" rev/min");
  println("speed = " +speed +" km/h");
  println("fuel = " +fuel +" l");
  println("front suspension = " +fsusp +" mm");
  println("rear suspension = " +rsusp +" mm");
  println("throttle = " +thro +" %");
  println("front brake = " +fBrak +" %");
  println("pitch = " +pitch +" °");
  println("lean = " +lean +" °");
  println("engine temp = " +tempEng +" °C");
  println("water temp = " +tempWat +" °C"); 
  println("-----------");
}



and this is an example of the results I get:
gear = 5
rpm = 14633 rev/min
speed = 217 km/h
fuel = 21.85146 l
front suspension = 68 mm
rear suspension = 38 mm
throttle = 36 %
front brake = 0 %
pitch = 4 °
lean = 50 °
engine temp = 87 °C
water temp = 85 °C
-----------

maggikk22

Hi,

Based on the previous messages, I made a simple dashboard for GP Bikes.
i just wanted to share it.
Thank you !

maggikk22


h106frp

Very nice project, have you tried connecting to the UDP host from another computer on the same network to see if it still works?

Just thinking that I might finally have a use for the Raspberry PI that has been sitting on my shelf for a while

maggikk22

I haven't tried to connect it to another computer, but I'm planning to buy a 5 inch display for Raspberry, and connect it to the pc with the hdmi cable (no Raspberry,). That way, I would expand the desktop: main screen for the game, 5 inch display for dash.

Manu

October 31, 2018, 08:25:13 am #9 Last Edit: October 31, 2018, 08:27:34 am by Manu
Amazing work maggikk.

Are you planning to launch it as an internal plugin?

maggikk22

no, i will not include it as an internal plugin for the following reasons:
1. I'm not sure I'm able to
2. MaxHUD is a very nice and efficient plugin that already makes the job
3. my goal was to have an external dashboard so I can display it on a 2nd screen.

h106frp

You could compile the standalone so its just click and run from the desktop - I think this is what Manu is after

Manu

Quote from: h106frp on October 31, 2018, 05:51:39 pm
You could compile the standalone so its just click and run from the desktop - I think this is what Manu is after


I meant to use it together with MaxHud

h106frp

Got this working to read the data on a remote PC on my LAN via wireless  :)

edit proxy_udp

[params]
enable = 1
port = 30000
;ip = 127.0.0.1:30001; original localhost
ip = 192.168.1.20:30001  ;the IP of the client on the LAN
delay = 1

modify the line below in the original processing code
udp= new UDP(this,PORT_RX,HOST_IP);

to read
udp = new UDP (this,PORT_RX);

very cool  8)  Should be able to make an e-dash using the raspberry pi now


davidboda46

Hi,

Any chance it's possible to get it to work on an Android with an app (sadly I'm not a programmer)? There is one I use for car games, https://www.apkmonk.com/app/de.barz.hud_dash/, been in touch with the guy but he didn't seem to be interested to include GPB unfortunately.

Cheers,

/David "Gonzo" Boda #46
"THE EDGE... THERE IS NO HONEST WAY TO EXPLAIN IT BECAUSE THE ONLY PEOPLE WHO REALLY KNOW WHERE IT IS ARE THE ONES WHO HAVE GONE OVER"