-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
26 lines (24 loc) · 702 Bytes
/
index.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
var rssiQuality = require('plott-rssi-quality');
/**
* Converts quality of RSSI signal strength to distance.
*
* @module plott/qualityDistance
* @category helper
* @param {Integer} m dBm RSSI dBm
* @param {Number} p maximum coverage of signal
* @return {Number} distance
* @example
* var distance = plott.qualityDistance(-75, 400);
*
* //=distance
*/
var isInteger = Number.isInteger || function(value) {
return typeof value === "number" &&
isFinite(value) &&
Math.floor(value) === value;
};
module.exports = function (m, p) {
if (!isInteger(p)) throw new Error ('Maximum coverage of signal must be an integer');
m = rssiQuality(m);
return p * (1 - m);
};