From 2eb900c433006831f8bab83587ca00f33bd3fe61 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Fri, 3 Jul 2020 23:23:24 +0200 Subject: [PATCH] teach reporter to do ephemeris calculations (still using the WRONG af0!) and feed them into influxdb --- Makefile | 2 +- reporter.cc | 394 +++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 364 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 5e45bc8..fea9f34 100644 --- a/Makefile +++ b/Makefile @@ -79,7 +79,7 @@ decrypt: decrypt.o bits.o ext/fmt-6.1.2/src/format.o navparse: navparse.o ext/fmt-6.1.2/src/format.o $(H2OPP) $(SIMPLESOCKETS) minicurl.o ubx.o bits.o navmon.pb.o gps.o ephemeris.o beidou.o glonass.o $(patsubst %.cc,%.o,$(wildcard ext/sgp4/libsgp4/*.cc)) tle.o navmon.o coverage.o osen.o trkmeas.o influxpush.o ${EXTRADEP} githash.o sbas.o rtcm.o $(CXX) -std=gnu++17 $^ -o $@ -pthread -L/usr/local/lib -L/usr/local/opt/openssl/lib/ -lh2o-evloop -lssl -lcrypto -lz -lcurl -lprotobuf $(WSLAY) -reporter: reporter.o ext/fmt-6.1.2/src/format.o $(SIMPLESOCKETS) minicurl.o ubx.o bits.o navmon.pb.o gps.o ephemeris.o beidou.o glonass.o $(patsubst %.cc,%.o,$(wildcard ext/sgp4/libsgp4/*.cc)) tle.o navmon.o coverage.o osen.o githash.o +reporter: reporter.o ext/fmt-6.1.2/src/format.o $(SIMPLESOCKETS) minicurl.o ubx.o bits.o navmon.pb.o gps.o ephemeris.o beidou.o glonass.o $(patsubst %.cc,%.o,$(wildcard ext/sgp4/libsgp4/*.cc)) tle.o navmon.o coverage.o osen.o githash.o influxpush.o $(CXX) -std=gnu++17 $^ -o $@ -pthread -L/usr/local/lib -lprotobuf -lcurl sp3feed: sp3feed.o ext/fmt-6.1.2/src/format.o $(SIMPLESOCKETS) minicurl.o ubx.o bits.o navmon.pb.o gps.o ephemeris.o beidou.o glonass.o $(patsubst %.cc,%.o,$(wildcard ext/sgp4/libsgp4/*.cc)) tle.o navmon.o coverage.o osen.o influxpush.o githash.o sp3.o diff --git a/reporter.cc b/reporter.cc index 5395dc7..9383cde 100644 --- a/reporter.cc +++ b/reporter.cc @@ -4,9 +4,13 @@ #include "navmon.hh" #include "fmt/format.h" #include "fmt/printf.h" - +#include "galileo.hh" +#include "gps.hh" #include "CLI/CLI.hpp" #include "version.hh" +#include "ephemeris.hh" +#include "influxpush.hh" +#include "sp3.hh" static char program[]="reporter"; @@ -25,7 +29,7 @@ public: struct Results { vector d; - bool dirty{false}; + mutable bool dirty{false}; double median() const { return quantile(0.5); @@ -41,7 +45,7 @@ public: } }; - const Results& done() + const Results& done() const { if(results.dirty) { sort(results.d.begin(), results.d.end()); @@ -49,9 +53,12 @@ public: } return results; } - + bool empty() const + { + return results.d.empty(); + } private: - Results results; + mutable Results results; }; /* @@ -81,6 +88,7 @@ struct IntervalStat bool ripe{false}; bool expired{false}; double rtcmDist{-1}; + std::optional rtcmDClock; }; @@ -100,11 +108,15 @@ int main(int argc, char **argv) CLI::App app(program); string periodarg("1d"); string beginarg, endarg; + string sp3src("default"); + int gnssid=2; app.add_flag("--version", doVERSION, "show program version and copyright"); app.add_option("--period,-p", periodarg, "period over which to report (1h, 1w)"); app.add_option("--begin,-b", beginarg, "Beginning"); app.add_option("--end,-e", endarg, "End"); + app.add_option("--sp3src", sp3src, "Identifier of SP3 source"); app.add_option("--sigid,-s", sigid, "Signal identifier. 1 or 5 for Galileo."); + app.add_option("--gnssid,-g", gnssid, "gnssid, 0 GPS, 2 Galileo"); app.add_option("--influxdb", influxDBName, "Name of influxdb database"); try { app.parse(argc, argv); @@ -131,7 +143,8 @@ int main(int argc, char **argv) string url="http://127.0.0.1:8086/query?db="+influxDBName+"&epoch=s&q="; - string query="select distinct(value) from sisa where "+period+" and sigid='"+to_string(sigid)+"' group by gnssid,sv,sigid,time(10m)"; + string sisaname = (gnssid==2) ? "sisa" : "gpsura"; + string query="select distinct(value) from "+sisaname+" where "+period+" and sigid='"+to_string(sigid)+"' group by gnssid,sv,sigid,time(10m)"; cout<<"query: "< 1 && v[1] != nullptr) { @@ -187,17 +201,50 @@ int main(int argc, char **argv) } } - ///////////////////// + ///////////////////// rtcm-eph - res = mc.getURL(url + mc.urlEncode("select mean(\"total-dist\") from \"rtcm-eph-correction\" where "+period+" and sigid='"+to_string(sigid)+"' group by gnssid,sv,sigid,time(10m)")); + + string rtcmQuery = "select mean(\"radial\") from \"rtcm-eph-correction\" where "+period+" and sigid='"+to_string(sigid)+"' and gnssid='"+to_string(gnssid)+"' group by gnssid,sv,sigid,time(10m)"; + cout<<"rtcmquery: "<> galephs; + map> gpsephs; + + res = mc.getURL(url + mc.urlEncode("select * from \"ephemeris-actual\" where "+period+" and sigid='"+to_string(sigid)+"' and gnssid='"+to_string(gnssid)+"' group by gnssid,sv,sigid")); + j = nlohmann::json::parse(res); + for(const auto& sv : j["results"][0]["series"]) { + try { + const auto& tags=sv["tags"]; + SatID id{(unsigned int)std::stoi((string)tags["gnssid"]), (unsigned int)std::stoi((string)tags["sv"]), (unsigned int)std::stoi((string)tags["sigid"])}; + // cout << makeSatIDName(id) <<": "< cmap; + for(const auto& c : sv["columns"]) { + cmap[c]=cmap.size(); + } + + for(const auto& v : sv["values"]) { + // cout << makeSatIDName(id)<<": crc "<> sp3s; + string spq3="select * from \"sp3\" where "+period+" and sp3src =~ /"+sp3src+"/ and gnssid='"+to_string(gnssid)+"' group by gnssid,sv,sigid"; + cout<<"sp3 query: "< cmap; + for(const auto& c : sv["columns"]) { + cmap[c]=cmap.size(); + } + + for(const auto& v : sv["values"]) { + // cout << makeSatIDName(id)<<": time "< sp3zerrors, sp3clockerrors; + ///////////////////// + for(const auto& svsp3 : sp3s) { + const auto& id = svsp3.first; + const auto& es = svsp3.second; + // cout<<"Looking at SP3 for " << makeSatIDName(id)<<", have "<first)<<" iod "<second.iodnav; + + // our UTC timestamp from SP3 need to be converted into a tow + + int offset = id.gnss ? 935280000 : 315964800; + int sp3tow = (e.first - offset) % (7*86400); + Point epos; + getCoordinates(sp3tow, iter->second, &epos); + + double clkoffset= iter->second.getAtomicOffset(sp3tow).first - e.second.clockBias; + + // cout<<" "<second.getAtomicOffset(sp3tow).first <<" v " << e.second.clockBias<<" ns "; + // cout << " ("< ("< " << v.length(); + + Vector dir(Point(0,0,0), sp3pos); + dir.norm(); + + Point cv=sp3pos; + cv.x -= 0.519 * dir.x; + cv.y -= 0.519 * dir.y; + cv.z -= 0.519 * dir.z; + + Vector v2(epos, cv); + // cout<< " -> " << v2.length(); + + // cout<<" z-error: "<second.iodnav}}, + e.first); + + sp3clockerrors[id].add(clkoffset); // nanoseconds + sp3zerrors[id].add(100*dir.inner(v) - 80); // meters -> cm + } + } + else if(id.gnss==0) { + const auto& svephs = gpsephs[id]; + // this is keyed on the moment of _issue_ + auto iter = svephs.lower_bound(e.first); + if(iter != svephs.end() && iter != svephs.begin()) { + --iter; + // cout << "found ephemeris from "<< humanTimeShort(iter->first)<<" iod "<second.iodnav; + + // our UTC timestamp from SP3 need to be converted into a tow + + int offset = 315964800; + int sp3tow = (e.first - offset) % (7*86400); + Point epos; + getCoordinates(sp3tow, iter->second, &epos); + + double clkoffset= getGPSAtomicOffset(sp3tow, iter->second).first - e.second.clockBias; + + // cout<<" "<second.getAtomicOffset(sp3tow).first <<" v " << e.second.clockBias<<" ns "; + // cout << " ("< ("< " << v.length(); + + Vector dir(Point(0,0,0), sp3pos); + dir.norm(); + + Point cv=sp3pos; + cv.x -= 0.519 * dir.x; + cv.y -= 0.519 * dir.y; + cv.z -= 0.519 * dir.z; + + Vector v2(epos, cv); + // cout<< " -> " << v2.length(); + + // cout<<" z-error: "<second.gpsiod}}, + e.first); + + sp3clockerrors[id].add(clkoffset); // nanoseconds + sp3zerrors[id].add(100*dir.inner(v)); // meters -> cm + } + } + } + } + + + ///////////////////// + g_stats.erase({2,14,1}); g_stats.erase({2,18,1}); g_stats.erase({2,14,5}); @@ -225,9 +519,17 @@ int main(int argc, char **argv) if(sv.second.rbegin()->first > stop) stop = sv.second.rbegin()->first; } - - if(sv.second.size() > maxintervals) - maxintervals = sv.second.size(); + unsigned int liveInterval=0; + for(const auto i : sv.second) { + if(i.second.sisa.has_value()) + liveInterval++; + else { + // cout< maxintervals) + maxintervals = liveInterval; } cout<<"Report on "<= 0) { rtcm.add(i.second.rtcmDist); totRTCM.add(i.second.rtcmDist); } + + if(i.second.rtcmDClock) + clockRtcm.add(*i.second.rtcmDClock * 100); if(i.second.ripe) ripe++; @@ -273,37 +579,63 @@ int main(int argc, char **argv) napa++; } } + // cout<