aboutsummaryrefslogtreecommitdiff
path: root/src/formatter.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-04-07 19:03:05 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2017-04-07 19:03:05 +0200
commit36e59a1991f075e36e117a08321d5e4c4dc00eac (patch)
tree2c89d0b9ad67eb6ebdcd5ed4b1789ebc61ce6723 /src/formatter.cpp
parent84939234eb66fe7957eaf39956f18224e3108c25 (diff)
downloadwifi-triangulator-36e59a1991f075e36e117a08321d5e4c4dc00eac.tar.gz
wifi-triangulator-36e59a1991f075e36e117a08321d5e4c4dc00eac.tar.bz2
wifi-triangulator-36e59a1991f075e36e117a08321d5e4c4dc00eac.tar.xz
wifi-triangulator-36e59a1991f075e36e117a08321d5e4c4dc00eac.zip
o Splitting capture into just two, capture and send to stdout and transmit from stdin.
o Adding formatter that formats the incoming message.
Diffstat (limited to 'src/formatter.cpp')
-rw-r--r--src/formatter.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/formatter.cpp b/src/formatter.cpp
new file mode 100644
index 0000000..b165a89
--- /dev/null
+++ b/src/formatter.cpp
@@ -0,0 +1,54 @@
+#include <iostream>
+#include "wifi-triangulator/core.h"
+
+using namespace std;
+using namespace wifi_triangulator;
+
+void on_probe_request(const pb::probe &p) {
+ cout << "PROBE REQUEST"
+ << ", src=" << eth_mac(p.src()).to_string()
+ << ", dst=" << eth_mac(p.dst()).to_string()
+ << ", rssi=" << p.rssi()
+ << flush
+ << endl;
+}
+
+void on_envelope(pb::envelope envelope) {
+ if (envelope.type() == pb::probe_request) {
+ on_probe_request(envelope.probe());
+ } else {
+ cout << to_string(envelope.type()) << endl;
+ }
+}
+
+int main(int argc, char *argv[]) {
+ GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+ if (argc != 1) {
+ fprintf(stderr, "usage: %s\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ int count = 0;
+ uint8_t buffer[1 << 16];
+ while (!feof(stdin)) {
+ pb::envelope envelope;
+
+ uint16_t size;
+ cin >> size;
+ cin.read(reinterpret_cast<char *>(buffer), size);
+ bool ok = envelope.ParseFromArray(buffer, size);
+ if (!ok) {
+ cerr << "bad read" << endl;
+ continue;
+ }
+
+// cerr << "count=" << count++ << endl;
+
+ on_envelope(envelope);
+ }
+
+ google::protobuf::ShutdownProtobufLibrary();
+
+ return EXIT_SUCCESS;
+}