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
63 bool sendSkySafari(const char *message);
64
65 void sendGeographicCoords();
66 void sendUTCtimedate();
67
68 template <typename Out>
69 void split(const std::string &s, char delim, Out result);
70 std::vector<std::string> split(const std::string &s, char delim);
71
72 // Settings
73 ITextVectorProperty SettingsTP;
74 IText SettingsT[3] {};
75 enum
76 {
77 INDISERVER_HOST,
78 INDISERVER_PORT,
79 SKYSAFARI_PORT
80 };
81
82 // Active Devices
83 ITextVectorProperty ActiveDeviceTP;
84 IText ActiveDeviceT[1] {};
85 enum
86 {
87 ACTIVE_TELESCOPE
88 };
89
90 // Server Control
91 ISwitchVectorProperty ServerControlSP;
92 ISwitch ServerControlS[2];
93 enum
94 {
95 SERVER_ENABLE,
96 SERVER_DISABLE
97 };
98
99 // Our client
100 std::unique_ptr<SkySafariClient> skySafariClient;
101
102 int lsocket = -1, clientFD = -1;
103
104 bool isSkySafariConnected = false, haveLatitude = false, haveLongitude = false;
105 bool haveUTCoffset = false, haveUTCtime = false, haveUTCdate = false;
106
107 double siteLatitude = 0, siteLongitude = 0;
108 double RA = 0, DE = 0;
109 double timeUTCOffset = 0;
110 int timeYear = 0, timeMonth = 0, timeDay = 0, timeHour = 0, timeMin = 0, timeSec = 0;
111};
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:82
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:63
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual const char * getDefaultName() override
Definition skysafari.cpp:58
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:77
ISState
Switch state.
Definition indiapi.h:148
uint8_t cmd[4]
Definition pwc-ioctl.h:2
One switch descriptor.
One text descriptor.
Switch vector property descriptor.
Definition indiapi.h:365
Text vector property descriptor.
Definition indiapi.h:244