14#include <QtCore/QtNumeric>
15#include <QtCore/QDateTime>
16#include <QtCore/QTimeZone>
22#define USE_POSITION_NMEA_PIMPL 0
24#if USE_POSITION_NMEA_PIMPL
34QGeoPositionInfoPrivateNmea::~QGeoPositionInfoPrivateNmea()
49 updated |= (
c.latitude() != srcCoordinate.
latitude());
53 && (!
qIsFinite(
dst.coordinate().longitude()) || force)) {
54 updated |= (
c.longitude() != srcCoordinate.
longitude());
55 c.setLongitude(
src.coordinate().longitude());
59 updated |= (
c.altitude() != srcCoordinate.
altitude());
60 c.setAltitude(
src.coordinate().altitude());
68 if (!
dst.timestamp().date().isValid() &&
src.timestamp().isValid()) {
69 dst.setTimestamp(
src.timestamp());
85 for (
const auto a:
attrs) {
86 if (
src.hasAttribute(
a) && (!
dst.hasAttribute(
a) || force)) {
87 updated |= (
dst.attribute(
a) !=
src.attribute(
a));
88 dst.setAttribute(
a,
src.attribute(
a));
105#if USE_POSITION_NMEA_PIMPL
107 dstPimpl->nmeaSentences.append(nmeaSentence);
139 pushDelay = std::clamp(pushDelay, -1, 1000);
143 if (pushDelay >= 0) {
188 if (
pos.timestamp().time().isValid()) {
189 const bool newerTime = infoTime <
pos.timestamp().time();
190 const bool newerDate = (infoDate.
isValid()
191 &&
pos.timestamp().date().isValid()
192 && infoDate <
pos.timestamp().date());
193 if (newerTime || newerDate) {
199 const bool invalidDate = !(updateDate.
isValid() && lastPushedDate.
isValid());
201 if ( newerTimestampSinceLastPushed || (invalidDate && newerTimeSinceLastPushed)) {
211 if (infoTime ==
pos.timestamp().time())
228#if USE_POSITION_NMEA_PIMPL
251 if (newerTime || newerDate) {
264 m_hasValidDateTime(
false)
270 if (m_currTimerId > 0)
276 if (m_currTimerId > 0)
279 if (!m_hasValidDateTime) {
282 if (!setFirstDateTime()) {
284 qWarning(
"QNmeaPositionInfoSource: cannot find NMEA sentence with valid date & time");
288 m_hasValidDateTime =
true;
289 simulatePendingUpdate();
293 processNextSentence();
303 int timeToNextUpdate = -1;
305 if (!m_pendingUpdates.
isEmpty())
306 prevTs = m_pendingUpdates.
head().info.timestamp();
311 char static_buf[1024];
312 char *
buf = static_buf;
318 nextLine = m_nextLine;
328 const QTime infoTime =
info.timestamp().time();
329 const QDate infoDate =
info.timestamp().date();
357 if (
pos.timestamp().time().isValid()) {
358 const bool newerTime = infoTime <
pos.timestamp().time();
359 const bool newerDate = (infoDate.
isValid()
360 &&
pos.timestamp().date().isValid()
361 && infoDate <
pos.timestamp().date());
362 if (newerTime || newerDate) {
367 if (infoTime ==
pos.timestamp().time())
378#if USE_POSITION_NMEA_PIMPL
385 timeToNextUpdate =
msecsTo(prevTs,
info.timestamp());
386 if (timeToNextUpdate < 0)
392 return timeToNextUpdate;
395bool QNmeaSimulatedReader::setFirstDateTime()
402 if (
info.timestamp().time().isValid()) {
412void QNmeaSimulatedReader::simulatePendingUpdate()
414 if (!m_pendingUpdates.
isEmpty()) {
420 processNextSentence();
427 simulatePendingUpdate();
430void QNmeaSimulatedReader::processNextSentence()
436 if (timeToNextUpdate < 0)
454 m_updateMode(updateMode),
456 m_invokedStart(
false),
458 m_userEquivalentRangeError(
qQNaN()),
463 m_horizontalAccuracy(
qQNaN()),
464 m_verticalAccuracy(
qQNaN()),
465 m_noUpdateLastInterval(
false),
466 m_updateTimeoutSent(
false),
467 m_connectedReadyRead(
false)
474 delete m_updateTimer;
477bool QNmeaPositionInfoSourcePrivate::openSourceDevice()
480 qWarning(
"QNmeaPositionInfoSource: no QIODevice data source, call setDevice() first");
485 qWarning(
"QNmeaPositionInfoSource: cannot open QIODevice data source");
496void QNmeaPositionInfoSourcePrivate::sourceDataClosed()
508bool QNmeaPositionInfoSourcePrivate::initialize()
513 if (!openSourceDevice())
524void QNmeaPositionInfoSourcePrivate::prepareSourceDevice()
532 if (!m_connectedReadyRead) {
534 m_connectedReadyRead =
true;
553 m_noUpdateLastInterval =
false;
555 bool initialized = initialize();
573 m_updateTimer->
stop();
582 prepareSourceDevice();
589 m_updateTimer->
stop();
591 m_noUpdateLastInterval =
false;
596 if (m_requestTimer && m_requestTimer->
isActive())
601 if (msec <= 0 || msec < m_source->minimumUpdateInterval()) {
606 if (!m_requestTimer) {
607 m_requestTimer =
new QTimer(
this);
611 bool initialized = initialize();
617 m_requestTimer->
start(msec);
618 prepareSourceDevice();
621void QNmeaPositionInfoSourcePrivate::updateRequestTimeout()
623 m_requestTimer->
stop();
634 m_currentDate =
date;
646 else if (!
qIsNaN(m_horizontalAccuracy))
651 else if (!
qIsNaN(m_verticalAccuracy))
654 if (hasFix && update->
isValid()) {
655 if (m_requestTimer && m_requestTimer->
isActive()) {
656 m_requestTimer->
stop();
657 emitUpdated(*update);
659 if (m_updateTimer && m_updateTimer->
isActive()) {
661 m_pendingUpdate = *update;
662 if (m_noUpdateLastInterval) {
666 m_noUpdateLastInterval =
false;
669 emitUpdated(*update);
681void QNmeaPositionInfoSourcePrivate::emitPendingUpdate()
683 if (m_pendingUpdate.
isValid()) {
684 m_updateTimeoutSent =
false;
685 m_noUpdateLastInterval =
false;
686 emitUpdated(m_pendingUpdate);
689 if (m_noUpdateLastInterval && !m_updateTimeoutSent) {
690 m_updateTimeoutSent =
true;
694 m_noUpdateLastInterval =
true;
698void QNmeaPositionInfoSourcePrivate::emitUpdated(
const QGeoPositionInfo &update)
818#if QT_DEPRECATED_SINCE(7, 0)
822#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
834#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
870 qWarning(
"QNmeaPositionInfoSource: source device has already been set");
963#include "moc_qnmeapositioninfosource_p.cpp"
964#include "moc_qnmeapositioninfosource.cpp"
IOBluetoothDevice * device
void start(int msec, QObject *obj)
\obsolete Use chrono overload instead.
void stop()
Stops the timer.
bool isActive() const noexcept
Returns true if the timer is running and has not been stopped; otherwise returns false.
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
void clear()
Clears the contents of the byte array and makes it null.
\inmodule QtCore\reentrant
qint64 msecsTo(const QDateTime &) const
Returns the number of milliseconds from this datetime to the other datetime.
QTime time() const
Returns the time part of the datetime.
QDate date() const
Returns the date part of the datetime.
\inmodule QtCore \reentrant
constexpr bool isValid() const
Returns true if this date is valid; otherwise returns false.
double longitude
This property holds the longitude in decimal degrees.
double latitude
This property holds the latitude in decimal degrees.
double altitude
This property holds the altitude in meters above sea level.
void setLatitude(double latitude)
Sets the latitude (in decimal degrees) to latitude.
static QGeoPositionInfoPrivate * get(const QGeoPositionInfo &info)
int updateInterval
This property holds the requested interval in milliseconds between each update.
void positionUpdated(const QGeoPositionInfo &update)
If startUpdates() or requestUpdate() is called, this signal is emitted when an update becomes availab...
@ SatellitePositioningMethods
void errorOccurred(QGeoPositionInfoSource::Error)
This signal is emitted after an error occurred.
Error
The Error enumeration represents the errors which can occur.
virtual void setUpdateInterval(int msec)
bool isValid() const
Returns true if the timestamp() and coordinate() values are both valid.
qreal attribute(Attribute attribute) const
Returns the value of the specified attribute as a qreal value.
void setAttribute(Attribute attribute, qreal value)
Sets the value for attribute to value.
void setTimestamp(const QDateTime ×tamp)
Sets the date and time at which this position was reported to timestamp.
QDateTime timestamp() const
Returns the date and time at which this position was reported, in UTC time.
bool hasAttribute(Attribute attribute) const
Returns true if the specified attribute is present for this QGeoPositionInfo object.
\inmodule QtCore \reentrant
virtual bool open(QIODeviceBase::OpenMode mode)
Opens the device and sets its OpenMode to mode.
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
qint64 readLine(char *data, qint64 maxlen)
This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes,...
bool isOpen() const
Returns true if the device is open; otherwise returns false.
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
QIODeviceBase::OpenMode openMode() const
Returns the mode in which the device has been opened; i.e.
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success,...
virtual bool canReadLine() const
Returns true if a complete line of data can be read from the device; otherwise returns false.
bool isEmpty() const noexcept
static bool getPosInfoFromNmea(QByteArrayView bv, QGeoPositionInfo *info, double uere, bool *hasFix=nullptr)
void notifyNewUpdate(QGeoPositionInfo *update, bool fixStatus)
~QNmeaPositionInfoSourcePrivate()
QGeoPositionInfo m_lastUpdate
bool parsePosInfoFromNmeaData(QByteArrayView data, QGeoPositionInfo *posInfo, bool *hasFix)
void requestUpdate(int msec)
QNmeaPositionInfoSource::UpdateMode m_updateMode
double m_userEquivalentRangeError
QNmeaPositionInfoSourcePrivate(QNmeaPositionInfoSource *parent, QNmeaPositionInfoSource::UpdateMode updateMode)
QPointer< QIODevice > m_device
QGeoPositionInfoSource::Error m_positionError
void timerEvent(QTimerEvent *event) override
This event handler can be reimplemented in a subclass to receive timer events for the object.
double userEquivalentRangeError() const
Returns the current User Equivalent Range Error (UERE).
void setUserEquivalentRangeError(double uere)
Sets the User Equivalent Range Error (UERE) to uere.
UpdateMode updateMode() const
Returns the update mode.
PositioningMethods supportedPositioningMethods() const override
\reimp
UpdateMode
Defines the available update modes.
bool parsePosInfoFromNmeaData(QByteArrayView data, QGeoPositionInfo *posInfo, bool *hasFix)
Parses an NMEA sentence string into a QGeoPositionInfo.
int minimumUpdateInterval() const override
\reimp
void startUpdates() override
\reimp
void stopUpdates() override
\reimp
Error error() const override
\reimp
QIODevice * device() const
Returns the NMEA data source.
QNmeaPositionInfoSource(UpdateMode updateMode, QObject *parent=nullptr)
Constructs a QNmeaPositionInfoSource instance with the given parent and updateMode.
void setError(QGeoPositionInfoSource::Error positionError)
void setDevice(QIODevice *source)
Sets the NMEA data source to device.
QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly=false) const override
\reimp
~QNmeaPositionInfoSource()
Destroys the position source.
void setUpdateInterval(int msec) override
\reimp
void requestUpdate(int timeout=0) override
\reimp
QNmeaPositionInfoSourcePrivate * m_proxy
virtual void readAvailableData()=0
void readAvailableData() override
~QNmeaRealTimeReader() override
QNmeaRealTimeReader(QNmeaPositionInfoSourcePrivate *sourcePrivate)
QGeoPositionInfo m_update
void timerEvent(QTimerEvent *event) override
This event handler can be reimplemented in a subclass to receive timer events for the object.
QNmeaSimulatedReader(QNmeaPositionInfoSourcePrivate *sourcePrivate)
void readAvailableData() override
int startTimer(int interval, Qt::TimerType timerType=Qt::CoarseTimer)
This is an overloaded function that will start a timer of type timerType and a timeout of interval mi...
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
void killTimer(int id)
Kills the timer with timer identifier, id.
void enqueue(const T &t)
Adds value t to the tail of the queue.
T & head()
Returns a reference to the queue's head item.
T dequeue()
Removes the head item in the queue and returns it.
\inmodule QtCore \reentrant
bool isValid() const
Returns true if the time is valid; otherwise returns false.
int msecsTo(QTime t) const
Returns the number of milliseconds from this time to t.
void setSingleShot(bool singleShot)
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
void setInterval(int msec)
bool isActive() const
Returns true if the timer is running (pending); otherwise returns false.
void stop()
Stops the timer.
void timeout(QPrivateSignal)
This signal is emitted when the timer times out.
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage return DBusPendingCall * pending
static struct AttrInfo attrs[]
bool qIsFinite(qfloat16 f) noexcept
bool qIsNaN(qfloat16 f) noexcept
constexpr const T & qMax(const T &a, const T &b)
QGeoPositionInfoPrivate QGeoPositionInfoPrivateNmea
static bool propagateCoordinate(QGeoPositionInfo &dst, const QGeoPositionInfo &src, bool force=true)
static int processSentence(QGeoPositionInfo &info, QByteArray &m_nextLine, QNmeaPositionInfoSourcePrivate *m_proxy, QQueue< QPendingGeoPositionInfo > &m_pendingUpdates, bool &hasFix)
static bool propagateAttributes(QGeoPositionInfo &dst, const QGeoPositionInfo &src, bool force=true)
static qint64 msecsTo(const QDateTime &from, const QDateTime &to)
static bool propagateDate(QGeoPositionInfo &dst, const QGeoPositionInfo &src)
static bool mergePositions(QGeoPositionInfo &dst, const QGeoPositionInfo &src, QByteArray nmeaSentence)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION double qQNaN()
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLbitfield GLuint64 timeout
[4]
GLenum GLuint GLenum GLsizei const GLchar * buf
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
QFileInfo info(fileName)
[8]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent