Page 5 of 6 FirstFirst ... 3456 LastLast
Results 41 to 50 of 54

Thread: [HowTo] Shared Memory (API) App

  1. #41
    GT5 Pilot
    Join Date
    Sep 2015
    Location
    Florida
    Posts
    1,181
    Platform
    PS4
    So, if it's not obvious from the above, the 1st and 2nd bytes don't appear to change from record to record. The third byte increments by 4 with each record that is transmitted. I just did a sampling at settings 8 (200ms interval) and 9 (1000ms interval), and the increment is 4 in both:

    Sample at setting 8, 3rd byte
    28
    2c
    30
    34

    Sample at setting 9, 3rd byte
    ec
    f0
    f4
    f8

    These samples were taken while sitting in the menus, so there's something more to this than just the SharedMemory.h struct.

  2. #42
    Console lead Tim Mann's Avatar
    Join Date
    Oct 2011
    Location
    Bristol
    Posts
    117
    Platform
    PC
    The following 2 users likes this Post: Lars Rosenquist, memoric77


  3. #43
    GT5 Pilot
    Join Date
    Sep 2015
    Location
    Florida
    Posts
    1,181
    Platform
    PS4
    Thanks, Tim!

  4. #44
    GT5 Pilot mr_belowski's Avatar
    Join Date
    May 2015
    Posts
    1,490
    Platform
    PC
    My PC (C#) code is open source, you're welcome to have a rummage around in here https://github.com/mrbelowski/r3e_crewchief_v3. This cheats a little though and just dumps the byte array straight into a C# struct so it only has to get into fiddling with the bytes when 2 or more values are packed into the same single byte.

    The closed source Android port gets the byte array from the datagram then does

    Code:
    // rawData[0] and [1] are version information
    int frameTypeAndSequence = rawData[2] & 0xFF;
    int frameType = frameTypeAndSequence & 3;// 0, 1, or 2
    int sequence = frameTypeAndSequence >> 2; // the sequence number in the type 0 packets
    it then has to manually unpack the byte array into an object, iterating over the byte array and keeping an offset value each time it gets another value from the array - stuff like

    Code:
    private int getNextUInt8() {
                int i = this.data[this.offset] & 0xFF;
                this.offset++;
                return i;
    }
    private int getNextInt8() {
                int i = this.data[this.offset];
                this.offset++;
                return i;
            }
    
    private float getNextFloat() {
                float f = ByteBuffer.wrap(this.data, this.offset, 4).order(ByteOrder.LITTLE_ENDIAN).getFloat();
                this.offset = this.offset + 4;
                return f;
            }
    There are a few more of these helper methods that retrieve a Java type from one or more bytes and increment the counters as they go along. It's all quite fiddly and error-prone

    The calling code can then do stuff like this:

    Code:
    public void processRawData(byte[] rawData) {
                // start at 3 as we don't care about the build / version number (0 & 1) and the sequence and packet type (2)
                this.offset = 3;
                this.data = rawData;
                int gameAndSessionState = getNextUInt8();
                mGameState = gameAndSessionState & 7;
                mSessionState = gameAndSessionState >> 4;
                mViewedParticipantIndex = getNextInt8();
                mNumParticipants = getNextInt8();
    The following 2 users likes this Post: bradleyland, Lars Rosenquist


  5. #45
    GT5 Pilot
    Join Date
    Sep 2015
    Location
    Florida
    Posts
    1,181
    Platform
    PS4
    It seems odd that the shared memory API and the UDP stream API are documented in separate forums. I searched quite a bit in the 'PC - Technical Help & Support' section for UDP stream information to no avail. When Tim posted the link above, I was initially puzzled as to why I didn't find the UDP documentation in my searches. Then I noticed that the UDP thread is in the 'General Discussion' forum.

    Given the importance of both the shared memory and UDP stream documentation to application developers, would it be possible to get the UDP stream sticky'd to 'PC - Technical Help & Support' forum as well? If not, maybe Lars add a link to the UDP thread at the bottom of the first post?

  6. #46
    WMD Member Lars Rosenquist's Avatar
    Join Date
    Oct 2011
    Location
    The Netherlands
    Posts
    301
    Platform
    PC
    I added a small section about UDP with a link to the thread Tim mentioned.
    PC: i7-4790k/16GB/GTX970 4GB/Z97-PRO/Logitech G27/Xbox 360 Controller
    Laptop: i7-6700HQ/16GB/GTX1070 8GB/Xbox One Controller
    LT Profiler: Strength: 100% - Spring 0% - Damper 0% - Center Spring 0% - 900 degrees - game can change
    The following user likes this Post: bradleyland


  7. #47
    GT5 Pilot
    Join Date
    Sep 2015
    Location
    Florida
    Posts
    1,181
    Platform
    PS4
    Quote Originally Posted by mr_belowski View Post
    My PC (C#) code is open source, you're welcome to have a rummage around in here https://github.com/mrbelowski/r3e_crewchief_v3. This cheats a little though and just dumps the byte array straight into a C# struct so it only has to get into fiddling with the bytes when 2 or more values are packed into the same single byte.

    The closed source Android port gets the byte array from the datagram then does

    Code:
    // rawData[0] and [1] are version information
    int frameTypeAndSequence = rawData[2] & 0xFF;
    int frameType = frameTypeAndSequence & 3;// 0, 1, or 2
    int sequence = frameTypeAndSequence >> 2; // the sequence number in the type 0 packets
    it then has to manually unpack the byte array into an object, iterating over the byte array and keeping an offset value each time it gets another value from the array - stuff like

    Code:
    private int getNextUInt8() {
                int i = this.data[this.offset] & 0xFF;
                this.offset++;
                return i;
    }
    private int getNextInt8() {
                int i = this.data[this.offset];
                this.offset++;
                return i;
            }
    
    private float getNextFloat() {
                float f = ByteBuffer.wrap(this.data, this.offset, 4).order(ByteOrder.LITTLE_ENDIAN).getFloat();
                this.offset = this.offset + 4;
                return f;
            }
    There are a few more of these helper methods that retrieve a Java type from one or more bytes and increment the counters as they go along. It's all quite fiddly and error-prone

    The calling code can then do stuff like this:

    Code:
    public void processRawData(byte[] rawData) {
                // start at 3 as we don't care about the build / version number (0 & 1) and the sequence and packet type (2)
                this.offset = 3;
                this.data = rawData;
                int gameAndSessionState = getNextUInt8();
                mGameState = gameAndSessionState & 7;
                mSessionState = gameAndSessionState >> 4;
                mViewedParticipantIndex = getNextInt8();
                mNumParticipants = getNextInt8();
    Wow! I can't tell you how much I appreciate you open-sourcing your code. I'm a Ruby programmer, so all the C stuff is pretty deep for me, but I have uncovered some interesting things about the way TelemetryData is packed in the UDP stream. I'm using a Ruby library called BinData to parse the stream (example [incomplete] Gist below). I quickly stumbled upon the fiddly bits you're referring to. What's interesting is that it's really only fiddly if you treat the values as the types specified in the TelemetryData examples. If your library supports additional types (outside of the standard intN, uintN, etc), you can actually unpack much of the data directly.

    For example the sGameSessionState field is specified as uint8 in the sTelemetryData struct.

    Code:
      u8    sGameSessionState;            // 3
    However, in we can see that this is actually a packed set of bytes (composed of two 4-bit values) when we look at how sGameSessionState is created from the SharedMemory struct:

    Code:
              // Game state
              mTelemetryData.sGameSessionState=((u8)pMemory->mGameState)|(((u8)pMemory->mSessionState)<<4);                     // (enum 3 bits/enum 3 bits)->u8
    Initially, I was specifying sGameSessionState as a uint8 using the BinData library, then unpacking the bits, but after I started dissecting this code, I shifted strategies. Instead, I used BinData's bit4 data type to extract 4 bytes at a time.

    I'm not sure if anything like BinData exists for C#, but it's made working with this UDP payload much easier for me.

    https://gist.github.com/bradland/910...e-pcars_net-rb

  8. #48
    Rookie
    Join Date
    Jun 2016
    Posts
    1
    Platform
    PC

    Question

    Hi guys,
    would you please tell me what is the main difference between mLocalAcceleration and mWorldAcceleration in the game data?

  9. #49
    Kart Driver
    Join Date
    Nov 2015
    Location
    Moncton, NB
    Posts
    10
    Platform
    PC
    I'm not sure if anyone is monitoring this particular section in the forum but I am going to post anyway. Has anyone noticed that sometimes other real drivers are not in the data stream? With the assistance of some very talented people here, I have put a little visual studio app together that reads the data stream and writes it into a text file as a log that I later load into a database and use for scoring. We have run 7 races with no issues and all of a sudden, last night none of the other real drivers were ever reported in the telemetry at all for any of the sessions. I have not made any changes to my app that reads the data since the first event. Just curious if anyone else has ever seen this activity.

  10. #50
    Superkart Pilot Chawabax's Avatar
    Join Date
    Aug 2015
    Location
    Udine (ITA)
    Posts
    254
    Platform
    PS4
    Quote Originally Posted by Scott Mullin View Post
    I'm not sure if anyone is monitoring this particular section in the forum but I am going to post anyway. Has anyone noticed that sometimes other real drivers are not in the data stream? With the assistance of some very talented people here, I have put a little visual studio app together that reads the data stream and writes it into a text file as a log that I later load into a database and use for scoring. We have run 7 races with no issues and all of a sudden, last night none of the other real drivers were ever reported in the telemetry at all for any of the sessions. I have not made any changes to my app that reads the data since the first event. Just curious if anyone else has ever seen this activity.
    What do you mean with "OTHER real drivers" ?
    Your data were correct in the telemetry but no other driver data on it?
    or no data at all ?

    UDP or shared memory?

Similar Threads

  1. [Solved - Shared Memory] Geko system GS 105 dynamic seat
    By stf_m in forum PC - Technical Help & Support
    Replies: 3
    Last Post: 15-06-2015, 14:39
  2. Just how hard is it then to make a game like Project Cars
    By KK78 in forum General Discussion
    Replies: 27
    Last Post: 10-06-2015, 21:31
  3. How to make cars less twitchy?
    By MilkyBarKid16 in forum General Discussion
    Replies: 11
    Last Post: 04-06-2015, 18:25
  4. Project Cars audio make me headache with headphone !!!
    By paulguru in forum General Discussion
    Replies: 38
    Last Post: 02-06-2015, 22:31
  5. [ANSWERED] what its shared memory
    By Chanur in forum PC - Technical Help & Support
    Replies: 7
    Last Post: 08-05-2015, 21:34

Tags for this Thread

Posting Permissions

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