1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-14 04:11:48 -05:00
sdrangel/plugins/feature/satellitetracker/satellitetrackerworker.h

164 lines
6.5 KiB
C
Raw Normal View History

2021-02-26 15:25:48 -05:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2019-2020, 2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// Copyright (C) 2020-2023 Jon Beniston, M7RCE <jon@beniston.com> //
// Copyright (C) 2020 Vort <vvort@yandex.ru> //
// Copyright (C) 2022 Jiří Pinkava <jiri.pinkava@rossum.ai> //
2021-02-26 15:25:48 -05:00
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_FEATURE_SATELLITETRACKERWORKER_H_
#define INCLUDE_FEATURE_SATELLITETRACKERWORKER_H_
#include <QObject>
#include <QTimer>
#include <QAbstractSocket>
#include "util/message.h"
#include "util/messagequeue.h"
#include "util/astronomy.h"
#include "satellitetrackersettings.h"
#include "satellitetrackersgp4.h"
#include "satnogs.h"
class WebAPIAdapterInterface;
class QTcpServer;
class QTcpSocket;
class SatelliteTracker;
class SatelliteTrackerWorker;
class QDateTime;
class QGeoCoordinate;
class ObjectPipe;
2021-02-26 15:25:48 -05:00
class SatWorkerState
{
public:
SatWorkerState(QString name) :
m_name(name)
{
m_satState.m_name = name;
m_hasSignalledAOS = false;
2021-02-26 15:25:48 -05:00
}
bool hasAOS(const QDateTime& currentTime);
2021-02-26 15:25:48 -05:00
protected:
QString m_name; // Name of the satellite
QDateTime m_aos; // Time of next AOS
QDateTime m_los; // Time of next LOS
QTimer m_aosTimer;
QTimer m_losTimer;
QTimer m_dopplerTimer;
QList<int> m_initFrequencyOffset;
QList<int> m_doppler; // How much doppler we've applied to a channel
2021-02-26 15:25:48 -05:00
SatelliteState m_satState;
bool m_hasSignalledAOS; // For pass specified by m_aos and m_los
2021-02-26 15:25:48 -05:00
friend SatelliteTrackerWorker;
};
class SatelliteTrackerWorker : public QObject
{
Q_OBJECT
public:
class MsgConfigureSatelliteTrackerWorker : public Message {
MESSAGE_CLASS_DECLARATION
public:
const SatelliteTrackerSettings& getSettings() const { return m_settings; }
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
2021-02-26 15:25:48 -05:00
bool getForce() const { return m_force; }
static MsgConfigureSatelliteTrackerWorker* create(const SatelliteTrackerSettings& settings, const QList<QString>& settingsKeys, bool force) {
return new MsgConfigureSatelliteTrackerWorker(settings, settingsKeys, force);
2021-02-26 15:25:48 -05:00
}
private:
SatelliteTrackerSettings m_settings;
QList<QString> m_settingsKeys;
2021-02-26 15:25:48 -05:00
bool m_force;
MsgConfigureSatelliteTrackerWorker(const SatelliteTrackerSettings& settings, const QList<QString>& settingsKeys, bool force) :
2021-02-26 15:25:48 -05:00
Message(),
m_settings(settings),
m_settingsKeys(settingsKeys),
2021-02-26 15:25:48 -05:00
m_force(force)
{ }
};
SatelliteTrackerWorker(SatelliteTracker* satelliteTracker, WebAPIAdapterInterface *webAPIAdapterInterface);
~SatelliteTrackerWorker();
2022-09-18 11:45:25 -04:00
void startWork();
2021-02-26 15:25:48 -05:00
MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
void setMessageQueueToFeature(MessageQueue *messageQueue) { m_msgQueueToFeature = messageQueue; }
void setMessageQueueToGUI(MessageQueue *messageQueue) { m_msgQueueToGUI = messageQueue; }
private:
SatelliteTracker* m_satelliteTracker;
WebAPIAdapterInterface *m_webAPIAdapterInterface;
MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication
MessageQueue *m_msgQueueToFeature; //!< Queue to report channel change to main feature object
MessageQueue *m_msgQueueToGUI;
SatelliteTrackerSettings m_settings;
QRecursiveMutex m_mutex;
2021-02-26 15:25:48 -05:00
QTimer m_pollTimer;
QHash<QString, SatNogsSatellite *> m_satellites;
QHash<QString, SatWorkerState *> m_workerState;
bool m_recalculatePasses; //!< Recalculate passes as something has changed
bool m_flipRotation; //!< Use 180 elevation to avoid 360/0 degree discontinutiy
bool m_extendedAzRotation; //!< Use 450+ degree azimuth to avoid 360/0 degree discontinuity
QDateTime m_lastUpdateDateTime;
2021-02-26 15:25:48 -05:00
bool handleMessage(const Message& cmd);
void applySettings(const SatelliteTrackerSettings& settings, const QList<QString>& settingsKeys, bool force = false);
2021-02-26 15:25:48 -05:00
MessageQueue *getMessageQueueToGUI() { return m_msgQueueToGUI; }
void removeFromMap(QString id);
void sendToMap(
const QList<ObjectPipe*>& mapMessagePipes,
QString id,
QString image,
QString model,
QString text,
float labelOffset,
double lat,
double lon,
double altitude,
double rotation,
QList<QGeoCoordinate *> *track = nullptr,
QList<QDateTime *> *trackDateTime = nullptr,
QList<QGeoCoordinate *> *predictedTrack = nullptr,
QList<QDateTime *> *predictedTrackDateTime = nullptr
);
2021-02-26 15:25:48 -05:00
void applyDeviceAOSSettings(const QString& name);
void startStopSinks(bool start);
void calculateRotation(SatWorkerState *satWorkerState);
QString substituteVariables(const QString &textIn, const QString &satelliteName);
void executeCommand(const QString &command, const QString &satelliteName);
void enableDoppler(SatWorkerState *satWorkerState);
void disableDoppler(SatWorkerState *satWorkerState);
2021-02-26 15:25:48 -05:00
private slots:
void stopWork();
2021-02-26 15:25:48 -05:00
void handleInputMessages();
void update();
void aos(SatWorkerState *satWorkerState);
void los(SatWorkerState *satWorkerState);
void doppler(SatWorkerState *satWorkerState);
};
#endif // INCLUDE_FEATURE_SATELLITETRACKERWORKER_H_