defines.js
5.77 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
var PID = {
TS: 0,
FUEL_PRESSURE: 0x10A,
SPEED: 0x10d,
RPM: 0x10c,
ENGINE_LOAD: 0x104,
THROTTLE: 0x111,
COOLANT_TEMP: 0x105,
TIMING_ADVANCE: 0x10E,
INTAKE_TEMP: 0x10F,
PID_DISTANCE: 0x131,
PID_BAROMETRIC: 0x133,
PID_AMBIENT_TEMP: 0x146,
PID_FUEL_RATE: 0x15E,
GPS : {
LATITUDE: 0xA,
LONGITUDE: 0xB,
ALTITUDE: 0xC,
SPEED: 0xD,
HEADING: 0xE,
SAT_COUNT: 0xF,
TIME: 0x10,
DATE: 0x11,
HDOP: 0x12
},
ACC: 0x20,
GYRO: 0x21,
COMPASS: 0x22,
MEMS_TEMP: 0x23,
BATTERY_VOLTAGE: 0x24,
ORIENTATION: 0x25,
TRIP_DISTANCE: 0x30,
DEVICE_TEMP: 0x82,
HALL_SENSOR: 0x83,
getName: function(pid)
{
switch (pid) {
case this.SPEED:
return "Vehicle Speed";
case this.RPM:
return "Engine RPM";
case this.FUEL_PRESSURE:
return "Fuel Pressure";
case this.TIMING_ADVANCE:
return "Timing Advance";
case this.ENGINE_LOAD:
return "Engine Load";
case this.THROTTLE:
return "Throttle Position";
case this.COOLANT_TEMP:
return "Coolant Temp.";
case this.INTAKE_TEMP:
return "Intake Temp.";
case this.PID_AMBIENT_TEMP:
return "Ambient Temp.";
case this.PID_BAROMETRIC:
return "Barometric";
case this.PID_DISTANCE:
return "Distance Since Service";
case this.PID_FUEL_RATE:
return "Fuel Rate";
case this.BATTERY_VOLTAGE:
return "Battery Voltage";
case this.TRIP_DISTANCE:
return "Trip Distance";
case this.DEVICE_TEMP:
return "Device Temp.";
case this.ACC:
return "Acceleration";
case this.ORIENTATION:
return "Orientation";
case this.GPS.LATITUDE:
return "Latitude";
case this.GPS.LONGITUDE:
return "Longitude";
case this.GPS.ALTITUDE:
return "Altitude";
case this.GPS.SPEED:
return "Speed";
case this.GPS.HEADING:
return "Course";
case this.GPS.SAT_COUNT:
return "Satellites in Use";
case this.GPS.TIME:
return "UTC Time";
case this.GPS.DATE:
return "UTC Date";
case this.GPS.HDOP:
return "HDOP";
case this.HALL_SENSOR:
return "Hall Sensor";
default:
return "PID " + (pid.toString(16));
}
},
getUnit: function (pid) {
switch (pid) {
case this.SPEED:
return "km/h";
case this.RPM:
return "rpm";
case this.FUEL_PRESSURE:
return "kPa";
case this.ENGINE_LOAD:
case this.THROTTLE:
return "%";
case this.COOLANT_TEMP:
case this.INTAKE_TEMP:
case this.PID_AMBIENT_TEMP:
case this.DEVICE_TEMP:
return "°C";
case this.PID_BAROMETRIC:
return "bar";
case this.PID_DISTANCE:
return "km";
case this.PID_FUEL_RATE:
return "L/hr";
case this.BATTERY_VOLTAGE:
return "V";
case this.TRIP_DISTANCE:
return "km";
case this.ACC:
return "g";
case this.ORIENTATION:
return "yaw/pitch/roll";
case this.GPS.ALTITUDE:
return "m";
case this.GPS.SPEED:
return "km/h";
case this.GPS.HEADING:
case this.TIMING_ADVANCE:
return "°";
default:
return null;
}
},
getNameUnit: function (pid) {
var s = this.getName(pid);
var unit = this.getUnit(pid);
if (unit) s += " (" + unit + ")";
return s;
},
getUTCTime: function (t)
{
var hours = Math.floor(t / 1000000);
var minutes = Math.floor((t % 1000000) / 10000);
var seconds = Math.floor((t % 10000) / 100);
var ms = t % 100;
if (hours < 10) {hours = "0"+hours;}
if (minutes < 10) {minutes = "0"+minutes;}
if (seconds < 10) {seconds = "0"+seconds;}
if (ms < 10) {ms = "0"+ms;}
return hours+':'+minutes+':'+seconds+'.'+ms;
},
getUTCDate: function (d)
{
var day = Math.floor(d / 10000);
var mon = Math.floor((d % 10000) / 100);
var year = d % 100;
return "20" + year + "-" + mon + "-" + day;
},
getXYZ: function(d)
{
if (d.length == 3) {
return (d[0] / 100).toFixed(1) + "/" + (d[1] / 100).toFixed(1) + "/" + (d[2] / 100).toFixed(1);
} else {
return d;
}
},
getXYZComposed: function(d)
{
if (d.length == 3) {
return (d[0] / 100) ^ 2 + (d[1] / 100) ^ 2 + (d[2] / 100) ^ 2;
} else {
return 0;
}
},
normalize: function (pid, value)
{
switch (pid) {
case this.BATTERY_VOLTAGE:
return value / 100;
case this.TRIP_DISTANCE:
return (value / 1000).toFixed(1);
case this.GPS.TIME:
return this.getUTCTime(value);
case this.GPS.DATE:
return this.getUTCDate(value);
case this.ACC:
case this.GYRO:
case this.COMPASS:
case this.ORIENTATION:
return this.getXYZ(value);
case this.GPS.LATITUDE:
case this.GPS.LONGITUDE:
return parseFloat(value);
case this.GPS.ALTITUDE:
return value; /* m */
case this.GPS.SPEED:
return parseFloat(value); /* kph */
}
return value;
},
toNumber: function (pid, value)
{
switch (pid) {
case this.BATTERY_VOLTAGE:
return value / 100;
case this.TRIP_DISTANCE:
return value / 1000;
case this.GPS.ALTITUDE:
return value;
case this.ACC:
case this.GYRO:
return this.getXYZComposed(value);
}
return typeof value != "number" ? parseFloat(value) : value;
},
illustratable: function(pid)
{
switch (pid) {
case 0:
case PID.GYRO:
case PID.COMPASS:
case PID.ORIENTATION:
case PID.GPS.LATITUDE:
case PID.GPS.LONGITUDE:
case PID.GPS.HEADING:
case PID.GPS.TIME:
case PID.GPS.DATE:
return false;
}
return true;
}
};