Instrument Neutral Distributed Interface INDI  1.9.5
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 }
Scope::updateLocation
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
Definition: alignment_scope.h:87
INDI::IHorizontalCoordinates::azimuth
double azimuth
Definition: libastro.h:58
INDI::IEquatorialCoordinates::declination
double declination
Definition: libastro.h:51
INDI::Telescope::initProperties
virtual bool initProperties() override
Called to initialize basic properties required all the time.
Definition: inditelescope.cpp:82
Scope::Handshake
virtual bool Handshake() override
perform handshake with device to check communication
Definition: alignment_scope.h:69
Scope::ISSnoopDevice
bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Definition: alignment_scope.h:56
indicom.h
Implementations for common driver routines.
AlignmentSubsystemForDrivers.h
Scope::ISNewNumber
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: alignment_scope.h:27
INDI::Telescope::Handshake
virtual bool Handshake()
perform handshake with device to check communication
Definition: inditelescope.cpp:1602
Pulsar2Commands::getDeviceName
const char * getDeviceName()
Definition: lx200pulsar2.cpp:455
INDI_UNUSED
#define INDI_UNUSED(x)
Definition: indidevapi.h:799
INDI::AlignmentSubsystem
Namespace to encapsulate the INDI Alignment Subsystem classes. For more information see "INDI Alignme...
Definition: AlignmentSubsystemForClients.cpp:13
Scope::Scope
Scope(MountType mountType)
Definition: alignment_scope.h:15
Scope::ISNewBLOB
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.
Definition: alignment_scope.h:45
Scope::ISGetProperties
void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
Definition: alignment_scope.h:52
range24
double range24(double r)
range24 Limits a number to be between 0-24 range.
Definition: indicom.c:1485
Scope
Definition: alignment_scope.h:12
Scope::ISNewSwitch
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: alignment_scope.h:39
range360
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
Definition: indicom.c:1495
Telescope
Class to provide general functionality of a telescope device.
Scope::ReadScopeStatus
virtual bool ReadScopeStatus() override
Read telescope status.
Definition: alignment_scope.h:98
Scope::m_mountType
MountType m_mountType
Definition: alignment_scope.h:196
INDI::IEquatorialCoordinates::rightascension
double rightascension
Definition: libastro.h:50
MountType
MountType
Definition: lx200_OnStep.h:147
Scope::Sync
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
Definition: alignment_scope.h:146
ra
double ra
Definition: ieqprolegacydriver.cpp:43
ISGetProperties
void ISGetProperties(const char *dev)
Get Device Properties.
Definition: alignment_scope.h:201
ISNewText
void ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Update the value of an existing text vector property.
Definition: alignment_scope.h:215
INDI::EquatorialToHorizontal
void EquatorialToHorizontal(IEquatorialCoordinates *object, IGeographicCoordinates *observer, double JD, IHorizontalCoordinates *position)
EquatorialToHorizontal Calculate horizontal coordinates from equatorial coordinates.
Definition: libastro.cpp:140
inditelescope.h
INDI::IHorizontalCoordinates::altitude
double altitude
Definition: libastro.h:59
ISNewBLOB
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.
Definition: alignment_scope.h:233
me
char * me
Definition: alignment_scope.h:10
dec
double dec
Definition: ieqprolegacydriver.cpp:44
xml_ele_
Definition: lilxml.c:105
INDI::Telescope
Definition: inditelescope.h:70
INDI::IGeographicCoordinates
Definition: libastro.h:64
INDI::HorizontalToEquatorial
void HorizontalToEquatorial(IHorizontalCoordinates *object, IGeographicCoordinates *observer, double JD, IEquatorialCoordinates *position)
HorizontalToEquatorial Calculate Equatorial EOD Coordinates from horizontal coordinates.
Definition: libastro.cpp:156
INDI::Telescope::ISGetProperties
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...
Definition: inditelescope.cpp:320
ISNewSwitch
void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Update the value of an existing switch vector property.
Definition: alignment_scope.h:206
name
const char * name
Definition: indiserver.c:116
INDI::Telescope::ISSnoopDevice
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Definition: inditelescope.cpp:536
INDI
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: AlignmentSubsystemForClients.cpp:11
Scope::initProperties
virtual bool initProperties() override
Called to initialize basic properties required all the time.
Definition: alignment_scope.h:61
rangeDec
double rangeDec(double decdegrees)
rangeDec Limits declination value to be in -90 to 90 range.
Definition: indicom.c:1505
ISSnoopDevice
void ISSnoopDevice(XMLEle *root)
Function defined by Drivers that is called when another Driver it is snooping (by having previously c...
Definition: alignment_scope.h:246
ISState
ISState
Switch state.
Definition: indiapi.h:148
INDI::IHorizontalCoordinates
Definition: libastro.h:56
INDI::IEquatorialCoordinates
Definition: libastro.h:48
Scope::Goto
virtual bool Goto(double ra, double dec) override
Move the scope to the supplied RA and DEC coordinates.
Definition: alignment_scope.h:173
ISNewNumber
void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Definition: alignment_scope.h:224
Scope::ISNewText
bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition: alignment_scope.h:33
Scope::getDefaultName
virtual const char * getDefaultName() override
Definition: alignment_scope.h:21
INDI::AlignmentSubsystem::AlignmentSubsystemForDrivers
This class encapsulates all the alignment subsystem classes that are useful to driver implementations...
Definition: AlignmentSubsystemForDrivers.h:29
_me
char _me[]
Definition: alignment_scope.h:9