Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 27

Thread: C# Udp V2 library

  1. #11
    Superkart Pilot Maskmagog's Avatar
    Join Date
    Sep 2017
    Posts
    399
    Platform
    XBOX1 X
    In the words of Montgomery C. Burns: Excellent!

    I had some issues at first, all because I'm a total noob at this. Here's what I did, in case someone else has the same problem:
    I installed Microsoft Visual Studio Community, the free version of Visual Studio. It threw an error when I tried to open the UDP example, something about missing .NET,Version 4.6.1, Targeted Pack or something like that. In Visual Studio, I went to Tools->Get tools and features. There I selected .NET Desktop Development, and then pressed Modify-button to install it. After this, I could open, and run the example which worked like a charm! Thanks Zeratall, time to start googling C# tutorials
    Thrustmaster TX, Italia 458 wheel, 2 pedals, Firmware 54, Xbox One X since Aug -18, 24" 1080 monitor
    Don't miss Yorkie065's excellent videos: Ep26-LiveTrack pt1. Ep 27-LiveTrack pt2.

  2. #12
    Superkart Pilot Maskmagog's Avatar
    Join Date
    Sep 2017
    Posts
    399
    Platform
    XBOX1 X
    Hi again
    Not sure if I managed to break something, but uDP.Speed shows roughly a quarter of my speed in km/h. So I if I drive in 80 km/h, uDP.Speed shows around 20?
    Other values such as Tyre Temp, Brake Temp seem fine.
    Thrustmaster TX, Italia 458 wheel, 2 pedals, Firmware 54, Xbox One X since Aug -18, 24" 1080 monitor
    Don't miss Yorkie065's excellent videos: Ep26-LiveTrack pt1. Ep 27-LiveTrack pt2.

  3. #13
    GT4 Pilot
    Join Date
    Jul 2017
    Posts
    2,626
    Platform
    PC
    Quote Originally Posted by Maskmagog View Post
    Hi again
    Not sure if I managed to break something, but uDP.Speed shows roughly a quarter of my speed in km/h. So I if I drive in 80 km/h, uDP.Speed shows around 20?
    Other values such as Tyre Temp, Brake Temp seem fine.
    It's in m/sec

  4. #14
    Superkart Pilot Maskmagog's Avatar
    Join Date
    Sep 2017
    Posts
    399
    Platform
    XBOX1 X
    Quote Originally Posted by cpcdem View Post
    It's in m/sec
    Aaah that makes sense! Should have figured. Thanks!
    Thrustmaster TX, Italia 458 wheel, 2 pedals, Firmware 54, Xbox One X since Aug -18, 24" 1080 monitor
    Don't miss Yorkie065's excellent videos: Ep26-LiveTrack pt1. Ep 27-LiveTrack pt2.
    The following user likes this Post: cpcdem


  5. #15
    Superkart Pilot Zeratall's Avatar
    Join Date
    Oct 2017
    Posts
    291
    Platform
    PC
    Yeah the documentation that sms gave out for udp had little to no explanation of units, typically what I do is refer to the sms shared memory documentation as that one does, and a lot of the udp variables have the exact same name in the shared memory so should be similar.

    If you guys have any questions let me know!

  6. #16
    Superkart Pilot Maskmagog's Avatar
    Join Date
    Sep 2017
    Posts
    399
    Platform
    XBOX1 X
    Quote Originally Posted by Zeratall View Post
    If you guys have any questions let me know!
    You might regret that
    I've been trying to add more variables to the library, but I'm stabbing in the dark most of the time. I'd like to add the rest from TelemetryData, and then RaceData. That would keep me busy for a while But this byte[], char, binaryReader etc is Greek to me. I realize that at least parts of this is simple for a programmer, but I have googled a lot, and learned a lot, and failed.
    This is what I've added in TelemetryData:

    private byte _Handbrake;
    private byte _AeroDamage;
    private byte _EngineDamage;
    private UInt32 _Joypad0;
    private byte _DPad;
    private char[] _TyreCompound[TYRE_NAME_LENGTH_MAX] = new byte [4];
    private float _TurboBoostPressure;
    private float _FullPosition;
    private byte _BrakeBias;
    private UInt32 _TickCount;


    I've tried to copy settings from other, working variables, but TyreCompound for example is char, which has not been in use before.
    Also, I don't have a clue what to do with the #define from SMS UDP definitions (from here). For example these two for TelemetryData stream:
    #define UDP_STREAMER_CAR_PHYSICS_HANDLER_VERSION 2
    #define TYRE_NAME_LENGTH_MAX
    40

    Following is my addition to public void ReadTelemetryData:

    Handbrake = binaryReader.ReadByte();
    AeroDamage = binaryReader.ReadByte();
    EngineDamage = binaryReader.ReadByte();
    Joypad0 = binaryReader.ReadUInt32();
    DPad = binaryReader.ReadByte();
    TyreCompound[0] = binaryReader.ReadChar();
    TyreCompound[1] = binaryReader.ReadChar();
    TyreCompound[2] = binaryReader.ReadChar();
    TyreCompound[3] = binaryReader.ReadChar();
    TurboBoostPressure = binaryReader.ReadSingle();
    FullPosition = binaryReader.ReadSingle();
    BrakeBias = binaryReader.ReadByte();
    TickCount = binaryReader.ReadUInt32();


    I've also added following at the end for each variable. Byte for Handbrake, AeroDamage, EngineDamage, DPad, BrakeBias. UInt32 for Joypad0 and TickCount. Char[] for TyreCompound and float for TurboBoostPressure and FullPosition. All same as above.

    public byte AeroDamage
    {
    get
    {
    return _AeroDamage;
    }
    set
    {
    _AeroDamage = value;
    }
    }


    I think that EngineDamage is working, but I can't get something I understand from AeroDamage or BrakeBias, for example. And I can't get TyreCompound to even compile.
    Any help's much appreciated! Or if someone else with the needed skills should find the time and motivation to do it, that would work too
    Thrustmaster TX, Italia 458 wheel, 2 pedals, Firmware 54, Xbox One X since Aug -18, 24" 1080 monitor
    Don't miss Yorkie065's excellent videos: Ep26-LiveTrack pt1. Ep 27-LiveTrack pt2.

  7. #17
    GT4 Pilot
    Join Date
    Jul 2017
    Posts
    2,626
    Platform
    PC
    Well, that looks Greek to me, too, but I am actually Greek, so that helps

    You are also doing fine in your translation, too, only problem as you have already found out is the sTyreCompound. First of all though, about UDP_STREAMER_CAR_PHYSICS_HANDLER_VERSION and TYRE_NAME_LENGTH_MAX, those are c++ directives, for the c# code you can define them in the beginning of the PCars2_UDP class as consts:

    const int UDP_STREAMER_CAR_PHYSICS_HANDLER_VERSION = 2;
    const int TYRE_NAME_LENGTH_MAX = 40;

    Now about _TyreCompound, this is a 4 items long array, with each item being another (byte) array, holding the name of each tire. One way to define it is to use

    private byte[][] _TyreCompound = new byte[4][];

    and then, when reading it, you must use this:

    _TyreCompound[0] = binaryReader.ReadBytes(TYRE_NAME_LENGTH_MAX);
    _TyreCompound[1] = binaryReader.ReadBytes(TYRE_NAME_LENGTH_MAX);
    _TyreCompound[2] = binaryReader.ReadBytes(TYRE_NAME_LENGTH_MAX);
    _TyreCompound[3] = binaryReader.ReadBytes(TYRE_NAME_LENGTH_MAX);

    Finally, in order to convert each tire name to a string, you must use something like

    tireName = System.Text.Encoding.UTF8.GetString(_TyreCompound[0]);

    for the front left tire, _TyreCompound[1] for the front right etc.

    I made sure that the above compiles, but have not tested it if it really works correctly, too. I assume it does, unless I have made some stupid mistake! Please try it and if it doesn't, I or someone else will look further into it.
    The following user likes this Post: Maskmagog


  8. #18
    Superkart Pilot Maskmagog's Avatar
    Join Date
    Sep 2017
    Posts
    399
    Platform
    XBOX1 X
    Thanks cpcdem! Too tired to try this now, but I'll give it a go tomorrow.
    Thrustmaster TX, Italia 458 wheel, 2 pedals, Firmware 54, Xbox One X since Aug -18, 24" 1080 monitor
    Don't miss Yorkie065's excellent videos: Ep26-LiveTrack pt1. Ep 27-LiveTrack pt2.
    The following user likes this Post: cpcdem


  9. #19
    WMD Member Sampo's Avatar
    Join Date
    Jun 2012
    Location
    Finland
    Posts
    641
    Platform
    PC
    In C, your _AeroDamage and _EngineDamage are unsigned chars (so unsigned bytes) (with values between 0-255) and represent the percentage of damage with 255 being 100%. I convert those to float and then divide by 2.55 to get the percentage easily. With BrakeBias you have to do (255-BrakeBias)/2.55 to get the front break bias percentage (again, converting BrakeBias to float helps with accuracy). I'm not familiar with C#, so can't give the straight answer.
    Last edited by Sampo; 25-06-2018 at 23:59.
    CPU Intel i5 3570K @ 4.2 GHz | Motherboard Asus P8Z77-V LK | RAM 16GB 1600MHz DDR3 | GPU nVidia GTX980 4GB (390.77) | Audio Realtek 5.1 on MB | Screen AOC U3477PQU | OS Windows 7 Pro 64-bit | Wheel Logitech G27
    In-game settings: 2560x1080 / 3440x1440 | Texture Resolution HIGH | AF 16x | VSync ON | AA None | Reflections MED | Envmap MED | Vehicle HIGH | World HIGH | Shadows MED | Motion Blur NO | Render Frames Ahead 1 | Particles MED/MED/MED

    PC2Info, a PC program that shows most stats the game provides over UDP
    The following user likes this Post: Maskmagog


  10. #20
    Superkart Pilot Zeratall's Avatar
    Join Date
    Oct 2017
    Posts
    291
    Platform
    PC
    So to understand a binary reader you need to understand the structure of udp. A udp is a message that broadcasts a message in binary. The size of the binary message depends on how much data is sent. Let's say we want to receive a udp message with two ints. We know the message would be 8 bytes long. Because an int is 4 bytes long and 2x4 =8. We can remove bytes 0-3 and save into variable 1 and then save bytes 4-8 in variable 2.

    In the code where you see stream.index = 12 we are telling the code for the message we want to start at byte 12 ( base packet are bytes 0-12 which we don't care about) then when you see binaryReader.convertTo. It's take our current stream position and moving the index over the amount the data type used in the convert and saving those bytes to a variable. Basically your dissecting the message in chunks.
    The following user likes this Post: Maskmagog


Similar Threads

  1. Simresults.net - a webbased result reader & PHP library
    By Mauserrifle in forum Multiplayer
    Replies: 123
    Last Post: 19-10-2018, 12:40
  2. Interest in GTE championship?
    By p66pittfan in forum Project CARS 2 on XBOX One
    Replies: 1
    Last Post: 19-02-2018, 21:08
  3. Project Cars closed, but keeps running in steam library
    By Kunal_Racedriver in forum PC - Technical Help & Support
    Replies: 2
    Last Post: 14-02-2016, 16:41
  4. Aug old vs new DLC not showing under Library/DLC in steam
    By Kobus Maree in forum General Discussion
    Replies: 6
    Last Post: 30-08-2015, 23:02
  5. highlight video to capture library question
    By BORIStheBLADE1 in forum PS4 - Technical Help & Support
    Replies: 1
    Last Post: 19-05-2015, 02:03

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •