Telemetry UDP - example

Discussion in 'Plugins' started by formula1996, Oct 5, 2013.

  1. formula1996

    formula1996 Registered

    Joined:
    Nov 2, 2012
    Messages:
    42
    Likes Received:
    1
    I would like to send speed, rpm, gear data through UDP. But i don't well in programming. Can anybody send me a basic plugin example how to send data on UDP or help me? It would be great :)
     
  2. Kev

    Kev Registered

    Joined:
    Oct 28, 2010
    Messages:
    156
    Likes Received:
    0
    Hmm. I tried this approach and been really diappointed by winsockets2. Data went slow and sometimes been lost so my display flickered.
    If you plan to use it on the same machine, use mapped files instead, they should work better imo (i didn't try it yet though, gonna do in next week or two).
     
  3. Marcel Offermans

    Marcel Offermans Registered

    Joined:
    Oct 4, 2010
    Messages:
    647
    Likes Received:
    2,936
    Sending data via UDP works just fine for me, and if you're looking for an example you can check out: https://bitbucket.org/marrs/rfactor...542bc469607b9bd9/cpp/DataPlugin_v2/?at=master

    This is a plugin that sends all kinds of telemetry data and can easily be customized. For my application (endurance racing software) I am receiving that data in Java (example: https://bitbucket.org/marrs/rfactor...scoring/v2/impl/PluginListener.java?at=master) and using it mainly to do my own scoring in a practice session, but I have used the same code to display telemetry data as well so it's a good starting point.
     
  4. NewRider

    NewRider Registered

    Joined:
    Apr 15, 2014
    Messages:
    4
    Likes Received:
    0
    Sorry :)

    But I felt so bad when I could not know how to down load the two folders DataPlugin & DataPlugin_v2.
    Do I need to edit them and copy the contents? I can not find the download link from that site
     
  5. B1K3R

    B1K3R Registered

    Joined:
    Apr 6, 2012
    Messages:
    1,605
    Likes Received:
    88
    You should have not given up that easily :) Go to Downloads tab, then Branches. I used Marrs code and works wonderfully.
     
  6. NewRider

    NewRider Registered

    Joined:
    Apr 15, 2014
    Messages:
    4
    Likes Received:
    0
    Thank you B1K3R, I could get it,

    I compiled the both projects and copied .dll file to the plugin directory and started listing to 127.0.0.1 port 6789 but i did not get any data
    I am using rFactor 1 and C# while my firewall is tuned off, is there anything special thing I need to do to start receiving the data?
    even there was not a popup screen showing any data, any suggestion?
     
  7. Noel Hibbard

    Noel Hibbard Registered

    Joined:
    Oct 5, 2010
    Messages:
    2,744
    Likes Received:
    40
    What are you using to receive the data?
     
  8. B1K3R

    B1K3R Registered

    Joined:
    Apr 6, 2012
    Messages:
    1,605
    Likes Received:
    88
    Ye, like noel said, it depends what code your doing to receive data. I will post some c# code but won't be home any time soon.

    Sent from my GT-I9300 using Tapatalk

    Edit: Here's some code based on Marrs example. These are code extracts so that you get an idea.

     
    Last edited by a moderator: Apr 19, 2014
  9. NewRider

    NewRider Registered

    Joined:
    Apr 15, 2014
    Messages:
    4
    Likes Received:
    0
    Thank you guys,

    I could test that in rFactor2 and I could detect the data, but in rFactor1 I could not.
    I am using simple C# code that I already used for listening to UDP ports.

    is DataPlugin_v2 project is for rFactor2 and DataPlugin project is for rFactor1?
    I only want it to work in rFactor1 since rFactor 2 is a demo version at me.
     
  10. B1K3R

    B1K3R Registered

    Joined:
    Apr 6, 2012
    Messages:
    1,605
    Likes Received:
    88
    Yes, V2 is for rF2 etc. Sorry, I did not try it for rF1.
     
  11. NewRider

    NewRider Registered

    Joined:
    Apr 15, 2014
    Messages:
    4
    Likes Received:
    0
    Thank you B1K3R for the code,

    I want to use this data to build a hardware simulator and send them to com port later. I could see that data such as the orientation matrix, pitch, roll..etc are not available in the telemetry, so I will try to do some modification to get them on both projects.
     
  12. formula1996

    formula1996 Registered

    Joined:
    Nov 2, 2012
    Messages:
    42
    Likes Received:
    1
    When I launch the game it freezes :/
    This line cause the crash anybody can help why?
     
    Last edited by a moderator: Jan 16, 2016
  13. PhilM

    PhilM Registered

    Joined:
    Jan 9, 2018
    Messages:
    1
    Likes Received:
    0
    I have created a Wind Simulator that works on other SimRacing games.
    I want to make it compatible with RF2.

    I am trying to fetch telemetry variables such as speed, rpm, gear, etc. using a Python script.

    I downloaded the DataPlugin_V2.dll and added it to the game Bin folders.
    When I open the in-game options, I do not see this plugin available (all other plugins appear)

    Here is a piece of my Python code:

    Code:
    import struct
    import socket
    
    # Configure listener IP & Port for UDP transmission of packed values
    udp_ip = "127.0.0.1"
    udp_port = 6789
    unpacked_data = None
    data = None
    
    def checkStatus():
        global data, udp_ip, udp_port
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # UDP
        #sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    
        sock.bind((udp_ip, udp_port))
        sock.settimeout(1/30)
    
        try:
            data, addr = sock.recvfrom(1024)  # receiving from socket
            sock.close()
            return data
        except:
            return False
    
    def receiveData():
        global unpacked_data, data
        fmt = '<' + '70' + 'f'                                 # define structure of packed data
        s = struct.Struct(fmt)                                  # declare structure
    
        #rx_data = net_rx(udp_ip, udp_port)
        #unpacked_data = s.unpack(data)                  #  unpack data into tuple, requires correct 'fmt'
        unpacked_data = struct.unpack('64f', data[0:256])
        return True
    
    
    def getChannel(channel):
        global unpacked_data
        if channel == 'rpm':
            return str(int(unpacked_data[37]))
        elif channel == 'max_rpm':
            return str(int(unpacked_data[63]))
        elif channel == 'gear':
            return str(int(unpacked_data[33])-1)
        elif channel == 'speed':
            return str(int(unpacked_data[7]*0.6214))
        elif channel == 'track_loc':
            return '-1'
        elif channel == 'car_name':
            return '-1'
        else:
            return 0
    For more information about the Wind Simulator, you can visit our website at: https://www.simracingstudio.com/

    Thanks,
    Phil.
     

Share This Page