-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
198 lines (169 loc) · 6.64 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>DSE Simulator</title>
<script defer src="/static/alpine.min.js"></script>
<link rel="stylesheet" href="/static/new.min.css">
<style>body { max-width: 1280px; }</style>
</head>
<body x-data="{
ws: null,
scheduler: null,
registers: [],
alarms: [],
interval: null,
alarmVals: [
'Disabled digital input',
'Not active alarm',
'Warning alarm',
'Shutdown alarm',
'Electrical trip alarm',
'Reserved',
'Reserved',
'Reserved',
'Inactive indication (no string)',
'Inactive indication (displayed string)',
'Active indication',
'Reserved',
'Reserved',
'Reserved',
'Reserved',
'Unimplemented alarm',
],
statusCodes: {
0: 'Engine stopped',
1: 'Pre-Start',
2: 'Warming up',
3: 'Running',
4: 'Cooling down',
5: 'Engine Stopped',
6: 'Post run',
15: 'Not available'
},
init() {
this.connect();
},
connect() {
this.ws = new WebSocket('ws://localhost:8000/ws');
this.ws.onmessage = (e) => this.recv(e);
this.ws.onclose = (e) => {
console.log('Socket closed, reconnecting in 1s.', e.reason);
clearInterval(this.scheduler);
setTimeout(() => this.connect(), 1000);
};
this.ws.onerror = (e) => this.ws.close();
this.scheduler = setInterval(() => {
this.sendCommand('send_registers');
this.sendCommand('send_alarms');
}, 1000);
},
recv(event) {
let d = JSON.parse(event.data)
// console.log('WS message received:', d)
if (d.hasOwnProperty('registers')) {
this.registers = d.registers;
}
if (d.hasOwnProperty('alarms')) {
this.alarms = d.alarms;
}
},
registerValueChanged(item) {
let newVal = +this.$el.parentNode.querySelector('input').value;
console.log(item.path, 'changed val to', newVal);
this.ws.send(JSON.stringify({
'msg': 'set_register',
'path': item.path,
'val': newVal
}));
this.$el.parentNode.querySelector('input').value = null;
},
alarmChanged(item) {
let newVal = +this.$el.value;
console.log(item.desc, 'changed val to', newVal);
this.ws.send(JSON.stringify({
'msg': 'set_alarm',
'id': item.id,
'val': newVal
}));
},
sendCommand(cmd) {
this.ws.send(JSON.stringify({
'msg': cmd
}));
},
sendScf(cmd) {
this.ws.send(JSON.stringify({
'msg': 'scf',
'cmd': cmd
}));
},
get statusCode() {
let t = this.registers.find(i => i.path == '/StatusCode');
return t ? this.statusCodes[t.val] : 'Unknown';
},
get remoteStartMode() {
let t = this.registers.find(i => i.path == '/AutoStart');
return t ? (t.val == 0 ? 'Disabled' : 'Enabled') : 'Unknown';
}
}">
<head>
<h1>DSE Simulator</h1>
<hr>
</head>
<main>
<div style="padding-bottom: 16px; display: flex; flex: 1; gap: 2rem;">
<div>
<h3>Status</h3>
<kbd x-text="statusCode"></kbd>
</div>
<div>
<h3>Remote start mode</h3>
<kbd x-text="remoteStartMode"></kbd>
</div>
<div>
<h3>Actions</h3>
<button @click="sendScf('TELEMETRY_START')">Start</button>
<button @click="sendScf('TELEMETRY_STOP')">Stop</button>
<button @click="sendScf('SELECT_AUTO_MODE')">Enable Remote Start Mode</button>
</div>
</div>
<hr>
<div style="display: flex; flex-wrap: wrap; gap: 2rem;">
<div>
<h2>Registers</h2>
<ul>
<template x-for="item in registers" :key="item.path">
<li style="display: flex; flex-direction: row; justify-content: space-between; border-bottom: solid 0.5px black; padding-top: 4px; max-width: 600px;">
<span x-text="item.path" style="display: block;"></span>
<span x-text="Number(item.val).toFixed(Math.trunc(item.scale/10))" style="display: block; flex-grow: 1; text-align: right; padding: 0 8px;"></span>
<span x-text="item.unit" style="padding-left: 4px; width: 40px;"></span>
<span style="padding: 0 16px;">//</span>
<div style="display: flex; flex-direction: row;">
<input type="number" style="text-align: right; border: solid 0.5px grey; margin-right: 8px;">
<button @click="registerValueChanged(item)">Set</button>
</div>
</li>
</template>
</ul>
<hr>
</div>
<div>
<h2>Alarms</h2>
<ul>
<template x-for="item in alarms" :key="item.desc">
<li style="display: flex; flex-direction: row; justify-content: space-between; border-bottom: solid 0.5px black; padding-top: 4px; max-width: 600px;">
<span x-text="item.desc" style="display: block;"></span>
<select :name="item.desc" @change="alarmChanged(item)">
<template x-for="(val, idx) in alarmVals" :key="idx">
<option :value="idx" x-text="val" :selected="idx == item.val" :disabled="val == 'Reserved'"></option>
</template>
</select>
</li>
</template>
</ul>
<hr>
</div>
</div>
</main>
</body>
</html>