Merge branch 'master' into console-log-with-time

pull/19/head
bert hubert 2019-10-15 18:12:18 +02:00 committed by GitHub
commit b7e2ea0c93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 303 additions and 1246 deletions

View File

@ -22,7 +22,7 @@ clean:
rm -f ext/fmt-5.2.1/src/format.o
navparse: navparse.o ext/fmt-5.2.1/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
navparse: navparse.o ext/fmt-5.2.1/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
$(CXX) -std=gnu++17 $^ -o $@ -pthread -L/usr/local/lib -L/usr/local/opt/openssl/lib/ -lh2o-evloop -lssl -lcrypto -lz -lcurl -lprotobuf $(WSLAY)
navdump: navdump.o ext/fmt-5.2.1/src/format.o bits.o navmon.pb.o gps.o ephemeris.o beidou.o glonass.o navmon.o $(patsubst %.cc,%.o,$(wildcard ext/sgp4/libsgp4/*.cc)) tle.o sp3.o

View File

@ -79,7 +79,7 @@ Running
-------
Once compiled, run for example `./ubxtool --wait --port /dev/ttyACM0
--station 1 --stdout | ./ubxparse 10000 html null`
--station 1 --stdout | ./navparse 10000 html null`
Next up, browse to http://[::1]:10000 (or try http://localhost:10000/ and
you should be in business. ubxtool changes (non-permanently) the

78
coverage.cc 100644
View File

@ -0,0 +1,78 @@
#include <map>
#include "galileo.hh"
#include "minivec.hh"
#include "navmon.hh"
#include "navparse.hh"
#include "ephemeris.hh"
#include "fmt/format.h"
#include "fmt/printf.h"
#include <fstream>
using namespace std;
extern GetterSetter<map<int, GalileoMessage::Almanac>> g_galileoalmakeeper;
extern GetterSetter<svstats_t> g_statskeeper;
covmap_t emitCoverage()
{
covmap_t ret;
ofstream cmap("covmap.csv");
cmap<<"latitude longitude count5 count10 count20"<<endl;
map<int, Point> sats;
auto galileoalma = g_galileoalmakeeper.get();
auto svstats = g_statskeeper.get();
auto pseudoTow = (time(0) - 820368000) % (7*86400);
// cout<<"pseudoTow "<<pseudoTow<<endl;
for(const auto &g : galileoalma) {
Point sat;
getCoordinates(pseudoTow, g.second, &sat);
if(g.first < 0)
continue;
if(svstats[{2,g.first,1}].completeIOD() && svstats[{2,g.first,1}].liveIOD().sisa == 255) {
// cout<<g.first<<" NAPA!"<<endl;
continue;
}
sats[g.first]=sat;
}
double R = 6371000;
for(double latitude = 90 ; latitude > -90; latitude-=0.5) { // north-south
double phi = M_PI* latitude / 180;
double longsteps = 1 + 360.0 * cos(phi);
double step = 180.0 / longsteps;
vector<tuple<double, int, int, int>> latvect;
for(double longitude = -180; longitude < 180; longitude += step) { // east - west
Point p;
// phi = latitude, lambda = longitude
double lambda = M_PI* longitude / 180;
p.x = R * cos(phi) * cos(lambda);
p.y = R * cos(phi) * sin(lambda);
p.z = R * sin(phi);
if(longitude == -180) {
auto longlat = getLongLat(p.x, p.y, p.z);
// cout<<fmt::sprintf("%3.0f ", 180.0*longlat.second/M_PI);
}
int numsats5=0, numsats10=0, numsats20=0;
for(const auto& s : sats) {
// double getElevationDeg(const Point& sat, const Point& our);
double elev = getElevationDeg(s.second, p);
if(elev > 5.0)
numsats5++;
if(elev > 10.0)
numsats10++;
if(elev > 20.0)
numsats20++;
}
if(numsats20 < 4)
latvect.push_back(make_tuple(longitude, numsats5, numsats10, numsats20));
// cmap << longitude <<" " <<latitude <<" " << numsats5 << " " <<numsats10<<" "<<numsats20<<endl;
}
if(!latvect.empty())
ret.push_back(make_pair(latitude, latvect));
}
return ret;
}

View File

@ -32,7 +32,7 @@ struct GalileoMessage
{
wtype = getbitu(&page[0], 0, 6);
if(wtype >= parsers.size()) {
std::cerr<<"Asked for impossible galileo type "<<wtype<<std::endl;
// std::cerr<<"Asked for impossible galileo type "<<(int)wtype<<std::endl;
return wtype;
}

View File

@ -150,7 +150,7 @@ function maketable(str, arr)
if(column == "sisa" && myRe.test(row[column]))
ret.color="#ff2222";
if(column == "sisa" && row[column]=="NO SIS AVAILABLE")
if(column == "sisa" && row[column]=="NO SISA AVAILABLE")
ret.color="#ff2222";
return ret;
})

View File

@ -4,6 +4,7 @@
#include <time.h>
#include <string>
#include <tuple>
#include <mutex>
struct EofException{};
size_t readn2(int fd, void* buffer, size_t len);
@ -20,3 +21,28 @@ struct SatID
return std::tie(gnss, sv, sigid) < std::tie(rhs.gnss, rhs.sv, rhs.sigid);
}
};
template<typename T>
class GetterSetter
{
public:
void set(const T& t)
{
std::lock_guard<std::mutex> mut(d_lock);
d_t = t;
}
T get()
{
T ret;
{
std::lock_guard<std::mutex> mut(d_lock);
ret = d_t;
}
return ret;
}
private:
T d_t;
std::mutex d_lock;
};

View File

@ -27,6 +27,7 @@
#include <optional>
#include "navmon.hh"
#include <Tle.h>
#include "navparse.hh"
using namespace std;
struct ObserverPosition
@ -36,31 +37,6 @@ struct ObserverPosition
};
std::map<int, ObserverPosition> g_srcpos;
template<typename T>
class GetterSetter
{
public:
void set(const T& t)
{
std::lock_guard<std::mutex> mut(d_lock);
d_t = t;
}
T get()
{
T ret;
{
std::lock_guard<std::mutex> mut(d_lock);
ret = d_t;
}
return ret;
}
private:
T d_t;
std::mutex d_lock;
};
map<int, BeidouAlmanacEntry> g_beidoualma;
map<int, pair<GlonassMessage, GlonassMessage>> g_glonassalma;
@ -117,7 +93,7 @@ string humanSisa(uint8_t sisa)
return std::to_string(200 + 16*(sval-100))+" cm";
if(sisa < 255)
return "SPARE";
return "NO SIS AVAILABLE";
return "NO SISA AVAILABLE";
}
string humanUra(uint8_t ura)
@ -130,64 +106,6 @@ string humanUra(uint8_t ura)
}
struct SVIOD
{
std::bitset<32> words;
int gnssid;
uint32_t t0e;
uint32_t e, sqrtA;
int32_t m0, omega0, i0, omega, idot, omegadot, deltan;
int16_t cuc{0}, cus{0}, crc{0}, crs{0}, cic{0}, cis{0};
// 60 seconds
uint16_t t0c; // clock epoch, stored UNSCALED, since it is not in the same place as GPS
// 2^-34 2^-46
int32_t af0{0} , af1{0};
// 2^-59
int8_t af2{0};
uint8_t sisa;
uint32_t wn{0}, tow{0};
bool complete() const
{
if(gnssid==2)
return words[1] && words[2] && words[3] && words[4];
else
return words[2] && words[3];
}
void addGalileoWord(std::basic_string_view<uint8_t> page);
double getMu() const
{
if(gnssid == 2) return 3.986004418 * pow(10.0, 14.0);
if(gnssid == 0) return 3.986005 * pow(10.0, 14.0);
throw std::runtime_error("getMu() called for unsupported gnssid "+to_string(gnssid));
} // m^3/s^2
// same for galileo & gps
double getOmegaE() const { return 7.2921151467 * pow(10.0, -5.0);} // rad/s
uint32_t getT0e() const { return t0e; }
uint32_t getT0c() const { return 60*t0c; }
double getSqrtA() const { return ldexp(sqrtA, -19); }
double getE() const { return ldexp(e, -33); }
double getCuc() const { return ldexp(cuc, -29); } // radians
double getCus() const { return ldexp(cus, -29); } // radians
double getCrc() const { return ldexp(crc, -5); } // meters
double getCrs() const { return ldexp(crs, -5); } // meters
double getM0() const { return ldexp(m0 * M_PI, -31); } // radians
double getDeltan()const { return ldexp(deltan *M_PI, -43); } //radians/s
double getI0() const { return ldexp(i0 * M_PI, -31); } // radians
double getCic() const { return ldexp(cic, -29); } // radians
double getCis() const { return ldexp(cis, -29); } // radians
double getOmegadot() const { return ldexp(omegadot * M_PI, -43); } // radians/s
double getOmega0() const { return ldexp(omega0 * M_PI, -31); } // radians
double getIdot() const { return ldexp(idot * M_PI, -43); } // radians/s
double getOmega() const { return ldexp(omega * M_PI, -31); } // radians
};
void SVIOD::addGalileoWord(std::basic_string_view<uint8_t> page)
{
@ -231,78 +149,7 @@ void SVIOD::addGalileoWord(std::basic_string_view<uint8_t> page)
}
struct SVPerRecv
{
int el{-1}, azi{-1}, db{-1};
time_t deltaHzTime{-1};
double deltaHz{-1};
double prres{-1};
time_t t; // last seen
};
/* Most of thes fields are raw, EXCEPT:
t0t = seconds, raw fields are 3600 seconds (galileo), 4096 seconds (GPS)
*/
struct SVStat
{
uint8_t e5bhs{0}, e1bhs{0};
uint8_t gpshealth{0};
uint16_t ai0{0};
int16_t ai1{0}, ai2{0};
bool sf1{0}, sf2{0}, sf3{0}, sf4{0}, sf5{0};
int BGDE1E5a{0}, BGDE1E5b{0};
bool e5bdvs{false}, e1bdvs{false};
uint16_t wn{0}; // we put the "unrolled" week number here!
uint32_t tow{0}; // "last seen"
//
// 2^-30 2^-50 1 8-bit week
int32_t a0{0}, a1{0}, t0t{0}, wn0t{0};
int32_t a0g{0}, a1g{0}, t0g{0}, wn0g{0};
int8_t dtLS{0}, dtLSF{0};
uint16_t wnLSF{0};
uint8_t dn; // leap second day number
// 1 2^-31 2^-43 2^-55 16 second
int ura, af0, af1, af2, t0c, gpsiod; // GPS parameters that should not be here XXX (or perhaps they should)
GPSAlmanac gpsalma;
// beidou:
int t0eMSB{-1}, t0eLSB{-1}, aode{-1}, aodc{-1};
BeidouMessage beidouMessage, oldBeidouMessage;
BeidouMessage lastBeidouMessage1, lastBeidouMessage2;
TLERepo::Match tleMatch;
double lastTLELookupX{0};
// new galileo
GalileoMessage galmsg;
map<int, GalileoMessage> galmsgTyped;
// Glonass
GlonassMessage glonassMessage;
pair<uint32_t, GlonassMessage> glonassAlmaEven;
map<uint64_t, SVPerRecv> perrecv;
double latestDisco{-1}, latestDiscoAge{-1}, timeDisco{-1000};
map<int, SVIOD> iods;
void addGalileoWord(std::basic_string_view<uint8_t> page);
bool completeIOD() const;
uint16_t getIOD() const;
SVIOD liveIOD() const;
SVIOD& getEph(int i) { return iods[i]; } // XXXX gps adaptor
pair<int,SVIOD> prevIOD{-1, SVIOD()};
void clearPrev()
{
prevIOD.first = -1;
}
void checkCompleteAndClean(int iod);
};
bool SVStat::completeIOD() const
{
@ -409,7 +256,6 @@ void SVStat::addGalileoWord(std::basic_string_view<uint8_t> page)
}
typedef std::map<SatID, SVStat> svstats_t;
svstats_t g_svstats;
GetterSetter<svstats_t> g_statskeeper;
@ -657,7 +503,7 @@ std::optional<double> getHzCorrection(time_t now, int src, unsigned int gnssid,
std::string humanBhs(int bhs)
{
static vector<string> options{"ok", "out of service", "will be out of service", "test"};
if(bhs >= options.size()) {
if(bhs >= (int)options.size()) {
cerr<<"Asked for humanBHS "<<bhs<<endl;
return "??";
}
@ -869,8 +715,17 @@ try
item["observed"] = false;
for(uint32_t sigid : {0,1,5}) {
if(auto iter = svstats.find({2, (uint32_t)ae.first, sigid}); iter != svstats.end()) {
if(time(0) - nanoTime(2, iter->second.wn, iter->second.tow)/1000000000 < 300)
if(iter->second.completeIOD()) {
item["sisa"] = iter->second.liveIOD().sisa;
}
// if we hit an 'observed', stop trying sigids
if(time(0) - nanoTime(2, iter->second.wn, iter->second.tow)/1000000000 < 300) {
item["observed"] = true;
break;
}
}
}
@ -1027,7 +882,6 @@ try
h2s.addHandler("/sv.json", [](auto handler, auto req) {
string_view path = convert(req->path);
cout<<path<<endl;
nlohmann::json ret = nlohmann::json::object();
SatID id;
@ -1121,6 +975,33 @@ try
return ret;
}
);
h2s.addHandler("/galcov.json", [](auto handler, auto req) {
auto cov = emitCoverage();
auto ret = nlohmann::json::array();
// ret =
// [ [90, [[-180, 3,2,1], [-179, 3,2,1], ... [180,3,2,1] ]]
// [89, [[-180, 4], [-179, 4], ... [180,2] ]]
// ]
for(const auto& latvect : cov) {
auto jslatvect = nlohmann::json::array();
auto jslongvect = nlohmann::json::array();
for(const auto& longpair : latvect.second) {
auto jsdatum = nlohmann::json::array();
jsdatum.push_back((int)get<0>(longpair));
jsdatum.push_back(get<1>(longpair));
jsdatum.push_back(get<2>(longpair));
jsdatum.push_back(get<3>(longpair));
jslongvect.push_back(jsdatum);
}
jslatvect.push_back(latvect.first);
jslatvect.push_back(jslongvect);
ret.push_back(jslatvect);
}
return ret;
});
h2s.addHandler("/svs.json", [](auto handler, auto req) {
auto svstats = g_statskeeper.get();

149
navparse.hh 100644
View File

@ -0,0 +1,149 @@
#include "navmon.hh"
#include "galileo.hh"
#include "gps.hh"
#include "beidou.hh"
#include "glonass.hh"
#include <map>
#include "tle.hh"
using namespace std; // XXX
struct SVPerRecv
{
int el{-1}, azi{-1}, db{-1};
time_t deltaHzTime{-1};
double deltaHz{-1};
double prres{-1};
time_t t; // last seen
};
struct SVIOD
{
std::bitset<32> words;
int gnssid;
uint32_t t0e;
uint32_t e, sqrtA;
int32_t m0, omega0, i0, omega, idot, omegadot, deltan;
int16_t cuc{0}, cus{0}, crc{0}, crs{0}, cic{0}, cis{0};
// 60 seconds
uint16_t t0c; // clock epoch, stored UNSCALED, since it is not in the same place as GPS
// 2^-34 2^-46
int32_t af0{0} , af1{0};
// 2^-59
int8_t af2{0};
uint8_t sisa;
uint32_t wn{0}, tow{0};
bool complete() const
{
if(gnssid==2)
return words[1] && words[2] && words[3] && words[4];
else
return words[2] && words[3];
}
void addGalileoWord(std::basic_string_view<uint8_t> page);
double getMu() const
{
if(gnssid == 2) return 3.986004418 * pow(10.0, 14.0);
if(gnssid == 0) return 3.986005 * pow(10.0, 14.0);
throw std::runtime_error("getMu() called for unsupported gnssid "+to_string(gnssid));
} // m^3/s^2
// same for galileo & gps
double getOmegaE() const { return 7.2921151467 * pow(10.0, -5.0);} // rad/s
uint32_t getT0e() const { return t0e; }
uint32_t getT0c() const { return 60*t0c; }
double getSqrtA() const { return ldexp(sqrtA, -19); }
double getE() const { return ldexp(e, -33); }
double getCuc() const { return ldexp(cuc, -29); } // radians
double getCus() const { return ldexp(cus, -29); } // radians
double getCrc() const { return ldexp(crc, -5); } // meters
double getCrs() const { return ldexp(crs, -5); } // meters
double getM0() const { return ldexp(m0 * M_PI, -31); } // radians
double getDeltan()const { return ldexp(deltan *M_PI, -43); } //radians/s
double getI0() const { return ldexp(i0 * M_PI, -31); } // radians
double getCic() const { return ldexp(cic, -29); } // radians
double getCis() const { return ldexp(cis, -29); } // radians
double getOmegadot() const { return ldexp(omegadot * M_PI, -43); } // radians/s
double getOmega0() const { return ldexp(omega0 * M_PI, -31); } // radians
double getIdot() const { return ldexp(idot * M_PI, -43); } // radians/s
double getOmega() const { return ldexp(omega * M_PI, -31); } // radians
};
/* Most of thes fields are raw, EXCEPT:
t0t = seconds, raw fields are 3600 seconds (galileo), 4096 seconds (GPS)
*/
struct SVStat
{
uint8_t e5bhs{0}, e1bhs{0};
uint8_t gpshealth{0};
uint16_t ai0{0};
int16_t ai1{0}, ai2{0};
bool sf1{0}, sf2{0}, sf3{0}, sf4{0}, sf5{0};
int BGDE1E5a{0}, BGDE1E5b{0};
bool e5bdvs{false}, e1bdvs{false};
uint16_t wn{0}; // we put the "unrolled" week number here!
uint32_t tow{0}; // "last seen"
//
// 2^-30 2^-50 1 8-bit week
int32_t a0{0}, a1{0}, t0t{0}, wn0t{0};
int32_t a0g{0}, a1g{0}, t0g{0}, wn0g{0};
int8_t dtLS{0}, dtLSF{0};
uint16_t wnLSF{0};
uint8_t dn; // leap second day number
// 1 2^-31 2^-43 2^-55 16 second
int ura, af0, af1, af2, t0c, gpsiod; // GPS parameters that should not be here XXX (or perhaps they should)
GPSAlmanac gpsalma;
// beidou:
int t0eMSB{-1}, t0eLSB{-1}, aode{-1}, aodc{-1};
BeidouMessage beidouMessage, oldBeidouMessage;
BeidouMessage lastBeidouMessage1, lastBeidouMessage2;
TLERepo::Match tleMatch;
double lastTLELookupX{0};
// new galileo
GalileoMessage galmsg;
map<int, GalileoMessage> galmsgTyped;
// Glonass
GlonassMessage glonassMessage;
pair<uint32_t, GlonassMessage> glonassAlmaEven;
map<uint64_t, SVPerRecv> perrecv;
double latestDisco{-1}, latestDiscoAge{-1}, timeDisco{-1000};
map<int, SVIOD> iods;
void addGalileoWord(std::basic_string_view<uint8_t> page);
bool completeIOD() const;
uint16_t getIOD() const;
SVIOD liveIOD() const;
SVIOD& getEph(int i) { return iods[i]; } // XXXX gps adaptor
pair<int,SVIOD> prevIOD{-1, SVIOD()};
void clearPrev()
{
prevIOD.first = -1;
}
void checkCompleteAndClean(int iod);
};
typedef std::map<SatID, SVStat> svstats_t;
// a vector of pairs of latidude,vector<longitude,numsats>
typedef vector<pair<double,vector<tuple<double, int, int, int> > > > covmap_t;
covmap_t emitCoverage();

2
tle.cc
View File

@ -98,7 +98,7 @@ TLERepo::Match TLERepo::getBestMatch(time_t now, double x, double y, double z, T
distances.insert({1000.0*(rot - sat).Magnitude(),sgp4.first});
}
catch(SatelliteException& se) {
cerr<<"TLE error: "<<se.what()<<endl;
// cerr<<"TLE error: "<<se.what()<<endl;
continue;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -726,6 +726,7 @@ int main(int argc, char** argv)
pvt.nano += 1000000000;
}
if(!g_gnssutc.tv_sec) {
if (doDEBUG) { cerr<<humanTimeNow()<<" Got initial timestamp: "<<humanTime(satt)<<endl; }
}
g_gnssutc.tv_sec = satt;
@ -733,6 +734,7 @@ int main(int argc, char** argv)
continue;
}
if(!g_gnssutc.tv_sec) {
if (doDEBUG) { cerr<<humanTimeNow()<<" Ignoring message with class "<<(int)msg.getClass()<< " and type "<< (int)msg.getType()<<": have not yet received a timestamp"<<endl; }
continue;
}
@ -1032,7 +1034,7 @@ int main(int argc, char** argv)
}
else
; // if (doDEBUG) { cerr<<humanTimeNow()<<" SFRBX from unsupported GNSSID/sigid combination "<<id.first<<", sv "<<id.second<<", sigid "<<sigid<<", "<<payload.size()<<" bytes"<<endl; }
}
catch(CRCMismatch& cm) {
if (doDEBUG) { cerr<<humanTimeNow()<<" Had CRC mismatch!"<<endl; }
@ -1123,6 +1125,7 @@ int main(int argc, char** argv)
}
else if(msg.getClass() == 0x02 && msg.getType() == 0x14) { // UBX-RXM-MEASX
// if (doDEBUG) { cerr<<humanTimeNow()<<" Got RXM-MEASX for "<<(int)payload[34]<<" satellites, r0 "<< (int)payload[30]<<" r1 " <<(int)payload[31]<<endl; }
for(unsigned int n = 0 ; n < payload[34] ; ++n) {
uint16_t wholeChips;
@ -1158,6 +1161,7 @@ int main(int argc, char** argv)
string hexstring;
for(int n = 0; n < 15; ++n)
hexstring+=fmt::sprintf("%x", (int)getbitu(payload.c_str(), 36 + 4*n, 4));
if (doDEBUG) { cerr<<humanTimeNow()<<" "<<humanTime(g_gnssutc.tv_sec)<<" SAR RLM type "<<type<<" from gal sv " << sv << " beacon "<<hexstring <<" code "<<(int)payload[12]<<" params "<<payload[12] + 256*payload[13]<<endl; }
// wk.emitLine(sv, "SAR "+hexstring);