Advertisement
Siorai

Untitled

Aug 6th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.54 KB | None | 0 0
  1. #include "sti_gnss_lib.h"
  2. #include "GNSS.h"
  3.  
  4. /*
  5.   NOTE: To initialize the UART console port with baud rate 19,200
  6. */
  7. void setup() {
  8.   // put your setup code here, to run once:
  9.   GnssConf.setNavMode(STGNSS_NAV_MODE_AUTO);
  10.   GnssConf.setUpdateRate(STGNSS_POSITION_UPDATE_RATE_1HZ);
  11.   GnssConf.setDopMaskMode(STGNSS_DOP_MASK_AUTO);
  12.   GnssConf.setPdopMask(30.0);
  13.   GnssConf.setHdopMask(30.0);
  14.   GnssConf.setGdopMask(30.0);
  15.   GnssConf.init(); /* do initialization for GNSS */
  16.  
  17.   Serial.config(STGNSS_UART_8BITS_WORD_LENGTH, STGNSS_UART_1STOP_BITS, STGNSS_UART_NOPARITY);
  18.   Serial.begin(19200);
  19. }
  20.  
  21. void loop() {
  22.   // put your main code here, to run repeatedly:
  23.  
  24. }
  25.  
  26. /*
  27.   NOTE: "task_called_after_GNSS_update()" will be called about every second
  28.         (for 1Hz update rate), so we display the info. here.
  29. */
  30. void task_called_after_GNSS_update(void)
  31. {
  32.   char buf[64];
  33.   uint16_t prnList[STGNSS_GPS_NCHAN];
  34.  
  35.   // Get info. of setallite
  36.   GnssInfo.update();
  37.   if (GnssInfo.isUpdated() == true) {
  38.     Serial.print("\r\n");
  39.  
  40.     // display the date from GNSS
  41.     GnssInfo.date.formatString(buf);
  42.     Serial.print(buf);
  43.     Serial.print(", ");
  44.     // display the time from GNSS
  45.     GnssInfo.time.formatString(buf);
  46.     Serial.print(buf);
  47.     Serial.print("\r\n");
  48.  
  49.     // display how many satellites are in the sky and how many of them are
  50.     // used for position fix
  51.     sprintf(buf, "NumGPSInView = %2d, NumGPSInUse = %2d\r\n",
  52.       GnssInfo.satellites.numGPSInView(prnList),
  53.       GnssInfo.satellites.numGPSInUse(NULL));
  54.     Serial.print(buf);
  55.  
  56.     // an example to show the info. of 1st satellite in prnList
  57.     sprintf(buf, "Satellite %d: elv = %2d, azi = %3d, CNR = %d\r\n",
  58.         prnList[0],
  59.       GnssInfo.satellites.elevation(CONSTELLATION_GPS, prnList[0]),
  60.       GnssInfo.satellites.azimuth(CONSTELLATION_GPS, prnList[0]),
  61.       GnssInfo.satellites.CNR(CONSTELLATION_GPS, prnList[0]));
  62.     Serial.print(buf);
  63.  
  64.     // display the longitude
  65.     GnssInfo.location.longitude_formatString(buf);
  66.     Serial.print(buf);
  67.     Serial.print(", ");
  68.     GnssInfo.location.latitude_formatString(buf);
  69.     Serial.print(buf);
  70.     Serial.print(", ");
  71.  
  72.     // display the altitude in meters
  73.     sprintf(buf, "height = %.2f(m), ", GnssInfo.altitude.meters());
  74.     Serial.print(buf);
  75.  
  76.     // display the course in degree
  77.     sprintf(buf, "course = %.2f (deg), ", GnssInfo.course.deg());
  78.     Serial.print(buf);
  79.  
  80.     // display the speed in KM per hour
  81.     sprintf(buf, "speed = %.2f (km/s)\r\n", GnssInfo.speed.kph());
  82.     Serial.print(buf);
  83.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement