From 4eba89add8db804c33e8692edf5b27c2d3a2e365 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 7 Apr 2017 21:49:36 +0200 Subject: o Cleaning up code, fixing many small bugs. o Making a better envelope format. o Reading out the interface's channel. --- src/formatter.cpp | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) (limited to 'src/formatter.cpp') 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(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(); -- cgit v1.2.3