Skip to content

Commit 64ff88f

Browse files
authored
Merge pull request #133 from openxc/view-diagnostic-responses
View Diagnostic Responses
2 parents 3a15e0c + ae14f87 commit 64ff88f

File tree

2 files changed

+101
-28
lines changed

2 files changed

+101
-28
lines changed

openxc/tools/static/js/dashboard.js

Lines changed: 86 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ let dataPoints = {};
33
/* --- Dashboard parameters ------- */
44
let justChangedHighlightDuration;
55
let recentlyChangedHighlightDuration;
6+
let diagnosticCount = 0;
67
/* --- End dashboard parameters --- */
78

89
$(document).ready(function() {
@@ -13,34 +14,43 @@ $(document).ready(function() {
1314
socket.on('vehicle data', function(msg, cb) {
1415
// console.log(msg);
1516

16-
17-
if (!msg.hasOwnProperty('name')) {
18-
msg.name = 'Raw-' + msg.bus + '-0x' + msg.id.toString(16);
19-
msg.value = msg.data;
20-
}
21-
22-
if (msg.hasOwnProperty('event')) {
23-
msg.value = msg.value + ': ' + msg.event
24-
}
25-
26-
if (!(msg.name in dataPoints)) {
27-
dataPoints[msg.name] = {
28-
current_data: undefined,
29-
events: {},
30-
messages_received: 0,
31-
measurement_type: undefined,
32-
min: undefined,
33-
max: undefined,
34-
last_update_time: undefined,
35-
average_time_since_update: undefined
36-
};
37-
}
38-
39-
updateDataPoint(dataPoints[msg.name], msg);
40-
updateDisplay(dataPoints[msg.name]);
41-
42-
if (cb)
43-
cb();
17+
if (!msg.hasOwnProperty('command_response')) {
18+
if (msg.hasOwnProperty('success')) {
19+
// Using the 'success' property to identify a diagnostic response
20+
diagnosticCount++;
21+
let diagnosticName = 'diagnostic_' + diagnosticCount;
22+
addDiagnosticResponse(diagnosticName, msg);
23+
} else {
24+
if (!msg.hasOwnProperty('name')) {
25+
msg.name = 'Raw-' + msg.bus + '-0x' + msg.id.toString(16);
26+
msg.value = msg.data;
27+
}
28+
29+
if (msg.hasOwnProperty('event')) {
30+
msg.value = msg.value + ': ' + msg.event
31+
}
32+
33+
if (!(msg.name in dataPoints)) {
34+
dataPoints[msg.name] = {
35+
current_data: undefined,
36+
events: {},
37+
messages_received: 0,
38+
measurement_type: undefined,
39+
min: undefined,
40+
max: undefined,
41+
last_update_time: undefined,
42+
average_time_since_update: undefined
43+
};
44+
}
45+
46+
updateDataPoint(dataPoints[msg.name], msg);
47+
updateDisplay(dataPoints[msg.name]);
48+
49+
if (cb) {
50+
cb();
51+
}
52+
}
53+
}
4454
});
4555
});
4656

@@ -170,3 +180,51 @@ function calculateAverageTimeSinceUpdate(updateTime, dataPoint) {
170180
? time_since_update
171181
: (0.1 * time_since_update) + (0.9 * dataPoint.average_time_since_update);
172182
}
183+
184+
function addDiagnosticResponse(name, message) {
185+
$('<tr/>', {
186+
id: name
187+
}).appendTo('#diagnostic');
188+
189+
$('<td/>', {
190+
id: name + '_bus',
191+
text: message.bus
192+
}).appendTo('#' + name);
193+
194+
$('<td/>', {
195+
id: name + '_id',
196+
text: message.id
197+
}).appendTo('#' + name);
198+
199+
$('<td/>', {
200+
id: name + '_mode',
201+
text: message.mode
202+
}).appendTo('#' + name);
203+
204+
$('<td/>', {
205+
id: name + '_pid',
206+
text: message.pid
207+
}).appendTo('#' + name);
208+
209+
$('<td/>', {
210+
id: name + '_success',
211+
text: message.success
212+
}).appendTo('#' + name);
213+
214+
$('<td/>', {
215+
id: name + '_payload',
216+
text: message.payload
217+
}).appendTo('#' + name);
218+
219+
$('<td/>', {
220+
id: name + '_value',
221+
text: message.value
222+
}).appendTo('#' + name);
223+
224+
if (message.success == false) {
225+
$('<td/>', {
226+
id: name + '_neg_resp_code',
227+
text: message.negative_response_code
228+
}).appendTo('#' + name);
229+
}
230+
}

openxc/tools/templates/dashboard.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ <h2>Settings</h2>
4040
<input id="dashboardSettingsSubmitBtn" type="submit" value="Update" onclick="return validateSettingsForm();">
4141
</form>
4242
</div>
43+
<div>
44+
<table id="diagnostic">
45+
<caption>Diagnostic Responses</caption>
46+
<tr>
47+
<th>Bus</th>
48+
<th>ID</th>
49+
<th>Mode</th>
50+
<th>PID</th>
51+
<th>Success</th>
52+
<th>Payload</th>
53+
<th>Value</th>
54+
<th>Neg. Resp. Code</th>
55+
</tr>
56+
</table>
57+
</div>
4358
</div>
4459
</body>
4560
</html>

0 commit comments

Comments
 (0)