aboutsummaryrefslogtreecommitdiff
path: root/src/formatter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/formatter.cpp')
-rw-r--r--src/formatter.cpp50
1 files changed, 27 insertions, 23 deletions
diff --git a/src/formatter.cpp b/src/formatter.cpp
index b165a89..e4874dc 100644
--- a/src/formatter.cpp
+++ b/src/formatter.cpp
@@ -7,21 +7,42 @@ 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());
+void on_frame(const pb::frame &f) {
+ if (f.type() == pb::frame_type::probe_request) {
+ on_probe_request(f.probe());
} else {
- cout << to_string(envelope.type()) << endl;
+// cout << "frame: " << to_string(f.type()) << endl;
}
}
+void on_listener_station_info(const pb::listener_station_info &i) {
+ cout << "LISTENER STATION INFO"
+ << " mac=" << eth_mac(i.mac()).to_string()
+ << ", freq=" << i.freq()
+ << flush
+ << endl;
+}
+
+bool on_envelope(const pb::envelope &envelope) {
+ if (envelope.type() == pb::letter_type::frame_lt) {
+ on_frame(envelope.frame());
+ } else if (envelope.type() == pb::letter_type ::listener_station_info_lt) {
+ on_listener_station_info(envelope.listener_station_info());
+ } else {
+ cout << "Unknown letter type: " << envelope.type() << endl;
+ }
+
+ return true;
+}
+
int main(int argc, char *argv[]) {
+ app_name = argv[0];
+
GOOGLE_PROTOBUF_VERIFY_VERSION;
if (argc != 1) {
@@ -29,24 +50,7 @@ int main(int argc, char *argv[]) {
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);
- }
+ launch_reader_envelope(on_envelope);
google::protobuf::ShutdownProtobufLibrary();