Instrument Neutral Distributed Interface INDI  1.2.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  enum
63  {
64  TELESCOPE_CAN_SYNC = 1 << 0,
65  TELESCOPE_CAN_PARK = 1 << 1,
67  TELESCOPE_HAS_TIME = 1 << 3,
70 
71  Telescope();
72  virtual ~Telescope();
73 
74  virtual bool ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n);
75  virtual bool ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n);
76  virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n);
77  virtual void ISGetProperties (const char *dev);
78  virtual bool ISSnoopDevice(XMLEle *root);
79 
83  uint32_t GetTelescopeCapability() const { return capability;}
84 
91  void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount=0);
92 
96  bool CanSync() { return capability & TELESCOPE_CAN_SYNC; }
97 
101  bool CanAbort() { return capability & TELESCOPE_CAN_ABORT; }
102 
106  bool CanPark() { return capability & TELESCOPE_CAN_PARK; }
107 
111  bool HasTime() { return capability & TELESCOPE_HAS_TIME;}
112 
116  bool HasLocation() { return capability & TELESCOPE_HAS_LOCATION; }
117 
119  virtual bool initProperties();
121  virtual bool updateProperties();
122 
124  virtual void TimerHit();
125 
129  virtual bool Connect();
130 
133  virtual bool Disconnect();
134 
142  virtual bool Connect(const char *port, uint32_t baud);
143 
144 
145  //Park
150  void SetParkDataType(TelescopeParkData type);
151 
160  bool InitPark();
161 
166  bool isParked();
167 
172  void SetParked(bool isparked);
173 
177  double GetAxis1Park();
178 
182  double GetAxis1ParkDefault();
183 
187  double GetAxis2Park();
188 
192  double GetAxis2ParkDefault();
193 
198  void SetAxis1Park(double value);
199 
204  void SetAxis1ParkDefault(double steps);
205 
210  void SetAxis2Park(double steps);
211 
216  void SetAxis2ParkDefault(double steps);
217 
218  // Joystick helpers
219  static void joystickHelper(const char * joystick_n, double mag, double angle, void *context);
220  static void buttonHelper(const char * button_n, ISState state, void *context);
221 
222  protected:
223 
224  virtual bool saveConfigItems(FILE *fp);
225 
227  void NewRaDec(double ra,double dec);
228 
238  virtual bool ReadScopeStatus()=0;
239 
244  virtual bool Goto(double ra,double dec)=0;
245 
250  virtual bool Sync(double ra,double dec);
251 
258  virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command);
259 
266  virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command);
267 
272  virtual bool Park();
273 
278  virtual bool UnPark();
279 
284  virtual bool Abort()=0;
285 
292  virtual bool updateTime(ln_date *utc, double utc_offset);
293 
301  virtual bool updateLocation(double latitude, double longitude, double elevation);
302 
307  virtual void SetCurrentPark();
308 
313  virtual void SetDefaultPark();
314 
323  virtual bool SetSlewRate(int index);
324 
325  // Joystick
326  void processNSWE(double mag, double angle);
327  void processJoystick(const char * joystick_n, double mag, double angle);
328  void processSlewPresets(double mag, double angle);
329  void processButton(const char * button_n, ISState state);
330 
331  // Since every mount I know of actually uses a serial port for control
332  // We put the serial helper into the base telescope class
333  // One less piece to worry about in the hardware specific
334  // low level stuff
335  int PortFD;
336 
337  // This is a variable filled in by the ReadStatus telescope
338  // low level code, used to report current state
339  // are we slewing, tracking, or parked.
340  TelescopeStatus TrackState;
341 
342  // All telescopes should produce equatorial co-ordinates
344  INumber EqN[2];
345 
346  // When a goto is issued, domes will snoop the target property
347  // to start moving the dome when a telescope moves
348  INumberVectorProperty TargetNP;
349  INumber TargetN[2];
350 
351  // Abort motion
352  ISwitchVectorProperty AbortSP;
353  ISwitch AbortS[1];
354 
355  // On a coord_set message, sync, or slew
356  ISwitchVectorProperty CoordSP;
357  ISwitch CoordS[3];
358 
359  // A number vector that stores lattitude and longitude
360  INumberVectorProperty LocationNP;
361  INumber LocationN[3];
362 
363  // A Switch in the client interface to park the scope
364  ISwitchVectorProperty ParkSP;
365  ISwitch ParkS[2];
366 
367  // Custom parking position
368  INumber ParkPositionN[2];
369  INumberVectorProperty ParkPositionNP;
370 
371  // Custom parking options
372  ISwitch ParkOptionS[3];
373  ISwitchVectorProperty ParkOptionSP;
374 
375  // Device physical port
376  ITextVectorProperty PortTP;
377  IText PortT[1];
378 
379  // A switch for North/South motion
380  ISwitch MovementNSS[2];
381  ISwitchVectorProperty MovementNSSP;
382 
383  // A switch for West/East motion
384  ISwitch MovementWES[2];
385  ISwitchVectorProperty MovementWESP;
386 
387  // Slew Rate
388  ISwitchVectorProperty SlewRateSP;
389  ISwitch *SlewRateS;
390 
391  // Telescope & guider aperture and focal length
392  INumber ScopeParametersN[4];
393  INumberVectorProperty ScopeParametersNP;
394 
395  // UTC and UTC Offset
396  IText TimeT[2];
397  ITextVectorProperty TimeTP;
398 
399  // Active devices to snoop
400  ITextVectorProperty ActiveDeviceTP;
401  IText ActiveDeviceT[1];
402 
403  ISwitch BaudRateS[6];
404  ISwitchVectorProperty BaudRateSP;
405 
406  uint32_t capability;
407  int last_we_motion, last_ns_motion;
408 
409  //Park
410  char *LoadParkData();
411  bool WriteParkData();
412 
413 private:
414 
415  bool processTimeInfo(const char *utc, const char *offset);
416  bool processLocationInfo(double latitude, double longitude, double elevation);
417 
418  TelescopeParkData parkDataType;
419  bool IsParked;
420  const char *ParkDeviceName;
421  const char * Parkdatafile;
422  XMLEle *ParkdataXmlRoot, *ParkdeviceXml, *ParkstatusXml, *ParkpositionXml, *ParkpositionAxis1Xml, *ParkpositionAxis2Xml;
423 
424  double Axis1ParkPosition;
425  double Axis1DefaultParkPosition;
426  double Axis2ParkPosition;
427  double Axis2DefaultParkPosition;
428 
429  uint8_t nSlewRate;
430 
431  IPState lastEqState;
432 
433  INDI::Controller *controller;
434 
435 };
436 
437 #endif // INDI::Telescope_H
void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount=0)
SetTelescopeCapability sets the Telescope capabilities. All capabilities must be initialized.
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 ...
uint32_t GetTelescopeCapability() const
GetTelescopeCapability returns the capability of the Telescope.
Definition: inditelescope.h:83
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&#39;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
Holds the capabilities of a telescope.
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.
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.
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.
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.