eckhchri / pcars-ds-liveview

Provides a html page for project cars dedicated server and display a map of the current race.
14 stars 1 forks source link

Using http://cars-rest-api.com/ #23

Closed eckhchri closed 8 years ago

eckhchri commented 9 years ago

Use Rest API instead of DS. Maybe faster polling of Data.

viper4gh commented 9 years ago

DS API response:


{ "result" : "ok", "response" : { "state" : "Idle", "name" : "", "lobbyid" : "0", "joinable" : false, "max_member_count" : 0, "now" : 1438927720, "attributes" : { "GridSize" : 0, "MaxPlayers" : 0, "Practice1Length" : 0, "Practice2Length" : 0, "QualifyLength" : 0, "WarmupLength" : 0, "Race1Length" : 0, "Race2Length" : 0, "Flags" : 0, "Privacy" : 0, "DamageType" : 0, "TireWearType" : 0, "FuelUsageType" : 0, "PenaltiesType" : 0, "AllowedViews" : 0, "TrackId" : 0, "VehicleGroupId" : 0, "VehicleModelId" : 0, "DateYear" : 0, "DateMonth" : 0, "DateDay" : 0, "DateHour" : 0, "DateMinute" : 0, "DateProgression" : 0, "ForecastProgression" : 0, "WeatherSlots" : 0, "WeatherSlot1" : 0, "WeatherSlot2" : 0, "WeatherSlot3" : 0, "WeatherSlot4" : 0, "GameMode" : 0, "SessionState" : "", "SessionStage" : "", "SessionPhase" : "", "SessionTimeElapsed" : 0, "SessionTimeDuration" : 0, "NumParticipantsValid" : 0, "NumParticipantsDisqualified" : 0, "NumParticipantsRetired" : 0, "NumParticipantsDNF" : 0, "NumParticipantsFinished" : 0 }, "members" : [], "participants" : [] } }

Game API response:


{ "buildinfo": { "mVersion": 5, "mBuildVersionNumber": 917 }, "gameStates": { "mGameState": 3, "mSessionState": 5, "mRaceState": 2 }, "participants": { "mViewedParticipantIndex": 0, "mNumParticipants": 18, "mParticipantInfo": [ { "mIsActive": true, "mName": "Lars Rosenquist", "mWorldPosition": [ 197.58, 20.4255, 226.268 ], "mCurrentLapDistance": 400.639, "mRacePosition": 9, "mLapsCompleted": 0, "mCurrentLap": 1, "mCurrentSector": 1 }, { "mIsActive": true, "mName": "Harald Immervoll", "mWorldPosition": [ 162.489, 30.1042, 143.497 ], "mCurrentLapDistance": 492.188, "mRacePosition": 5, "mLapsCompleted": 0, "mCurrentLap": 1, "mCurrentSector": 1 }, . . . } ] }, "unfilteredInput": { "mUnfilteredThrottle": 1, "mUnfilteredBrake": 0, "mUnfilteredSteering": 0, "mUnfilteredClutch": 0 }, "vehicleInformation": { "mCarName": "Renault Megane R.S. 265", "mCarClassName": "Road C2" }, "eventInformation": { "mLapsInEvent": 10, "mTrackLocation": "Azure Circuit", "mTrackVariation": "Grand Prix", "mTrackLength": 3325.76 }, "timings": { "mLapInvalidated": false, "mBestLapTime": -1, "mLastLapTime": -1, "mCurrentTime": 25.231, "mSplitTimeAhead": 1.02798, "mSplitTimeBehind": 0.194626, "mSplitTime": 0, "mEventTimeRemaining": -1, "mPersonalFastestLapTime": -1, "mWorldFastestLapTime": 115.046, "mCurrentSector1Time": -1, "mCurrentSector2Time": -1, "mCurrentSector3Time": -1, "mFastestSector1Time": -1, "mFastestSector2Time": -1, "mFastestSector3Time": -1, "mPersonalFastestSector1Time": -1, "mPersonalFastestSector2Time": -1, "mPersonalFastestSector3Time": -1, "mWorldFastestSector1Time": 33.497, "mWorldFastestSector2Time": 40.074, "mWorldFastestSector3Time": 41.475 }, "flags": { "mHighestFlagColour": 0, "mHighestFlagReason": 0 }, "pitInfo": { "mPitMode": 0, "mPitSchedule": 0 }, "carState": { "mCarFlags": 2, "mOilTempCelsius": 52.7033, "mWaterTempCelsius": 49.0548, "mWaterPressureKPa": 182.547, "mFuelPressureKPa": 58.5, "mFuelLevel": 0.391907, "mFuelCapacity": 60, "mSpeed": 32.9303, "mRpm": 5871.44, "mMaxRPM": 6500, "mBrake": 0, "mThrottle": 1, "mClutch": 0, "mSteering": -0.0000142459, "mGear": 3, "mNumGears": 6, "mOdometerKM": 58.2071, "mAntiLockActive": false, "mLastOpponentCollisionIndex": -1, "mLastOpponentCollisionMagnitude": 0, "mBoostActive": false, "mBoostAmount": 0 }, "motionAndDeviceRelated": { "mOrientation": [ 0.117326, 0.328209, 0.000313204 ], "mLocalVelocity": [ -0.00461388, -0.290465, -32.9289 ], "mWorldVelocity": [ -10.5572, 3.56614, -30.9876 ], "mAngularVelocity": [ -0.00724832, 0.0010549, 0.00358948 ], "mLocalAcceleration": [ 0.0248438, 0.194704, -2.17865 ], "mWorldAcceleration": [ -0.666669, 0.4484, -2.03459 ], "mExtentsCentre": [ -0.00000500679, 0.790445, -0.0407101 ] }, "wheelsAndTyres": { "mTyreFlags": [ 7, 7, 7, 7 ], "mTerrain": [ 0, 0, 0, 0 ], "mTyreY": [ 0.0782597, 0.0768357, 0.095097, 0.0931077 ], "mTyreRPS": [ -105.846, -105.864, -101.137, -101.143 ], "mTyreSlipSpeed": [ 1.34283, 1.36286, 0.199473, 0.152253 ], "mTyreTemp": [ 68.5149, 67.8133, 65.189, 65.1095 ], "mTyreGrip": [ 0.644026, 0.634983, 0.933223, 0.948769 ], "mTyreHeightAboveGround": [ -0.0149067, -0.0127458, -0.0095718, -0.00830468 ], "mTyreLateralStiffness": [ 250000, 250000, 250000, 250000 ], "mTyreWear": [ 0.00380903, 0.00269157, 0.000451088, 0.000247836 ], "mBrakeDamage": [ 0, 0, 0, 0 ], "mSuspensionDamage": [ 0, 0, 0, 0 ], "mBrakeTempCelsius": [ 295.939, 291.019, 293.714, 290.159 ], "mTyreTreadTemp": [ 341.801, 341.19, 338.399, 338.32 ], "mTyreLayerTemp": [ 346.098, 341.062, 325.991, 324.604 ], "mTyreCarcassTemp": [ 349.172, 347.887, 345.994, 345.379 ], "mTyreRimTemp": [ 353.915, 353.854, 356.897, 356.825 ], "mTyreInternalAirTemp": [ 350.446, 349.533, 349.373, 348.919 ] }, "carDamage": { "mCrashState": 0, "mAeroDamage": 0, "mEngineDamage": 1.19209e-7 }, "weather": { "mAmbientTemperature": 24.3459, "mTrackTemperature": 34.5188, "mRainDensity": 0, "mWindSpeed": 9.17293, "mWindDirectionX": 0.707107, "mWindDirectionY": -0.707107, "mCloudBrightness": 2.61409 } }

viper4gh commented 9 years ago

2 Probleme:

viper4gh commented 9 years ago

Aufruf: http://localhost:8080/crest/v1/api Das JSON Ergebnis kann dann in folgendem Stil geparst werden: myArr.participants.mParticipantInfo[i].mName, myArr.participants.mParticipantInfo[i].mRacePosition, myArr.participants.mParticipantInfo[i].mWorldPosition[0] * 1000, //PosX myArr.participants.mParticipantInfo[i].mWorldPosition[1] * 1000, //PosY myArr.participants.mParticipantInfo[i].mWorldPosition[2] * 1000 //PosZ

Positionsdaten sind in Metern, wir rechnen aber wegen der DS API in Millimetern, deshalb mal 1000

viper4gh commented 9 years ago

Da die Game API nicht alle Variablen enthält, macht es Sinn z.B. an folgender Stelle ein assoziatives Array zu benutzen anstatt dem festen Objekt: https://github.com/eckhchri/pcars-ds-liveview/blob/master/receive_ds_data.js#L147 Sonst müsste man die fehlenden Objektvariablen mit Dummy Daten füllen.