Instrument Neutral Distributed Interface INDI  2.0.2
uranusmeteo.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2022 Jasem Mutlaq. All rights reserved.
3 
4  Pegasus Uranus Meteo Sensor Driver.
5 
6  This program is free software; you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by the Free
8  Software Foundation; either version 2 of the License, or (at your option)
9  any later version.
10 
11  This program is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 
21  The full GNU General Public License is included in this distribution in the
22  file called LICENSE.
23 *******************************************************************************/
24 
25 #pragma once
26 
27 #include "indigps.h"
28 #include "indiweatherinterface.h"
29 
30 #include <vector>
31 #include <stdint.h>
32 
33 namespace Connection
34 {
35 class Serial;
36 }
37 
39 {
40  public:
41  UranusMeteo();
42 
43  virtual bool initProperties() override;
44  virtual bool updateProperties() override;
45 
46  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
47  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
48 
49  protected:
50  const char *getDefaultName() override;
51  virtual bool saveConfigItems(FILE *fp) override;
52 
53  // Event loop
54  virtual void TimerHit() override;
55 
56  // GPS Override
57  virtual IPState updateGPS() override;
58 
59  // Weather Overrides
60  virtual IPState updateWeather() override;
61 
62  private:
63  bool Handshake();
64 
68  bool readSensors();
69  enum
70  {
71  AmbientTemperature,
72  RelativeHumidity,
73  DewPoint,
74  AbsolutePressure,
75  RelativePressure,
76  BarometricAltitude,
77  SkyTemperature,
78  InfraredTemperature,
79  BatteryUsage,
80  BatteryVoltage,
81  };
82  INDI::PropertyNumber SensorNP {10};
83 
87  bool readSkyQuality();
88  void measureSkyQuality();
89  enum
90  {
91  MPAS,
92  NELM,
93  FullSpectrum,
94  VisualSpectrum,
95  InfraredSpectrum,
96  };
97  INDI::PropertyNumber SkyQualityNP {5};
98  INDI::PropertyNumber SkyQualityUpdateNP {1};
99 
103  bool readClouds();
104  enum
105  {
106  TemperatureDifference,
107  CloudIndex,
108  CloudSkyTemperature,
109  CloudAmbientTemperature,
110  InfraredEmissivity,
111  };
112  INDI::PropertyNumber CloudsNP {5};
113 
117  enum
118  {
119  GPSFix,
120  GPSTime,
121  UTCOffset,
122  Latitude,
123  Longitude,
124  SatelliteNumber,
125  GPSSpeed,
126  GPSBearing
127  };
128  INDI::PropertyNumber GPSNP {8};
129 
133  bool readMoon();
134  enum
135  {
136  MoonPhase,
137  MoonType,
138  MoonVisibility
139  };
140  INDI::PropertyNumber MoonNP {3};
141 
145  bool readTwilight();
146  enum
147  {
148  TwilightSunrise,
149  TwilightSunset,
150  TwilightMoonPhase,
151  };
152  INDI::PropertyNumber TwilightNP {3};
153 
157  bool readConfig();
158  enum
159  {
160  CONFIG_UNITS,
161  CONFIG_NMEA_RJ12,
162  CONFIG_OLED_ON,
163  CONFIG_RESERVED_1,
164  CONFIG_SLEEP,
165  CONFIG_SQM_OFFSET,
166  CONFIG_TIMEZONE_OFFSET,
167  CONFIG_RESERVED_2,
168  CONFIG_LAST_ID,
169  CONFIG_TIMEZONE_ID,
170  };
171  INDI::PropertyNumber ConfigNP {10};
172 
176  bool reset();
177  INDI::PropertySwitch ResetSP {1};
178 
179  INDI::PropertyText DeviceInfoTP {2};
180  enum
181  {
182  DEVICE_RELEASE,
183  DEVICE_SERIAL
184  };
185 
189 
195  bool sendCommand(const char *cmd, char *res);
196  std::vector<std::string> split(const std::string &input, const std::string &regex);
197 
201 
202  int PortFD { -1 };
203  bool m_SetupComplete { false };
204  Connection::Serial *serialConnection { nullptr };
205 
206  INDI::Timer m_SkyQualityUpdateTimer;
207  std::vector<std::string> m_Sensors;
208  std::vector<std::string> m_Clouds;
209  std::vector<std::string> m_SkyQuality;
210  std::vector<std::string> m_GPS;
211 
212  static constexpr const uint8_t PEGASUS_STOP_CHAR {0xA};
213  static constexpr const uint8_t PEGASUS_TIMEOUT {3};
214  static constexpr const uint8_t PEGASUS_LEN {128};
215  static constexpr const char *SENSORS_TAB {"Sensors"};
216  static constexpr const char *SKYQUALITY_TAB {"Sky Quality"};
217  static constexpr const char *CLOUDS_TAB {"Clouds"};
218  static constexpr const char *ENVIRONMENT_TAB {"Environment"};
219  static constexpr const char *GPS_TAB {"GPS"};
220 };
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
The Timer class provides repetitive and single-shot timers.
Definition: inditimer.h:41
Provides interface to implement weather reporting functionality.
virtual void TimerHit() override
TimerHit Keep calling updateGPS() until it is successfull, if it fails upon first connection.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save refresh period
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
const char * getDefaultName() override
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: uranusmeteo.cpp:50
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual IPState updateGPS() override
updateGPS Retrieve Location & Time from GPS. Update LocationNP & TimeTP properties (value and state) ...
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition: arduino_st4.h:34
__u8 cmd[4]
Definition: pwc-ioctl.h:2