Instrument Neutral Distributed Interface INDI 2.2.5
snapcap.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2017-2024 Jarno Paananen. All right reserved.
3
4 Driver for SnapCap dust cap / flat panel
5
6 based on Flip Flat driver by:
7
8 Copyright(c) 2015 Jasem Mutlaq. All rights reserved.
9
10 This program is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2 of the License, or (at your option)
13 any later version.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 more details.
19
20 You should have received a copy of the GNU Library General Public License
21 along with this library; see the file COPYING.LIB. If not, write to
22 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA.
24
25 The full GNU General Public License is included in this distribution in the
26 file called LICENSE.
27*******************************************************************************/
28
29#pragma once
30
31#include "defaultdevice.h"
34
35namespace Connection
36{
37class Serial;
38class TCP;
39}
40
42{
43 public:
44 SnapCap();
45 virtual ~SnapCap();
46
47 virtual bool initProperties() override;
48 virtual void ISGetProperties(const char *dev) override;
49 virtual bool updateProperties() override;
50
51 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
52 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
53 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
54 virtual bool ISSnoopDevice(XMLEle *root) override;
55
59 enum
60 {
61 CONNECTION_NONE = 1 << 0,
63 CONNECTION_TCP = 1 << 2
65
71 void setDustcapConnection(const uint8_t &value);
72
76 uint8_t getDustcapConnection() const;
77
78 protected:
79 const char *getDefaultName() override;
80
81 virtual bool saveConfigItems(FILE *fp) override;
82 void TimerHit() override;
83
84 // From Dust Cap
85 virtual IPState ParkCap() override;
86 virtual IPState UnParkCap() override;
87 virtual IPState AbortCap() override;
88
89 // From Light Box
90 virtual bool SetLightBoxBrightness(uint16_t value) override;
91 virtual bool EnableLightBox(bool enable) override;
92
93 private:
94 bool getStartupData();
95 bool ping();
96 bool getStatus();
97 bool getFirmwareVersion();
98 bool getBrightness();
99
100 bool Handshake();
101
102 bool sendCommand(const char *command, char *response);
103
104 // Status
105 INDI::PropertyText StatusTP{3};
106
107 // Firmware version
108 INDI::PropertyText FirmwareTP{1};
109
110 // Force open & close
111 INDI::PropertySwitch ForceSP{2};
112
113 int PortFD{ -1 };
114 bool hasLight{ true };
115 uint8_t simulationWorkCounter{ 0 };
116 uint8_t targetCoverStatus{ 0xFF };
117 uint8_t prevCoverStatus{ 0xFF };
118 uint8_t prevLightStatus{ 0xFF };
119 uint8_t prevMotorStatus{ 0xFF };
120 uint8_t prevBrightness{ 0xFF };
121
122 Connection::Serial *serialConnection = nullptr;
123 Connection::TCP *tcpConnection = nullptr;
124
125 private:
126 bool callHandshake();
127 uint8_t dustcapConnection = CONNECTION_SERIAL | CONNECTION_TCP;
128};
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
The TCP class manages connection with devices over the network via TCP/IP. Upon successful connection...
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
virtual ~SnapCap()
Definition snapcap.cpp:51
virtual IPState UnParkCap() override
unPark dust cap (open cover). Must be implemented by child.
Definition snapcap.cpp:328
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
Definition snapcap.cpp:58
virtual IPState AbortCap() override
Abort motion. Must be implemented by child.
Definition snapcap.cpp:358
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Definition snapcap.cpp:233
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...
Definition snapcap.cpp:113
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition snapcap.cpp:190
void setDustcapConnection(const uint8_t &value)
setDustcapConnection Set Dustcap connection mode. Child class should call this in the constructor bef...
Definition snapcap.cpp:668
virtual bool SetLightBoxBrightness(uint16_t value) override
setBrightness Set light level. Must be implemented in the child class, if supported.
Definition snapcap.cpp:627
virtual IPState ParkCap() override
Park dust cap (close cover). Must be implemented by child.
Definition snapcap.cpp:298
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition snapcap.cpp:586
@ CONNECTION_TCP
Definition snapcap.h:63
@ CONNECTION_SERIAL
Definition snapcap.h:62
@ CONNECTION_NONE
Definition snapcap.h:61
virtual bool EnableLightBox(bool enable) override
EnableLightBox Turn on/off on a light box. Must be implemented in the child class.
Definition snapcap.cpp:381
SnapCap()
Definition snapcap.cpp:46
uint8_t getDustcapConnection() const
Definition snapcap.cpp:663
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition snapcap.cpp:212
enum SnapCap::@70 DustcapConnection
const char * getDefaultName() override
Definition snapcap.cpp:153
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition snapcap.cpp:121
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition snapcap.cpp:201
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition snapcap.cpp:240
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition arduino_st4.h:34