1
|
|
|
/* global describe, it */ |
2
|
|
|
const chai = require('chai') |
3
|
|
|
const dirtyChai = require('dirty-chai') |
4
|
|
|
chai.use(dirtyChai) |
5
|
|
|
const should = chai.should() |
6
|
|
|
chai.use(require('../dist/').chaiModule) |
7
|
|
|
const FullSignalK = require('../dist/fullsignalk') |
8
|
|
|
const debug = require('debug')('test:sources') |
9
|
|
|
|
10
|
|
|
var deltaWithMiscSources = { |
11
|
|
|
'context': 'vessels.urn:mrn:imo:mmsi:200000000', |
12
|
|
|
'updates': [{ |
13
|
|
|
'source': { |
14
|
|
|
'sentence': 'HDT', |
15
|
|
|
'label': '0183-1', |
16
|
|
|
'talker': 'II' |
17
|
|
|
}, |
18
|
|
|
'timestamp': '2016-08-03T07:55:57.000Z', |
19
|
|
|
'values': [{ |
20
|
|
|
'path': 'navigation.headingTrue', |
21
|
|
|
'value': 0.2231 |
22
|
|
|
}] |
23
|
|
|
}, { |
24
|
|
|
'source': { |
25
|
|
|
'src': '37', |
26
|
|
|
'pgn': 127251, |
27
|
|
|
'label': 'N2000-01' |
28
|
|
|
}, |
29
|
|
|
'timestamp': '2016-06-20T10:33:36Z', |
30
|
|
|
'values': [{ |
31
|
|
|
'path': 'navigation.rateOfTurn', |
32
|
|
|
'value': 0.108908 |
33
|
|
|
}] |
34
|
|
|
}, { |
35
|
|
|
'$source': '1W.0316013faeff', |
36
|
|
|
'timestamp': '2016-07-28T18:18:46.074Z', |
37
|
|
|
'values': [{ |
38
|
|
|
'path': 'propulsion.engine1.temperature', |
39
|
|
|
'value': 301.837 |
40
|
|
|
}] |
41
|
|
|
}, { |
42
|
|
|
'$source': 'i2c-0.0x48.volts', |
43
|
|
|
'timestamp': '2016-07-28T18:18:46.074Z', |
44
|
|
|
'values': [{ |
45
|
|
|
'path': 'electrical.batteries.house.voltage', |
46
|
|
|
'value': 12.837 |
47
|
|
|
}] |
48
|
|
|
}, { |
49
|
|
|
'$source': 'i2c-0.0x48.amps', |
50
|
|
|
'timestamp': '2016-07-28T18:18:46.074Z', |
51
|
|
|
'values': [{ |
52
|
|
|
'path': 'electrical.batteries.house.current', |
53
|
|
|
'value': -0.837 |
54
|
|
|
}] |
55
|
|
|
}, { |
56
|
|
|
'timestamp': '2016-08-03T07:55:57.000Z', |
57
|
|
|
'values': [{ |
58
|
|
|
'path': 'navigation.headingTrue', |
59
|
|
|
'value': 0.2231 |
60
|
|
|
}] |
61
|
|
|
}] |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
describe('Sources in delta', function () { |
65
|
|
|
it('are valid', function () { |
66
|
|
|
var fullSignalK = new FullSignalK('urn:mrn:imo:mmsi:200000000') |
67
|
|
|
fullSignalK.addDelta(deltaWithMiscSources) |
68
|
|
|
var full = fullSignalK.retrieve() |
69
|
|
|
full.sources['0183-1']['II'].talker.should.equal('II') |
70
|
|
|
full.sources['N2000-01']['37']['n2k']['src'].should.equal('37') |
71
|
|
|
should.exist(full.sources['i2c-0']['0x48']) |
72
|
|
|
should.exist(full.sources['1W']['0316013faeff']) |
73
|
|
|
// FIXME for some reason tv4 complains about source's type property being undefined |
74
|
|
|
// renaming the type property of the source fixes the problem |
75
|
|
|
// fix with a better validation tool or dig deeper |
76
|
|
|
// full.should.be.validSignalK |
77
|
|
|
deltaWithMiscSources.should.be.validSignalKDelta() |
78
|
|
|
}) |
79
|
|
|
}) |
80
|
|
|
|
81
|
|
|
describe('Delta with source.instance', function () { |
82
|
|
|
it('produces valid full', function () { |
83
|
|
|
const delta = { |
84
|
|
|
'context': 'vessels.urn:mrn:imo:mmsi:200000000', |
85
|
|
|
'updates': [ |
86
|
|
|
{ |
87
|
|
|
'source': { |
88
|
|
|
'label': 'aLabel', |
89
|
|
|
'type': 'NMEA2000', |
90
|
|
|
'pgn': 130312, |
91
|
|
|
'src': '41', |
92
|
|
|
'instance': '5' |
93
|
|
|
}, |
94
|
|
|
'timestamp': '2015-01-15T16:15:18.136Z', |
95
|
|
|
'values': [ |
96
|
|
|
{ |
97
|
|
|
'path': 'environment.inside.engineRoom.temperature', |
98
|
|
|
'value': 70 |
99
|
|
|
} |
100
|
|
|
] |
101
|
|
|
} |
102
|
|
|
] |
103
|
|
|
} |
104
|
|
|
delta.should.be.validSignalKDelta() |
105
|
|
|
|
106
|
|
|
const fullSignalK = new FullSignalK('urn:mrn:imo:mmsi:200000000') |
107
|
|
|
fullSignalK.addDelta(delta) |
108
|
|
|
const full = fullSignalK.retrieve() |
109
|
|
|
debug((JSON.stringify(full, null, 2))) |
110
|
|
|
full.should.be.validSignalK() |
111
|
|
|
}) |
112
|
|
|
}) |
113
|
|
|
|