Instrument Neutral Distributed Interface INDI  1.4.1
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 <string>
23 
24 #include <libnova.h>
25 
26 #include "defaultdevice.h"
27 #include "indicontroller.h"
28 
51 {
52  public:
53 
54  enum TelescopeStatus { SCOPE_IDLE, SCOPE_SLEWING, SCOPE_TRACKING, SCOPE_PARKING, SCOPE_PARKED };
55  enum TelescopeMotionCommand { MOTION_START, MOTION_STOP };
56  enum TelescopeSlewRate { SLEW_GUIDE, SLEW_CENTERING, SLEW_FIND, SLEW_MAX };
57  enum TelescopeTrackMode { TRACK_SIDEREAL, TRACK_SOLAR, TRACK_LUNAR, TRACK_CUSTOM };
58  enum TelescopeParkData { PARK_NONE, PARK_RA_DEC, PARK_AZ_ALT, PARK_RA_DEC_ENCODER, PARK_AZ_ALT_ENCODER };
59  enum TelescopeLocation { LOCATION_LATITUDE, LOCATION_LONGITUDE, LOCATION_ELEVATION };
60 
64  enum
65  {
66  TELESCOPE_CAN_SYNC = 1 << 0,
67  TELESCOPE_CAN_PARK = 1 << 1,
69  TELESCOPE_HAS_TIME = 1 << 3,
72 
73  Telescope();
74  virtual ~Telescope();
75 
76  virtual bool ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n);
77  virtual bool ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n);
78  virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n);
79  virtual void ISGetProperties (const char *dev);
80  virtual bool ISSnoopDevice(XMLEle *root);
81 
85  uint32_t GetTelescopeCapability() const { return capability;}
86 
93  void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount=0);
94 
98  bool CanSync() { return capability & TELESCOPE_CAN_SYNC; }
99 
103  bool CanAbort() { return capability & TELESCOPE_CAN_ABORT; }
104 
108  bool CanPark() { return capability & TELESCOPE_CAN_PARK; }
109 
113  bool HasTime() { return capability & TELESCOPE_HAS_TIME;}
114 
118  bool HasLocation() { return capability & TELESCOPE_HAS_LOCATION; }
119 
121  virtual bool initProperties();
123  virtual bool updateProperties();
124 
126  virtual void TimerHit();
127 
131  virtual bool Connect();
132 
135  virtual bool Disconnect();
136 
144  virtual bool Connect(const char *port, uint32_t baud);
145 
152  virtual bool Connect(const char *hostname, const char *port);
153 
154  //Park
159  void SetParkDataType(TelescopeParkData type);
160 
169  bool InitPark();
170 
175  bool isParked();
176 
181  void SetParked(bool isparked);
182 
186  double GetAxis1Park();
187 
191  double GetAxis1ParkDefault();
192 
196  double GetAxis2Park();
197 
201  double GetAxis2ParkDefault();
202 
207  void SetAxis1Park(double value);
208 
213  void SetAxis1ParkDefault(double steps);
214 
219  void SetAxis2Park(double steps);
220 
225  void SetAxis2ParkDefault(double steps);
226 
231  bool isLocked();
232 
233  // Joystick helpers
234  static void joystickHelper(const char * joystick_n, double mag, double angle, void *context);
235  static void buttonHelper(const char * button_n, ISState state, void *context);
236 
237  protected:
238 
239  virtual bool saveConfigItems(FILE *fp);
240 
242  void NewRaDec(double ra,double dec);
243 
253  virtual bool ReadScopeStatus()=0;
254 
259  virtual bool Goto(double ra,double dec)=0;
260 
265  virtual bool Sync(double ra,double dec);
266 
273  virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command);
274 
281  virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command);
282 
287  virtual bool Park();
288 
293  virtual bool UnPark();
294 
299  virtual bool Abort()=0;
300 
307  virtual bool updateTime(ln_date *utc, double utc_offset);
308 
316  virtual bool updateLocation(double latitude, double longitude, double elevation);
317 
322  virtual void SetCurrentPark();
323 
328  virtual void SetDefaultPark();
329 
338  virtual bool SetSlewRate(int index);
339 
340  // Joystick
341  void processNSWE(double mag, double angle);
342  void processJoystick(const char * joystick_n, double mag, double angle);
343  void processSlewPresets(double mag, double angle);
344  void processButton(const char * button_n, ISState state);
345 
346  // Since every mount I know of actually uses a serial port for control
347  // We put the serial helper into the base telescope class
348  // One less piece to worry about in the hardware specific
349  // low level stuff
350  // Mounts with ethernet can copy the socket fd into PortFD and override Connect and Disconnect.
351  int PortFD;
352 
353  // This is a variable filled in by the ReadStatus telescope
354  // low level code, used to report current state
355  // are we slewing, tracking, or parked.
356  TelescopeStatus TrackState;
357 
358  // All telescopes should produce equatorial co-ordinates
360  INumber EqN[2];
361 
362  // When a goto is issued, domes will snoop the target property
363  // to start moving the dome when a telescope moves
364  INumberVectorProperty TargetNP;
365  INumber TargetN[2];
366 
367  // Abort motion
368  ISwitchVectorProperty AbortSP;
369  ISwitch AbortS[1];
370 
371  // On a coord_set message, sync, or slew
372  ISwitchVectorProperty CoordSP;
373  ISwitch CoordS[3];
374 
375  // A number vector that stores lattitude and longitude
376  INumberVectorProperty LocationNP;
377  INumber LocationN[3];
378 
379  // A Switch in the client interface to park the scope
380  ISwitchVectorProperty ParkSP;
381  ISwitch ParkS[2];
382 
383  // Custom parking position
384  INumber ParkPositionN[2];
385  INumberVectorProperty ParkPositionNP;
386 
387  // Custom parking options
388  ISwitch ParkOptionS[3];
389  ISwitchVectorProperty ParkOptionSP;
390 
391  // Device physical port
392  ITextVectorProperty PortTP;
393  IText PortT[1];
394 
395  // A switch for North/South motion
396  ISwitch MovementNSS[2];
397  ISwitchVectorProperty MovementNSSP;
398 
399  // A switch for West/East motion
400  ISwitch MovementWES[2];
401  ISwitchVectorProperty MovementWESP;
402 
403  // Slew Rate
404  ISwitchVectorProperty SlewRateSP;
405  ISwitch *SlewRateS;
406 
407  // Telescope & guider aperture and focal length
408  INumber ScopeParametersN[4];
409  INumberVectorProperty ScopeParametersNP;
410 
411  // UTC and UTC Offset
412  IText TimeT[2];
413  ITextVectorProperty TimeTP;
414 
415  // Active GPS/Dome device to snoop
416  ITextVectorProperty ActiveDeviceTP;
417  IText ActiveDeviceT[2];
418 
419  // Switch to lock if dome is closed, and or force parking if dome parks
420  ISwitchVectorProperty DomeClosedLockTP;
421  ISwitch DomeClosedLockT[4];
422 
423  // IP Address/Port
424  ITextVectorProperty AddressTP;
425  IText AddressT[2];
426 
427  ISwitch BaudRateS[6];
428  ISwitchVectorProperty BaudRateSP;
429 
430  // Lock Joystick Axis to one direciton only
431  ISwitch LockAxisS[2];
432  ISwitchVectorProperty LockAxisSP;
433 
434  uint32_t capability;
435  int last_we_motion, last_ns_motion;
436 
437  // Period in milliseconds to call ReadScopeStatus(). 1000 milliseconds by default
438  uint32_t updatePeriodMS = 1000;
439 
440  //Park
441  char *LoadParkData();
442  bool WriteParkData();
443 
444 private:
445 
446  bool processTimeInfo(const char *utc, const char *offset);
447  bool processLocationInfo(double latitude, double longitude, double elevation);
448 
449  void triggerSnoop(const char *driverName, const char *propertyName);
450 
451  TelescopeParkData parkDataType;
452  bool IsLocked;
453  bool IsParked;
454  const char *ParkDeviceName;
455  const char * Parkdatafile;
456  XMLEle *ParkdataXmlRoot, *ParkdeviceXml, *ParkstatusXml, *ParkpositionXml, *ParkpositionAxis1Xml, *ParkpositionAxis2Xml;
457 
458  double Axis1ParkPosition;
459  double Axis1DefaultParkPosition;
460  double Axis2ParkPosition;
461  double Axis2DefaultParkPosition;
462 
463  uint8_t nSlewRate;
464 
465  IPState lastEqState;
466 
467  INDI::Controller *controller;
468 
469  int sockfd = -1;
470  const uint8_t SOCKET_TIMEOUT = 5;
471 
472 };
473 
474 #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:128
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:50
One number descriptor.
Definition: indiapi.h:237
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:85
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 minimum 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.
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Switch vector property descriptor.
Definition: indiapi.h:304
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:293
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:265
One text descriptor.
Definition: indiapi.h:191
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:119
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:209
bool isLocked()
isLocked is mount currently locked?
virtual void SetCurrentPark()
SetCurrentPark Set current coordinates/encoders value as the desired parking position.