aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.cpp13
-rwxr-xr-xtri-batcher28
-rwxr-xr-xtri-import-batch8
-rwxr-xr-xtri-influx-exec23
4 files changed, 68 insertions, 4 deletions
diff --git a/main.cpp b/main.cpp
index eac6aeb..e862ee1 100644
--- a/main.cpp
+++ b/main.cpp
@@ -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