Skip to content

Commit

Permalink
move to new unified processing model, plus hook up sbas
Browse files Browse the repository at this point in the history
  • Loading branch information
ahupowerdns committed Feb 25, 2020
1 parent 62c0662 commit 63827d8
Show file tree
Hide file tree
Showing 16 changed files with 1,114 additions and 876 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CFLAGS = -O3 -Wall -ggdb

CXXFLAGS:= -std=gnu++17 -Wall -O2 -MMD -MP -fno-omit-frame-pointer -Iext/CLI11 \
CXXFLAGS:= -std=gnu++17 -Wall -O2 -ggdb -MMD -MP -fno-omit-frame-pointer -Iext/CLI11 \
-Iext/fmt-6.1.2/include/ -Iext/powerblog/ext/simplesocket -Iext/powerblog/ext/ \
-I/usr/local/opt/openssl/include/ \
-Iext/sgp4/libsgp4/ \
Expand Down Expand Up @@ -36,7 +36,7 @@ clean:
decrypt: decrypt.o bits.o ext/fmt-6.1.2/src/format.o
$(CXX) -std=gnu++17 $^ -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
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
$(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
Expand All @@ -46,7 +46,7 @@ galmonmon: galmonmon.o ext/fmt-6.1.2/src/format.o $(SIMPLESOCKETS) minicurl.o ub
$(CXX) -std=gnu++17 $^ -o $@ -pthread -L/usr/local/lib -lprotobuf -lcurl


navdump: navdump.o ext/fmt-6.1.2/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 osen.o trkmeas.o githash.o rinex.o ${EXTRADEP}
navdump: navdump.o ext/fmt-6.1.2/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 osen.o trkmeas.o githash.o rinex.o sbas.o ${EXTRADEP}
$(CXX) -std=gnu++17 $^ -o $@ -L/usr/local/lib -pthread -lprotobuf -lz

navdisplay: navdisplay.o ext/fmt-6.1.2/src/format.o bits.o navmon.pb.o gps.o ephemeris.o beidou.o glonass.o ephemeris.o navmon.o osen.o githash.o
Expand Down
8 changes: 6 additions & 2 deletions beidou.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int beidouBitconv(int their);
C05 (58.75E)
*/

struct BeidouMessage
struct BeidouMessage : GPSLikeEphemeris
{
uint8_t strtype;

Expand Down Expand Up @@ -118,7 +118,11 @@ struct BeidouMessage
double getCrc() const { return ldexp(crc, -6); } // meters
double getCrs() const { return ldexp(crs, -6); } // meters
double getM0() const { return ldexp(m0 * M_PI, -31); } // radians


int getIOD() const
{
return -1;
}

void parse2(std::basic_string_view<uint8_t> cond)
{
Expand Down
31 changes: 31 additions & 0 deletions ephemeris.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@
#include "minivec.hh"
#include <iostream>
#include <tuple>
#include <stdint.h>
struct GPSLikeEphemeris
{
virtual double getMu() const = 0;
virtual double getOmegaE() const = 0;
virtual double getE() const = 0;
virtual uint32_t getT0e() const = 0;

virtual double getI0() const = 0;

virtual double getOmegadot() const = 0;

virtual double getSqrtA() const = 0;
virtual double getOmega0() const = 0;
virtual double getOmega() const = 0;

virtual double getM0() const = 0;
virtual double getIdot() const = 0;
virtual double getCic() const = 0;
virtual double getCis() const = 0;
virtual double getCuc() const = 0;
virtual double getCus() const = 0;
virtual double getCrc() const = 0;
virtual double getCrs() const = 0;
virtual double getDeltan()const = 0;

virtual int getIOD() const = 0;
// maybe af0, af1, af2?
// maybe getUTCOffset? getAtomicOffset etc

};

// lat, lon, height (rad, rad, meters)
std::tuple<double, double, double> ecefToWGS84(double x, double y, double z);
Expand Down
18 changes: 13 additions & 5 deletions galileo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

bool getTOWFromInav(std::basic_string_view<uint8_t> inav, uint32_t *satTOW, uint16_t *wn);

struct GalileoMessage
struct GalileoMessage : GPSLikeEphemeris
{
uint8_t wtype;

Expand Down Expand Up @@ -41,8 +41,8 @@ struct GalileoMessage
}

uint8_t sparetime{0};
uint16_t wn{0}; // we put the "unrolled" week number here!
uint32_t tow{0}; // "last seen"
uint16_t wn{0};
uint32_t tow{0};
int iodalmanac;
int wnalmanac;
int t0almanac;
Expand Down Expand Up @@ -99,6 +99,11 @@ struct GalileoMessage

uint16_t iodnav;

int getIOD() const
{
return iodnav;
}

struct Almanac
{
int svid{-1};
Expand Down Expand Up @@ -131,7 +136,10 @@ struct GalileoMessage
double getCrc() const { return 0; } // meters
double getCrs() const { return 0; } // meters
double getDeltan()const { return 0; } //radians/s

int getIOD() const
{
return -1;
}
} alma1, alma2, alma3;


Expand Down Expand Up @@ -211,7 +219,7 @@ struct GalileoMessage

return {factor * cur, factor * trend};
}

// pair of nanosecond, nanosecond/s
std::pair<double, double> getGPSOffset(int tow, int wn) const
{
int dw = (int)(uint8_t)wn - (int)(uint8_t) wn0g;
Expand Down
40 changes: 33 additions & 7 deletions galmonmon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ std::optional<string> StateKeeper::reportState(string_view thing, string_view na


StateKeeper g_sk;

#if 0
static std::string string_replace(const std::string& str, const std::string& match,
const std::string& replacement, unsigned int max_replacements = UINT_MAX)
{
Expand All @@ -182,12 +182,14 @@ static std::string string_replace(const std::string& str, const std::string& mat
}
return newstr;
}

#endif
void sendTweet(const string& tweet)
{
string etweet = tweet;
//system((string("twurl -X POST /1.1/statuses/update.json -d \"media_ids=1215649475231997953&status=")+etweet+"\" >> twitter.log").c_str());
system((string("twurl -X POST /1.1/statuses/update.json -d \"status=")+etweet+"\" >> twitter.log").c_str());
if(system((string("twurl -X POST /1.1/statuses/update.json -d \"status=")+etweet+"\" >> twitter.log").c_str()) < 0) {
cout<<"Problem tweeting!"<<endl;
}
return;
}

Expand Down Expand Up @@ -247,7 +249,27 @@ int main(int argc, char **argv)
cout<<"Galmon behind by " << (time(0) - (long) iter.value()) <<" seconds"<<endl;
}
*/


res = mc.getURL(url+"sbas.json");
j = nlohmann::json::parse(res);
std::optional<string> sbasHealthChange;
for(auto iter = j.begin(); iter != j.end(); ++iter) {
if(iter.value().count("health")) {
string name = sbasName(atoi(iter.key().c_str()));
sbasHealthChange = g_sk.reportState(name, "sbas-health", (string)iter.value()["health"]);
// cout<<"Setting state for "<< name <<" to "<< (string)iter.value()["health"] << endl;


if(sbasHealthChange) {
ostringstream out;
out<<"✈️ augmentation system "<<name<<" health changed: "<<*sbasHealthChange;
cout<<out.str()<<endl;
if(doTweet)
sendTweet(out.str());

}
}
}

res = mc.getURL(url+"svs.json");
j = nlohmann::json::parse(res);
Expand Down Expand Up @@ -295,7 +317,7 @@ int main(int argc, char **argv)

auto seenChange = g_sk.reportState(fullName, "silent", notseen);

auto sisaChange = g_sk.reportState(fullName, "sisa", (string)sv["sisa"]);
auto sisaChange = g_sk.reportState(fullName, "sisa", (double) sv["sisa-m"], (string)sv["sisa"]);

double ephdisco = sv.count("latest-disco") ? (double)sv["latest-disco"] : -1.0;
auto ephdiscochange = g_sk.reportState(fullName, "eph-disco", ephdisco);
Expand Down Expand Up @@ -357,9 +379,13 @@ int main(int argc, char **argv)

if(sisaChange) {
ostringstream tmp;
tmp<< " SISA/URA reported ranging accuracy changed, new: "<<*sisaChange<<", old: " << *g_sk.getPrevState(fullName, "sisa");
if(tmp.str().find("200 cm") == string::npos || tmp.str().find("282 cm") == string::npos)
auto state = g_sk.getFullState(fullName, "sisa");
auto prevState = g_sk.getPrevFullState(fullName, "sisa");
tmp<< " SISA/URA reported ranging accuracy changed, new: "<<state->text<<", old: " << prevState->text;
if(get<double>(state->state) > 3 || get<double>(prevState->state) > 3)
out << tmp.str();
else
cout<<"Not reporting: "<<tmp.str()<<endl;
}

string tweet;
Expand Down
23 changes: 23 additions & 0 deletions glonass.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "glonass.hh"
#include <math.h>
#include <string.h>
#include <chrono>
#include <iostream>
using std::cout;
using std::endl;

static const double ae = 6378.136; // km // IERS: 6378136.6
static const double mu = 398.6004418E3; // km3/s2 // IERS: 3.986004418
Expand Down Expand Up @@ -98,8 +102,25 @@ static void rk4step (const double A[3], double y[6], double h)
y[j] = y[j] + h * (k1[j] + 2*(k2[j] + k3[j]) + k4[j]) / 6;
}


using Clock = std::chrono::steady_clock;

static double passedMsec(const Clock::time_point& then, const Clock::time_point& now)
{
return std::chrono::duration_cast<std::chrono::microseconds>(now - then).count()/1000.0;
}


static double passedMsec(const Clock::time_point& then)
{
return passedMsec(then, Clock::now());
}


double getCoordinates(double tow, const GlonassMessage& eph, Point* p)
{
auto start = Clock::now();

double y0[6] = {ldexp(eph.x, -11), ldexp(eph.y, -11), ldexp(eph.z, -11),
ldexp(eph.dx, -20), ldexp(eph.dy, -20), ldexp(eph.dz, -20)};
double A[3] = {ldexp(eph.ddx, -30), ldexp(eph.ddy, -30), ldexp(eph.ddz, -30)};
Expand All @@ -116,5 +137,7 @@ double getCoordinates(double tow, const GlonassMessage& eph, Point* p)
rk4step (A, y0, h);

*p = Point (1E3*y0[0], 1E3*y0[1], 1E3*y0 [2]);
static double total=0;
// cout<<"Took: "<<(total+=passedMsec(start))<<" ms" <<endl;
return 0;
}
24 changes: 23 additions & 1 deletion glonass.hh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ struct GlonassMessage
double getdY() { return ldexp(dy*1000.0, -20); }
double getdZ() { return ldexp(dz*1000.0, -20); }

// this is there to make doDoppler work, which sadly wants to do
// arithmetic to get the age of an ephemeris
double getT0e() const { return 0; }

double getRadius() { return sqrt(getX()*getX() + getY()*getY() + getZ()*getZ()); }

Expand Down Expand Up @@ -127,7 +130,26 @@ struct GlonassMessage
P4 = getbitu(&gstr[0], 85-34, 1);
deltaTaun = getbitsglonass(&gstr[0], 85 - 58, 4);
}
// nanosecond, nanosecond/s pair
std::pair<double, double> getUTCOffset(int tow) const
{
std::pair<double, double> ret;
ret.second=0;

ret.first = 1000000000.0*ldexp(tauc, -31); // this is Glonass-M

return ret;
}

std::pair<double, double> getGPSOffset(int tow) const
{
std::pair<double, double> ret;
ret.second=0;
ret.first = 1000000000.0*ldexp(taugps, -30);
return ret;
}


uint32_t getGloTime() const;

uint8_t n4{0}; // counting from 1996 ('n4=1'), this is the 4-year plan index we are currently in
Expand All @@ -138,7 +160,7 @@ struct GlonassMessage
{
n4=getbitu(&gstr[0], 85-36, 5);
taugps = getbitsglonass(&gstr[0], 85-31, 22);
tauc = getbitsglonass(&gstr[0], 85-69, 32);
tauc = getbitsglonass(&gstr[0], 85-69, 32); // check the NEW ICD
l_n = getbitu(&gstr[0], 85 - 9, 1);
}

Expand Down
Loading

0 comments on commit 63827d8

Please sign in to comment.