-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeacondist.cpp
More file actions
64 lines (54 loc) · 1.84 KB
/
beacondist.cpp
File metadata and controls
64 lines (54 loc) · 1.84 KB
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
/* distance to station based on RSSI and reference station
* stations must be very very close to same
* Project Crew™ 9/3/2025
*/
#include <iostream>
#include <cmath>
#include <exception>
#include <filesystem>
using namespace std;
namespace fs = std::filesystem;
int
main(int argc, char * argv[])
{
float ref,
d,
N,
measured;
string progname;
try
{
fs::path argv0(argv[0]);
/* strip dirname and extension */
progname = (argv0.stem().string());
if (argc > 5)
/* too many args, throw excretion */
throw invalid_argument("too many args");
/* get the args */
ref = stof(argv[1]);
d = stof(argv[2]);
N = stof(argv[3]);
measured = stof(argv[4]);
/* output */
cout << fixed << setprecision(1)
/* we are servants of our formulaic ways */
<< powf(10.0, ((ref - measured) /
(10.0 * N))) * d << endl;
}catch (...)
{
/* usage */
cerr << endl
<< " " << progname << " can find you about what distance to the transmitter" << endl
<< " base on the RSSI. Reference value from a station close to same" << endl
<< " build is use to compare the wave." << endl
<< endl
<< " Path-loss exponent (N): Accounts for signal loss due to environmental" << endl
<< " factors, ranging from 2 in open spaces to 4 in" << endl
<< " more obstructed environments." << endl
<< endl
<< " USAGE: $ " << progname << " [RefRSSI] [RefDistance] [Path-loss exponent (N)] [RSSI]" << endl
<< endl;
return(EXIT_FAILURE);
}
return(EXIT_SUCCESS);
}