Instrument Neutral Distributed Interface INDI  2.0.2
alignment_scope.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <inditelescope.h>
4 #include <indicom.h>
6 
7 using namespace INDI::AlignmentSubsystem;
8 
9 char _me[] = "MockAlignmentScope";
10 char *me = _me;
11 
13 {
14  public:
15  Scope(MountType mountType) : INDI::Telescope(), INDI::AlignmentSubsystem::AlignmentSubsystemForDrivers()
16  {
17  m_mountType = mountType;
18  ISGetProperties(nullptr);
19  }
20 
21  virtual const char *getDefaultName() override
22  {
23  return "MockAlignmentScope";
24  }
25 
26  // make sure to pass new values into the alignment subsytem with all the ISNew* methods
27  bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
28  {
29  if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
30  ProcessAlignmentNumberProperties(this, name, values, names, n);
31  return true;
32  }
33  bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
34  {
35  if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
36  ProcessAlignmentTextProperties(this, name, texts, names, n);
37  return true;
38  }
39  bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
40  {
41  if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
42  ProcessAlignmentSwitchProperties(this, name, states, names, n);
43  return true;
44  }
45  bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
46  char *formats[], char *names[], int n) override
47  {
48  if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
49  ProcessAlignmentBLOBProperties(this, name, sizes, blobsizes, blobs, formats, names, n);
50  return true;
51  }
52  void ISGetProperties(const char *dev) override
53  {
55  }
56  bool ISSnoopDevice(XMLEle *root) override
57  {
58  return INDI::Telescope::ISSnoopDevice(root);
59  }
60 
61  virtual bool initProperties() override
62  {
64  // initialize the alignment subsystem properties AFTER creating the base telescope properties
65  InitAlignmentProperties(this);
66  return true;
67  }
68 
69  virtual bool Handshake() override
70  {
71  // should be called before Initialise
72  SetApproximateMountAlignmentFromMountType(m_mountType);
73 
74  // the next two lines reset the alignment database
75  // skip if you want to reuse your model
76  // these also need to be called before Initialise
77  GetAlignmentDatabase().clear();
78  UpdateSize();
79 
80  Initialise(this);
81 
82  SetAlignmentSubsystemActive(true);
83 
85  }
86 
87  virtual bool updateLocation(double latitude, double longitude, double elevation) override
88  {
89  // call UpdateLocation in the alignment subsystem
90  UpdateLocation(latitude, longitude, elevation);
91  m_Location.longitude = longitude;
92  m_Location.latitude = latitude;
93  m_Location.elevation = elevation;
94 
95  return true;
96  }
97 
98  virtual bool ReadScopeStatus() override
99  {
100  if (m_mountType == EQUATORIAL)
101  {
102  // TODO: Implement your own code to read the RA/Dec from the scope.
103  // mountRA should be in decimal hours.
104  double mountRA = 0, mountDec = 0;
105  double actualRA, actualDec;
106 
107  // use the alignment subsystem to convert where the mount thinks it is
108  // to where the alignment subsystem calculates we are actually pointing
109  if (!TelescopeEquatorialToSky(range24(mountRA), rangeDec(mountDec), actualRA, actualDec))
110  {
111  // We were unable to transform the coordinates, just use what we have.
112  actualRA = mountRA;
113  actualDec = mountDec;
114  }
115 
116  // tell the driver where we are pointing
117  NewRaDec(actualRA, actualDec);
118  }
119  else if (m_mountType == ALTAZ)
120  {
121  // TODO: Implement your own code to read the Alt/Az from the scope.
122  double mountAlt = 0, mountAz = 0;
123  double actualRA, actualDec;
124 
125  // use the alignment subsystem to convert where the mount thinks it is
126  // to where the alignment subsystem calculates we are actually pointing
127  if (!TelescopeAltAzToSky(range360(mountAlt), range360(mountAz), actualRA, actualDec))
128  {
129  // We were unable to transform the coordinates, just convert the mountAlt/mountAz
130  // directly to ra/dec
131 
132  INDI::IHorizontalCoordinates altAz {mountAz, mountAlt};
134  INDI::HorizontalToEquatorial(&altAz, &m_Location, ln_get_julian_from_sys(), &raDec);
135  actualRA = range360(raDec.rightascension);
136  actualDec = rangeDec(raDec.declination);
137  }
138 
139  // tell the driver where we are pointing
140  NewRaDec(actualRA, actualDec);
141  }
142 
143  return true;
144  }
145 
146  virtual bool Sync(double ra, double dec) override
147  {
148  if (m_mountType == EQUATORIAL)
149  {
150  // In an actual driver, you would get the mounts RA/Dec and use them here.
151  // For the test class, we are assuming a "perfect" sync.
152  double mountRA = ra, mountDec = dec;
153 
154  return AddAlignmentEntryEquatorial(ra, dec, mountRA, mountDec);
155  }
156  else if (m_mountType == ALTAZ)
157  {
158  // In an actual driver, you would get the mounts Alt/Az and use them here.
159  // For the test class, we are assuming a "perfect" sync.
160 
161  // BEGIN perfect sync code
163  GetDatabaseReferencePosition(location);
166  INDI::EquatorialToHorizontal(&raDec, &m_Location, ln_get_julian_from_sys(), &altAz);
167  double mountAlt = range360(altAz.altitude), mountAz = range360(altAz.azimuth);
168  return AddAlignmentEntryAltAz(ra, dec, mountAlt, mountAz);
169  }
170  return false;
171  }
172 
173  virtual bool Goto(double ra, double dec) override
174  {
175  if (m_mountType == EQUATORIAL)
176  {
177  double mountRA, mountDec;
178  SkyToTelescopeEquatorial(ra, dec, mountRA, mountDec);
179 
180  // In an actual driver, you would send the mount to mountRA/mountDec
181  // here.
182 
183  return true;
184  }
185  else if (m_mountType == ALTAZ)
186  {
187  double mountAlt, mountAz;
188  SkyToTelescopeAltAz(ra, dec, mountAlt, mountAz);
189 
190  // In an actual driver, you would send the mount to mountAlt/mountAz
191  // here.
192  }
193  return false;
194  }
195 
197 };
198 
199 // static std::unique_ptr<Scope> scope(new Scope());
200 
201 void ISGetProperties(const char *dev)
202 {
203  INDI_UNUSED(dev);
204 }
205 
206 void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
207 {
208  INDI_UNUSED(dev);
209  INDI_UNUSED(name);
210  INDI_UNUSED(states);
211  INDI_UNUSED(names);
212  INDI_UNUSED(n);
213 }
214 
215 void ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
216 {
217  INDI_UNUSED(dev);
218  INDI_UNUSED(name);
219  INDI_UNUSED(texts);
220  INDI_UNUSED(names);
221  INDI_UNUSED(n);
222 }
223 
224 void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
225 {
226  INDI_UNUSED(dev);
227  INDI_UNUSED(name);
228  INDI_UNUSED(values);
229  INDI_UNUSED(names);
230  INDI_UNUSED(n);
231 }
232 
233 void ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[],
234  char *names[], int n)
235 {
236  INDI_UNUSED(dev);
237  INDI_UNUSED(name);
238  INDI_UNUSED(sizes);
239  INDI_UNUSED(blobsizes);
240  INDI_UNUSED(blobs);
241  INDI_UNUSED(formats);
242  INDI_UNUSED(names);
243  INDI_UNUSED(n);
244 }
245 
247 {
248  INDI_UNUSED(root);
249 }
void ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
Update data of an existing blob vector property.
void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Update the value of an existing switch vector property.
void ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Update the value of an existing text vector property.
void ISGetProperties(const char *dev)
Get Device Properties.
char _me[]
void ISSnoopDevice(XMLEle *root)
Function defined by Drivers that is called when another Driver it is snooping (by having previously c...
void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
char * me
This class encapsulates all the alignment subsystem classes that are useful to driver implementations...
virtual bool initProperties() override
Called to initialize basic properties required all the time.
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...
virtual bool Handshake()
perform handshake with device to check communication
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
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 ReadScopeStatus() override
Read telescope status.
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
Scope(MountType mountType)
virtual const char * getDefaultName() override
virtual bool Goto(double ra, double dec) override
Move the scope to the supplied RA and DEC coordinates.
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n) override
Process the client newBLOB command.
MountType m_mountType
virtual bool Handshake() override
perform handshake with device to check communication
void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
Class to provide general functionality of a telescope device.
double ra
double dec
ISState
Switch state.
Definition: indiapi.h:150
double range24(double r)
range24 Limits a number to be between 0-24 range.
Definition: indicom.c:1235
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
Definition: indicom.c:1245
double rangeDec(double decdegrees)
rangeDec Limits declination value to be in -90 to 90 range.
Definition: indicom.c:1255
Implementations for common driver routines.
#define INDI_UNUSED(x)
Definition: indidevapi.h:131
MountType
Definition: lx200_OnStep.h:158
Namespace to encapsulate the INDI Alignment Subsystem classes. For more information see "INDI Alignme...
Namespace to encapsulate INDI client, drivers, and mediator classes.
void EquatorialToHorizontal(IEquatorialCoordinates *object, IGeographicCoordinates *observer, double JD, IHorizontalCoordinates *position)
EquatorialToHorizontal Calculate horizontal coordinates from equatorial coordinates.
Definition: libastro.cpp:140
void HorizontalToEquatorial(IHorizontalCoordinates *object, IGeographicCoordinates *observer, double JD, IEquatorialCoordinates *position)
HorizontalToEquatorial Calculate Equatorial EOD Coordinates from horizontal coordinates.
Definition: libastro.cpp:156
const char * getDeviceName()