forked from SignalK/n2k-signalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
51 lines (47 loc) · 1.04 KB
/
utils.js
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
function chooseField (n2k, field1, field2) {
let res =
typeof n2k.fields[field1] === 'undefined'
? n2k.fields[field2]
: n2k.fields[field1]
// console.log(`chooseField ${typeof n2k.fields[field1]} '${field1}' '${field2}' ${res} ${JSON.stringify(n2k.fields)}`)
return res
}
function skEngineId (n2k) {
let id = chooseField(n2k, 'Engine Instance', 'Instance')
if (typeof id === 'number') {
return id
} else {
return id === 'Single Engine or Dual Engine Port' ? 'port' : 'starboard'
}
}
function skEngineTitle (n2k) {
var engine = skEngineId(n2k)
if (typeof engine === 'number') {
return engine
} else {
return engine.charAt(0).toUpperCase() + engine.slice(1)
}
}
function acPhase(n2k) {
const line = n2k.fields['Line']
if ( !line ) {
return 'A'
} else {
switch ( line ) {
case 'Line 1':
return 'A'
case 'Line 2':
return 'B'
case 'Line 3':
return 'C'
default:
return 'A'
}
}
}
module.exports = {
chooseField,
skEngineId,
skEngineTitle,
acPhase
}