diff --git a/include/gnss_utils/navigation.h b/include/gnss_utils/navigation.h index fe11cb2fb725c13512fbe8b30af61ed5f03fcd1f..54a3073702553733e054bcd7259a199c352a45d3 100644 --- a/include/gnss_utils/navigation.h +++ b/include/gnss_utils/navigation.h @@ -30,8 +30,6 @@ class Navigation void clearNavigation(); - void freeNavigation(); - void setNavigation(nav_t nav); void loadFromRinex(const std::string& rnx_file, gtime_t t_start, gtime_t t_end, double dt = 0.0, const char* opt = ""); @@ -40,11 +38,15 @@ class Navigation /****************** Array memory management ******************/ - // Ephemeris bool addEphemeris(const eph_t& eph); bool addGLONASSEphemeris(const geph_t& geph); bool addSBASEphemeris(const seph_t& seph); bool addAlmanac(const alm_t& alm); + + void clearEphemeris(); + void clearGLONASSEphemeris(); + void clearSBASEphemeris(); + void clearAlmanac(); //void allocateEphemeris(int n_sat = MAXSAT); //void deleteEphemeris(); diff --git a/include/gnss_utils/ublox_raw.h b/include/gnss_utils/ublox_raw.h index b4cf59cc589d76db5a8f3a349f6adbbeac21874b..e204b52c38a1645424f40d36dd46a4bdef14caf6 100644 --- a/include/gnss_utils/ublox_raw.h +++ b/include/gnss_utils/ublox_raw.h @@ -23,9 +23,7 @@ class UBloxRaw Observations obs_; Navigation nav_; - void updateObservations(); - void updateNavigation(); - + void updateObservations(); }; diff --git a/src/navigation.cpp b/src/navigation.cpp index cfba893fabc47292bf3dbad1bfc344b2f3627536..8376460d00b5af67dd02f0a6b11475413f2d6a09 100644 --- a/src/navigation.cpp +++ b/src/navigation.cpp @@ -32,32 +32,12 @@ Navigation::Navigation() Navigation::~Navigation() { - freeNavigation(); -} - -void Navigation::freeNavigation() -{ - freenav(&nav_,255); + clearNavigation(); } void Navigation::clearNavigation() { - nav_.eph =NULL; - nav_.geph=NULL; - nav_.seph=NULL; - nav_.peph=NULL; - nav_.pclk=NULL; - nav_.alm =NULL; - nav_.tec =NULL; - nav_.fcb =NULL; - nav_.n =nav_.nmax =0; - nav_.ng=nav_.ngmax=0; - nav_.ns=nav_.nsmax=0; - nav_.ne=nav_.nemax=0; - nav_.nc=nav_.ncmax=0; - nav_.na=nav_.namax=0; - nav_.nt=nav_.ntmax=0; - nav_.nf=nav_.nfmax=0; + freenav(&nav_,255); } void Navigation::setNavigation(nav_t _nav) @@ -109,6 +89,7 @@ bool Navigation::addEphemeris(const eph_t& eph) nav_.eph[nav_.n++]=eph; return true; } + bool Navigation::addGLONASSEphemeris(const geph_t& geph) { // "inspired" from RTKLIB rinex.c @@ -126,6 +107,7 @@ bool Navigation::addGLONASSEphemeris(const geph_t& geph) nav_.geph[nav_.ng++]=geph; return true; } + bool Navigation::addSBASEphemeris(const seph_t& seph) { // "inspired" from RTKLIB rinex.c @@ -143,6 +125,7 @@ bool Navigation::addSBASEphemeris(const seph_t& seph) nav_.seph[nav_.ns++]=seph; return true; } + bool Navigation::addAlmanac(const alm_t& alm) { // "inspired" from RTKLIB rinex.c @@ -161,6 +144,26 @@ bool Navigation::addAlmanac(const alm_t& alm) return true; } +void Navigation::clearEphemeris() +{ + if (nav_.eph != NULL) {free(nav_.eph ); nav_.eph =NULL; nav_.n =nav_.nmax =0;} +} + +void Navigation::clearGLONASSEphemeris() +{ + if (nav_.geph != NULL) {free(nav_.geph); nav_.geph=NULL; nav_.ng=nav_.ngmax=0;} +} + +void Navigation::clearSBASEphemeris() +{ + if (nav_.seph != NULL) {free(nav_.seph); nav_.seph=NULL; nav_.ns=nav_.nsmax=0;} +} + +void Navigation::clearAlmanac() +{ + if (nav_.alm != NULL) {free(nav_.alm ); nav_.alm =NULL; nav_.na=nav_.namax=0;} +} + /****************** Array memory management ******************/ //void Navigation::allocateEphemeris(int n_sat) //{ diff --git a/src/ublox_raw.cpp b/src/ublox_raw.cpp index f68783fc8aeba6d6334c0813a801817b18baccd4..5a1f463aa99323287f86856dcc0dc5d7e2be6673 100644 --- a/src/ublox_raw.cpp +++ b/src/ublox_raw.cpp @@ -29,15 +29,27 @@ int UBloxRaw::addDataStream(const std::vector<u_int8_t>& data_stream) break; case 2: // Ephemeris - updateNavigation(); + nav_.clearEphemeris(); + nav_.clearGLONASSEphemeris(); + nav_.clearSBASEphemeris(); + nav_.addEphemeris(*(raw_data_.nav.eph)); + nav_.addGLONASSEphemeris(*(raw_data_.nav.geph)); + nav_.addSBASEphemeris(*(raw_data_.nav.seph)); break; case 3: - // SBAS Message (we should update observations, right?) + // SBAS + nav_.clearEphemeris(); + nav_.clearGLONASSEphemeris(); + nav_.clearSBASEphemeris(); + nav_.addEphemeris(*(raw_data_.nav.eph)); + nav_.addGLONASSEphemeris(*(raw_data_.nav.geph)); + nav_.addSBASEphemeris(*(raw_data_.nav.seph)); updateObservations(); break; case 9: // Almanac - updateNavigation(); + nav_.clearAlmanac(); + nav_.addAlmanac(*(raw_data_.nav.alm)); break; } @@ -49,20 +61,15 @@ const Navigation& UBloxRaw::getNavigation() const {return nav_;} void UBloxRaw::updateObservations() { - std::cout << "---------------------------JUST BEFORE!-------------------" << std::endl; - obs_.print(); + // std::cout << "---------------------------JUST BEFORE!-------------------" << std::endl; + // obs_.print(); obs_.clearObservations(); for (int ii = 0; ii < raw_data_.obs.n; ++ii) { obs_.addObservation(raw_data_.obs.data[ii]); } - std::cout << "--------------------------JUST AFTER!---------------------" << std::endl; - obs_.print(); + // std::cout << "--------------------------JUST AFTER!---------------------" << std::endl; + // obs_.print(); -} - -void UBloxRaw::updateNavigation() -{ - nav_.setNavigation(raw_data_.nav); } \ No newline at end of file