Instrument Neutral Distributed Interface INDI 2.2.5
skysafari.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2017 Jasem Mutlaq. All rights reserved.
3
4 INDI SkySafar Middleware Driver.
5
6 The driver expects a heartbeat from the client every X minutes. If no heartbeat
7 is received, the driver executes the shutdown procedures.
8
9 This program is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2 of the License, or (at your option)
12 any later version.
13
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with this library; see the file COPYING.LIB. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA.
23
24 The full GNU General Public License is included in this distribution in the
25 file called LICENSE.
26*******************************************************************************/
27
28#pragma once
29
30#include "defaultdevice.h"
31
32#include <memory>
33
34class SkySafariClient;
35
37{
38 public:
39 SkySafari();
40
41 virtual void ISGetProperties(const char *dev) override;
42
43 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
44 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
45
46 protected:
47 virtual bool initProperties() override;
48
49 virtual void TimerHit() override;
50
51 virtual bool Connect() override;
52 virtual bool Disconnect() override;
53 virtual const char *getDefaultName() override;
54
55 virtual bool saveConfigItems(FILE *fp) override;
56
57 private:
58 void processCommand(std::string cmd);
59
60 bool startServer();
61 bool stopServer();
62 bool startDiscovery();
63 void stopDiscovery();
64 void handleDiscovery();
65
66 bool sendSkySafari(const char *message);
67
68 void sendGeographicCoords();
69 void sendUTCtimedate();
70
71 template <typename Out>
72 void split(const std::string &s, char delim, Out result);
73 std::vector<std::string> split(const std::string &s, char delim);
74
75 // Settings
76 ITextVectorProperty SettingsTP;
77 IText SettingsT[3] {};
78 enum
79 {
80 INDISERVER_HOST,
81 INDISERVER_PORT,
82 SKYSAFARI_PORT
83 };
84
85 // Active Devices
86 ITextVectorProperty ActiveDeviceTP;
87 IText ActiveDeviceT[1] {};
88 enum
89 {
90 ACTIVE_TELESCOPE
91 };
92
93 // Server Control
94 ISwitchVectorProperty ServerControlSP;
95 ISwitch ServerControlS[2];
96 enum
97 {
98 SERVER_ENABLE,
99 SERVER_DISABLE
100 };
101
102 // SkyFi Discovery
103 ISwitchVectorProperty SkyFiDiscoverySP;
104 ISwitch SkyFiDiscoveryS[2] {};
105 enum
106 {
107 SKYFI_DISCOVERY_ENABLE,
108 SKYFI_DISCOVERY_DISABLE
109 };
110
111 // Our client
112 std::unique_ptr<SkySafariClient> skySafariClient;
113
114 int lsocket = -1, clientFD = -1, discoverySocket = -1;
115 unsigned short serverPort = 0;
116
117 bool isSkySafariConnected = false, haveLatitude = false, haveLongitude = false;
118 bool haveUTCoffset = false, haveUTCtime = false, haveUTCdate = false;
119
120 double siteLatitude = 0, siteLongitude = 0;
121 double RA = 0, DE = 0;
122 double timeUTCOffset = 0;
123 int timeYear = 0, timeMonth = 0, timeDay = 0, timeHour = 0, timeMin = 0, timeSec = 0;
124};
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
Definition skysafari.cpp:91
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
Definition skysafari.cpp:72
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual const char * getDefaultName() override
Definition skysafari.cpp:67
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool Disconnect() override
Disconnect from device.
Definition skysafari.cpp:86
ISState
Switch state.
Definition indiapi.h:148
struct _ISwitchVectorProperty ISwitchVectorProperty
struct _ITextVectorProperty ITextVectorProperty
*brief user defined string literal for JSON values *sa std::size_t n
uint8_t cmd[4]
Definition pwc-ioctl.h:2
One switch descriptor.
One text descriptor.