Instrument Neutral Distributed Interface INDI  1.1.0
inditelescope.h
1 /*******************************************************************************
2  Copyright(c) 2011 Gerry Rozema, 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 #ifndef INDI_TELESCOPE_H
20 #define INDI_TELESCOPE_H
21 
22 #include <libnova.h>
23 
24 #include "defaultdevice.h"
25 #include "indicontroller.h"
26 
49 {
50  public:
51 
52  enum TelescopeStatus { SCOPE_IDLE, SCOPE_SLEWING, SCOPE_TRACKING, SCOPE_PARKING, SCOPE_PARKED };
53  enum TelescopeMotionCommand { MOTION_START, MOTION_STOP };
54  enum TelescopeSlewRate { SLEW_GUIDE, SLEW_CENTERING, SLEW_FIND, SLEW_MAX };
55  enum TelescopeTrackMode { TRACK_SIDEREAL, TRACK_SOLAR, TRACK_LUNAR, TRACK_CUSTOM };
56  enum TelescopeParkData { PARK_NONE, PARK_RA_DEC, PARK_AZ_ALT, PARK_RA_DEC_ENCODER, PARK_AZ_ALT_ENCODER };
57  enum TelescopeLocation { LOCATION_LATITUDE, LOCATION_LONGITUDE, LOCATION_ELEVATION };
58 
62  typedef struct
63  {
65  bool canSync;
67  bool canPark;
69  bool canAbort;
71  bool hasTime;
75  int nSlewRate;
77 
78  Telescope();
79  virtual ~Telescope();
80 
81  virtual bool ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n);
82  virtual bool ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n);
83  virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n);
84  virtual void ISGetProperties (const char *dev);
85  virtual bool ISSnoopDevice(XMLEle *root);
86 
90  TelescopeCapability GetTelescopeCapability() const { return capability;}
91 
96  void SetTelescopeCapability(TelescopeCapability * cap);
97 
99  virtual bool initProperties();
101  virtual bool updateProperties();
102 
104  virtual void TimerHit();
105 
109  virtual bool Connect();
110 
113  virtual bool Disconnect();
114 
122  virtual bool Connect(const char *port, uint16_t baud);
123 
124 
125  //Park
130  void SetParkDataType(TelescopeParkData type);
131 
140  bool InitPark();
141 
146  bool isParked();
147 
152  void SetParked(bool isparked);
153 
157  double GetAxis1Park();
158 
162  double GetAxis1ParkDefault();
163 
167  double GetAxis2Park();
168 
172  double GetAxis2ParkDefault();
173 
178  void SetAxis1Park(double value);
179 
184  void SetAxis1ParkDefault(double steps);
185 
190  void SetAxis2Park(double steps);
191 
196  void SetAxis2ParkDefault(double steps);
197 
198  // Joystick helpers
199  static void joystickHelper(const char * joystick_n, double mag, double angle, void *context);
200  static void buttonHelper(const char * button_n, ISState state, void *context);
201 
202  protected:
203 
204  virtual bool saveConfigItems(FILE *fp);
205 
207  void NewRaDec(double ra,double dec);
208 
218  virtual bool ReadScopeStatus()=0;
219 
224  virtual bool Goto(double ra,double dec)=0;
225 
230  virtual bool Sync(double ra,double dec);
231 
238  virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command);
239 
246  virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command);
247 
252  virtual bool Park();
253 
258  virtual bool UnPark();
259 
264  virtual bool Abort()=0;
265 
272  virtual bool updateTime(ln_date *utc, double utc_offset);
273 
281  virtual bool updateLocation(double latitude, double longitude, double elevation);
282 
287  virtual void SetCurrentPark();
288 
293  virtual void SetDefaultPark();
294 
303  virtual bool SetSlewRate(int index);
304 
305  // Joystick
306  void processNSWE(double mag, double angle);
307  void processJoystick(const char * joystick_n, double mag, double angle);
308  void processSlewPresets(double mag, double angle);
309  void processButton(const char * button_n, ISState state);
310 
311  // Since every mount I know of actually uses a serial port for control
312  // We put the serial helper into the base telescope class
313  // One less piece to worry about in the hardware specific
314  // low level stuff
315  int PortFD;
316 
317  // This is a variable filled in by the ReadStatus telescope
318  // low level code, used to report current state
319  // are we slewing, tracking, or parked.
320  TelescopeStatus TrackState;
321 
322  // All telescopes should produce equatorial co-ordinates
324  INumber EqN[2];
325 
326  // Abort motion
327  ISwitchVectorProperty AbortSP;
328  ISwitch AbortS[1];
329 
330  // On a coord_set message, sync, or slew
331  ISwitchVectorProperty CoordSP;
332  ISwitch CoordS[3];
333 
334  // A number vector that stores lattitude and longitude
335  INumberVectorProperty LocationNP;
336  INumber LocationN[3];
337 
338  // A Switch in the client interface to park the scope
339  ISwitchVectorProperty ParkSP;
340  ISwitch ParkS[2];
341 
342  // Custom parking position
343  INumber ParkPositionN[2];
344  INumberVectorProperty ParkPositionNP;
345 
346  // Custom parking options
347  ISwitch ParkOptionS[3];
348  ISwitchVectorProperty ParkOptionSP;
349 
350  // Device physical port
351  ITextVectorProperty PortTP;
352  IText PortT[1];
353 
354  // A switch for North/South motion
355  ISwitch MovementNSS[2];
356  ISwitchVectorProperty MovementNSSP;
357 
358  // A switch for West/East motion
359  ISwitch MovementWES[2];
360  ISwitchVectorProperty MovementWESP;
361 
362  // Slew Rate
363  ISwitchVectorProperty SlewRateSP;
364  ISwitch *SlewRateS;
365 
366  // Telescope & guider aperture and focal length
367  INumber ScopeParametersN[4];
368  INumberVectorProperty ScopeParametersNP;
369 
370  // UTC and UTC Offset
371  IText TimeT[2];
372  ITextVectorProperty TimeTP;
373 
374  // Active devices to snoop
375  ITextVectorProperty ActiveDeviceTP;
376  IText ActiveDeviceT[1];
377 
378  ISwitch BaudRateS[6];
379  ISwitchVectorProperty BaudRateSP;
380 
381  TelescopeCapability capability;
382  int last_we_motion, last_ns_motion;
383 
384  //Park
385  char *LoadParkData();
386  bool WriteParkData();
387 
388 private:
389 
390  bool processTimeInfo(const char *utc, const char *offset);
391  bool processLocationInfo(double latitude, double longitude, double elevation);
392 
393  TelescopeParkData parkDataType;
394  bool IsParked;
395  const char *ParkDeviceName;
396  const char * Parkdatafile;
397  XMLEle *ParkdataXmlRoot, *ParkdeviceXml, *ParkstatusXml, *ParkpositionXml, *ParkpositionAxis1Xml, *ParkpositionAxis2Xml;
398 
399  double Axis1ParkPosition;
400  double Axis1DefaultParkPosition;
401  double Axis2ParkPosition;
402  double Axis2DefaultParkPosition;
403 
404  IPState lastEqState;
405 
406  INDI::Controller *controller;
407 
408 };
409 
410 #endif // INDI::Telescope_H
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command)
Move the telescope in the direction dir.
virtual void SetDefaultPark()
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
Definition: defaultdevice.h:93
void NewRaDec(double ra, double dec)
The child class calls this function when it has updates.
IPState
Property state.
Definition: indiapi.h:129
void SetParkDataType(TelescopeParkData type)
setParkDataType Sets the type of parking data stored in the park data file and presented to the user...
virtual bool Goto(double ra, double dec)=0
Move the scope to the supplied RA and DEC coordinates.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
Class to provide general functionality of a telescope device.
Definition: inditelescope.h:48
One number descriptor.
Definition: indiapi.h:238
virtual void TimerHit()
Called when setTimer() time is up.
The Controller class provides functionality to access a controller (e.g. joystick) input and send it ...
void SetAxis2ParkDefault(double steps)
SetDEParkDefault Set default DEC/ALT parking position.
virtual bool SetSlewRate(int index)
SetSlewRate Set desired slew rate index.
virtual bool updateTime(ln_date *utc, double utc_offset)
Update telescope time, date, and UTC offset.
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
double GetAxis2ParkDefault()
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minumum set of properties are defined t...
virtual bool Sync(double ra, double dec)
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
Switch vector property descriptor.
Definition: indiapi.h:305
bool isParked()
isParked is mount currently parked?
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
One switch descriptor.
Definition: indiapi.h:294
virtual bool updateProperties()
Called when connected state changes, to add/remove properties.
void SetAxis2Park(double steps)
SetDEPark Set current DEC/ALT parking position. The data park file (stored in ~/.indi/ParkData.xml) is updated in the process.
double GetAxis1ParkDefault()
virtual bool initProperties()
Called to initialize basic properties required all the time.
Holds the capabilities of a telescope.
Definition: inditelescope.h:62
Number vector property descriptor.
Definition: indiapi.h:266
One text descriptor.
Definition: indiapi.h:192
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command)
Start or Stop the telescope motion in the direction dir.
void SetAxis1Park(double value)
SetRAPark Set current RA/AZ parking position. The data park file (stored in ~/.indi/ParkData.xml) is updated in the process.
virtual bool Abort()=0
Abort telescope motion.
TelescopeCapability GetTelescopeCapability() const
GetTelescopeCapability returns the capability of the Telescope.
Definition: inditelescope.h:90
virtual bool Disconnect()
Disconnect from telescope.
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
void SetAxis1ParkDefault(double steps)
SetRAPark Set default RA/AZ parking position.
void SetTelescopeCapability(TelescopeCapability *cap)
SetTelescopeCapability sets the Telescope capabilities. All capabilities must be initialized.
virtual bool Park()
Park the telescope to its home position.
ISState
Switch state.
Definition: indiapi.h:120
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
virtual bool ReadScopeStatus()=0
Read telescope status. This function checks the following:
void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData.xml) is updated in the process.
virtual bool UnPark()
Unpark the telescope if already parked.
virtual bool Connect()
Connect to the telescope.
virtual bool updateLocation(double latitude, double longitude, double elevation)
Update telescope location settings.
Text vector property descriptor.
Definition: indiapi.h:210
virtual void SetCurrentPark()
SetCurrentPark Set current coordinates/encoders value as the desired parking position.