-
Notifications
You must be signed in to change notification settings - Fork 7
/
constants.js
329 lines (251 loc) · 8.13 KB
/
constants.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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/****************************************************************************
* recordingCOnfigurations.js
* openacousticdevices.info
* December 2019
*****************************************************************************/
/* Setting parameters */
exports.CONFIGURATIONS = [{
trueSampleRate: 8,
clockDivider: 4,
acquisitionCycles: 16,
oversampleRate: 1,
sampleRate: 384000,
sampleRateDivider: 48,
recordCurrent: 9.22,
energySaverRecordCurrent: 5.92,
listenCurrent: 8.59,
energySaverListenCurrent: 5.41
}, {
trueSampleRate: 16,
clockDivider: 4,
acquisitionCycles: 16,
oversampleRate: 1,
sampleRate: 384000,
sampleRateDivider: 24,
recordCurrent: 9.83,
energySaverRecordCurrent: 6.63,
listenCurrent: 8.72,
energySaverListenCurrent: 5.54
}, {
trueSampleRate: 32,
clockDivider: 4,
acquisitionCycles: 16,
oversampleRate: 1,
sampleRate: 384000,
sampleRateDivider: 12,
recordCurrent: 11.3,
energySaverRecordCurrent: 8.04,
listenCurrent: 8.95,
energySaverListenCurrent: 5.78
}, {
trueSampleRate: 48,
clockDivider: 4,
acquisitionCycles: 16,
oversampleRate: 1,
sampleRate: 384000,
sampleRateDivider: 8,
recordCurrent: 12.3,
energySaverRecordCurrent: 8.93,
listenCurrent: 9.14,
energySaverListenCurrent: 5.98
}, {
trueSampleRate: 96,
clockDivider: 4,
acquisitionCycles: 16,
oversampleRate: 1,
sampleRate: 384000,
sampleRateDivider: 4,
recordCurrent: 15.8,
energySaverRecordCurrent: 15.8,
listenCurrent: 10.0,
energySaverListenCurrent: 10.0
}, {
trueSampleRate: 192,
clockDivider: 4,
acquisitionCycles: 16,
oversampleRate: 1,
sampleRate: 384000,
sampleRateDivider: 2,
recordCurrent: 24.1,
energySaverRecordCurrent: 24.1,
listenCurrent: 11.5,
energySaverListenCurrent: 11.5
}, {
trueSampleRate: 250,
clockDivider: 4,
acquisitionCycles: 16,
oversampleRate: 1,
sampleRate: 250000,
sampleRateDivider: 1,
recordCurrent: 26.4,
energySaverRecordCurrent: 26.4,
listenCurrent: 10.6,
energySaverListenCurrent: 10.6
}, {
trueSampleRate: 384,
clockDivider: 4,
acquisitionCycles: 16,
oversampleRate: 1,
sampleRate: 384000,
sampleRateDivider: 1,
recordCurrent: 38.5,
energySaverRecordCurrent: 38.5,
listenCurrent: 12.7,
energySaverListenCurrent: 12.7
}];
/* Configuration settings to be used when a device is on firmware < 1.4.4 */
/* Only sent to devices. Not used in energy calculations */
exports.OLD_CONFIGURATIONS = [{
trueSampleRate: 8,
clockDivider: 4,
acquisitionCycles: 16,
oversampleRate: 1,
sampleRate: 128000,
sampleRateDivider: 16
}, {
trueSampleRate: 16,
clockDivider: 4,
acquisitionCycles: 16,
oversampleRate: 1,
sampleRate: 128000,
sampleRateDivider: 8
}, {
trueSampleRate: 32,
clockDivider: 4,
acquisitionCycles: 16,
oversampleRate: 1,
sampleRate: 128000,
sampleRateDivider: 4
}];
/* GPS energy consumption */
exports.GPS_FIX_TIME = 0.5 / 60.0;
exports.GPS_FIX_CONSUMPTION = 30.0;
exports.MINIMUM_GPS_FIX_TIME = 30;
/* Packet lengths for each version */
exports.PACKET_LENGTH_VERSIONS = [{
firmwareVersion: [0, 0, 0],
packetLength: 39
}, {
firmwareVersion: [1, 2, 0],
packetLength: 40
}, {
firmwareVersion: [1, 2, 1],
packetLength: 42
}, {
firmwareVersion: [1, 2, 2],
packetLength: 43
}, {
firmwareVersion: [1, 4, 0],
packetLength: 58
}, {
firmwareVersion: [1, 5, 0],
packetLength: 59
}, {
firmwareVersion: [1, 6, 0],
packetLength: 62
}];
const FIRMWARE_OFFICIAL_RELEASE = 0;
const FIRMWARE_OFFICIAL_RELEASE_CANDIDATE = 1;
const FIRMWARE_CUSTOM_EQUIVALENT = 2;
const FIRMWARE_UNSUPPORTED = 3;
exports.FIRMWARE_OFFICIAL_RELEASE = FIRMWARE_OFFICIAL_RELEASE;
exports.FIRMWARE_OFFICIAL_RELEASE_CANDIDATE = FIRMWARE_OFFICIAL_RELEASE_CANDIDATE;
exports.FIRMWARE_CUSTOM_EQUIVALENT = FIRMWARE_CUSTOM_EQUIVALENT;
exports.FIRMWARE_UNSUPPORTED = FIRMWARE_UNSUPPORTED;
const EQUIVALENCE_REGEX = /E[0-9]+\.[0-9]+\.[0-9]+/g;
exports.EQUIVALENCE_REGEX = EQUIVALENCE_REGEX;
/* Remove trailing digit and check if description is in list of supported firmware descriptions */
exports.getFirmwareClassification = (desc) => {
/* If official firmware or a release candidate of the official firmware */
if (desc === 'AudioMoth-Firmware-Basic') {
return FIRMWARE_OFFICIAL_RELEASE;
}
if (desc.replace(/-RC\d+$/, '-RC') === 'AudioMoth-Firmware-Basic-RC') {
return FIRMWARE_OFFICIAL_RELEASE_CANDIDATE;
}
const foundEquivalence = desc.match(EQUIVALENCE_REGEX);
if (foundEquivalence) {
return FIRMWARE_CUSTOM_EQUIVALENT;
}
return FIRMWARE_UNSUPPORTED;
};
/**
* @returns -1: A < B, 0: A === B, 1: A > B
*/
function compareSemanticVersion (version, major, minor, patch) {
for (let i = 0; i < 3; i++) {
const versionNumber = parseInt(version[i]);
const comparator = i === 0 ? major : i === 1 ? minor : patch;
if (versionNumber > comparator) {
return 1;
} else if (versionNumber < comparator) {
return -1;
}
}
return 0;
}
exports.compareSemanticVersion = compareSemanticVersion;
exports.isOlderSemanticVersion = (version, major, minor, patch) => {
return compareSemanticVersion(version, major, minor, patch) === -1;
};
exports.isNewerSemanticVersion = (version, major, minor, patch) => {
return compareSemanticVersion(version, major, minor, patch) === 1;
};
exports.isSameSemanticVersion = (version, major, minor, patch) => {
return compareSemanticVersion(version, major, minor, patch) === 0;
};
exports.isOlderOrEqualSemanticVersion = (version, major, minor, patch) => {
const comparisonResult = compareSemanticVersion(version, major, minor, patch);
return comparisonResult === -1 || comparisonResult === 0;
};
exports.isNewerOrEqualSemanticVersion = (version, major, minor, patch) => {
const comparisonResult = compareSemanticVersion(version, major, minor, patch);
return comparisonResult === 0 || comparisonResult === 1;
};
/* Version number for the latest firmware */
const LATEST_FIRMWARE_VERSION_MAJOR = 1;
const LATEST_FIRMWARE_VERSION_MINOR = 11;
const LATEST_FIRMWARE_VERSION_PATCH = 0;
exports.LATEST_FIRMWARE_VERSION_MAJOR = LATEST_FIRMWARE_VERSION_MAJOR;
exports.LATEST_FIRMWARE_VERSION_MINOR = LATEST_FIRMWARE_VERSION_MINOR;
exports.LATEST_FIRMWARE_VERSION_PATCH = LATEST_FIRMWARE_VERSION_PATCH;
exports.LATEST_FIRMWARE_VERSION_ARRAY = [LATEST_FIRMWARE_VERSION_MAJOR, LATEST_FIRMWARE_VERSION_MINOR, LATEST_FIRMWARE_VERSION_PATCH];
exports.LATEST_FIRMWARE_VERSION_STRING = LATEST_FIRMWARE_VERSION_MAJOR.toString() + '.' + LATEST_FIRMWARE_VERSION_MINOR.toString() + '.' + LATEST_FIRMWARE_VERSION_PATCH.toString();
/* Time zone modes */
exports.TIME_ZONE_MODE_UTC = 0;
exports.TIME_ZONE_MODE_LOCAL = 1;
exports.TIME_ZONE_MODE_CUSTOM = 2;
exports.TIME_ZONE_MODE_STRINGS = ['UTC', 'LOCAL', 'CUSTOM'];
/* Calculation values */
exports.UINT32_MAX = 0xFFFFFFFF;
exports.UINT16_MAX = 0xFFFF;
exports.MILLISECONDS_IN_SECOND = 1000;
exports.SECONDS_IN_MINUTE = 60;
exports.SECONDS_IN_DAY = 86400;
exports.MINUTES_IN_HOUR = 60;
exports.MINUTES_IN_DAY = 1440;
/* Schedule limitations */
exports.MAX_PERIODS = 4;
/* Sunrise and sunset results */
exports.SUN_ABOVE_HORIZON = 0;
exports.NORMAL_SOLUTION = 1;
exports.SUN_BELOW_HORIZON = 2;
exports.DAY_LONGER_THAN_NIGHT = 0;
exports.DAY_EQUAL_TO_NIGHT = 1;
exports.DAY_SHORTER_THAN_NIGHT = 2;
exports.MINIMUM_SUN_RECORDING_GAP = 60;
exports.SUN_RECORDING_GAP_MULTIPLIER = 4;
/* Sun schedule modes */
exports.MODE_BEFORE_SUNRISE_AFTER_SUNRISE = 0;
exports.MODE_BEFORE_SUNSET_AFTER_SUNSET = 1;
exports.MODE_BEFORE_BOTH_AFTER_BOTH = 2;
exports.MODE_BEFORE_SUNSET_AFTER_SUNRISE = 3;
exports.MODE_BEFORE_SUNRISE_AFTER_SUNSET = 4;
/* Sun events modes */
exports.SUNRISE_AND_SUNSET = 0;
exports.CIVIL_DAWN_AND_DUSK = 1;
exports.NAUTICAL_DAWN_AND_DUSK = 2;
exports.ASTRONOMICAL_DAWN_AND_DUSK = 3;
/* First/last recording date range */
exports.MIN_FIRST_LAST_DATE = '2020-01-01';
exports.MAX_FIRST_LAST_DATE = '2029-12-31';