Instrument Neutral Distributed Interface INDI  2.0.2
inditelescope.h
Go to the documentation of this file.
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 #pragma once
20 
21 #include "defaultdevice.h"
22 #include "libastro.h"
23 #include "indipropertyswitch.h"
24 #include <libnova/julian_day.h>
25 
26 #include <string>
27 
68 namespace INDI
69 {
70 
71 class Telescope : public DefaultDevice
72 {
73  public:
75  {
81  };
83  {
86  };
88  {
92  SLEW_MAX
93  };
95  {
100  };
102  {
106  };
108  {
115  };
117  {
121  };
123  {
126  PIER_EAST = 1
127  };
128 
130  {
132  PEC_OFF = 0,
133  PEC_ON = 1
134  };
135 
138  {
141  };
142 
147  enum
148  {
149  CONNECTION_NONE = 1 << 0,
150  CONNECTION_SERIAL = 1 << 1,
151  CONNECTION_TCP = 1 << 2
153 
158  enum
159  {
167  TELESCOPE_HAS_PEC = 1 << 7,
173  TELESCOPE_CAN_FLIP = 1 << 13,
175 
176  Telescope();
177  virtual ~Telescope();
178 
179  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
180  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
181  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
182  virtual void ISGetProperties(const char *dev) override;
183  virtual bool ISSnoopDevice(XMLEle *root) override;
184 
188  uint32_t GetTelescopeCapability() const
189  {
190  return capability;
191  }
192 
201  void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount);
202 
206  bool CanGOTO()
207  {
209  }
210 
214  bool CanSync()
215  {
217  }
218 
222  bool CanFlip()
223  {
225  }
226 
230  bool CanAbort()
231  {
233  }
234 
238  bool CanPark()
239  {
241  }
242 
247  {
249  }
250 
254  bool HasTime()
255  {
257  }
258 
262  bool HasLocation()
263  {
265  }
266 
270  bool HasPierSide()
271  {
273  }
274 
279  {
281  }
286  {
288  }
292  bool HasPECState()
293  {
294  return capability & TELESCOPE_HAS_PEC;
295  }
296 
301  {
303  }
304 
309  {
311  }
312 
314  virtual bool initProperties() override;
316  virtual bool updateProperties() override;
317 
319  virtual bool Handshake();
320 
322  virtual void TimerHit() override;
323 
331 
340  bool InitPark();
341 
346  bool isParked();
347 
353  virtual void SetParked(bool isparked);
354 
358  double GetAxis1Park() const;
359 
363  double GetAxis1ParkDefault() const;
364 
368  double GetAxis2Park() const;
369 
373  double GetAxis2ParkDefault() const;
374 
381  void SetAxis1Park(double value);
382 
388  void SetAxis1ParkDefault(double steps);
389 
396  void SetAxis2Park(double steps);
397 
403  void SetAxis2ParkDefault(double steps);
404 
409  bool isLocked() const;
410 
411  // Joystick helpers
412  static void joystickHelper(const char *joystick_n, double mag, double angle, void *context);
413  static void axisHelper(const char *axis_n, double value, void *context);
414  static void buttonHelper(const char *button_n, ISState state, void *context);
415 
421  void setTelescopeConnection(const uint8_t &value);
422 
426  uint8_t getTelescopeConnection() const;
427 
428  void setPierSide(TelescopePierSide side);
430  {
431  return currentPierSide;
432  }
433 
434  void setPECState(TelescopePECState state);
436  {
437  return currentPECState;
438  }
439 
440  protected:
441  virtual bool saveConfigItems(FILE *fp) override;
442 
444  void NewRaDec(double ra, double dec);
445 
459  virtual bool ReadScopeStatus() = 0;
460 
467  virtual bool Flip(double ra, double dec);
468 
475  virtual bool Goto(double ra, double dec);
476 
483  virtual bool Sync(double ra, double dec);
484 
493  virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command);
494 
503  virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command);
504 
511  virtual bool Park();
512 
519  virtual bool UnPark();
520 
527  virtual bool Abort();
528 
536  virtual bool SetTrackMode(uint8_t mode);
537 
546  virtual bool SetTrackRate(double raRate, double deRate);
547 
556  virtual int AddTrackMode(const char *name, const char *label, bool isDefault = false);
557 
566  virtual bool SetTrackEnabled(bool enabled);
567 
576  virtual bool updateTime(ln_date *utc, double utc_offset);
577 
587  virtual bool updateLocation(double latitude, double longitude, double elevation);
588 
598  void updateObserverLocation(double latitude, double longitude, double elevation);
599 
609  virtual bool SetParkPosition(double Axis1Value, double Axis2Value);
610 
617  virtual bool SetCurrentPark();
618 
625  virtual bool SetDefaultPark();
626 
627 
632  virtual void SyncParkStatus(bool isparked);
633 
643  virtual bool SetSlewRate(int index);
644 
650  bool callHandshake();
651 
652  // Joystick
653  void processNSWE(double mag, double angle);
654  void processJoystick(const char *joystick_n, double mag, double angle);
655  void processAxis(const char *axis_n, double value);
656  void processSlewPresets(double mag, double angle);
657  void processButton(const char *button_n, ISState state);
658 
664 
665  // Geographic Location
667 
672  bool LoadScopeConfig();
673 
678  bool HasDefaultScopeConfig();
679 
683  bool UpdateScopeConfig();
684 
690  std::string GetHomeDirectory() const;
691 
696  int GetScopeConfigIndex() const;
697 
704  bool CheckFile(const std::string &file_name, bool writable) const;
705 
712 
717 
718  // All telescopes should produce equatorial co-ordinates
721 
722  // When a goto is issued, domes will snoop the target property
723  // to start moving the dome when a telescope moves
726 
727  // Abort motion
730 
731  // On a coord_set message, sync, or slew
734 
735  // A number vector that stores lattitude and longitude
738 
739  // A Switch in the client interface to park the scope
742 
743  // Custom parking position
746 
747  // Custom parking options
750  enum
751  {
756  };
757 
758  // A switch for North/South motion
761 
762  // A switch for West/East motion
765 
766  // Reverse NS or WE
768  enum
769  {
771  REVERSE_WE
772  };
773 
774  // Slew Rate
776  ISwitch *SlewRateS {nullptr};
777 
778  // Telescope & guider aperture and focal length
781 
782  // UTC and UTC Offset
783  IText TimeT[2] {};
785  void sendTimeFromSystem();
786 
787  // Active GPS/Dome device to snoop
790 
791  // Switch to lock if dome is closed.
794 
795  // Switch for choosing between motion control by 4-way joystick or two seperate axes
798  enum
799  {
802  };
803 
804  // Lock Joystick Axis to one direciton only
807 
808  // Pier Side
811 
812  // Pier Side Simulation
815  bool getSimulatePierSide() const;
816  void setSimulatePierSide(bool value);
817 
818  // Pier Side
820 
821  const char * getPierSideStr(TelescopePierSide ps);
822 
823  // Satellite tracking
834  enum
835  {
850  enum
851  {
862 
863  // PEC State
866 
867  // Track Mode
869  ISwitch *TrackModeS { nullptr };
870 
871  // Track State
874 
875  // Track Rate
878 
879  // PEC State
881 
882  uint32_t capability {0};
884 
885  //Park
886  const char *LoadParkData();
887  bool WriteParkData();
888  bool PurgeParkData();
889 
890  int PortFD = -1;
893 
894  // XML node names for scope config
895  const std::string ScopeConfigRootXmlNode { "scopeconfig" };
896  const std::string ScopeConfigDeviceXmlNode { "device" };
897  const std::string ScopeConfigNameXmlNode { "name" };
898  const std::string ScopeConfigScopeFocXmlNode { "scopefoc" };
899  const std::string ScopeConfigScopeApXmlNode { "scopeap" };
900  const std::string ScopeConfigGScopeFocXmlNode { "gscopefoc" };
901  const std::string ScopeConfigGScopeApXmlNode { "gscopeap" };
902  const std::string ScopeConfigLabelApXmlNode { "label" };
903 
904  // A switch to apply custom aperture/focal length config
905  enum
906  {
913  };
916 
917  // Scope config name
920 
922  const std::string ScopeConfigFileName;
923 
924  bool IsParked {false};
926 
927  private:
928  bool processTimeInfo(const char *utc, const char *offset);
929  bool processLocationInfo(double latitude, double longitude, double elevation);
930  void triggerSnoop(const char *driverName, const char *propertyName);
931 
936  const char *LoadParkXML();
937 
938  bool IsLocked {true};
939  const char *ParkDeviceName {nullptr};
940  const std::string ParkDataFileName;
941  XMLEle *ParkdataXmlRoot {nullptr}, *ParkdeviceXml {nullptr}, *ParkstatusXml {nullptr}, *ParkpositionXml {nullptr},
942  *ParkpositionAxis1Xml {nullptr}, *ParkpositionAxis2Xml {nullptr};
943 
944  double Axis1ParkPosition {0};
945  double Axis1DefaultParkPosition {0};
946  double Axis2ParkPosition {0};
947  double Axis2DefaultParkPosition {0};
948 
949  uint8_t nSlewRate {0};
950  IPState lastEqState { IPS_IDLE };
951 
952  uint8_t telescopeConnection = (CONNECTION_SERIAL | CONNECTION_TCP);
953 
954  Controller *controller {nullptr};
955 
956  float motionDirNSValue {0};
957  float motionDirWEValue {0};
958 
959  bool m_simulatePierSide; // use setSimulatePierSide and getSimulatePierSide for public access
960 
961  // 100 millisecond of arc or time.
962  static constexpr double EQ_NOTIFY_THRESHOLD {1.0 / (60 * 60 * 10)};
963 };
964 
965 }
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 successfull connectio...
Definition: connectiontcp.h:38
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
bool CanControlTrack()
const std::string ScopeConfigGScopeFocXmlNode
INumberVectorProperty TrackRateNP
TelescopeStatus TrackState
bool isLocked() const
isLocked is mount currently locked?
ISwitchVectorProperty SimulatePierSideSP
virtual bool SetTrackMode(uint8_t mode)
SetTrackMode Set active tracking mode. Do not change track state.
ISwitchVectorProperty TrackStateSP
ISwitchVectorProperty ParkOptionSP
void SetAxis1Park(double value)
SetRAPark Set current RA/AZ parking position. The data park file (stored in ~/.indi/ParkData....
ISwitchVectorProperty DomePolicySP
bool HasPierSideSimulation()
TelescopePierSide currentPierSide
IText ActiveDeviceT[2]
virtual bool Goto(double ra, double dec)
Move the scope to the supplied RA and DEC coordinates.
enum INDI::Telescope::@258 TelescopeCapability
ISwitchVectorProperty MovementNSSP
ITextVectorProperty ScopeConfigNameTP
void processButton(const char *button_n, ISState state)
static void axisHelper(const char *axis_n, double value, void *context)
ISwitchVectorProperty AbortSP
void processAxis(const char *axis_n, double value)
bool CheckFile(const std::string &file_name, bool writable) const
Check if a file exists and it is readable.
void SetAxis1ParkDefault(double steps)
SetRAPark Set default RA/AZ parking position.
virtual bool ReadScopeStatus()=0
Read telescope status.
void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount)
SetTelescopeCapability sets the Telescope capabilities. All capabilities must be initialized.
virtual bool Park()
Park the telescope to its home position.
INumberVectorProperty LocationNP
enum INDI::Telescope::@263 SatelliteTracking
int GetScopeConfigIndex() const
Get the scope config index.
virtual bool SetCurrentPark()
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
TelescopeParkData parkDataType
INumberVectorProperty ScopeParametersNP
std::string GetHomeDirectory() const
Validate a file name.
ISwitch AbortS[1]
virtual bool initProperties() override
Called to initialize basic properties required all the time.
ITextVectorProperty ActiveDeviceTP
const std::string ScopeConfigLabelApXmlNode
bool CanTrackSatellite()
ITextVectorProperty TimeTP
IText TLEtoTrackT[1]
virtual void TimerHit() override
Called when setTimer() time is up.
INumberVectorProperty TargetNP
ISwitch MotionControlModeT[2]
@ SAT_PASS_WINDOW_COUNT
Number of indices.
@ SAT_PASS_WINDOW_END
Index for end of the window.
@ SAT_PASS_WINDOW_START
Index for start of the window.
ITextVectorProperty SatPassWindowTP
Text Vector property defining the start and end of a satellite pass (window contains pass)....
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
TelescopePierSide lastPierSide
virtual bool SetTrackRate(double raRate, double deRate)
SetTrackRate Set custom tracking rates.
double GetAxis1Park() const
virtual bool UnPark()
Unpark the telescope if already parked.
const std::string ScopeConfigDeviceXmlNode
INumberVectorProperty ParkPositionNP
virtual bool SetSlewRate(int index)
SetSlewRate Set desired slew rate index.
bool getSimulatePierSide() const
ISwitchVectorProperty CoordSP
virtual bool SetDefaultPark()
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
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...
void setTelescopeConnection(const uint8_t &value)
setTelescopeConnection Set telescope connection mode. Child class should call this in the constructor...
double GetAxis2Park() const
const std::string ScopeConfigScopeFocXmlNode
ISwitchVectorProperty ScopeConfigsSP
bool isParked()
isParked is mount currently parked?
ISwitchVectorProperty PECStateSP
void processNSWE(double mag, double angle)
virtual int AddTrackMode(const char *name, const char *label, bool isDefault=false)
AddTrackMode.
ISwitchVectorProperty TrackModeSP
ISwitch ParkOptionS[4]
INumber TargetN[2]
ISwitchVectorProperty SlewRateSP
Connection::Serial * serialConnection
@ SAT_TRACK
Track signal.
@ SAT_HALT
Halt signal (abort)
@ SAT_TRACK_COUNT
State counter.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
ISwitchVectorProperty PierSideSP
static void joystickHelper(const char *joystick_n, double mag, double angle, void *context)
void updateObserverLocation(double latitude, double longitude, double elevation)
Update location settings of the observer.
const std::string ScopeConfigFileName
The telescope/guide scope configuration file name.
double GetAxis1ParkDefault() const
virtual bool Handshake()
perform handshake with device to check communication
ISwitch MovementWES[2]
virtual bool SetTrackEnabled(bool enabled)
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
const std::string ScopeConfigRootXmlNode
virtual void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
virtual bool updateTime(ln_date *utc, double utc_offset)
Update telescope time, date, and UTC offset.
Connection::TCP * tcpConnection
INumberVectorProperty EqNP
virtual ~Telescope()
@ TELESCOPE_HAS_PIER_SIDE_SIMULATION
static void buttonHelper(const char *button_n, ISState state, void *context)
uint8_t getTelescopeConnection() const
ISwitch DomePolicyS[2]
const char * LoadParkData()
void setPECState(TelescopePECState state)
ISwitchVectorProperty TrackSatSP
Switch Vector property defining the state of the satellite tracking of the mount. Example implementat...
enum INDI::Telescope::@257 TelescopeConnection
ISwitchVectorProperty MotionControlModeTP
TelescopePierSide getPierSide()
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool updateLocation(double latitude, double longitude, double elevation)
Update telescope location settings.
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
virtual bool SetParkPosition(double Axis1Value, double Axis2Value)
SetParkPosition Set desired parking position to the supplied value. This ONLY sets the desired park p...
INumber EqN[2]
ISwitchVectorProperty ParkSP
INumber ScopeParametersN[4]
const std::string ScopeConfigNameXmlNode
ISwitch TrackSatS[SAT_TRACK_COUNT]
INDI::PropertySwitch ReverseMovementSP
const std::string ScopeConfigGScopeApXmlNode
INumber TrackRateN[2]
IGeographicCoordinates m_Location
ISwitchVectorProperty LockAxisSP
ISwitch ScopeConfigs[6]
void processJoystick(const char *joystick_n, double mag, double angle)
ISwitch LockAxisS[2]
ISwitch PierSideS[2]
IText SatPassWindowT[SAT_PASS_WINDOW_COUNT]
ISwitch PECStateS[2]
bool callHandshake()
callHandshake Helper function that sets the port file descriptor before calling the actual Handshake ...
uint32_t GetTelescopeCapability() const
GetTelescopeCapability returns the capability of the Telescope.
bool LoadScopeConfig()
Load scope settings from XML files.
ISwitch MovementNSS[2]
void NewRaDec(double ra, double dec)
The child class calls this function when it has updates.
bool UpdateScopeConfig()
Save scope settings to XML files.
INumber LocationN[3]
virtual void SyncParkStatus(bool isparked)
SyncParkStatus Update the state and switches for parking.
ISwitch * TrackModeS
void setSimulatePierSide(bool value)
void setPierSide(TelescopePierSide side)
ISwitch * SlewRateS
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
INumber ParkPositionN[2]
uint32_t capability
ISwitch ParkS[2]
enum INDI::Telescope::@262 SatelliteWindow
ISwitchVectorProperty MovementWESP
TelescopePECState getPECState()
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command)
Move the telescope in the direction dir.
TelescopeStatus RememberTrackState
RememberTrackState Remember last state of Track State to fall back to in case of errors or aborts.
virtual bool Abort()
Abort any telescope motion including tracking if possible.
double GetAxis2ParkDefault() const
TelescopePECState currentPECState
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
void SetAxis2Park(double steps)
SetDEPark Set current DEC/ALT parking position. The data park file (stored in ~/.indi/ParkData....
const std::string ScopeConfigScopeApXmlNode
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command)
Start or Stop the telescope motion in the direction dir.
ITextVectorProperty TLEtoTrackTP
Text Vector property defining the orbital elements of an artificial satellite (TLE)....
virtual bool Flip(double ra, double dec)
Move and flip the scope to the supplied RA and DEC coordinates.
bool HasDefaultScopeConfig()
Load scope settings from XML files.
ISwitch SimulatePierSideS[2]
void processSlewPresets(double mag, double angle)
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
const char * getPierSideStr(TelescopePierSide ps)
void SetParkDataType(TelescopeParkData type)
setParkDataType Sets the type of parking data stored in the park data file and presented to the user.
TelescopePECState lastPECState
ISwitch CoordS[4]
ISwitch TrackStateS[2]
TelescopePierSide expectedPierSide(double ra)
Calculate the expected pier side for scopes that do not report this property themselves.
IText ScopeConfigNameT[1]
void SetAxis2ParkDefault(double steps)
SetDEParkDefault Set default DEC/ALT parking position.
virtual bool Sync(double ra, double dec)
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
double ra
double dec
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
@ IPS_IDLE
Definition: indiapi.h:161
INDI_DIR_WE
Definition: indibasetypes.h:55
INDI_DIR_NS
Definition: indibasetypes.h:48
Namespace to encapsulate INDI client, drivers, and mediator classes.
__le16 type
Definition: pwc-ioctl.h:0
One number descriptor.
One switch descriptor.
One text descriptor.
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246