⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpsstatus.cpp

📁 给予QT的qps开源最新源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:

   (void)new QLabel(" GPS:", horbox3);
   d_pReceiverStatus = new QLabel(tr("???"), horbox3);
   d_pReceiverStatus->setBackgroundColor(Qt::red);
   d_pReceiverStatus->setFrameStyle(QFrame::Panel | QFrame::Raised);
   d_pReceiverStatus->setUpdatesEnabled(true);
   d_pReceiverStatus->setAlignment(Qt::AlignLeft | AlignVCenter);
   d_pReceiverStatus->setFixedWidth(30);

   /*   99/99/9999 99:99:99  */
   d_pStatus = new QPushButton(tr("* No GMT Signal rcvd *"), group2);
   d_pStatus->setUpdatesEnabled(true);
   d_pStatus->setFlat(true);
   d_pStatus->setBackgroundColor(Qt::red);
   // d_pStatus->setFrameStyle( QFrame::Panel | QFrame::Raised );
   //d_pStatus->setAlignment(Qt::AlignCenter);
   requestTimeAdj = false;

   group2->setMaximumHeight(106);

   d_pSatStat = new SatStat(gpsData, hsep);
   d_pSatStat->setMinimumSize(100, 110);
   //d_pSatStat->setMaximumHeight(130);
   //d_pSatStat->setFrameStyle( QFrame::Panel | QFrame::Raised );
   //d_pSatStat->setBackgroundColor(Qt::lightGray);

   QHBox * horbox4 = new QHBox(group2);
   (void)new QLabel(tr("Lat: "), horbox4);
   //d_pLatitude  = new QLineEdit(horbox4);
   d_pLatitude  = new QLabel("", horbox4);
   d_pLatitude->setText(tr("???"));
   d_pLatitude->setAlignment(Qt::AlignRight);
   //d_pLatitude->setReadOnly(true);

   QHBox * horbox5 = new QHBox(group2);
   (void)new QLabel(tr("Lon: "), horbox5);
   //d_pLongitude = new QLineEdit(horbox5);
   d_pLongitude = new QLabel("", horbox5);
   d_pLongitude->setText(tr("???"));
   d_pLongitude->setAlignment(Qt::AlignRight);
   //d_pLongitude->setReadOnly(true);

   d_pSatSNR = new SatSNR(gpsData, this);
   d_pSatSNR->setMinimumSize(220, 73);
   d_pSatSNR->setFrameStyle(QFrame::Panel | QFrame::Raised);
   d_pSatSNR->setBackgroundColor(Qt::lightGray);
   //d_pSatSNR->setBackgroundMode(QWidget::NoBackground);

   connect( startB, SIGNAL(pressed()),
         SLOT(setGpsdStart()) );
   connect( resumeB, SIGNAL(pressed()),
         SLOT(setGpsdResume()) );
   connect( stopB, SIGNAL(pressed()),
         SLOT(setGpsdStop()) );

#if 0
   connect( gpsdArgumentsB, SIGNAL(pressed()),
         SLOT(setGpsdDefaultArg()) );
   connect( gpsdArguments, SIGNAL(returnPressed()),
         SLOT(gpsdArgLEChanged()) );
#endif
   connect( gpsdHostPortB, SIGNAL(pressed()),
         SLOT(setGpsdDefaultHostPort()) );
   connect( gpsdHostArg, SIGNAL(returnPressed()),
         SLOT(gpsdHostArgLEChanged()) );
   connect( gpsdPortArg, SIGNAL(returnPressed()),
         SLOT(gpsdPortArgLEChanged()) );

   //connect( this, SIGNAL(gpsdArgChanged()),
   //         gData->appl()->gpsd, SLOT(restartGpsd()) );

   connect( d_pStatus, SIGNAL(clicked()),
         this, SLOT(setSysTime()) );
}

#if 0
void GpsStatus::setGpsdDefaultArg()
{
   //gpsData->gpsdArgStr = gpsdDefaultArg;
   gpsData->gpsdArgStr = gpsdDefaultArg;
   //gpsdArguments->setText(gpsData->gpsdArgStr);
   gpsdArguments->setText(gpsData->gpsdArgStr);

   settings->writeConfig();
   emit gpsdArgChanged();
}
#endif

void GpsStatus::setGpsdStart()
{
   ScriptDialog sd(gpsOptions->startScript, this, "startup script", true, 0);
   sd.setCaption(tr("Startup Script"));
   sd.exec();

   if ( sd.result() == QDialog::Accepted ) {
      gpsOptions->startScript = QStringList::split('\n', sd.script->text(), true);
      app->writeConfig();
   }
}

void GpsStatus::setGpsdResume()
{
   ScriptDialog sd(gpsOptions->resumeScript, this, "resume script", true, 0);
   sd.setCaption(tr("Resume Script"));
   sd.exec();

   if ( sd.result() == QDialog::Accepted ) {
      gpsOptions->resumeScript = QStringList::split('\n', sd.script->text(), true);
      app->writeConfig();
   }

}

void GpsStatus::updateConfig()
{
   gpsdHostArg->setText(gpsOptions->host);
   gpsdPortArg->setText(tr("%1").arg(gpsOptions->port));
}

void GpsStatus::setGpsdStop()
{
   ScriptDialog sd(gpsOptions->stopScript, this, "stop script", true, 0);
   sd.setCaption(tr("Stop Script"));
   sd.exec();

   if ( sd.result() == QDialog::Accepted) {
      gpsOptions->stopScript = QStringList::split('\n', sd.script->text(), true);
      app->writeConfig();
   }
}

void GpsStatus::setGpsdDefaultHostPort()
{
   //gpsOptions->host = gpsdDefaultHost;
   gpsOptions->host = gpsdDefaultHost;
   //gpsdHostArg->setText(gpsOptions->host);
   gpsdHostArg->setText(gpsOptions->host);

   //gpsOptions->port = gpsdDefaultPort;
   gpsOptions->port = gpsdDefaultPort;
   //gpsdPortArg->setText(tr("%1").arg(gpsOptions->port));
   gpsdPortArg->setText(tr("%1").arg(gpsOptions->port));

   //07/2005 gpsdArguments->setDisabled(false);

   app->writeConfig();

   emit gpsdArgChanged();
//    gpsd->closeConnection();
//    gpsd->startConnection();
}

#if 0
void GpsStatus::gpsdArgLEChanged()
{
   //gpsData->gpsdArgStr = gpsdArguments->text();
   gpsData->gpsdArgStr = gpsdArguments->text();
   settings->writeConfig();
   emit gpsdArgChanged();
}
#endif

void GpsStatus::gpsdHostArgLEChanged()
{
   //gpsOptions->host = gpsdHostArg->text();
   gpsOptions->host = gpsdHostArg->text();
   app->writeConfig();

   //if (gpsOptions->host.compare(gpsdDefaultHost))
#if 0
   if ( gpsOptions->host.compare(gpsdDefaultHost) ) {
      gpsdArguments->setDisabled(true);
   } else {
      gpsdArguments->setDisabled(false);
   }
#endif

   emit gpsdArgChanged();
}

void GpsStatus::gpsdPortArgLEChanged()
{
   //gpsOptions->port = atoi(gpsdPortArg->text());
   gpsOptions->port = atoi(gpsdPortArg->text());
   app->writeConfig();
   emit gpsdArgChanged();
}

void GpsStatus::paintEvent(QPaintEvent * ev)
{
   //get tab size and calc adjustment values
   xScreenCorr = width() / 236.0;
   yScreenCorr = height() / 256.0;
   // 240x320 is smallest
   xScreenCorr = ( xScreenCorr < 1.0 ) ? 1.0 : xScreenCorr;
   yScreenCorr = ( yScreenCorr < 1.0 ) ? 1.0 : yScreenCorr;
   xyScreenCorr = ( xScreenCorr < yScreenCorr ) ? xScreenCorr : yScreenCorr;

   // fon of "Data Status"

   QFont f = font();
   f.setPointSize(S_ADJ(10));
   group2->setFont(f);

   // set width/height again
   group1->setMaximumHeight(Y_ADJ(72));
   d_pGpsdStatus->setFixedWidth(X_ADJ(30));
   d_pReceiverStatus->setFixedWidth(X_ADJ(30));
   group2->setMaximumHeight(Y_ADJ(106));

   d_pSatStat->setMinimumSize(X_ADJ(100), Y_ADJ(110));
   d_pSatSNR->setMinimumSize(X_ADJ(220), Y_ADJ(73));

   // any repaint event will force a full update
   d_fullUpdate = true;

   update();

   QVBox::paintEvent(ev);
}

void GpsStatus::updateQuick()
{
   static QString lastFix = "";
   static QString lastReceiver = "";
    static int mode = -1;
    static bool connected = false;
    static bool alive = false;

    QString ts;
    if (!gpsData->timestamp.isNull())
      ts = gpsData->timestamp.date().toString() + " " +
         gpsData->timestamp.time().toString() + " ";
    else
       ts = tr("* No GMT Signal rcvd *");

   bool needStatusUpdate = false;
   bool needReceiverUpdate = false;

	//if (connected != gpsData->d_connected) {
	if (gpsData->connected)
	{
		if (connected != true) {
			connected = true;

			// connected ?
			d_pGpsdStatus->setBackgroundColor(Qt::green);
			d_pGpsdStatus->setText(tr("OK"));
			d_pGpsdStatus->update();//repaint();
		}
		if ( ts.compare(lastFix) != 0 ) {
         // new time stamp came in, reset counter
         lastFix = ts;

			if(requestTimeAdj) {
				requestTimeAdj = FALSE;

				//set TZ env. variable to UTC time => for settimeofday and QDateTime
				QString tzenv = getenv("TZ");
				setenv("TZ","UTC",1);

				// Set system clock
            QDateTime tsDT(gpsData->timestamp);
            // Set system clock
            if ( tsDT.isValid() ) {
               // consider timezone !
               int t = TimeConversion::toUTC(tsDT); // isn't UTC, it's local time in seconds..
               tsDT.setTime_t(t);
               t = TimeConversion::toUTC(tsDT);
               struct timeval myTv;
               myTv.tv_sec = t;
               myTv.tv_usec = 0;

               if ( myTv.tv_sec != -1 ) {
                  ::settimeofday(&myTv, 0);
               }

               // the TZ env. variable must be set correctly
               // No! it must be set to the same value as before
               setenv("TZ", tzenv, 1);

               // cause update of other apps (badly, the timeZone didn't change)
               TimeZoneSelector ts;
               QString tz = ts.currentZone();

               QCopEnvelope setTimeZone("QPE/System", "timeChange(QString)");
               setTimeZone << tz;
            } else {
               qWarning(tr("%1").arg(tsDT.toString()));
            }
         }
			d_pStatus->setText(ts);
			needStatusUpdate = true;
		}

		//if (gpsData->d_Receiver.compare(lastReceiver) != 0) {
		if (gpsData->gpsName != NULL && lastReceiver.compare(gpsData->gpsName) != 0)
		{
			//lastReceiver = gpsData->d_Receiver;
         lastReceiver = gpsData->gpsName;
         d_pReceiverStatus->setText(lastReceiver);
			needReceiverUpdate = true;
		}

		if (mode != gpsData->status) 
		{
			mode = gpsData->status;
			
			// notify user about change in status
			QApplication::beep();

			QColor sc;
         if (gpsData->status) {
            if (mode == GpsData::Fix3D)
					// 3D fix
					sc = Qt::green;
				else
					// 2D fix
					sc = Qt::yellow;
         } else
				// no fix
				sc = Qt::red;
			d_pStatus->setBackgroundColor(sc);

			needStatusUpdate = true;
			// Any FIX status change forces full update
			d_fullUpdate = true;
		}

		if (alive != gpsData->online) 
		{
         alive = gpsData->online;
			d_pReceiverStatus->setBackgroundColor((alive ? Qt::green : Qt::red) );

			needReceiverUpdate = true;
			// Any GPS status change forces full update
			d_fullUpdate = true;
		}

		if (gpsData->status) 
		{
			// new position
			//QColor * color = (gpsData->status ? gpsData->statusNoFixColor : gpsData->statusOkColor);
			//d_pGpsdStatus->setBackgroundColor( (gpsData->d_connected ? Qt::green : Qt::red) );
         //if (!d_pLongitude->hasMarkedText())
         d_pLongitude->setText(
               Position::string(gpsData->fix.position.lon, Position::Lon));
         //if (!d_pLatitude->hasMarkedText())
         d_pLatitude->setText(
               Position::string(gpsData->fix.position.lat, Position::Lat));
		}

		if (needReceiverUpdate)
			d_pReceiverStatus->update();//repaint();

		if (needStatusUpdate)
			d_pStatus->update();//repaint();
	}
	else
	{
		if (connected != false) 
		{
			connected = false;

			// disconnected
			d_pGpsdStatus->setBackgroundColor(Qt::red);
			d_pGpsdStatus->setText(tr("ERR"));
			d_pGpsdStatus->update();//repaint();
		}

		d_pReceiverStatus->setText(tr("???"));
		d_pReceiverStatus->setBackgroundColor(Qt::red);
		d_pReceiverStatus->update();//repaint();

		d_pStatus->setText(tr("* No GMT Signal rcvd *"));
		d_pStatus->setBackgroundColor(Qt::red);
		d_pStatus->update();//repaint();

		lastReceiver = "";
		mode = -1;
		connected = false;
		alive = false;
	}
}

void GpsStatus::update()
{
   static QString lastInfo = "";

   updateQuick();

   bool needUpdate = d_fullUpdate;
   for (uint i = 0; i < 12; ++i) {
      Satellite *satInfo;
		if (i < gpsData->satellites.count()) {
         satInfo = gpsData->satellites.at(i);
         // check if satellite data has changed
         if (!(d_pSatSNR->d_pSatInfo[i] == *satInfo) || d_fullUpdate) {
            // satellite data has changed
            d_pSatSNR->d_pSatInfo[i] = *satInfo;

            d_pSatSNR->d_pSatInfo[i].updated = true;
            needUpdate = true;
         }
      }
      else {
         // not used
         d_pSatSNR->d_pSatInfo[i].name = -1;
      }
   }
   if ( needUpdate ) {
      d_pSatSNR->update();//repaint(false);
   }

   int no_of_satellites = 0;
   no_of_satellites = gpsData->satellites_used;
   // mangle all strings together
   QString tmp = gpsData->fix.bearing.toString() + 
         gpsData->fix.heading.toString() +
         gpsData->fix.altitude.toString() + 
         gpsData->fix.speed.toString() +
      tr("%1").arg(no_of_satellites);

   if ( lastInfo.compare(tmp) != 0 ) {
      // new info arrived
      lastInfo = tmp;
      d_pSatStat->update();//repaint();
   }

   // if it was requested, it is now updated
   d_fullUpdate = false;
}

// end of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -