aboutsummaryrefslogtreecommitdiff
path: root/src/transmitter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/transmitter.cpp')
-rw-r--r--src/transmitter.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/transmitter.cpp b/src/transmitter.cpp
new file mode 100644
index 0000000..047d37d
--- /dev/null
+++ b/src/transmitter.cpp
@@ -0,0 +1,79 @@
+#include <iostream>
+#include "wifi-triangulator/core.h"
+
+#include <arpa/inet.h>
+#include <cstring>
+#include <unistd.h>
+
+using namespace std;
+using namespace wifi_triangulator;
+
+class human_output {
+public:
+ void handle(const data &data) {
+ printf("timestamp=%lu, rssi=%d, src=%s, dst=%s, type=%s\n", ((data.sec * 1000 * 1000) + data.usec) * 1000,
+ data.rssi, data.src.to_string().c_str(), data.dst.to_string().c_str(), to_string(data.type).c_str());
+ fflush(stdout);
+ };
+};
+
+int main(int argc, char *argv[]) {
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s [host]\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ string host = argv[1];
+
+ GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+ int s;
+ struct sockaddr_in addr_si;
+ struct sockaddr *addr;
+ socklen_t addr_len;
+
+ if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
+ throw std::runtime_error("socket");
+ }
+
+ memset((char *) &addr_si, 0, sizeof(addr_si));
+ addr_si.sin_family = AF_INET;
+ addr_si.sin_port = htons(3333);
+ if (inet_aton(host.c_str(), &addr_si.sin_addr) == 0) {
+ throw std::runtime_error("Could not resolve " + host);
+ }
+
+ addr = reinterpret_cast<struct sockaddr *>(&addr_si);
+ addr_len = sizeof(addr_si);
+
+ 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;
+ }
+ */
+
+ if (sendto(s, buffer, size, 0, addr, addr_len) == -1) {
+ throw std::runtime_error("sendto failed");
+ }
+
+ cerr << "count=" << count++ << endl;
+ }
+
+ cerr << "transmitter exiting" << endl;
+
+ google::protobuf::ShutdownProtobufLibrary();
+
+ return EXIT_SUCCESS;
+}