-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRTIDemo.js
More file actions
120 lines (106 loc) · 4.83 KB
/
RTIDemo.js
File metadata and controls
120 lines (106 loc) · 4.83 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
import AnimatedWipers from "./reusable/AnimatedWipers.js"
import StatusTable from "./reusable/StatusTable.js"
import GoogleMapsFromSignal from "./reusable/GoogleMapsFromSignal.js"
import TitleWidget from "./reusable/TitleWidget.js"
import LineChart from "./reusable/LineChart.js"
const getRTIData = async (title) => {
const response = await fetch(`https://rti.ngrok.io/dds/rest1/applications/CovesaDemoApp/domain_participants/MyParticipant/subscribers/MySubscriber/data_readers/${title}`)
return new DOMParser().parseFromString(await response.text(), "text/xml")
}
const RTIDemo = ({ widgets, vehicle, simulator }) => {
widgets.register("AnimatedWipers", AnimatedWipers("Vehicle.Body.Windshield.Front.Wiping.Mode", vehicle))
widgets.register("SpeedLineChart", LineChart([
{
signal: "Vehicle.Speed"
}
], vehicle), 5000)
widgets.register("MeterLineChart", LineChart([
{
signal: "Vehicle.TripMeterReading"
}
], vehicle), 5000)
const SIGNALS = [
"Vehicle.CurrentLocation.Latitude",
"Vehicle.CurrentLocation.Longitude",
"Vehicle.CurrentLocation.Heading",
"Vehicle.CurrentLocation.HorizontalAccuracy",
"Vehicle.CurrentLocation.Altitude",
"Vehicle.CurrentLocation.VerticalAccuracy",
"Vehicle.CurrentLocation.GNSSReceiver.FixType",
"Vehicle.Speed",
"Vehicle.AverageSpeed",
"Vehicle.TripMeterReading",
"Vehicle.IsBrokenDown",
"Vehicle.IsMoving",
"Vehicle.Body.Windshield.Front.Wiping.System.Mode",
"Vehicle.Body.Windshield.Front.Wiping.System.Frequency",
"Vehicle.Body.Windshield.Front.Wiping.System.TargetPosition",
"Vehicle.Body.Windshield.Front.Wiping.System.ActualPosition",
"Vehicle.Body.Windshield.Front.Wiping.System.DriveCurrent",
"Vehicle.Body.Windshield.Front.Wiping.System.IsWiping",
"Vehicle.Body.Windshield.Front.Wiping.System.IsEndingWipeCycle",
"Vehicle.Body.Windshield.Front.Wiping.System.IsWiperError",
"Vehicle.Body.Windshield.Front.Wiping.System.IsPositionReached",
"Vehicle.Body.Windshield.Front.Wiping.System.IsOverheated",
"Vehicle.Body.Windshield.Front.Wiping.System.IsBlocked",
"Vehicle.Body.Windshield.Front.Wiping.WiperWear",
"Vehicle.Body.Windshield.Front.Wiping.IsWipersWorn",
"Vehicle.Body.Windshield.Front.Wiping.Mode"
]
widgets.register("SignalTable", StatusTable({
apis: SIGNALS,
vehicle,
refresh: 1000
}))
widgets.register("Directions", GoogleMapsFromSignal([
{
lat: 39.36440665494062,
lng: -85.62349717186248
},
{
lat: 40.05174288244341,
lng: -86.4531371326884
}
], vehicle))
const STATE = {}
const refresh = () => {
getRTIData("MyVehicleLocationReader").then(data => {
if (!data.querySelector("data")) {
return
}
for (const parameter of ["Latitude", "Longitude", "Heading", "HorizontalAccuracy", "Altitude", "VerticalAccuracy"]) {
STATE[`Vehicle.CurrentLocation.${parameter}`] = data.querySelector(`data > ${parameter}`).textContent
}
STATE[`Vehicle.CurrentLocation.GNSSReceiver.FixType`] = data.querySelector(`data > FixType`).textContent
})
getRTIData("MyVehicleMotionReader").then(data => {
if (!data.querySelector("data")) {
return
}
for (const parameter of ["Speed", "AverageSpeed", "TripMeterReading", "IsBrokenDown", "IsMoving"]) {
STATE[`Vehicle.${parameter}`] = data.querySelector(`data > ${parameter}`).textContent
}
// Acceleration, AngularVelocity
})
getRTIData("MyWiperStatusReader").then(data => {
if (!data.querySelector("data")) {
return
}
for (const parameter of ["Mode", "Frequency", "TargetPosition", "ActualPosition", "DriveCurrent", "IsWiping", "IsEndingWipeCycle", "IsWiperError", "IsPositionReached", "IsOverheated", "IsBlocked"]) {
STATE[`Vehicle.Body.Windshield.Front.Wiping.System.${parameter}`] = data.querySelector(`data > ${parameter}`).textContent
}
for (const parameter of ["WiperWear", "IsWipersWorn"]) {
STATE[`Vehicle.Body.Windshield.Front.Wiping.${parameter}`] = data.querySelector(`data > ${parameter}`).textContent
}
STATE[`Vehicle.Body.Windshield.Front.Wiping.Mode`] = STATE["Vehicle.Body.Windshield.Front.Wiping.System.TargetPosition"] === 0 ? "OFF" : "MEDIUM"
})
}
refresh()
setInterval(refresh, 5 * 1000)
for (const signal of SIGNALS) {
simulator(signal, "get", () => {
return STATE[signal]
})
}
}
export default RTIDemo