📄 qgps.cc
字号:
//----------------------------------------------------------------------------// qgps.cc : implementation of GPS visualization classes//// - programmed by Boyoon Jung (boyoon@robotics.usc.edu)//----------------------------------------------------------------------------#include "qgps.h"#include "qgps_led.h"#include "qgps_satmap.h"#include "qglobe.h"#include <math.h>#include <cstdio>// header files for Qt library#include <qtabwidget.h>#include <qlabel.h>#include <qprogressbar.h>#include <qcheckbox.h>// constructorQGps::QGps(GPS* gps, QWidget* parent, const char* name, WFlags f) : QGpsUI(parent, name, f){ // store the pointer of the GPS if (gps) setGPS(gps); else gps = 0; // initialize variables aprns[0] = -1; // create LEDs led_red = qembed_findImage("led_red"); led_green = qembed_findImage("led_green"); led_blue = qembed_findImage("led_blue"); // automatically start to update GPS info start();}// destructorQGps::~QGps(void){ // stop updating info terminate(); wait();}// set the GPSvoid QGps::setGPS(GPS* gps){ // store the pointer of the GPS this->gps = gps;}// retrieve the GPS info from the devicevoid QGps::run(void){ while (true) { // retrieve the next sentence int sid = gps->update(); // update the information switch (sid) { case GPGGA: updateGGA(); break; case GPGSA: updateGSA(); break; case GPGSV: updateGSV(); break; case PGRME: updatePGRME(); break; case PGRMV: updatePGRMV(); break; } // be nice to other threads usleep(10000); }}// update the position pagevoid QGps::updateGGA(void){ if (gps && mainTab->currentPageIndex() == 0) { char buffer[20]; double x, y, z; double e, n; // update fix quality information switch (gps->fix_quality) { case 0: // fix not available led->setPixmap(led_red); nsat_used->setNum(gps->nsat_used); dgps_on->setChecked(false); globe->hidePosition(); return; case 1: // non-differential GPS fix led->setPixmap(led_green); dgps_on->setChecked(false); break; case 2: // differential GPS fix led->setPixmap(led_green); dgps_on->setChecked(true); drs_id->setNum(gps->drs_id); sprintf(buffer, "%02d:%02d:%02d", gps->dgps_age/3600, (gps->dgps_age%3600)/60, gps->dgps_age%60); rtcm_age->setText(buffer); break; case 3: // estimated dgps_on->setChecked(false); led->setPixmap(led_blue); break; } // update UTC time strncpy(buffer, gps->fix_time, 2); strncpy(buffer+3, gps->fix_time+2, 2); strncpy(buffer+6, gps->fix_time+4, 2); buffer[2] = buffer[5] = ':'; buffer[8] = '\0'; fix_time->setText(buffer); // update the number of satellites nsat_used->setNum(gps->nsat_used); // update geodetic position info latitude->setText(lat2str(gps->latitude, buffer)); longitude->setText(long2str(gps->longitude, buffer)); altitude->setNum(gps->altitude); geoid->setNum(gps->geoid); globe->setPosition(gps->latitude, gps->longitude, gps->altitude, gps->geoid); // update DOP info dop->setNum(gps->dop); // update ECEF position info gps->ecef(x, y, z); QString qs; ecefx->setText(qs.setNum(x,'f',4)); ecefy->setText(qs.setNum(y,'f',4)); ecefz->setText(qs.setNum(z,'f',4)); // update UTM position info gps->utm(e, n); easting->setText(qs.setNum(e,'f',4)); northing->setText(qs.setNum(n,'f',4)); }}// update the satellites page (active-satellite info only)void QGps::updateGSA(void){ if (gps && mainTab->currentPageIndex() == 1) { // update the GPS mode switch (gps->fix_type) { case 1: // not available sat_mode->setText("Not Available"); return; case 2: // 2D fix if (gps->mode == 'M') sat_mode->setText("Manual selection of 2D fix"); else sat_mode->setText("Auto selection of 2D fix"); break; case 3: // 3D fix if (gps->mode == 'M') sat_mode->setText("Manual selection of 3D fix"); else sat_mode->setText("Auto selection of 3D fix"); break; } // update the active satelite info for (int i=0; i<12 && gps->prns_used[i] >= 0; i++) aprns[i] = gps->prns_used[i]; // update DOP info dop_pos->setNum(gps->dop_pos); dop_horiz->setNum(gps->dop_horiz); dop_vert->setNum(gps->dop_pos); }}// update the garmin page (estimated errors only)void QGps::updatePGRME(void){ if (gps && mainTab->currentPageIndex() == 2) { // update estimated error info if (gps->horiz_error > 0) horiz_error->setNum(gps->horiz_error); else horiz_error->setText(""); if (gps->horiz_error > 0) vert_error->setNum(gps->vert_error); else vert_error->setText(""); if (gps->horiz_error > 0) pos_error->setNum(gps->pos_error); else pos_error->setText(""); }}// update the garmin page (3D velocity only)void QGps::updatePGRMV(void){ if (gps && mainTab->currentPageIndex() == 2) { // update estimated error info vel_east->setNum(gps->vel_east); vel_north->setNum(gps->vel_north); vel_up->setNum(gps->vel_up); }}// inline function used by updateGSV()inline void update_prn(int idx, GPS* gps, QLabel* lbl, QProgressBar* bar, bool active){ if (gps->nsat_view > idx) { // make it red if it is active; otherwise, make it black if (active) lbl->setPaletteForegroundColor(Qt::red); else lbl->setPaletteForegroundColor(Qt::black); // update the info lbl->setNum(gps->sat_view[idx].prn); bar->setProgress(gps->sat_view[idx].snr); } else { // reset lbl->setPaletteForegroundColor(Qt::black); lbl->setText(""); bar->setProgress(0); }}// update the satellites page (satellite-in-view info only)void QGps::updateGSV(void){ if (gps && mainTab->currentPageIndex() == 1) { // update the number of satellites in view nsat_view->setNum(gps->nsat_view); // update the PRN & SNR info update_prn(0, gps, prn0, snr0, isActive(gps->sat_view[0].prn)); update_prn(1, gps, prn1, snr1, isActive(gps->sat_view[1].prn)); update_prn(2, gps, prn2, snr2, isActive(gps->sat_view[2].prn)); update_prn(3, gps, prn3, snr3, isActive(gps->sat_view[3].prn)); update_prn(4, gps, prn4, snr4, isActive(gps->sat_view[4].prn)); update_prn(5, gps, prn5, snr5, isActive(gps->sat_view[5].prn)); update_prn(6, gps, prn6, snr6, isActive(gps->sat_view[6].prn)); update_prn(7, gps, prn7, snr7, isActive(gps->sat_view[7].prn)); update_prn(8, gps, prn8, snr8, isActive(gps->sat_view[8].prn)); update_prn(9, gps, prn9, snr9, isActive(gps->sat_view[9].prn)); update_prn(10, gps, prn10, snr10, isActive(gps->sat_view[10].prn)); update_prn(11, gps, prn11, snr11, isActive(gps->sat_view[11].prn)); // update the satellite map satmap->updateSatellites(gps->nsat_view, gps->sat_view, gps->prns_used); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -