1. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Download Package Now!
  2. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  3. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant here. Do not following these rules will lead to permanent exclusion from this website: Read the forum rules.

UDP record and playback in Python

Discussion in 'Miscellaneous' started by vthinsel, Jun 15, 2016.

  1. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    359
    Location:
    FRANCE
    Balance:
    4,472Coins
    Ratings:
    +458 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Hello,

    I decided to learn Python recently and was looking for a small project to start. When I started developing my first UDP plugin for ProjectCars in VB, I was annoyed with the test/debug which required me to launch PCars on my PS4 and drive for some time, pause, restart, .... If only I had a way to capture UDP data accurately and replay it, with the exact same timing...... I dreamt of it, and here it is !
    You just need to install python 3.x from www.python.org and unzip the attached files in a directory.
    The first tool is used to capture UDP data:
    D:\Perso\Python_UDP_Receiver>python UDPReceive.py -h
    usage: UDPReceive.py [-h] -p PORT [-f FILE] [-b BUFFER] [-c COUNT]
    [-s SECONDS]

    Capture UDP packets for further analysis and playback

    optional arguments:
    -h, --help show this help message and exit
    -p PORT, --port PORT Port to listen to
    -f FILE, --file FILE File to write data to
    -b BUFFER, --buffer BUFFER
    Host target
    -c COUNT, --count COUNT
    Stop capture after x packets
    -s SECONDS, --seconds SECONDS
    Stop capture after x seconds

    D:\Perso\Python_UDP_Receiver>


    As an example : D:\Perso\Python_UDP_Receiver>python UDPReceive.py -p 5606 -f pcars.bin -c 500 -s 60 will capture UDP data from ProjectCars for 60 seconds or 500 packets.

    This tool also generates another output file with .raw suffix which is the raw UDP received data, without any additional data such as timing. The pcars.bin file from the example is compressed and includes timing data used for playback.

    The second tool is for regular playback :
    D:\Perso\Python_UDP_Receiver>python UDPSend_timed.py -h
    usage: UDPSend_timed.py [-h] -p PORT -f FILE -s SERVER [-b BUFFER]

    Send UDP file captured previously using UDPReceive.py

    optional arguments:
    -h, --help show this help message and exit
    -p PORT, --port PORT Port to listen to
    -f FILE, --file FILE File to send
    -s SERVER, --server SERVER
    Host target
    -b BUFFER, --buffer BUFFER
    Buffer size

    D:\Perso\Python_UDP_Receiver>


    You can send to a given IP address, or even broadcast like ProjectCars is doing.
    The last tool uses the raw UDP file and replays it as fast as it can. In fact, I used this one to develop the two others :)

    By using the replay you can easily tune your rig using the same scenario again and again without having to drive. I also checked the behavior of PCars Dash on my tablet.... so many usecases and so easy !

    Feel free to give it a try, and if you have idea for features , feel free to use this thread !

    Python is a really nice language with so many ready-to-use modules making development journey a breeze. :thumbs

    Attached Files:

    • Like Like x 5
    • Creative Creative x 3
  2. AlexinChina

    AlexinChina Member

    Joined:
    Sep 2, 2015
    Messages:
    71
    Location:
    China
    Balance:
    304Coins
    Ratings:
    +7 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
    Good Tools ,I 'll try it later
  3. AlexinChina

    AlexinChina Member

    Joined:
    Sep 2, 2015
    Messages:
    71
    Location:
    China
    Balance:
    304Coins
    Ratings:
    +7 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
  4. Rebeka

    Rebeka New Member

    Joined:
    Mar 11, 2019
    Messages:
    2
    Balance:
    28Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    DC motor, AC motor, SCN6, SimAxe, SimforceGT, 4DOF
  5. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    359
    Location:
    FRANCE
    Balance:
    4,472Coins
    Ratings:
    +458 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    This thread is about recording UDP telemetry stream sent over network, nothing to do with serial transmission. Open another thread is you want.
    • Agree Agree x 1