File indexing completed on 2024-04-28 03:43:41

0001 /*  Ekos Observatory Module
0002     SPDX-FileCopyrightText: Wolfgang Reissenberger <sterne-jaeger@t-online.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "ekos/auxiliary/weather.h"
0010 
0011 #include <QObject>
0012 
0013 namespace Ekos
0014 {
0015 
0016 struct WeatherActions
0017 {
0018     bool parkDome, closeShutter, stopScheduler;
0019     uint delay;
0020 };
0021 
0022 class ObservatoryWeatherModel : public QObject
0023 {
0024 
0025         Q_OBJECT
0026 
0027     public:
0028         ObservatoryWeatherModel() = default;
0029 
0030         void initModel(Weather *weather);
0031         bool isActive()
0032         {
0033             return initialized;
0034         }
0035 
0036         ISD::Weather::Status status();
0037 
0038         bool refresh();
0039 
0040         /**
0041          * @brief Actions to be taken when a weather warning occurs
0042          */
0043         WeatherActions getWarningActions()
0044         {
0045             return warningActions;
0046         }
0047         QString getWarningActionsStatus();
0048         void setWarningActions(WeatherActions actions);
0049         bool getWarningActionsActive()
0050         {
0051             return warningActionsActive;
0052         }
0053 
0054         /**
0055          * @brief Actions to be taken when a weather alert occurs
0056          */
0057         WeatherActions getAlertActions()
0058         {
0059             return alertActions;
0060         }
0061         QString getAlertActionsStatus();
0062         void setAlertActions(WeatherActions actions);
0063         bool getAlertActionsActive()
0064         {
0065             return alertActionsActive;
0066         }
0067 
0068         /**
0069          * @brief Retrieve the currently known weather sensor values
0070          */
0071         const std::vector<ISD::Weather::WeatherData> &getWeatherData() const
0072         {
0073             return m_WeatherData;
0074         }
0075 
0076         /**
0077          * @brief Flag whether the X axis should be visible in the sensor graph
0078          */
0079         bool autoScaleValues()
0080         {
0081             return m_autoScaleValues;
0082         }
0083         void setAutoScaleValues(bool show);
0084 
0085     public slots:
0086         /**
0087          * @brief Activate or deactivate the weather warning actions
0088          */
0089         void setWarningActionsActive(bool active);
0090         /**
0091          * @brief Activate or deactivate the weather alert actions
0092          */
0093         void setAlertActionsActive(bool active);
0094 
0095     private:
0096         bool initialized = false;
0097         Weather *weatherInterface;
0098         QTimer warningTimer, alertTimer;
0099         struct WeatherActions warningActions, alertActions;
0100         bool warningActionsActive, alertActionsActive, m_autoScaleValues;
0101 
0102         void startAlertTimer();
0103         void startWarningTimer();
0104 
0105         // hold all sensor data received from the weather station
0106         std::vector<ISD::Weather::WeatherData> m_WeatherData;
0107         // update the stored values
0108         void updateWeatherData(const std::vector<ISD::Weather::WeatherData> &data);
0109         unsigned long findWeatherData(QString name);
0110 
0111     private slots:
0112         void weatherChanged(ISD::Weather::Status status);
0113         void updateWeatherStatus();
0114 
0115     signals:
0116         void newStatus(ISD::Weather::Status status);
0117         void newWeatherData(const std::vector<ISD::Weather::WeatherData> &data);
0118         void ready();
0119         void disconnected();
0120         /**
0121          * @brief signal that actions need to be taken due to weather conditions
0122          */
0123         void execute(WeatherActions actions);
0124 
0125 };
0126 
0127 }