1 | /* |
||
2 | * |
||
3 | * Description: |
||
4 | * Configuration file. Manage frame rate, port, etc. |
||
5 | * |
||
6 | */ |
||
7 | module.exports = function(frameworkDeps){ |
||
8 | var pino = frameworkDeps.logging.child({module:"config"}); |
||
9 | |||
10 | var nconf = require('nconf'); |
||
11 | //Add your Mock objects here using this same naming convention of library-mock for the mock version. |
||
12 | //be sure to add it to the expoft at the bottom of this file as well. |
||
13 | var argv = require('optimist').argv; |
||
14 | nconf.argv().env('__'); |
||
15 | //Also look for overrides in environment settings |
||
16 | // Will essentially rewrite the file when a change to the defaults are made if there is a parsing error. |
||
17 | try { |
||
18 | nconf.use('file', { file: nconf.get('configfile') ? nconf.get('configfile') : '/etc/rovconfig.json' }); |
||
19 | } catch (err) { |
||
20 | pino.error(err,'Unable to load the configuration file, resetting to defaults'); |
||
21 | } |
||
22 | pino.debug(nconf.get(),"Settings"); |
||
23 | nconf.env(); |
||
24 | //Also look for overrides in environment settings |
||
25 | // Do not change these values in this file for an individual ROV, use the ./etc/rovconfig.json instead |
||
26 | nconf.defaults({ |
||
27 | 'deadzone_pos': 50, |
||
28 | 'deadzone_neg': 50, |
||
29 | 'smoothingIncriment': 40, |
||
30 | 'photoDirectory': '/var/www/openrov/photos', |
||
31 | 'pluginsDownloadDirectory': '/usr/share/cockpit/bower_components', |
||
32 | 'cacheDirectory':'/usr/share/cockpit/cache', |
||
33 | 'thrust_modifier_port': 1, |
||
34 | 'thrust_modifier_vertical': -1, |
||
35 | 'thrust_modifier_starbord': 1, |
||
36 | 'thrust_modifier_nport': 2, |
||
37 | 'thrust_modifier_nvertical': -2, |
||
38 | 'thrust_modifier_nstarbord': 2, |
||
39 | 'debug': false, |
||
40 | 'debug_commands': false, |
||
41 | 'production': true, |
||
42 | 'sample_freq': 20, |
||
43 | 'dead_zone': 10, |
||
44 | 'video_frame_rate': 30, |
||
45 | 'video_resolution': 'SXGA', |
||
46 | 'video_device': '/dev/video0', |
||
47 | 'video_port': 8090, |
||
48 | 'port': 8080, |
||
49 | 'serial': '/dev/ttyO1', |
||
50 | 'serial_baud': 115200, |
||
51 | 'systemDirectory': '/opt/openrov/system', |
||
52 | 'dashboardURL': '', |
||
53 | 'USE_MOCK': false, |
||
54 | 'video_url': '/rov/forward-camera' |
||
55 | }); |
||
56 | function savePreferences() { |
||
57 | nconf.save(function (err) { |
||
58 | if (err) { |
||
59 | error(err.message); |
||
60 | return; |
||
61 | } |
||
62 | pino.debug('Configuration saved successfully.'); |
||
63 | }); |
||
64 | } |
||
65 | var getLibPath = function (lib) { |
||
66 | var result = lib; |
||
67 | if (nconf.get('USE_MOCK') === 'true') { |
||
68 | result += '-mock'; |
||
69 | } |
||
70 | return result; |
||
71 | }; |
||
72 | |||
73 | var finalconfig = { |
||
74 | debug: nconf.get('debug'), |
||
75 | debug_commands: nconf.get('debug_commands'), |
||
76 | production: nconf.get('production'), |
||
77 | sample_freq: nconf.get('sample_freq'), |
||
78 | dead_zone: nconf.get('dead_zone'), |
||
79 | video_frame_rate: nconf.get('video_frame_rate'), |
||
80 | video_resolution: nconf.get('video_resolution'), |
||
81 | video_device: nconf.get('video_device'), |
||
82 | video_port: nconf.get('video_port'), |
||
83 | video_url: nconf.get('video_url'), |
||
84 | port: nconf.get('port'), |
||
85 | serial: nconf.get('serial'), |
||
86 | serial_baud: nconf.get('serial_baud'), |
||
87 | dashboardURL: nconf.get('dashboardURL'), |
||
88 | preferences: nconf, |
||
89 | savePreferences: savePreferences, |
||
90 | systemDirectory: nconf.get('systemDirectory') |
||
91 | } |
||
0 ignored issues
–
show
|
|||
92 | |||
93 | pino.debug('config', finalconfig); |
||
94 | |||
95 | return finalconfig; |
||
96 | |||
97 | |||
98 | |||
99 | }; |
||
100 |
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.
Further Readings: