From f86ce165913f623df537a393fa7d8f0988fb8ec3 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Sat, 10 Aug 2019 00:54:35 +0200 Subject: [PATCH] the rest --- Makefile | 10 ++-- navnexus.cc | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++ navparse.cc | 71 +++++++++++++++--------- 3 files changed, 204 insertions(+), 30 deletions(-) create mode 100644 navnexus.cc diff --git a/Makefile b/Makefile index c726bf6..59409ed 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CXXFLAGS:= -std=gnu++17 -Wall -O3 -MMD -MP -ggdb -fno-omit-frame-pointer -Iext/fmt-5.2.1/include/ -Iext/powerblog/ext/simplesocket -Iext/powerblog/ext/ -PROGRAMS = ubxparse navparse ubxdisplay minread ubxtool +PROGRAMS = navparse ubxtool navnexus all: $(PROGRAMS) @@ -11,19 +11,17 @@ clean: H2OPP=ext/powerblog/h2o-pp.o SIMPLESOCKETS=ext/powerblog/ext/simplesocket/swrappers.o ext/powerblog/ext/simplesocket/sclasses.o ext/powerblog/ext/simplesocket/comboaddress.o -ubxparse: ubxparse.o ext/fmt-5.2.1/src/format.o $(H2OPP) $(SIMPLESOCKETS) minicurl.o ubx.o bits.o - g++ -std=gnu++17 $^ -o $@ -pthread -lncurses -L/usr/local/lib -lh2o-evloop -lssl -lcrypto -lz -lcurl # -lwslay navparse: navparse.o ext/fmt-5.2.1/src/format.o $(H2OPP) $(SIMPLESOCKETS) minicurl.o ubx.o bits.o navmon.pb.o g++ -std=gnu++17 $^ -o $@ -pthread -L/usr/local/lib -lh2o-evloop -lssl -lcrypto -lz -lcurl -lprotobuf # -lwslay +navnexus: navnexus.o ext/fmt-5.2.1/src/format.o $(H2OPP) $(SIMPLESOCKETS) minicurl.o ubx.o bits.o navmon.pb.o + g++ -std=gnu++17 $^ -o $@ -pthread -L/usr/local/lib -lh2o-evloop -lssl -lcrypto -lz -lcurl -lprotobuf # -lwslay + navmon.pb.h: navmon.proto protoc --cpp_out=./ navmon.proto -ubxdisplay: ubxdisplay.o ext/fmt-5.2.1/src/format.o - g++ -std=gnu++17 $^ -o $@ -pthread -lncurses - ubxtool: ubxtool.o ubx.o bits.o ext/fmt-5.2.1/src/format.o galileo.o navmon.pb.o g++ -std=gnu++17 $^ -o $@ -lprotobuf diff --git a/navnexus.cc b/navnexus.cc new file mode 100644 index 0000000..575f4bd --- /dev/null +++ b/navnexus.cc @@ -0,0 +1,153 @@ +#include "comboaddress.hh" +#include "sclasses.hh" +#include +#include +#include "navmon.pb.h" +#include "fmt/format.h" +#include "fmt/printf.h" +#include + + +#include +#include +#include +using namespace std; + +std::mutex g_clientmut; +set g_clients; + +std::mutex g_dedupmut; + +set> g_dedup; + +int g_store; + +std::multimap, string> g_history; + +void recvSession(int s, ComboAddress client) +{ + cerr<<"Receiving messages from "< lg(g_dedupmut); + if(g_dedup.count({nmm.gi().gnssid(), nmm.gi().gnsssv(), nmm.gi().gnsswn(), nmm.gi().gnsstow()})) { + cerr<<"Dedupped message from "<< nmm.sourceid()<<" "<< fmt::format("{0} {1} {2} {3}", nmm.gi().gnssid(), nmm.gi().gnsssv(), nmm.gi().gnsswn(), nmm.gi().gnsstow()) << endl; + continue; + } + cerr<<"New message from "<< nmm.sourceid()<<" "<< fmt::format("{0} {1} {2} {3}", nmm.gi().gnssid(), nmm.gi().gnsssv(), nmm.gi().gnsswn(), nmm.gi().gnsstow()) << endl; + g_dedup.insert({nmm.gi().gnssid(), nmm.gi().gnsssv(), nmm.gi().gnsswn(), nmm.gi().gnsstow()}); + } + else + ; // cerr<<"Not an inav message "<< (int) nmm.type()< start; + start.first=time(0)-1800; + start.second=0; + + int count =0; + for(auto iter = g_history.lower_bound(start); iter != g_history.end(); ++iter) { + SWriten(s, iter->second); + ++count; + } + cerr<<"Wrote "< page) } +struct SVPerRecv +{ + int el{-1}, azi{-1}, db{-1}; + uint16_t wn; + uint32_t tow; // last seen +}; + + struct SVStat { uint8_t e5bhs{0}, e1bhs{0}; @@ -124,7 +138,9 @@ struct SVStat int8_t dtLS{0}, dtLSF{0}; uint16_t wnLSF{0}; uint8_t dn; // leap second day number - int16_t el{-1}, azi{-1}, db{-1}; + + map perrecv; + map iods; void addWord(std::basic_string_view page); bool completeIOD() const; @@ -535,6 +551,8 @@ try map utcstats, gpsgststats; for(const auto& s: g_svstats) { + if(!s.second.wn) // this will suck in 20 years + continue; int dw = (uint8_t)s.second.wn - s.second.wn0t; int age = dw * 7 * 86400 + s.second.tow - s.second.t0t * 3600; utcstats[age]=s.first; @@ -551,7 +569,8 @@ try else { int sv = utcstats.begin()->second; // freshest SV long shift = g_svstats[sv].a0 * (1LL<<20) + g_svstats[sv].a1 * utcstats.begin()->first; // in 2^-50 seconds units - ret["utc-offset-ns"] = 1.073741824*ldexp(shift, -20); + // cout<<"sv: "<first<second; // freshest SV - long shift = g_svstats[sv].a0g * (1U<<16) + g_svstats[sv].a1g * utcstats.begin()->first; // in 2^-51 seconds units + long shift = g_svstats[sv].a0g * (1L<<16) + g_svstats[sv].a1g * gpsgststats.begin()->first; // in 2^-51 seconds units ret["gps-offset-ns"] = 1.073741824*ldexp(shift, -21); } @@ -587,8 +606,16 @@ try item["e1bdvs"]=s.second.e1bdvs; item["e5bhs"]=s.second.e5bhs; item["e1bhs"]=s.second.e1bhs; - item["elev"]=s.second.el; - item["db"]=s.second.db; + + nlohmann::json perrecv = nlohmann::json::object(); + for(const auto& pr : s.second.perrecv) { + nlohmann::json det = nlohmann::json::object(); + det["elev"] = pr.second.el; + det["db"] = pr.second.db; + det["last-seen-s"] = (7*86400*(latestWN() - pr.second.wn) + latestTow() - (int)pr.second.tow); + perrecv[to_string(pr.first)]=det; + } + item["perrecv"]=perrecv; item["eph-age-m"] = ephAge(s.second.tow, 60*s.second.liveIOD().t0e)/60.0; item["last-seen-s"] = s.second.tow ? (7*86400*(s.second.wn - s.second.wn) + latestTow() - (int)s.second.tow) : -1; @@ -606,20 +633,13 @@ try Vector core2us(core, our); Vector dx(our, p); // = x-ourx, dy = y-oury, dz = z-ourz; + + // https://ds9a.nl/articles/ - /* https://gis.stackexchange.com/questions/58923/calculating-view-angle - to calculate elevation: - Cos(elevation) = (x*dx + y*dy + z*dz) / Sqrt((x^2+y^2+z^2)*(dx^2+dy^2+dz^2)) - Obtain its principal inverse cosine. Subtract this from 90 degrees if you want - the angle of view relative to a nominal horizon. This is the "elevation." - NOTE! x = you on the ground! - */ double elev = acos ( core2us.inner(dx) / (core2us.length() * dx.length())); double deg = 180.0* (elev/M_PI); - item["calc-elev"] = 90 - deg; + item["elev"] = 90 - deg; - cout< (" - << p.x << ", "<< p.y <<", "<< p.z<<") "< inav((uint8_t*)nmm.gi().contents().c_str(), nmm.gi().contents().size()); int sv = nmm.gi().gnsssv(); g_svstats[sv].wn = nmm.gi().gnsswn(); g_svstats[sv].tow = nmm.gi().gnsstow(); + + g_svstats[sv].perrecv[nmm.sourceid()].wn = nmm.gi().gnsswn(); + g_svstats[sv].perrecv[nmm.sourceid()].tow = nmm.gi().gnsstow(); // cout<<"inav for "<