diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2017-04-07 13:02:41 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2017-04-07 13:02:41 +0200 |
commit | 9eb76adec8d6a6f15a461da7c5e1e6920a92105a (patch) | |
tree | 42b4759b463edb2c76bcdd94077ac0acc3b95da1 | |
parent | 384817a40c541ee48da3bdb5f88508fe871acf38 (diff) | |
download | wifi-triangulator-9eb76adec8d6a6f15a461da7c5e1e6920a92105a.tar.gz wifi-triangulator-9eb76adec8d6a6f15a461da7c5e1e6920a92105a.tar.bz2 wifi-triangulator-9eb76adec8d6a6f15a461da7c5e1e6920a92105a.tar.xz wifi-triangulator-9eb76adec8d6a6f15a461da7c5e1e6920a92105a.zip |
o Better logging.
-rw-r--r-- | main.cpp | 13 | ||||
-rwxr-xr-x | tri-batcher | 28 | ||||
-rwxr-xr-x | tri-import-batch | 8 | ||||
-rwxr-xr-x | tri-influx-exec | 23 |
4 files changed, 68 insertions, 4 deletions
@@ -255,7 +255,7 @@ void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *pa uint8_t type = ieee802_11_header->frame_1; - const char *type_str; + std::string type_str; switch (type) { case 0x40: type_str = "probe request"; @@ -290,8 +290,11 @@ void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *pa case 0x1a: type_str = "ps-poll"; break; - default: - type_str = nullptr; + default: { + std::stringstream s; + s << "0x" << std::hex << std::setw(2) << std::setfill('0') << (int) type; + type_str = s.str(); + } } // printf("ieee802_11_header->frame_ctl=%02x, %s\n", type, type_str ? type_str : "???"); @@ -316,7 +319,9 @@ void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *pa auto src = data.src.to_string(); auto dst = data.dst.to_string(); - printf("data: %lu.%lu, rssi=%d, src=%s, dst=%s\n", data.sec, data.usec, data.rssi, src.c_str(), dst.c_str()); + printf("timestamp=%lu, rssi=%d, src=%s, dst=%s, type=%s\n", ((data.sec * 1000 * 1000) + data.usec) * 1000, + data.rssi, src.c_str(), dst.c_str(), type_str.c_str()); + /// printf("\036{\"timestamp_us\": %lu, \"rssi\": %d, \"src\": \"%s\", \"dst\": \"%s\"}\n", data.sec * 1000 * 1000 + data.usec, data.rssi, src.c_str(), dst.c_str()); fflush(stdout); } diff --git a/tri-batcher b/tri-batcher new file mode 100755 index 0000000..4413100 --- /dev/null +++ b/tri-batcher @@ -0,0 +1,28 @@ +#!/bin/bash + +cmd=$(echo ${@}) + +time_buffer=3 + +rm -f buf + +now=$(date +%s) +ts=$d +while read contents +do + echo $contents >> buf + + # echo now=$now, ts=$ts + if (($ts + $time_buffer < $now)) + then + ts=$now + echo "$d Buf size: " $(wc -l buf) >/dev/stderr + $cmd < buf + rm buf + fi + now=$(date +%s) +done + +echo "$d Buf size: " $(wc -l buf) >/dev/stderr +$cmd < buf +rm buf diff --git a/tri-import-batch b/tri-import-batch new file mode 100755 index 0000000..ab4171c --- /dev/null +++ b/tri-import-batch @@ -0,0 +1,8 @@ +#!/bin/bash + +( +echo "# DML" +echo "# CONTEXT-DATABASE: tri" + +cat - +) | influx -database tri -import -path /dev/stdin diff --git a/tri-influx-exec b/tri-influx-exec new file mode 100755 index 0000000..49dff82 --- /dev/null +++ b/tri-influx-exec @@ -0,0 +1,23 @@ +#!/bin/bash + +file=tri-influx-exec-$$ + +rm -f $file + +buf=() + +while read line +do + l=${line//#*} + echo l: $l > /dev/stderr + + buf+=($l) + + if [[ $l =~ ";" ]] + then + echo cmd: ${buf[*]} > /dev/stderr + echo ${buf[*]} + buf=() + fi + +done |