GNSS C++

GNSS API related documentation. More...

Namespaces

 dpyGnss
 Deepsy Gnss namespace that includes the different enums, structs or method signatures that should be used.
 

Classes

class  GnssObserver
 Gnss Observer class. More...
 
class  Gnss
 Main application. More...
 
class  GnssPosition
 Class that defines a position. More...
 

Detailed Description

A quick overview of basic GNSS capabilities and examples is given.
If you find GNSS API useful and would like to know more details, please check out further sections of the GNSS API documentation or contact the Deepsy platform team.

Examples

  • Asking for the last position obtained
    In order to obtain the last position related information GnssPosition must be attended. An example is provided:

    #include <dpy/gnssApi.h>
    #include <iostream>
    #include <stdio.h>
    #include <map>
    #include <iomanip>
    volatile bool waiting = true;
    void get_last_position_handler(boost::system::error_code error_code,GnssPosition last_pos)
    {
    if (error_code) {
    std::cout << "GNSS get position Error = " << error_code.value() << ", " << error_code.message() << std::endl;
    fflush (stdout);
    } else {
    using namespace dpyGnssPosition;
    std::map<QualityIndicator, std::string> fix_to_string_map;
    fix_to_string_map[NO_FIX] = "NO FIX";
    fix_to_string_map[AUTONOMOUS_FIX] = "AUTONOMOUS FIX";
    fix_to_string_map[DIFFERENTIAL_FIX] = "DIFFERENTIAL FIX";
    fix_to_string_map[RTK_FIXED] = "RTK FIXED";
    fix_to_string_map[RTK_FLOAT] = "RTK FLOAT";
    fix_to_string_map[ESTIMATED_DEAD_RECKONING_FIX] = "ESTIMATED DEAD RECKONING FIX";
    std::cout << "Last position FIX status is " << fix_to_string_map[last_pos.fix_quality] << std::endl;
    std::cout << "\tSatellites used [" << last_pos.sky.satinuse << "]" << std::endl;
    std::cout << "\tSatellites in view [" << last_pos.sky.satinview << "]" << std::endl;
    char buffer[80];
    strftime (buffer,sizeof(buffer),"%d/%m/%Y",&(last_pos.date));
    std::cout << "\tLast position DATE is: "<< buffer << " [dd/mm/yyyy]" << std::endl;
    strftime (buffer,sizeof(buffer),"%H:%M:%S",&(last_pos.date));
    std::cout << "\tLast position UTC TIME is: " << buffer << " [hh:mm:ss]" << std::endl;
    if (last_pos.fix_quality != dpyGnssPosition::NO_FIX) {
    std::cout << std::fixed << std::setprecision(6); //To print 6 decimal digits for the float
    std::cout << "\tGeographic position in decimal degrees is: [" << last_pos.lat_deg << "," << last_pos.lon_deg << "]" << std::endl;
    std::cout << std::fixed << std::setprecision(2); //To print 2 decimal digits for the float
    std::cout << "\tAltitude above/below mean sea level is: " << last_pos.alt_m << " meters" << std::endl;
    std::cout << "\tHorizontal dilution of precision is: " << last_pos.HDOP << std::endl;
    std::cout << "\tSpeed over the ground is: " << last_pos.speed_kmh << " kilometres per hour" << std::endl;
    std::cout << "\tCourse over the ground (track angle) is: " << last_pos.dir_deg << " degrees" << std::endl;
    }
    }
    waiting = false;
    }
    int main()
    {
    Gnss gnss;
    gnss.asyncGetLastPosition(get_last_position_handler);
    while (waiting == true)
    {
    }
    }

  • Obtaining GNSS next position updates
    In order to obtain the position related information GnssPosition must be attended. An example is provided:

    #include <dpy/gnssApi.h>
    #include <iostream>
    #include <stdio.h>
    #include <map>
    #include <iomanip>
    void get_position_updates_handler(boost::system::error_code error_code, GnssPosition current_pos)
    {
    if (error_code) {
    std::cout << "GNSS get position Error = " << error_code.value() << ", " << error_code.message() << std::endl;
    fflush(stdout);
    } else {
    using namespace dpyGnssPosition;
    std::map<QualityIndicator, std::string> fix_to_string_map;
    fix_to_string_map[NO_FIX] = "NO FIX";
    fix_to_string_map[AUTONOMOUS_FIX] = "AUTONOMOUS FIX";
    fix_to_string_map[DIFFERENTIAL_FIX] = "DIFFERENTIAL FIX";
    fix_to_string_map[RTK_FIXED] = "RTK FIXED";
    fix_to_string_map[RTK_FLOAT] = "RTK FLOAT";
    fix_to_string_map[ESTIMATED_DEAD_RECKONING_FIX] = "ESTIMATED DEAD RECKONING FIX";
    std::cout << "Current position FIX status is " << fix_to_string_map[current_pos.fix_quality] << std::endl;
    std::cout << "\tSatellites used [" << current_pos.sky.satinuse << "]" << std::endl;
    std::cout << "\tSatellites in view [" << current_pos.sky.satinview << "]" << std::endl;
    char buffer[80];
    strftime(buffer, sizeof(buffer), "%d/%m/%Y", &(current_pos.date));
    std::cout << "\tCurrent position DATE is: " << buffer << " [dd/mm/yyyy]" << std::endl;
    strftime(buffer, sizeof(buffer), "%H:%M:%S", &(current_pos.date));
    std::cout << "\tCurrent position UTC TIME is: " << buffer << " [hh:mm:ss]" << std::endl;
    if (current_pos.fix_quality != dpyGnssPosition::NO_FIX) {
    std::cout << std::fixed << std::setprecision(6); //To print 6 decimal digits for the float
    std::cout << "\tGeographic position in decimal degrees is: [" << current_pos.lat_deg << "," << current_pos.lon_deg << "]" << std::endl;
    std::cout << std::fixed << std::setprecision(2); //To print 2 decimal digits for the float
    std::cout << "\tAltitude above/below mean sea level is: " << current_pos.alt_m << " meters" << std::endl;
    std::cout << "\tHorizontal dilution of precision is: " << current_pos.HDOP << std::endl;
    std::cout << "\tSpeed over the ground is: " << current_pos.speed_kmh << " kilometres per hour" << std::endl;
    std::cout << "\tCourse over the ground (track angle) is: " << current_pos.dir_deg << " degrees" << std::endl;
    }
    }
    }
    int main()
    {
    Gnss gnss;
    gnss.getPeriodicPosition_S(get_position_updates_handler);
    sleep(5);
    return 0;
    }

  • Using observer pattern
    To use observer pattern an class which overrides NewPosition method shall be used. An example is provided:

    #include <dpy/gnssApi.h>
    #include <iostream>
    #include <stdio.h>
    #include <map>
    class Observer: public GnssObserver
    {
    public:
    void NewPosition(const GnssPosition& current_pos) override
    {
    using namespace dpyGnssPosition;
    std::map<QualityIndicator, std::string> fix_to_string_map;
    fix_to_string_map[NO_FIX] = "NO FIX";
    fix_to_string_map[AUTONOMOUS_FIX] = "AUTONOMOUS FIX";
    fix_to_string_map[DIFFERENTIAL_FIX] = "DIFFERENTIAL FIX";
    fix_to_string_map[RTK_FIXED] = "RTK FIXED";
    fix_to_string_map[RTK_FLOAT] = "RTK FLOAT";
    fix_to_string_map[ESTIMATED_DEAD_RECKONING_FIX] = "ESTIMATED DEAD RECKONING FIX";
    std::cout << "\r\tLast position FIX status is: " << fix_to_string_map[current_pos.fix_quality] << std::endl;
    std::cout << "\tSatellites used: [" << current_pos.sky.satinuse << "]" << std::endl;
    std::cout << "\tSatellites in view [" << current_pos.sky.satinview << "]" << std::endl;
    if (current_pos.fix_quality != NO_FIX) {
    std::cout << "\tPosition coordinates in decimal degrees is: [" << current_pos.lat_deg << "," << current_pos.lon_deg << "]" << std::endl;
    std::cout << "\tAltitude above/below mean sea level is: " << current_pos.alt_m << " meters" << std::endl;
    std::cout << "\tHorizontal dilution of precision is: " << current_pos.HDOP << std::endl;
    std::cout << "\tSpeed over the ground is: " << current_pos.speed_kmh << " kilometres per hour" << std::endl;
    std::cout << "\tCourse over the ground (track angle) is: " << current_pos.dir_deg << " degrees" << std::endl;
    }
    std::cout << "\n";
    }
    };
    int main()
    {
    Gnss gnss;
    Observer obs;
    gnss.subscribe(&obs);
    sleep(5);
    gnss.unsubscribe(&obs);
    return 0;
    }

  • Obtaining GNSS position synchronously
    In order to obtain the position related information GnssPosition must be attended. An example is provided:

    #include <dpy/gnssApi.h>
    int main()
    {
    Gnss gnss;
    GnssPosition position;
    gnss.getLastPosition(position);
    return 0;
    }

int satinview
Number of satellites in view.
Definition: gnssPosition.h:13
dpyGnssPosition::QualityIndicator fix_quality
FIX quality. Module is FIXED if different from NO_FIX.
Definition: gnssPosition.h:40
double lon_deg
Geographic longitude expressed in Decimal Degrees (D.D�) Range [-180,+180].
Definition: gnssPosition.h:44
@ RTK_FLOAT
GNSS fixed : RTK_FLOAT.
Definition: gnssPosition.h:26
Main application.
Definition: gnssApi.h:136
Gnss Observer class.
Definition: gnssApi.h:116
virtual void NewPosition(const GnssPosition &position)=0
double HDOP
Horizontal Dilution of Precision.
Definition: gnssPosition.h:47
@ DIFFERENTIAL_FIX
GNSS fixed : DIFFERENTIAL_FIX.
Definition: gnssPosition.h:24
@ RTK_FIXED
GNSS fixed : RTK_FIXED.
Definition: gnssPosition.h:25
Class that defines a position.
Definition: gnssPosition.h:37
double lat_deg
Geographic latitude expressed in Decimal Degrees (D.D�) Range [-90,+90].
Definition: gnssPosition.h:42
@ AUTONOMOUS_FIX
GNSS fixed : AUTONOMOUS_FIX.
Definition: gnssPosition.h:23
dpyGnssPosition::SkyInfo sky
Sky satellite information.
Definition: gnssPosition.h:50
int satinuse
Number of satellites in use.
Definition: gnssPosition.h:14
double alt_m
Antenna altitude above/below mean sea level in meters.
Definition: gnssPosition.h:46
tm date
Date of position. Fields day of the week, day of the month or day of the year are unused (value = 0) ...
Definition: gnssPosition.h:41
double speed_kmh
Speed over the ground in km/h.
Definition: gnssPosition.h:48
double dir_deg
Course over the ground (track angle) in degrees.
Definition: gnssPosition.h:49
@ NO_FIX
GNSS module does not have a fixed position at this moment.
Definition: gnssPosition.h:22