Instrument Neutral Distributed Interface INDI 2.2.5
indirotator.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2017 Jasem Mutlaq. All rights reserved.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*******************************************************************************/
18
19#include "indirotator.h"
20
23
24#include <cstring>
25
26namespace INDI
27{
28
32
36
38{
40
42
43 // Presets
44 PresetNP[0].fill("PRESET_1", "Preset 1", "%.f", 0, 360, 10, 0);
45 PresetNP[1].fill("PRESET_2", "Preset 2", "%.f", 0, 360, 10, 0);
46 PresetNP[2].fill("PRESET_3", "Preset 3", "%.f", 0, 360, 10, 0);
47 PresetNP.fill(getDeviceName(), "Presets", "", "Presets", IP_RW, 0, IPS_IDLE);
48
49 //Preset GOTO
50 PresetGotoSP[0].fill("Preset 1", "", ISS_OFF);
51 PresetGotoSP[1].fill("Preset 2", "", ISS_OFF);
52 PresetGotoSP[2].fill("Preset 3", "", ISS_OFF);
53 PresetGotoSP.fill(getDeviceName(), "Goto", "", "Presets", IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
54
56
58
59 if (rotatorConnection & CONNECTION_SERIAL)
60 {
63 {
64 return callHandshake();
65 });
67 }
68
69 if (rotatorConnection & CONNECTION_TCP)
70 {
73 {
74 return callHandshake();
75 });
77 }
78
79 return true;
80}
81
82void Rotator::ISGetProperties(const char *dev)
83{
85
86 // If connected, let's define properties.
87 //if (isConnected())
88 // RotatorInterface::updateProperties();
89
90 return;
91}
92
94{
95 // #1 Update base device properties.
97
98 // #2 Update rotator interface properties
100
101 if (isConnected())
102 {
105 }
106 else
107 {
110 }
111
112 return true;
113}
114
115bool Rotator::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
116{
117 if (RotatorInterface::processNumber(dev, name, values, names, n))
118 return true;
119 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
120 {
121 if (PresetNP.isNameMatch(name))
122 {
123 PresetNP.update(values, names, n);
125 PresetNP.apply();
126
127 return true;
128 }
129 }
130
131 return DefaultDevice::ISNewNumber(dev, name, values, names, n);
132}
133
134bool Rotator::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
135{
136 if (RotatorInterface::processSwitch(dev, name, states, names, n))
137 return true;
138 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
139 {
140 if (PresetGotoSP.isNameMatch(name))
141 {
142 PresetGotoSP.update(states, names, n);
143 int index = PresetGotoSP.findOnSwitchIndex();
144
145 if (MoveRotator(PresetNP[index].getValue()) != IPS_ALERT)
146 {
147 // Ensure Goto Rotator is set to busy.
150
152 DEBUGF(Logger::DBG_SESSION, "Moving to Preset %d with angle %g degrees.", index + 1, PresetNP[index].getValue());
154 return true;
155 }
156
159 return false;
160 }
161 }
162
163 return DefaultDevice::ISNewSwitch(dev, name, states, names, n);
164}
165
167{
168 return false;
169}
170
172{
175
176 PresetNP.save(fp);
178
179 return true;
180}
181
182bool Rotator::callHandshake()
183{
184 if (rotatorConnection > 0)
185 {
190 }
191
192 return Handshake();
193}
194
196{
197 return rotatorConnection;
198}
199
200void Rotator::setRotatorConnection(const uint8_t &value)
201{
203
204 if (value == 0 || (mask & value) == 0)
205 {
206 DEBUGF(Logger::DBG_ERROR, "Invalid connection mode %d", value);
207 return;
208 }
209
210 rotatorConnection = value;
211}
212}
void registerHandshake(std::function< bool()> callback)
registerHandshake Register a handshake function to be called once the initial connection to the devic...
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...
int getPortFD() const
bool isConnected() const
const char * getDeviceName() const
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
void registerConnection(Connection::Interface *newConnection)
registerConnection Add new connection plugin to the existing connection pool. The connection type sha...
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool initProperties()
Initialize properties initial state and value. The child class must implement this function.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
Connection::Interface * getActiveConnection()
void addDebugControl()
Add Debug control to the driver.
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
void save(FILE *f) const
save Save property to configuration file.
bool isNameMatch(const char *otherName) const
bool update(const double values[], const char *const names[], int n)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
bool update(const ISState states[], const char *const names[], int n)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, ISRule rule, double timeout, IPState state)
bool processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process Rotator switch properties.
virtual IPState MoveRotator(double angle)=0
MoveRotator Go to specific angle.
bool saveConfigItems(FILE *fp)
saveConfigItems save focuser properties defined in the interface in config file
void initProperties(const char *groupName)
Initialize Rotator properties. It is recommended to call this function within initProperties() of you...
bool updateProperties()
updateProperties Define or Delete Rotator properties based on the connection status of the base devic...
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process Rotator number properties.
INDI::PropertySwitch ReverseRotatorSP
INDI::PropertyNumber GotoRotatorNP
Connection::Serial * serialConnection
Definition indirotator.h:95
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool Handshake()
perform handshake with device to check communication
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
INDI::PropertyNumber PresetNP
Definition indirotator.h:92
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...
INDI::PropertySwitch PresetGotoSP
Definition indirotator.h:93
virtual ~Rotator()
uint8_t getRotatorConnection() const
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
void setRotatorConnection(const uint8_t &value)
setRotatorConnection Set Rotator connection mode. Child class should call this in the constructor bef...
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the reverse direction property in the configuration file
Connection::TCP * tcpConnection
Definition indirotator.h:96
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ IP_RW
Definition indiapi.h:184
@ IPS_BUSY
Definition indiapi.h:161
@ IPS_ALERT
Definition indiapi.h:162
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
@ ISR_1OFMANY
Definition indiapi.h:171
#define DEBUGF(priority, msg,...)
Definition indilogger.h:57
Namespace to encapsulate INDI client, drivers, and mediator classes.