-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForzaApi.java
More file actions
916 lines (796 loc) · 32.3 KB
/
ForzaApi.java
File metadata and controls
916 lines (796 loc) · 32.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
package root.forza.telemetry;
import androidx.annotation.NonNull;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.text.DecimalFormat;
public class ForzaApi {
public static final int PACKET_SIZE = 323;
private final boolean isRaceOn;
private final Long timeStampMS;
private final Float engineMaxRpm;
private final Float engineIdleRpm;
private final Float currentEngineRpm;
private final Float accelerationX;
private final Float accelerationY;
private final Float accelerationZ;
private final Float velocityX;
private final Float velocityY;
private final Float velocityZ;
private final Float angularVelocityX;
private final Float angularVelocityY;
private final Float angularVelocityZ;
private final Float yaw;
private final Float pitch;
private final Float roll;
private final Float normalizedSuspensionTravelFrontLeft;
private final Float normalizedSuspensionTravelFrontRight;
private final Float normalizedSuspensionTravelRearLeft;
private final Float normalizedSuspensionTravelRearRight;
private final Float tireSlipRatioFrontLeft;
private final Float tireSlipRatioFrontRight;
private final Float tireSlipRatioRearLeft;
private final Float tireSlipRatioRearRight;
private final Float wheelRotationSpeedFrontLeft;
private final Float wheelRotationSpeedFrontRight;
private final Float wheelRotationSpeedRearLeft;
private final Float wheelRotationSpeedRearRight;
private final Integer wheelOnRumbleStripFrontLeft;
private final Integer wheelOnRumbleStripFrontRight;
private final Integer wheelOnRumbleStripRearLeft;
private final Integer wheelOnRumbleStripRearRight;
private final Float wheelInPuddleDepthFrontLeft;
private final Float wheelInPuddleDepthFrontRight;
private final Float wheelInPuddleDepthRearLeft;
private final Float wheelInPuddleDepthRearRight;
private final Float surfaceRumbleFrontLeft;
private final Float surfaceRumbleFrontRight;
private final Float surfaceRumbleRearLeft;
private final Float surfaceRumbleRearRight;
private final Float tireSlipAngleFrontLeft;
private final Float tireSlipAngleFrontRight;
private final Float tireSlipAngleRearLeft;
private final Float tireSlipAngleRearRight;
private final Float tireCombinedSlipFrontLeft;
private final Float tireCombinedSlipFrontRight;
private final Float tireCombinedSlipRearLeft;
private final Float tireCombinedSlipRearRight;
private final Float suspensionTravelMetersFrontLeft;
private final Float suspensionTravelMetersFrontRight;
private final Float suspensionTravelMetersRearLeft;
private final Float suspensionTravelMetersRearRight;
private final Integer carClass;
private final Integer carPerformanceIndex;
private final Integer drivetrainType;
private final Integer numCylinders;
private final Integer carType;
private final Long objectHit;
//private final Byte unknown1;
//private final Byte unknown2;
//private final Byte unknown3;
//private final Byte unknown4;
//private final Byte unknown5;
//private final Byte unknown6;
//private final Byte unknown7;
//private final Byte unknown8;
private final Integer carOrdinal;
private final Float positionX;
private final Float positionY;
private final Float positionZ;
private final Float speed;
private final Float power;
private final Float torque;
private final Float tireTempFrontLeft;
private final Float tireTempFrontRight;
private final Float tireTempRearLeft;
private final Float tireTempRearRight;
private final Float boost;
private final Float fuel;
private final Float distanceTraveled;
private final Float bestLap;
private final Float lastLap;
private final Float currentLap;
private final Float currentRaceTime;
private final Short lapNumber;
private final Byte racePosition;
private final Byte throttle;
private final Byte brake;
private final Byte clutch;
private final Byte handbrake;
private final Byte gear;
private final Byte steer;
private final Byte normalizedDrivingLine;
private final Byte normalizedAIBrakeDifference;
DecimalFormat df;
public ForzaApi(byte[] bytes) throws Exception {
//Check that all 323 bytes were received
if (bytes.length < PACKET_SIZE) {
try {
throw new Exception("Invalid byte length");
} catch (Exception e) {
e.printStackTrace();
}
}
//Set decimal formatting
df = new DecimalFormat("###.##");
df.setRoundingMode(RoundingMode.DOWN);
//Wrap bytes in a ByteBuffer for faster parsing. The encoding is in Little Endian
ByteBuffer bb = ByteBuffer.wrap(bytes);
bb.order(ByteOrder.LITTLE_ENDIAN);
//Set data by going through the bytebuffer
isRaceOn = getFromBuffer(bb, int.class) == 1;
timeStampMS = getFromBuffer(bb, long.class);
engineMaxRpm = getFromBuffer(bb, float.class);
engineIdleRpm = getFromBuffer(bb, float.class);
currentEngineRpm = getFromBuffer(bb, float.class);
accelerationX = getFromBuffer(bb, float.class);
accelerationY = getFromBuffer(bb, float.class);
accelerationZ = getFromBuffer(bb, float.class);
velocityX = getFromBuffer(bb, float.class);
velocityY = getFromBuffer(bb, float.class);
velocityZ = getFromBuffer(bb, float.class);
angularVelocityX = getFromBuffer(bb, float.class);
angularVelocityY = getFromBuffer(bb, float.class);
angularVelocityZ = getFromBuffer(bb, float.class);
yaw = getFromBuffer(bb, float.class);
pitch = getFromBuffer(bb, float.class);
roll = getFromBuffer(bb, float.class);
normalizedSuspensionTravelFrontLeft = getFromBuffer(bb, float.class);
normalizedSuspensionTravelFrontRight = getFromBuffer(bb, float.class);
normalizedSuspensionTravelRearLeft = getFromBuffer(bb, float.class);
normalizedSuspensionTravelRearRight = getFromBuffer(bb, float.class);
tireSlipRatioFrontLeft = getFromBuffer(bb, float.class);
tireSlipRatioFrontRight = getFromBuffer(bb, float.class);
tireSlipRatioRearLeft = getFromBuffer(bb, float.class);
tireSlipRatioRearRight = getFromBuffer(bb, float.class);
wheelRotationSpeedFrontLeft = getFromBuffer(bb, float.class);
wheelRotationSpeedFrontRight = getFromBuffer(bb, float.class);
wheelRotationSpeedRearLeft = getFromBuffer(bb, float.class);
wheelRotationSpeedRearRight = getFromBuffer(bb, float.class);
wheelOnRumbleStripFrontLeft = getFromBuffer(bb, int.class);
wheelOnRumbleStripFrontRight = getFromBuffer(bb, int.class);
wheelOnRumbleStripRearLeft = getFromBuffer(bb, int.class);
wheelOnRumbleStripRearRight = getFromBuffer(bb, int.class);
wheelInPuddleDepthFrontLeft = getFromBuffer(bb, float.class);
wheelInPuddleDepthFrontRight = getFromBuffer(bb, float.class);
wheelInPuddleDepthRearLeft = getFromBuffer(bb, float.class);
wheelInPuddleDepthRearRight = getFromBuffer(bb, float.class);
surfaceRumbleFrontLeft = getFromBuffer(bb, float.class);
surfaceRumbleFrontRight = getFromBuffer(bb, float.class);
surfaceRumbleRearLeft = getFromBuffer(bb, float.class);
surfaceRumbleRearRight = getFromBuffer(bb, float.class);
tireSlipAngleFrontLeft = getFromBuffer(bb, float.class);
tireSlipAngleFrontRight = getFromBuffer(bb, float.class);
tireSlipAngleRearLeft = getFromBuffer(bb, float.class);
tireSlipAngleRearRight = getFromBuffer(bb, float.class);
tireCombinedSlipFrontLeft = getFromBuffer(bb, float.class);
tireCombinedSlipFrontRight = getFromBuffer(bb, float.class);
tireCombinedSlipRearLeft = getFromBuffer(bb, float.class);
tireCombinedSlipRearRight = getFromBuffer(bb, float.class);
suspensionTravelMetersFrontLeft = getFromBuffer(bb, float.class);
suspensionTravelMetersFrontRight = getFromBuffer(bb, float.class);
suspensionTravelMetersRearLeft = getFromBuffer(bb, float.class);
suspensionTravelMetersRearRight = getFromBuffer(bb, float.class);
carOrdinal = getFromBuffer(bb, int.class);
carClass = getFromBuffer(bb, int.class);
carPerformanceIndex = getFromBuffer(bb, int.class);
drivetrainType = getFromBuffer(bb, int.class);
numCylinders = getFromBuffer(bb, int.class);
carType = getFromBuffer(bb, int.class);
objectHit = getFromBuffer(bb);
positionX = getFromBuffer(bb, float.class);
positionY = getFromBuffer(bb, float.class);
positionZ = getFromBuffer(bb, float.class);
speed = getFromBuffer(bb, float.class);
power = getFromBuffer(bb, float.class);
torque = getFromBuffer(bb, float.class);
tireTempFrontLeft = getFromBuffer(bb, float.class);
tireTempFrontRight = getFromBuffer(bb, float.class);
tireTempRearLeft = getFromBuffer(bb, float.class);
tireTempRearRight = getFromBuffer(bb, float.class);
boost = getFromBuffer(bb, float.class);
fuel = getFromBuffer(bb, float.class);
distanceTraveled = getFromBuffer(bb, float.class);
bestLap = getFromBuffer(bb, float.class);
lastLap = getFromBuffer(bb, float.class);
currentLap = getFromBuffer(bb, float.class);
currentRaceTime = getFromBuffer(bb, float.class);
lapNumber = getFromBuffer(bb, short.class);
racePosition = getFromBuffer(bb, byte.class);
throttle = getFromBuffer(bb, byte.class);
brake = getFromBuffer(bb, byte.class);
clutch = getFromBuffer(bb, byte.class);
handbrake = getFromBuffer(bb, byte.class);
gear = getFromBuffer(bb, byte.class);
steer = getFromBuffer(bb, byte.class);
normalizedDrivingLine = getFromBuffer(bb, byte.class);
normalizedAIBrakeDifference = getFromBuffer(bb, byte.class);
}
//Method to check if selected type length is not overflowing the length of the bytebuffer
private static boolean checkBuffer(ByteBuffer buffer, int size) {
return buffer.hasRemaining() && buffer.remaining() >= size;
}
//Return data if requirements are met, sets default value to 0 otherwise
@SuppressWarnings("unchecked")
private static <T> T getFromBuffer(ByteBuffer buffer, Class<T> type) throws Exception {
switch (type.getName()) {
case "int":
return (T) (checkBuffer(buffer, 4) ? (Object) buffer.getInt() : 0);
case "long":
return (T) (checkBuffer(buffer, 4) ? (Object) Integer.toUnsignedLong(buffer.getInt()) : 0L);
case "byte":
return (T) (checkBuffer(buffer, 1) ? (Object) buffer.get() : 0);
case "float":
return (T) (checkBuffer(buffer, 4) ? (Object) buffer.getFloat() : 0f);
case "short":
return (T) (checkBuffer(buffer, 2) ? (Object) buffer.getShort() : 0);
}
throw new Exception("Invalid Type");
}
//Object hit workaround. The value returned is unknown. Forza Mystery!
@SuppressWarnings("unchecked")
private static <T> T getFromBuffer(ByteBuffer buffer) {
return (T) (checkBuffer(buffer, 1) ? (Object) buffer.getLong() : 0L);
}
/*
* GETTERS FOR FORZA HORIZON 5 UDP STREAM DATA OUT.
*/
public Boolean getIsRaceOn() {
return isRaceOn;
}
public Long getTimeStampMS() {
return timeStampMS;
}
public Integer getEngineMaxRpm() {
return Math.round(engineMaxRpm);
}
public Integer getEngineIdleRpm() {
return Math.round(engineIdleRpm);
}
public Integer getCurrentEngineRpm() {
return Math.round(currentEngineRpm);
}
public Integer getAccelerationX() {
return Math.round(accelerationX * 100);
}
public Integer getAccelerationY() {
return Math.round(accelerationY * 100);
}
public Integer getAccelerationZ() {
return Math.round(accelerationZ * 100);
}
public Integer getVelocityX() {
return Math.round(velocityX * 100);
}
public Integer getVelocityY() {
return Math.round(velocityY * 100);
}
public Integer getVelocityZ() {
return Math.round(velocityZ * 100);
}
public Integer getAngularVelocityX() {
return Math.round(angularVelocityX * 100);
}
public Integer getAngularVelocityY() {
return Math.round(angularVelocityY * 100);
}
public Integer getAngularVelocityZ() {
return Math.round(angularVelocityZ * 100);
}
public Integer getYaw() {
return Math.round(yaw * 100);
}
public Integer getPitch() {
return Math.round(pitch * 100);
}
public Integer getRoll() {
return Math.round(roll * 100);
}
public Integer getNormalizedSuspensionTravelFrontLeft() {
return Math.round(normalizedSuspensionTravelFrontLeft * 100);
}
public Integer getNormalizedSuspensionTravelFrontRight() {
return Math.round(normalizedSuspensionTravelFrontRight * 100);
}
public Integer getNormalizedSuspensionTravelRearLeft() {
return Math.round(normalizedSuspensionTravelRearLeft * 100);
}
public Integer getNormalizedSuspensionTravelRearRight() {
return Math.round(normalizedSuspensionTravelRearRight * 100);
}
public Integer getTireSlipRatioFrontLeft() {
return Math.round(tireSlipRatioFrontLeft * 100);
}
public Integer getTireSlipRatioFrontRight() {
return Math.round(tireSlipRatioFrontRight * 100);
}
public Integer getTireSlipRatioRearLeft() {
return Math.round(tireSlipRatioRearLeft * 100);
}
public Integer getTireSlipRatioRearRight() {
return Math.round(tireSlipRatioRearRight * 100);
}
public Integer getWheelRotationSpeedFrontLeft() {
return Math.round(wheelRotationSpeedFrontLeft * 100);
}
public Integer getWheelRotationSpeedFrontRight() {
return Math.round(wheelRotationSpeedFrontRight * 100);
}
public Integer getWheelRotationSpeedRearLeft() {
return Math.round(wheelRotationSpeedRearLeft * 100);
}
public Integer getWheelRotationSpeedRearRight() {
return Math.round(wheelRotationSpeedRearRight * 100);
}
public Integer getWheelOnRumbleStripFrontLeft() {
return wheelOnRumbleStripFrontLeft;
}
public Integer getWheelOnRumbleStripFrontRight() {
return wheelOnRumbleStripFrontRight;
}
public Integer getWheelOnRumbleStripRearLeft() {
return wheelOnRumbleStripRearLeft;
}
public Integer getWheelOnRumbleStripRearRight() {
return wheelOnRumbleStripRearRight;
}
public Float getWheelInPuddleDepthFrontLeft() {
return wheelInPuddleDepthFrontLeft;
}
public Float getWheelInPuddleDepthFrontRight() {
return wheelInPuddleDepthFrontRight;
}
public Float getWheelInPuddleDepthRearLeft() {
return wheelInPuddleDepthRearLeft;
}
public Float getWheelInPuddleDepthRearRight() {
return wheelInPuddleDepthRearRight;
}
public Float getSurfaceRumbleFrontLeft() {
return surfaceRumbleFrontLeft;
}
public Float getSurfaceRumbleFrontRight() {
return surfaceRumbleFrontRight;
}
public Float getSurfaceRumbleRearLeft() {
return surfaceRumbleRearLeft;
}
public Float getSurfaceRumbleRearRight() {
return surfaceRumbleRearRight;
}
public Long getTireSlipAngleFrontLeft() {
return angle(tireSlipAngleFrontLeft);
}
public Long getTireSlipAngleFrontRight() {
return angle(tireSlipAngleFrontRight);
}
public Long getTireSlipAngleRearLeft() {
return angle(tireSlipAngleRearLeft);
}
public Long getTireSlipAngleRearRight() {
return angle(tireSlipAngleRearRight);
}
public Integer getTireCombinedSlipFrontLeft() {
return Math.round(tireCombinedSlipFrontLeft * 100);
}
public Integer getTireCombinedSlipFrontRight() {
return Math.round(tireCombinedSlipFrontRight * 100);
}
public Integer getTireCombinedSlipRearLeft() {
return Math.round(tireCombinedSlipRearLeft * 100);
}
public Integer getTireCombinedSlipRearRight() {
return Math.round(tireCombinedSlipRearRight * 100);
}
public Integer getSuspensionTravelMetersFrontLeft() {
return Math.round(suspensionTravelMetersFrontLeft * 100);
}
public Integer getSuspensionTravelMetersFrontRight() {
return Math.round(suspensionTravelMetersFrontRight * 100);
}
public Integer getSuspensionTravelMetersRearLeft() {
return Math.round(suspensionTravelMetersRearLeft * 100);
}
public Integer getSuspensionTravelMetersRearRight() {
return Math.round(suspensionTravelMetersRearRight * 100);
}
public String getCarClass() {
switch (carClass) {
case 0:
return "D";
case 1:
return "C";
case 2:
return "B";
case 3:
return "A";
case 4:
return "S1";
case 5:
return "S2";
case 6:
return "X";
default:
return "-";
}
}
public Integer getCarPerformanceIndex() {
return carPerformanceIndex;
}
public String getDrivetrain() {
switch(drivetrainType){
case 0:
return "FWD";
case 1:
return "RWD";
case 2:
return "AWD";
default:
return "-";
}
}
public Integer getNumCylinders() {
return numCylinders;
}
public String getCarType() {
switch (carType) {
case 11:
return "Modern Super Cars";
case 12:
return "Retro Super Cars";
case 13:
return "Hyper Cars";
case 14:
return "Retro Saloons";
case 16:
return "Vans & Utility";
case 17:
return "Retro Sports Cars";
case 18:
return "Modern Sports Cars";
case 19:
return "Super Saloons";
case 20:
return "Classic Racers";
case 21:
return "Cult Cars";
case 22:
return "Rare Classics";
case 25:
return "Super Hot Hatch";
case 29:
return "Rods & Customs";
case 30:
return "Retro Muscle";
case 31:
return "Modern Muscle";
case 32:
return "Retro Rally";
case 33:
return "Classic Rally";
case 34:
return "Rally Monsters";
case 35:
return "Modern Rally";
case 36:
return "GT Cars";
case 37:
return "Super GT";
case 38:
return "Extreme Offroad";
case 39:
return "Sports Utility Heroes";
case 40:
return "Offroad";
case 41:
return "Offroad Buggies";
case 42:
return "Classic Sports Cars";
case 43:
return "Track Toys";
case 44:
return "Vintage Racers";
case 45:
return "Trucks";
default:
return "Unknown (" + carType + ")";
}
}
public Long getObjectHit() {
return objectHit;
}
// public Byte getUnknown1() {
// return unknown1;
// }
//
// public Byte getUnknown2() {
// return unknown2;
// }
//
// public Byte getUnknown3() {
// return unknown3;
// }
//
// public Byte getUnknown4() {
// return unknown4;
// }
//
// public Byte getUnknown5() {
// return unknown5;
// }
//
// public Byte getUnknown6() {
// return unknown6;
// }
//
// public Byte getUnknown7() {
// return unknown7;
// }
//
// public Byte getUnknown8() {
// return unknown8;
// }
public Integer getCarOrdinal() {
return carOrdinal;
}
public Integer getPositionX() {
return Math.round(positionX * 1000);
}
public Integer getPositionY() {
return Math.round(positionY * 1000);
}
public Integer getPositionZ() {
return Math.round(positionZ * 1000);
}
public Integer getSpeedMps() {
return Math.round(speed);
}
public Integer getSpeedKph() {
return Math.round(getSpeedMps() * 3.6f);
}
public Integer getSpeedMph() {
return Math.round(getSpeedMps() * 2.23694f);
}
public Integer getPower() {
return Math.round(power);
}
public Integer getHorsePower() {
return Math.round(getPower() * 0.00134102f);
}
public Integer getTorque() {
return Math.round(torque);
}
public Integer getTireTempFrontLeft() {
return Math.round(tireTempFrontLeft);
}
public Integer getTireTempFrontRight() {
return Math.round(tireTempFrontRight);
}
public Integer getTireTempRearLeft() {
return Math.round(tireTempRearLeft);
}
public Integer getTireTempRearRight() {
return Math.round(tireTempRearRight);
}
public Integer getTireTempAverageFront() {
return Math.round(getAverage(getTireTempFrontLeft(), getTireTempFrontRight()));
}
public Integer getTireTempAverageRear() {
return Math.round(getAverage(getTireTempRearLeft(), getTireTempRearRight()));
}
public Integer getTireTempAverageLeft() {
return Math.round(getAverage(getTireTempFrontLeft(), getTireTempRearLeft()));
}
public Integer getTireTempAverageRight() {
return Math.round(getAverage(getTireTempFrontRight(), getTireTempRearRight()));
}
public Integer getTireTempAverageTotal() {
return Math.round(getAverage(
getTireTempFrontLeft(),
getTireTempFrontRight(),
getTireTempRearLeft(),
getTireTempRearRight()
));
}
public Integer getTireTempFrontLeft_C() {
return Math.round(((tireTempFrontLeft - 32) * 5 ) / 9);
}
public Integer getTireTempFrontRight_C() {
return Math.round(((tireTempFrontRight - 32) * 5 ) / 9);
}
public Integer getTireTempRearLeft_C() {
return Math.round(((tireTempRearLeft - 32) * 5 ) / 9);
}
public Integer getTireTempRearRight_C() {
return Math.round(((tireTempRearRight - 32) * 5 ) / 9);
}
public Integer getTireTempAverageFront_C() {
float avg = getAverage(getTireTempFrontLeft(), getTireTempFrontRight());
return Math.round(((avg - 32) * 5 ) / 9);
}
public Integer getTireTempAverageRear_C() {
float avg = (getAverage(getTireTempRearLeft(), getTireTempRearRight()));
return Math.round(((avg - 32) * 5 ) / 9);
}
public Integer getTireTempAverageLeft_C() {
float avg = getAverage(getTireTempFrontLeft(), getTireTempRearLeft());
return Math.round(((avg - 32) * 5 ) / 9);
}
public Integer getTireTempAverageRight_C() {
float avg = getAverage(getTireTempFrontRight(), getTireTempRearRight());
return Math.round(((avg - 32) * 5 ) / 9);
}
public Integer getTireTempAverageTotal_C() {
float avg = getAverage(
getTireTempFrontLeft(),
getTireTempFrontRight(),
getTireTempRearLeft(),
getTireTempRearRight()
);
return Math.round(((avg - 32) * 5 ) / 9);
}
public Integer getBoost() {
return Math.round(boost);
}
public Float getFuel() {
return new BigDecimal(fuel * 100).setScale(2, RoundingMode.DOWN).floatValue();
}
public Float getDistanceTraveled() {
return distanceTraveled;
}
public Float getBestLap() {
return bestLap;
}
public Float getLastLap() {
return lastLap;
}
public Float getCurrentLap() {
return currentLap;
}
public Float getCurrentRaceTime() {
return currentRaceTime;
}
public Short getLapNumber() {
return lapNumber;
}
public Byte getRacePosition() {
return racePosition;
}
public Integer getThrottle() {
return (throttle & 0xff) * 100 / 255;
}
public Integer getBrake() {
return (brake & 0xff) * 100 / 255;
}
public Integer getClutch() {
return (clutch & 0xff) * 100 / 255;
}
public Integer getHandbrake() {
return (handbrake & 0xff) * 100 / 255;
}
public Integer getGear() {
return gear & 0xff;
}
public Integer getSteer() {
return (steer & 0xff) * 100 / 127;
}
public Integer getNormalizedDrivingLine() {
return (normalizedDrivingLine & 0xff) * 100 / 127;
}
public Integer getNormalizedAIBrakeDifference() {
return (normalizedAIBrakeDifference & 0xff) * 100 / 127;
}
public Integer getAverageVelocity() {
return Math.round(getVector3DLength(getVelocityX(), getVelocityY(), getVelocityZ()));
}
private Float getAverage(float valueOne, float valueTwo) {
return (valueOne + valueTwo) / 2f;
}
private Float getAverage(float valueOne, float valueTwo, float valueThree, float valueFour) {
return (valueOne + valueTwo + valueThree + valueFour) / 4f;
}
private Float getVector3DLength(float x, float y, float z) {
return (float) Math.sqrt(x * x + y * y + z * z);
}
public Long angle(float i){
return Math.round(i * 180 / Math.PI);
}
@NonNull
@Override
public String toString() {
return "{" +
" isRaceOn='" + getIsRaceOn() + "'" +
", timeStampMS='" + getTimeStampMS() + "'" +
", engineMaxRpm='" + getEngineMaxRpm() + "'" +
", engineIdleRpm='" + getEngineIdleRpm() + "'" +
", currentEngineRpm='" + getCurrentEngineRpm() + "'" +
", accelerationX='" + getAccelerationX() + "'" +
", accelerationY='" + getAccelerationY() + "'" +
", accelerationZ='" + getAccelerationZ() + "'" +
", velocityX='" + getVelocityX() + "'" +
", velocityY='" + getVelocityY() + "'" +
", velocityZ='" + getVelocityZ() + "'" +
", averageVelocityZ='" + getAverageVelocity() + "'" +
", angularVelocityX='" + getAngularVelocityX() + "'" +
", angularVelocityY='" + getAngularVelocityY() + "'" +
", angularVelocityZ='" + getAngularVelocityZ() + "'" +
", yaw='" + getYaw() + "'" +
", pitch='" + getPitch() + "'" +
", roll='" + getRoll() + "'" +
", normalizedSuspensionTravelFrontLeft='" + getNormalizedSuspensionTravelFrontLeft() + "'" +
", normalizedSuspensionTravelFrontRight='" + getNormalizedSuspensionTravelFrontRight() + "'" +
", normalizedSuspensionTravelRearLeft='" + getNormalizedSuspensionTravelRearLeft() + "'" +
", normalizedSuspensionTravelRearRight='" + getNormalizedSuspensionTravelRearRight() + "'" +
", tireSlipRatioFrontLeft='" + getTireSlipRatioFrontLeft() + "'" +
", tireSlipRatioFrontRight='" + getTireSlipRatioFrontRight() + "'" +
", tireSlipRatioRearLeft='" + getTireSlipRatioRearLeft() + "'" +
", tireSlipRatioRearRight='" + getTireSlipRatioRearRight() + "'" +
", wheelRotationSpeedFrontLeft='" + getWheelRotationSpeedFrontLeft() + "'" +
", wheelRotationSpeedFrontRight='" + getWheelRotationSpeedFrontRight() + "'" +
", wheelRotationSpeedRearLeft='" + getWheelRotationSpeedRearLeft() + "'" +
", wheelRotationSpeedRearRight='" + getWheelRotationSpeedRearRight() + "'" +
", wheelOnRumbleStripFrontLeft='" + getWheelOnRumbleStripFrontLeft() + "'" +
", wheelOnRumbleStripFrontRight='" + getWheelOnRumbleStripFrontRight() + "'" +
", wheelOnRumbleStripRearLeft='" + getWheelOnRumbleStripRearLeft() + "'" +
", wheelOnRumbleStripRearRight='" + getWheelOnRumbleStripRearRight() + "'" +
", wheelInPuddleDepthFrontLeft='" + getWheelInPuddleDepthFrontLeft() + "'" +
", wheelInPuddleDepthFrontRight='" + getWheelInPuddleDepthFrontRight() + "'" +
", wheelInPuddleDepthRearLeft='" + getWheelInPuddleDepthRearLeft() + "'" +
", wheelInPuddleDepthRearRight='" + getWheelInPuddleDepthRearRight() + "'" +
", surfaceRumbleFrontLeft='" + getSurfaceRumbleFrontLeft() + "'" +
", surfaceRumbleFrontRight='" + getSurfaceRumbleFrontRight() + "'" +
", surfaceRumbleRearLeft='" + getSurfaceRumbleRearLeft() + "'" +
", surfaceRumbleRearRight='" + getSurfaceRumbleRearRight() + "'" +
", tireSlipAngleFrontLeft='" + getTireSlipAngleFrontLeft() + "'" +
", tireSlipAngleFrontRight='" + getTireSlipAngleFrontRight() + "'" +
", tireSlipAngleRearLeft='" + getTireSlipAngleRearLeft() + "'" +
", tireSlipAngleRearRight='" + getTireSlipAngleRearRight() + "'" +
", tireCombinedSlipFrontLeft='" + getTireCombinedSlipFrontLeft() + "'" +
", tireCombinedSlipFrontRight='" + getTireCombinedSlipFrontRight() + "'" +
", tireCombinedSlipRearLeft='" + getTireCombinedSlipRearLeft() + "'" +
", tireCombinedSlipRearRight='" + getTireCombinedSlipRearRight() + "'" +
", suspensionTravelMetersFrontLeft='" + getSuspensionTravelMetersFrontLeft() + "'" +
", suspensionTravelMetersFrontRight='" + getSuspensionTravelMetersFrontRight() + "'" +
", suspensionTravelMetersRearLeft='" + getSuspensionTravelMetersRearLeft() + "'" +
", suspensionTravelMetersRearRight='" + getSuspensionTravelMetersRearRight() + "'" +
", carClass='" + getCarClass() + "'" +
", carPerformanceIndex='" + getCarPerformanceIndex() + "'" +
", drivetrainType='" + getDrivetrain() + "'" +
", numCylinders='" + getNumCylinders() + "'" +
", carType='" + getCarType() + "'" +
", objectHit='" + getObjectHit() + "'" +
", carOrdinal='" + getCarOrdinal() + "'" +
", positionX='" + getPositionX() + "'" +
", positionY='" + getPositionY() + "'" +
", positionZ='" + getPositionZ() + "'" +
", speedMps='" + getSpeedMps() + "'" +
", speedMph='" + getSpeedMph() + "'" +
", speedKph='" + getSpeedKph() + "'" +
", power='" + getPower() + "'" +
", horsepower='" + getHorsePower() + "'" +
", torque='" + getTorque() + "'" +
", tireTempFrontLeft='" + getTireTempFrontLeft() + "'" +
", tireTempFrontRight='" + getTireTempFrontRight() + "'" +
", tireTempRearLeft='" + getTireTempRearLeft() + "'" +
", tireTempRearRight='" + getTireTempRearRight() + "'" +
", boost='" + getBoost() + "'" +
", fuel='" + getFuel() + "'" +
", distanceTraveled='" + getDistanceTraveled() + "'" +
", bestLap='" + getBestLap() + "'" +
", lastLap='" + getLastLap() + "'" +
", currentLap='" + getCurrentLap() + "'" +
", currentRaceTime='" + getCurrentRaceTime() + "'" +
", lapNumber='" + getLapNumber() + "'" +
", racePosition='" + getRacePosition() + "'" +
", accel='" + getThrottle() + "'" +
", brake='" + getBrake() + "'" +
", clutch='" + getClutch() + "'" +
", handbrake='" + getHandbrake() + "'" +
", gear='" + getGear() + "'" +
", steer='" + getSteer() + "'" +
", normalizedDrivingLine='" + getNormalizedDrivingLine() + "'" +
", normalizedAIBrakeDifference='" + getNormalizedAIBrakeDifference() + "'" +
"}";
}
}