diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2017-04-07 17:45:02 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2017-04-07 17:45:02 +0200 |
commit | 84939234eb66fe7957eaf39956f18224e3108c25 (patch) | |
tree | 97a6d77c92ad373199cd3aecb2cbcb6488357480 /include/wifi-triangulator | |
parent | bed4c80f31051ec47463caa3e9511374062c6536 (diff) | |
download | wifi-triangulator-84939234eb66fe7957eaf39956f18224e3108c25.tar.gz wifi-triangulator-84939234eb66fe7957eaf39956f18224e3108c25.tar.bz2 wifi-triangulator-84939234eb66fe7957eaf39956f18224e3108c25.tar.xz wifi-triangulator-84939234eb66fe7957eaf39956f18224e3108c25.zip |
o Refactoring into two parts, sender and receiver that sends protobuf messages over UDP.
Diffstat (limited to 'include/wifi-triangulator')
-rw-r--r-- | include/wifi-triangulator/core.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/include/wifi-triangulator/core.h b/include/wifi-triangulator/core.h new file mode 100644 index 0000000..042490a --- /dev/null +++ b/include/wifi-triangulator/core.h @@ -0,0 +1,65 @@ +#pragma once + +#include <cstdint> +#include <sstream> +#include <iomanip> +#include <functional> + +#include "wifi-triangulator.pb.h" + +namespace wifi_triangulator { + +struct eth_mac { + uint8_t a, b, c, d, e, f; + + eth_mac() {} + + eth_mac(uint64_t value) : a(uint8_t(value >> 40 & 0xff)), + b(uint8_t(value >> 32 & 0xff)), + c(uint8_t(value >> 24 & 0xff)), + d(uint8_t(value >> 16 & 0xff)), + e(uint8_t(value >> 9 & 0xff)), + f(uint8_t(value & 0xff)) {} + + std::string to_string() const { + std::stringstream s; + s << std::hex << std::setw(2) << std::setfill('0') + << (int) a << ":" + << std::setw(2) << std::setfill('0') << (int) b << ":" + << std::setw(2) << std::setfill('0') << (int) c << ":" + << std::setw(2) << std::setfill('0') << (int) d << ":" + << std::setw(2) << std::setfill('0') << (int) e << ":" + << std::setw(2) << std::setfill('0') << (int) f; + return s.str(); + } + + operator uint64_t() const { + return uint64_t(a) << 40 | + uint64_t(b) << 32 | + uint64_t(c) << 24 | + uint64_t(d) << 16 | + uint64_t(e) << 8 | + uint64_t(f); + } +} __attribute__((packed)); + +class data { +public: + pb::packet_type type; + long sec; + long usec; + + int rssi; + eth_mac src, dst; + + data(pb::packet_type type, long sec, long usec, int rssi, eth_mac src, eth_mac dst) : + type(type), sec(sec), usec(usec), src(src), rssi(rssi), dst(dst) {} +}; + +int launch_capture(std::string dev, std::function<void(const class data &)>); + +} // namespace wifi_triangulator + +namespace std { +string to_string(wifi_triangulator::pb::packet_type t); +} // namespace std |