Thanks, that seems to confirm my guess.

Looking at the gps_ctrl.cpp that I have (which is a little different than
yours, I have uhd-release_003_010_002_000, but it must do the same thing,
thanks for the pointer) .. it looks like the UHD lib gets the GPS
receiver's time via a NMEA GPRMC message from the receiver, which is
defined, I think, to return UTC time in basically ddmmyy, HHMMSS.SS format.
Which is parsed by that code into a Posix/Unix seconds quantity.


    ptime gps_time;

            // wait for next GPRMC string
            std::string reply = get_sentence("GPRMC",
GPS_NMEA_NORMAL_FRESHNESS, GPS_COMM_TIMEOUT_MS, true);

            std::string datestr = get_token(reply, 9);
            std::string timestr = get_token(reply, 1);

            if(datestr.size() == 0 or timestr.size() == 0) {
                throw uhd::value_error(str(boost::format("Invalid response
\"%s\"") % reply));
            }

            //just trust me on this one
            gps_time = ptime( date(

greg_year(boost::lexical_cast<int>(datestr.substr(4, 2)) + 2000),

greg_month(boost::lexical_cast<int>(datestr.substr(2, 2))),

greg_day(boost::lexical_cast<int>(datestr.substr(0, 2)))
                           ),
                          hours(
boost::lexical_cast<int>(timestr.substr(0, 2)))
                        +
minutes(boost::lexical_cast<int>(timestr.substr(2, 2)))
                        +
seconds(boost::lexical_cast<int>(timestr.substr(4, 2)))
                     );
            return gps_time;

thx,
Eric


On Fri, Mar 30, 2018 at 4:12 PM, Marcus D. Leech via USRP-users <
[email protected]> wrote:

> On 03/30/2018 04:00 PM, Eric W via USRP-users wrote:
>
> Hi all - I have an Octoclock-G. I'm trying to get confirmation on what
> get_sensor("gps_time")  actually returns.
>
> I guess it's not number of seconds since the GPS epoch (Jan 6 1980), as I
> had assumed from the tag "gps_time".
>
> It looks more like Unix seconds. So, seconds since  the Jan 1 1970 epoch
> (UTC epoch).
> Is that right, and if so, how are leap seconds handled? If it uses the
> Unix epoch then I would guess it is also subtracting leap seconds, but
> that's just a guess..
>
> If indeed it is returning Unix time, then I believe this would be correct
> (for now, until the next leap sec):
> gpsSeconds = get_sensor("gps_time") - 315964782;
>
> Our code looks something like:
>    uhd::device_addr_t dev_addr_octoclock;
>    dev_addr_octoclock["addr0"] = "192.168.13.1";
>    uhd::usrp_clock::multi_usrp_clock::sptr octoclock =
> uhd::usrp_clock::multi_usrp_clock::make(dev_addr_octoclock);
>    signed gps_time = octoclock->get_sensor("gps_time",0).to_int();
>
> Thanks much,
> Eric
>
>
> _______________________________________________
> USRP-users mailing 
> [email protected]http://lists.ettus.com/mailman/listinfo/usrp-users_lists.ettus.com
>
> The relevant code in gps_ctrl.cpp is here:
>
>            struct tm raw_date;
>             raw_date.tm_year = std::stoi(datestr.substr(4, 2)) + 2000 -
> 1900; // years since 1900
>             raw_date.tm_mon = std::stoi(datestr.substr(2, 2)) - 1; //
> months since january (0-11)
>             raw_date.tm_mday = std::stoi(datestr.substr(0, 2)); // dom
> (1-31)
>             raw_date.tm_hour = std::stoi(timestr.substr(0, 2));
>             raw_date.tm_min = std::stoi(timestr.substr(2, 2));
>             raw_date.tm_sec = std::stoi(timestr.substr(4,2));
>             gps_time = boost::posix_time::ptime_from_tm(raw_date);
>
> It's using boost::posix_time which is necessarily based on the Unix epoch.
>
> So, "gps_time" is "Posix Time based on the time given by the GPS receiver".
>
>
>
> _______________________________________________
> USRP-users mailing list
> [email protected]
> http://lists.ettus.com/mailman/listinfo/usrp-users_lists.ettus.com
>
>
_______________________________________________
USRP-users mailing list
[email protected]
http://lists.ettus.com/mailman/listinfo/usrp-users_lists.ettus.com

Reply via email to