diff --git a/gps.hh b/gps.hh index ddf2c1e..516da11 100644 --- a/gps.hh +++ b/gps.hh @@ -1,9 +1,55 @@ #pragma once #include +#include #include "bits.hh" #include std::basic_string getCondensedGPSMessage(std::basic_string_view payload); +struct GPSState +{ + 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 , af1; + // 2^-59 + int8_t af2; + uint32_t wn{0}, tow{0}; + }; + + uint8_t gpshealth{0}; + uint16_t ai0{0}; + int16_t ai1{0}, ai2{0}; + + int BGDE1E5a{0}, BGDE1E5b{0}; + + bool disturb1{false}, disturb2{false}, disturb3{false}, disturb4{false}, disturb5{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; // GPS parameters that should not be here XXX + + std::map iods; + SVIOD& getEph(int i) { return iods[i]; } // XXXX gps adaptor + void checkCompleteAndClean(int iod){} +}; + // expects input as 24 bit read to to use messages, returns frame number template int parseGPSMessage(std::basic_string_view cond, T& out, uint8_t* pageptr=0) @@ -45,7 +91,7 @@ int parseGPSMessage(std::basic_string_view cond, T& out, uint8_t* pagep int iod = getbitu(&cond[0], 2*24, 8); auto& eph = out.getEph(iod); eph.words[2]=1; - eph.t0e = getbits(&cond[0], 9*24, 16) * 16.0; // WE SCALE THIS FOR THE USER!! + eph.t0e = getbitu(&cond[0], 9*24, 16) * 16.0; // WE SCALE THIS FOR THE USER!! // cerr<<"IODe "<<(int)iod<<", t0e "<< eph.t0e << " = "<< 16* eph.t0e <<"s"<((uint8_t*)nmm.gpsi().contents().c_str(), nmm.gpsi().contents().size())); + struct GPSState gs; + uint8_t page; + int frame=parseGPSMessage(cond, gs, &page); + cout<<"GPS "<