1 | 'use strict'; |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
2 | const beaconRate = 5000; |
||
0 ignored issues
–
show
|
|||
3 | const ignorePressureChangeThreshold = 100000; |
||
0 ignored issues
–
show
|
|||
4 | const RESIN_APP_RELEASE = process.env.RESIN_APP_RELEASE; |
||
0 ignored issues
–
show
|
|||
5 | class RovBeacon{ |
||
0 ignored issues
–
show
|
|||
6 | constructor(name,deps){ |
||
7 | this.state={ |
||
8 | name: require('os').hostname(), |
||
0 ignored issues
–
show
|
|||
9 | //model:'trident', //TODO: Add model detection |
||
10 | battery:.7, |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||
11 | imageVersion:RESIN_APP_RELEASE |
||
12 | }; |
||
13 | this.beacon = null; |
||
14 | this.bus = deps.globalEventLoop; |
||
15 | |||
16 | this._lastIntPressureReading = {time:0,p:0,t:0}; |
||
17 | } |
||
18 | |||
19 | start() { |
||
20 | this.beacon = require('./beacon.js')({beaconRate}); |
||
0 ignored issues
–
show
|
|||
21 | this.beacon.broadcast(this._genBeaconMessage.bind(this)); |
||
22 | this._listenForStateChanges(); |
||
23 | } |
||
24 | |||
25 | stop(){ |
||
26 | this.beacon.stop(); |
||
27 | this._stopListenForStateChanges() |
||
0 ignored issues
–
show
There should be a semicolon.
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers. Further Readings: ![]() |
|||
28 | } |
||
29 | |||
30 | _genBeaconMessage(){ |
||
31 | this.state.exp=beaconRate*2; //Set the expeiration for this to 2X the broadcast rate. |
||
32 | return this.state; |
||
33 | } |
||
34 | |||
35 | _listenForStateChanges(){ |
||
36 | this.bus.on('mcu.status',this._processMCUStatus.bind(this)) |
||
0 ignored issues
–
show
There should be a semicolon.
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers. Further Readings: ![]() |
|||
37 | } |
||
38 | |||
39 | _stopListenForStateChanges(){ |
||
40 | this.bus.off('mcu.status',this._processMCUStatus.bind(this)) |
||
0 ignored issues
–
show
There should be a semicolon.
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers. Further Readings: ![]() |
|||
41 | } |
||
42 | |||
43 | _computerPressureTrend(currentpressure,currenttemp){ |
||
44 | //TODO: Do we need to enhance for temperature compensation? |
||
45 | if (this._lastIntPressureReading.p> (currentpressure+ignorePressureChangeThreshold)) { |
||
46 | return this._lastIntPressureReading.p-currentpressure; |
||
47 | } |
||
48 | if (this._lastIntPressureReading.p< ( currentpressure-ignorePressureChangeThreshold)){ |
||
49 | return this._lastIntPressureReading.p-currentpressure; |
||
50 | } |
||
51 | return 0 |
||
0 ignored issues
–
show
There should be a semicolon.
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers. Further Readings: ![]() |
|||
52 | } |
||
53 | |||
54 | _processMCUStatus(status){ |
||
55 | for (var data in status) { |
||
56 | switch (data) { |
||
57 | case 'baro_p' : |
||
58 | //TODO: Confirm the value units of baro_p |
||
59 | //https://gitlab.com/openrov/RIOT/blob/openrov/apps/trident/CMPL3115A2.cpp#L98 |
||
60 | this.state.intPressure_mb=status["baro_p"]; |
||
0 ignored issues
–
show
|
|||
61 | //TODO: Does this need to be smoothed over time? |
||
62 | this.state.intPressureRate=this._computerPressureTrend(this.state.intPressure_mb,status['baro_t']); |
||
0 ignored issues
–
show
|
|||
63 | this._lastIntPressureReading = {time: Date.now(), p:this.state.intPressure_mb, t:status['baro_t']}; |
||
0 ignored issues
–
show
|
|||
64 | break; |
||
65 | case 'vout' : |
||
66 | this.state.battery = status['vout']; |
||
0 ignored issues
–
show
|
|||
67 | break; |
||
68 | case 'batt_v': //Ma |
||
69 | this.state.battery = status['batt_v'] / 1000.0; |
||
0 ignored issues
–
show
|
|||
70 | break; |
||
71 | } |
||
72 | } |
||
73 | } |
||
74 | |||
75 | } |
||
76 | |||
77 | module.exports = function (name, deps) { |
||
0 ignored issues
–
show
|
|||
78 | return new RovBeacon(name, deps); |
||
79 | }; |