PDA

View Full Version : CREST - a.k.a. Cars REST API



Lars Rosenquist
11-06-2015, 06:26
Introducing CREST - also known as the CARS REST API

Project type: Data server/API.

Project status: 1.0.2 has been released.

Project web site: http://www.cars-rest-api.com

Public repository: https://github.com/NLxAROSA/CREST

Description:

This project provides a way for developers to have access to the data provided by pCars Shared Memory in a more portable and accessible format than a mapped memory file. It's a windows native command line application (written in C++ and a fair bit of plain old C) that will act as a local web/application server and serve the data via JSON over HTTP by accessing a URL. Any web browser or HTTP client will be able to access the data both locally and inside the local network, which facilitates easy add-on development in any language (e.g. JavaScript, Java, C, C++, C#, etc. etc.) and platform (e.g. web browser, iOS, Android, Windows Phone or other) with a vast array of client REST libraries at your disposal.

I started this mainly for myself to play around with the pCars Shared Memory SDK/API and to brush up on the good 'ol C/C++ skills, but decided to make it available to the general public for free. Since I'm using a couple of libraries that are licensed with the GNU GPL (http://www.gnu.org/copyleft/gpl.html) license.

Screenshots:

207102

Sample JSON

Click here (http://www.cars-rest-api.com/#data).

Current build:

Download link available at this location (http://www.cars-rest-api.com/#downloads).

Installation instructions

1. Download the source code from the Github repository and build/run it in Visual Studio (check the README for instructions).

- OR -

1. Download the application from the download link at this location (http://www.cars-rest-api.com/#downloads).
2. Start the application by double-clicking it.
3. Windows will complain about security (coming from an unknown/unverified source) both when downloading and starting the application. Please allow/unblock the application in order to allow it to start. Windows Firewall will also ask for permission to access the local network. Please allow it access for proper functioning.
4. If Windows complains about missing DLLs (e.g. MSVCR120.DLL or similar), please download and install the Visual C++ Redistributable Packages for Visual Studio 2013 from http://www.microsoft.com/en-us/download/details.aspx?id=40784 (vcredist_x86.exe), then start again.
5. Console will show a notification about the server being up and running and display port and URL information.

Connecting to Project CARS

1. Start Project CARS.
2. Enable Shared Memory in Options -> Visual -> Hardware
3. Open up a browser (Chrome works best) and go to http://localhost:8080/crest/v1/api
4. Profit! F5/Refresh until you drop!

Known issues:

Issues are listed in GitHub: https://github.com/NLxAROSA/CREST/issues.
Feel free to add bugs you may find, or feature requests, etc.

bendoe
13-11-2015, 20:47
Hi

I discovered that the Speed value in CREST (V.1.0.2) is wrong. When I drive with 100km/h the value "mSpeed" is 23 or little bit higher. I run the
standard json-request from the example. No own code!

As first I thinked that I have to convert from miles to kilometer, but that is not the solution.

Has anybody make the same discovery?

bendoe
14-11-2015, 04:13
OK, the Problem is solved. The value mSpeed is "Meter per Second"! :)

Sorry for the confusion!

Lars Rosenquist
15-11-2015, 08:53
No worries, it can get confusing sometimes, and bugs do happen, so always report if you think something is out of the ordinary. ;)

BulletEyeDK
09-01-2016, 12:05
Hi Lars, is this API working for console network data also?

TonyR
12-02-2016, 11:16
Thank you very much for creating this. It is a great help to add streaming tools via a website, wonderful!

TonyR
12-02-2016, 14:39
One thing though, it seems that Unicode characters like German umlauts are not available. Is that due to the Shared Mem or the Crest App?

Lars Rosenquist
14-02-2016, 13:53
Looking into this right now, not sure where the problem is just yet, but if it's on my end I'll fix it.

TonyR
15-02-2016, 00:37
Looking into this right now, not sure where the problem is just yet, but if it's on my end I'll fix it.

It's really strange Lars. When I'm showing the REST Url http://localhost:8080/crest/v1/api?participants=true in my browser all participant names are correct (Unicode characters correctly displayed).

So I now assume the problem is on my side :/ But I'm receiving the REST data with "$.getJSON('http://localhost:8080/crest/v1/api?participants=true', ....." (and displaying this raw data with Chrome console.log already shows wrongly displayed characters)
Not sure what can be wrong with that.

Lars Rosenquist
15-02-2016, 06:48
Sounds like a classical encoding issue to me. :) So what happens is that CREST returns the output (but it doesn't specifiy which encoding on the Content-Type header) and when rendered in your browser, Chrome correctly guesses (or defaults to) the correct encoding and displays it properly. The same probably does not apply to the console (or your) app, which probably defaults to the default system encoding (probably latin if it's Windows) instead of UTF-8. What I can do on my end is add the specific charset (UTF-8) to the Content-Type header. That should prevent any guessing about the charset on the client end. Quick fix on my end, so if I'm not interrupted I can have that out by tonight.

TonyR
15-02-2016, 10:49
Sounds like a classical encoding issue to me. :) So what happens is that CREST returns the output (but it doesn't specifiy which encoding on the Content-Type header) and when rendered in your browser, Chrome correctly guesses (or defaults to) the correct encoding and displays it properly. The same probably does not apply to the console (or your) app, which probably defaults to the default system encoding (probably latin if it's Windows) instead of UTF-8. What I can do on my end is add the specific charset (UTF-8) to the Content-Type header. That should prevent any guessing about the charset on the client end. Quick fix on my end, so if I'm not interrupted I can have that out by tonight.

Sounds good!

I tried everything last night. Also using XMLHttpRequest with the correct encoding in the headers but that didn't bring the result I wanted as well, really strange. But then again I haven't coded Javascript stuff for at least 2 years so the problem could still sit in front of the PC haha.

Lars Rosenquist
15-02-2016, 15:39
Did some looking up, UTF-8 is actually the default encoding for JSON (by spec), so there is no need to specify it. Hence why it's picked up automatically when rendered by Chrome. So I'm assuming your client is setting up a different locale/encoding somehow. I guess it could be something as simple as your files not being saved in UTF8, but some other encoding. http://stackoverflow.com/questions/6790593/utf-8-and-javascript

TonyR
15-02-2016, 20:19
Did some looking up, UTF-8 is actually the default encoding for JSON (by spec), so there is no need to specify it. Hence why it's picked up automatically when rendered by Chrome. So I'm assuming your client is setting up a different locale/encoding somehow. I guess it could be something as simple as your files not being saved in UTF8, but some other encoding. http://stackoverflow.com/questions/6790593/utf-8-and-javascript

I'm using Notepad++ and every file is encoded in utf-8:
http://i.imgur.com/8r8FDlz.png

Also the jquery file and css file, everything is in utf-8, I also put it into all headers :D I really don't know what is causing the problem, maybe for someone else on other systems it works correctly? I don't know. But thanks for your time, very much appreciated.

azidahaka
17-02-2016, 10:40
If i'm correct it just works on pc so no UDP support?

TonyR
17-02-2016, 11:02
If i'm correct it just works on pc so no UDP support?

That's correct. It would be awesome to have UDP, what do you think, Lars? ;)

Lars Rosenquist
17-02-2016, 15:48
If i'm correct it just works on pc so no UDP support?
Yes, I made this when only shared memory mapped file was available to make it easier for non-C developers to create their apps. Since Project CARS now has native UDP support, it's kind of obsolete, as it's a lot easier to connect to it now.


That's correct. It would be awesome to have UDP, what do you think, Lars? ;)
What kind of UDP support would you like to see? Streaming JSON over UDP?

TonyR
17-02-2016, 15:55
What kind of UDP support would you like to see? Streaming JSON over UDP?

Yeah, as far as I know it's not possible to receive UDP by Javascript because of safety concerns (DDos).
So basically the same as of now (JSON) with the additional data that UDP provides :)

TonyR
17-02-2016, 22:42
A problem, sometimes the API doesn't put out names. I know, that is hard to replicate at your place. But if you join a random online lobby it happens quite often:

----

{"participants":{"mViewedParticipantIndex":15,"mNumParticipants":17,"mParticipantInfo":[{"mIsActive":true,"mName":"TRT jotamaia_BR","mWorldPosition":[776.324,9.26852,338.17],"mCurrentLapDistance":0,"mRacePosition":17,"mLapsCompleted":0,"mCurrentLap":1,"mCurrentSector":3},{"mIsActive":true,"mName":"Paulo Preto (DF)","mWorldPosition":[341.517,1.24311,550.702],"mCurrentLapDistance":0,"mRacePosition":1,"mLapsCompleted":3,"mCurrentLap":4,"mCurrentSector":3},{"mIsActive":true,"mName":"malexandrehenrique","mWorldPosition":[810.65,10.4578,370.411],"mCurrentLapDistance":0,"mRacePosition":5,"mLapsCompleted":7,"mCurrentLap":8,"mCurrentSector":3},{"mIsActive":true,"mName":"vitinhopanisson","mWorldPosition":[910.253,8.12603,101.86],"mCurrentLapDistance":0,"mRacePosition":12,"mLapsCompleted":0,"mCurrentLap":1,"mCurrentSector":3},{"mIsActive":true,"mName":"FriskyPredat0r","mWorldPosition":[640.22,8.13123,130.922],"mCurrentLapDistance":0,"mRacePosition":6,"mLapsCompleted":0,"mCurrentLap":1,"mCurrentSector":3},{"mIsActive":true,"mName":"Brunomlenz","mWorldPosition":[1154.1,5.68703,546.338],"mCurrentLapDistance":0,"mRacePosition":2,"mLapsCompleted":5,"mCurrentLap":6,"mCurrentSector":2},{"mIsActive":true,"mName":"L. JUNIOR ","mWorldPosition":[899.378,4.75739,434.99],"mCurrentLapDistance":0,"mRacePosition":16,"mLapsCompleted":3,"mCurrentLap":4,"mCurrentSector":3},{"mIsActive":true,"mName":"Banner","mWorldPosition":[231.931,9.82335,108.25],"mCurrentLapDistance":0,"mRacePosition":4,"mLapsCompleted":2,"mCurrentLap":3,"mCurrentSector":3},{"mIsActive":true,"mName":"boudha","mWorldPosition":[751.659,8.13118,125.039],"mCurrentLapDistance":0,"mRacePosition":14,"mLapsCompleted":0,"mCurrentLap":1,"mCurrentSector":3},[B]{"mIsActive":true,"mName":"","mWorldPosition":[1153.18,5.09807,561.709],"mCurrentLapDistance":0,"mRacePosition":15,"mLapsCompleted":0,"mCurrentLap":1,"mCurrentSector":3},{"mIsActive":true,"mName":":-) ' Mr_Magoo","mWorldPosition":[74.9573,5.09253,464.049],"mCurrentLapDistance":0,"mRacePosition":3,"mLapsCompleted":4,"mCurrentLap":5,"mCurrentSector":2},{"mIsActive":true,"mName":"AOD_lepetit [TKR]","mWorldPosition":[1427.25,16.2283,361.274],"mCurrentLapDistance":0,"mRacePosition":13,"mLapsCompleted":0,"mCurrentLap":1,"mCurrentSector":3},{"mIsActive":true,"mName":"TheGermanTankmaster09","mWorldPosition":[113.545,6.0523,546.25],"mCurrentLapDistance":0,"mRacePosition":7,"mLapsCompleted":0,"mCurrentLap":1,"mCurrentSector":3},{"mIsActive":true,"mName":"FCampos_2000","mWorldPosition":[103.487,0.870481,306.414],"mCurrentLapDistance":0,"mRacePosition":11,"mLapsCompleted":0,"mCurrentLap":1,"mCurrentSector":3},{"mIsActive":true,"mName":"","mWorldPosition":[165.815,8.14285,137.765],"mCurrentLapDistance":0,"mRacePosition":10,"mLapsCompleted":0,"mCurrentLap":1,"mCurrentSector":3},{"mIsActive":true,"mName":"TonyR","mWorldPosition":[593.93,8.12294,133.146],"mCurrentLapDistance":0,"mRacePosition":8,"mLapsCompleted":0,"mCurrentLap":1,"mCurrentSector":3},{"mIsActive":true,"mName":"GiBoiauM-[BR]","mWorldPosition":[176.452,6.42413,622.426],"mCurrentLapDistance":0,"mRacePosition":9,"mLapsCompleted":0,"mCurrentLap":1,"mCurrentSector":3}]}}

----

This has nothing to do with unicode btw as it's already missing if I display the data with my browser :)

azidahaka
18-02-2016, 11:44
I'm looking for a software that will create a kind of race report like lap by lap standings, fastest laps for each driver, when one pits and similar informations...

Outputting live timing would be an outstanding extra

Lars Rosenquist
19-02-2016, 12:19
[751.659,8.13118,125.039],"mCurrentLapDistance":0,"mRacePosition":14,"mLapsCompleted":0,"mCurrentLap":1,"mCurrentSector":3},{"mIsActive":true,"mName":"","mWorldPosition":
Seems like it's missing in SharedMemory already. All I do is stream the struct value into the response (see my sourcecode (https://github.com/NLxAROSA/CREST/blob/master/SharedMemoryRenderer.cpp)). Since it's the only field missing I don't think it's a synchronization issue. I might reconsider rewriting CREST to use UDP rather than SharedMemory, but that will take some time. Might as well ditch Fossa for Proxygen in the process as well. :P


I'm looking for a software that will create a kind of race report like lap by lap standings, fastest laps for each driver, when one pits and similar informations...

Outputting live timing would be an outstanding extraWith SharedMemory at least (not sure about UDP), the information you get for all the others drivers is limited, timings are only received for the player itself, not the other participant. Lap standings are possible. Pit info is also for current player only. So for single player this is not possible. Multiplayer could work, if all use the same software.

Haven't looked into UDP yet and what it offers extra compared to SharedMemory.

TonyR
19-02-2016, 14:00
Seems like it's missing in SharedMemory already. All I do is stream the struct value into the response (see my sourcecode (https://github.com/NLxAROSA/CREST/blob/master/SharedMemoryRenderer.cpp)). Since it's the only field missing I don't think it's a synchronization issue. I might reconsider rewriting CREST to use UDP rather than SharedMemory, but that will take some time. Might as well ditch Fossa for Proxygen in the process as well. :P

With SharedMemory at least (not sure about UDP), the information you get for all the others drivers is limited, timings are only received for the player itself, not the other participant. Lap standings are possible. Pit info is also for current player only. So for single player this is not possible. Multiplayer could work, if all use the same software.

Haven't looked into UDP yet and what it offers extra compared to SharedMemory.

Lars, take your time, no need to rush but it would be really nice to have CREST working with UDP one day :)

In the UDP there are lap time information about all participants, that's a main advantage as well as a "class name" variable which would allow to improve my iracing like "relative" widget further.

Ramiboo
23-02-2016, 12:45
Hey TonyR!!!!!

Have you tried to use Overwolf to bring your browser screens into the game and not just in the broadcast?

Edit: Sorry meant to put this on tony's streamer help thread.... Thanks for your hard work on this Lars!