Instrument Neutral Distributed Interface INDI  1.9.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 
26 namespace INDI
27 {
28 
30 {
31 }
32 
34 {
35 }
36 
38 {
40 
42 
43  // Presets
44  IUFillNumber(&PresetN[0], "PRESET_1", "Preset 1", "%.f", 0, 360, 10, 0);
45  IUFillNumber(&PresetN[1], "PRESET_2", "Preset 2", "%.f", 0, 360, 10, 0);
46  IUFillNumber(&PresetN[2], "PRESET_3", "Preset 3", "%.f", 0, 360, 10, 0);
47  IUFillNumberVector(&PresetNP, PresetN, 3, getDeviceName(), "Presets", "", "Presets", IP_RW, 0, IPS_IDLE);
48 
49  //Preset GOTO
50  IUFillSwitch(&PresetGotoS[0], "Preset 1", "", ISS_OFF);
51  IUFillSwitch(&PresetGotoS[1], "Preset 2", "", ISS_OFF);
52  IUFillSwitch(&PresetGotoS[2], "Preset 3", "", ISS_OFF);
54  IPS_IDLE);
55 
57 
59 
60  if (rotatorConnection & CONNECTION_SERIAL)
61  {
64  {
65  return callHandshake();
66  });
68  }
69 
70  if (rotatorConnection & CONNECTION_TCP)
71  {
72  tcpConnection = new Connection::TCP(this);
74  {
75  return callHandshake();
76  });
78  }
79 
80  return true;
81 }
82 
83 void Rotator::ISGetProperties(const char *dev)
84 {
86 
87  // If connected, let's define properties.
88  //if (isConnected())
89  // RotatorInterface::updateProperties();
90 
91  return;
92 }
93 
95 {
96  // #1 Update base device properties.
98 
99  // #2 Update rotator interface properties
101 
102  if (isConnected())
103  {
106  }
107  else
108  {
111  }
112 
113  return true;
114 }
115 
116 bool Rotator::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
117 {
118  if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
119  {
120  if (!strcmp(name, PresetNP.name))
121  {
122  IUUpdateNumber(&PresetNP, values, names, n);
123  PresetNP.s = IPS_OK;
124  IDSetNumber(&PresetNP, nullptr);
125 
126  return true;
127  }
128 
129  if (strstr(name, "ROTATOR"))
130  {
131  if (RotatorInterface::processNumber(dev, name, values, names, n))
132  return true;
133  }
134  }
135 
136  return DefaultDevice::ISNewNumber(dev, name, values, names, n);
137 }
138 
139 bool Rotator::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
140 {
141  if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
142  {
143  if (!strcmp(PresetGotoSP.name, name))
144  {
145  IUUpdateSwitch(&PresetGotoSP, states, names, n);
146  int index = IUFindOnSwitchIndex(&PresetGotoSP);
147 
148  if (MoveRotator(PresetN[index].value) != IPS_ALERT)
149  {
150  // Ensure Goto Rotator is set to busy.
152  IDSetNumber(&GotoRotatorNP, nullptr);
153 
155  DEBUGF(Logger::DBG_SESSION, "Moving to Preset %d with angle %g degrees.", index + 1, PresetN[index].value);
156  IDSetSwitch(&PresetGotoSP, nullptr);
157  return true;
158  }
159 
161  IDSetSwitch(&PresetGotoSP, nullptr);
162  return false;
163  }
164 
165  if (strstr(name, "ROTATOR"))
166  {
167  if (RotatorInterface::processSwitch(dev, name, states, names, n))
168  return true;
169  }
170  }
171 
172  return DefaultDevice::ISNewSwitch(dev, name, states, names, n);
173 }
174 
175 bool Rotator::Handshake()
176 {
177  return false;
178 }
179 
180 bool Rotator::saveConfigItems(FILE *fp)
181 {
184 
187 
188  return true;
189 }
190 
191 bool Rotator::callHandshake()
192 {
193  if (rotatorConnection > 0)
194  {
197  else if (getActiveConnection() == tcpConnection)
199  }
200 
201  return Handshake();
202 }
203 
204 uint8_t Rotator::getRotatorConnection() const
205 {
206  return rotatorConnection;
207 }
208 
209 void Rotator::setRotatorConnection(const uint8_t &value)
210 {
212 
213  if (value == 0 || (mask & value) == 0)
214  {
215  DEBUGF(Logger::DBG_ERROR, "Invalid connection mode %d", value);
216  return;
217  }
218 
219  rotatorConnection = value;
220 }
221 }
INDI::RotatorInterface::saveConfigItems
bool saveConfigItems(FILE *fp)
saveConfigItems save focuser properties defined in the interface in config file
Definition: indirotatorinterface.cpp:332
INDI::Rotator::getRotatorConnection
uint8_t getRotatorConnection() const
Definition: indirotator.cpp:220
INDI::Rotator::CONNECTION_SERIAL
@ CONNECTION_SERIAL
Definition: indirotator.h:57
INDI::BaseDevice::ROTATOR_INTERFACE
@ ROTATOR_INTERFACE
Definition: basedevice.h:84
INDI::Rotator::setRotatorConnection
void setRotatorConnection(const uint8_t &value)
setRotatorConnection Set Rotator connection mode. Child class should call this in the constructor bef...
Definition: indirotator.cpp:225
Connection::TCP::getPortFD
int getPortFD() const
Definition: connectiontcp.h:120
INDI::Rotator::CONNECTION_NONE
@ CONNECTION_NONE
Definition: indirotator.h:56
INDI::Rotator::serialConnection
Connection::Serial * serialConnection
Definition: indirotator.h:95
IPS_OK
@ IPS_OK
Definition: indiapi.h:161
_INumberVectorProperty::s
IPState s
Definition: indiapi.h:332
RotatorInterface
Provides interface to implement Rotator functionality.
ISS_OFF
@ ISS_OFF
Definition: indiapi.h:150
connectiontcp.h
INDI::RotatorInterface::initProperties
void initProperties(const char *groupName)
Initilize Rotator properties. It is recommended to call this function within initProperties() of your...
Definition: indirotatorinterface.cpp:35
IPS_ALERT
@ IPS_ALERT
Definition: indiapi.h:163
Connection::Serial
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
Definition: connectionserial.h:56
INDI::Rotator::PortFD
int PortFD
Definition: indirotator.h:98
Connection::TCP
The TCP class manages connection with devices over the network via TCP/IP. Upon successfull connectio...
Definition: connectiontcp.h:55
IUFillNumber
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
Definition: indidriver.c:348
INDI::DefaultDevice::defineProperty
void defineProperty(INumberVectorProperty *property)
Definition: defaultdevice.cpp:997
INDI::RotatorInterface::updateProperties
bool updateProperties()
updateProperties Define or Delete Rotator properties based on the connection status of the base devic...
Definition: indirotatorinterface.cpp:248
MAIN_CONTROL_TAB
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
Definition: defaultdevice.cpp:34
INDI::Rotator::PresetNP
INumberVectorProperty PresetNP
Definition: indirotator.h:91
INDI::Logger::DBG_ERROR
@ DBG_ERROR
Definition: indilogger.h:192
INDI::Rotator::PresetGotoSP
ISwitchVectorProperty PresetGotoSP
Definition: indirotator.h:93
INDI::BaseDevice::getDeviceName
const char * getDeviceName() const
Definition: basedevice.cpp:799
INDI::Rotator::~Rotator
virtual ~Rotator()
Definition: indirotator.cpp:49
INDI::Logger::DBG_SESSION
@ DBG_SESSION
Definition: indilogger.h:194
INDI::Rotator::PresetN
INumber PresetN[3]
Definition: indirotator.h:90
IUSaveConfigNumber
void IUSaveConfigNumber(FILE *fp, const INumberVectorProperty *nvp)
Add a number vector property value to the configuration file.
Definition: indicom.c:1455
INDI::DefaultDevice::initProperties
virtual bool initProperties()
Initilize properties initial state and value. The child class must implement this function.
Definition: defaultdevice.cpp:917
INDI::Rotator::tcpConnection
Connection::TCP * tcpConnection
Definition: indirotator.h:96
INDI::Rotator::CONNECTION_TCP
@ CONNECTION_TCP
Definition: indirotator.h:58
INDI::Rotator::Handshake
virtual bool Handshake()
perform handshake with device to check communication
Definition: indirotator.cpp:191
INDI::Rotator::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: indirotator.cpp:53
indirotator.h
INDI::RotatorInterface::processNumber
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process Rotator number properties.
Definition: indirotatorinterface.cpp:79
INDI::RotatorInterface::MoveRotator
virtual IPState MoveRotator(double angle)=0
MoveRotator Go to specific angle.
INDI::DefaultDevice::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
Definition: defaultdevice.cpp:593
IUFillSwitchVector
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
Definition: indidriver.c:412
IUFillNumberVector
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
Definition: indidriver.c:455
IPS_BUSY
@ IPS_BUSY
Definition: indiapi.h:162
ISR_1OFMANY
@ ISR_1OFMANY
Definition: indiapi.h:172
connectionserial.h
IPS_IDLE
@ IPS_IDLE
Definition: indiapi.h:160
INDI::DefaultDevice::registerConnection
void registerConnection(Connection::Interface *newConnection)
registerConnection Add new connection plugin to the existing connection pool. The connection type sha...
Definition: defaultdevice.cpp:1107
_INumberVectorProperty::name
char name[MAXINDINAME]
Definition: indiapi.h:322
IUUpdateSwitch
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
Definition: indidriver.c:171
INDI::BaseDevice::isConnected
bool isConnected() const
Definition: basedevice.cpp:518
INDI::RotatorInterface::GotoRotatorNP
INumberVectorProperty GotoRotatorNP
Definition: indirotatorinterface.h:198
INDI::Rotator::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the reverse direction property in the configuration file
Definition: indirotator.cpp:196
INDI::Rotator::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: indirotator.cpp:110
INDI::RotatorInterface::processSwitch
bool processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process Rotator switch properties.
Definition: indirotatorinterface.cpp:153
INDI::DefaultDevice::ISGetProperties
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
Definition: defaultdevice.cpp:750
name
const char * name
Definition: indiserver.c:116
INDI::RotatorInterface::ReverseRotatorSP
ISwitchVectorProperty ReverseRotatorSP
Definition: indirotatorinterface.h:210
INDI::Rotator::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: indirotator.cpp:132
_ISwitchVectorProperty::s
IPState s
Definition: indiapi.h:382
INDI
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: AlignmentSubsystemForClients.cpp:11
Connection::Interface::registerHandshake
void registerHandshake(std::function< bool()> callback)
registerHandshake Register a handshake function to be called once the intial connection to the device...
Definition: connectioninterface.cpp:108
IUUpdateNumber
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
Definition: indidriver.c:225
DEBUGF
#define DEBUGF(priority, msg,...)
Definition: indilogger.h:57
INDI::DefaultDevice::saveConfigItems
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition: defaultdevice.cpp:175
INDI::Rotator::ISGetProperties
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: indirotator.cpp:99
IP_RW
@ IP_RW
Definition: indiapi.h:185
INDI::Rotator::Rotator
Rotator()
Definition: indirotator.cpp:45
INDI::Rotator::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: indirotator.cpp:155
ISState
ISState
Switch state.
Definition: indiapi.h:148
Connection::Serial::getPortFD
int getPortFD() const
Definition: connectionserial.h:136
INDI::DefaultDevice::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
Definition: defaultdevice.cpp:409
IUFindOnSwitchIndex
int IUFindOnSwitchIndex(const ISwitchVectorProperty *sp)
Returns the index of first ON switch it finds in the vector switch property.
Definition: indicom.c:1424
INDI::DefaultDevice::addDebugControl
void addDebugControl()
Add Debug control to the driver.
Definition: defaultdevice.cpp:639
IUSaveConfigSwitch
void IUSaveConfigSwitch(FILE *fp, const ISwitchVectorProperty *svp)
Add a switch vector property value to the configuration file.
Definition: indicom.c:1465
INDI::Rotator::PresetGotoS
ISwitch PresetGotoS[3]
Definition: indirotator.h:92
INDI::DefaultDevice::deleteProperty
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
Definition: defaultdevice.cpp:965
IDSetNumber
void void void IDSetNumber(const INumberVectorProperty *n, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing number vector property.
IDSetSwitch
void void void void void IDSetSwitch(const ISwitchVectorProperty *s, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing switch vector property.
INDI::DefaultDevice::setDriverInterface
void setDriverInterface(uint16_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
Definition: defaultdevice.cpp:902
IUFillSwitch
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
Definition: indidriver.c:320
INDI::DefaultDevice::updateProperties
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: defaultdevice.cpp:890
INDI::DefaultDevice::getActiveConnection
Connection::Interface * getActiveConnection()
Definition: defaultdevice.cpp:1245
_ISwitchVectorProperty::name
char name[MAXINDINAME]
Definition: indiapi.h:370