1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
|
#pragma once
#include <inditelescope.h>
#include <indicom.h>
#include <alignment/AlignmentSubsystemForDrivers.h>
using namespace INDI::AlignmentSubsystem;
char _me[] = "MockAlignmentScope";
char *me = _me;
class Scope : public INDI::Telescope, public INDI::AlignmentSubsystem::AlignmentSubsystemForDrivers
{
public:
Scope(MountType mountType) : INDI::Telescope(), INDI::AlignmentSubsystem::AlignmentSubsystemForDrivers()
{
m_mountType = mountType;
ISGetProperties(nullptr);
}
virtual const char *getDefaultName() override
{
return "MockAlignmentScope";
}
// make sure to pass new values into the alignment subsytem with all the ISNew* methods
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
{
if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
ProcessAlignmentNumberProperties(this, name, values, names, n);
return true;
}
bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
{
if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
ProcessAlignmentTextProperties(this, name, texts, names, n);
return true;
}
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
{
if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
ProcessAlignmentSwitchProperties(this, name, states, names, n);
return true;
}
bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
char *formats[], char *names[], int n) override
{
if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
ProcessAlignmentBLOBProperties(this, name, sizes, blobsizes, blobs, formats, names, n);
return true;
}
void ISGetProperties(const char *dev) override
{
INDI::Telescope::ISGetProperties(dev);
}
bool ISSnoopDevice(XMLEle *root) override
{
return INDI::Telescope::ISSnoopDevice(root);
}
virtual bool initProperties() override
{
INDI::Telescope::initProperties();
// initialize the alignment subsystem properties AFTER creating the base telescope properties
InitAlignmentProperties(this);
return true;
}
virtual bool Handshake() override
{
// should be called before Initialise
SetApproximateMountAlignmentFromMountType(m_mountType);
// the next two lines reset the alignment database
// skip if you want to reuse your model
// these also need to be called before Initialise
GetAlignmentDatabase().clear();
UpdateSize();
Initialise(this);
SetAlignmentSubsystemActive(true);
return INDI::Telescope::Handshake();
}
virtual bool updateLocation(double latitude, double longitude, double elevation) override
{
// call UpdateLocation in the alignment subsystem
UpdateLocation(latitude, longitude, elevation);
m_Location.longitude = longitude;
m_Location.latitude = latitude;
m_Location.elevation = elevation;
return true;
}
virtual bool ReadScopeStatus() override
{
if (m_mountType == EQUATORIAL)
{
// TODO: Implement your own code to read the RA/Dec from the scope.
// mountRA should be in decimal hours.
double mountRA = 0, mountDec = 0;
double actualRA, actualDec;
// use the alignment subsystem to convert where the mount thinks it is
// to where the alignment subsystem calculates we are actually pointing
if (!TelescopeEquatorialToSky(range24(mountRA), rangeDec(mountDec), actualRA, actualDec))
{
// We were unable to transform the coordinates, just use what we have.
actualRA = mountRA;
actualDec = mountDec;
}
// tell the driver where we are pointing
NewRaDec(actualRA, actualDec);
}
else if (m_mountType == ALTAZ)
{
// TODO: Implement your own code to read the Alt/Az from the scope.
double mountAlt = 0, mountAz = 0;
double actualRA, actualDec;
// use the alignment subsystem to convert where the mount thinks it is
// to where the alignment subsystem calculates we are actually pointing
if (!TelescopeAltAzToSky(range360(mountAlt), range360(mountAz), actualRA, actualDec))
{
// We were unable to transform the coordinates, just convert the mountAlt/mountAz
// directly to ra/dec
INDI::IHorizontalCoordinates altAz {mountAz, mountAlt};
INDI::IEquatorialCoordinates raDec;
INDI::HorizontalToEquatorial(&altAz, &m_Location, ln_get_julian_from_sys(), &raDec);
actualRA = range360(raDec.rightascension);
actualDec = rangeDec(raDec.declination);
}
// tell the driver where we are pointing
NewRaDec(actualRA, actualDec);
}
return true;
}
virtual bool Sync(double ra, double dec) override
{
if (m_mountType == EQUATORIAL)
{
// In an actual driver, you would get the mounts RA/Dec and use them here.
// For the test class, we are assuming a "perfect" sync.
double mountRA = ra, mountDec = dec;
return AddAlignmentEntryEquatorial(ra, dec, mountRA, mountDec);
}
else if (m_mountType == ALTAZ)
{
// In an actual driver, you would get the mounts Alt/Az and use them here.
// For the test class, we are assuming a "perfect" sync.
// BEGIN perfect sync code
INDI::IGeographicCoordinates location;
GetDatabaseReferencePosition(location);
INDI::IEquatorialCoordinates raDec {ra, dec};
INDI::IHorizontalCoordinates altAz;
INDI::EquatorialToHorizontal(&raDec, &m_Location, ln_get_julian_from_sys(), &altAz);
double mountAlt = range360(altAz.altitude), mountAz = range360(altAz.azimuth);
return AddAlignmentEntryAltAz(ra, dec, mountAlt, mountAz);
}
return false;
}
virtual bool Goto(double ra, double dec) override
{
if (m_mountType == EQUATORIAL)
{
double mountRA, mountDec;
SkyToTelescopeEquatorial(ra, dec, mountRA, mountDec);
// In an actual driver, you would send the mount to mountRA/mountDec
// here.
return true;
}
else if (m_mountType == ALTAZ)
{
double mountAlt, mountAz;
SkyToTelescopeAltAz(ra, dec, mountAlt, mountAz);
// In an actual driver, you would send the mount to mountAlt/mountAz
// here.
}
return false;
}
MountType m_mountType;
};
// static std::unique_ptr<Scope> scope(new Scope());
void ISGetProperties(const char *dev)
{
INDI_UNUSED(dev);
}
void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
INDI_UNUSED(dev);
INDI_UNUSED(name);
INDI_UNUSED(states);
INDI_UNUSED(names);
INDI_UNUSED(n);
}
void ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
{
INDI_UNUSED(dev);
INDI_UNUSED(name);
INDI_UNUSED(texts);
INDI_UNUSED(names);
INDI_UNUSED(n);
}
void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
{
INDI_UNUSED(dev);
INDI_UNUSED(name);
INDI_UNUSED(values);
INDI_UNUSED(names);
INDI_UNUSED(n);
}
void ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[],
char *names[], int n)
{
INDI_UNUSED(dev);
INDI_UNUSED(name);
INDI_UNUSED(sizes);
INDI_UNUSED(blobsizes);
INDI_UNUSED(blobs);
INDI_UNUSED(formats);
INDI_UNUSED(names);
INDI_UNUSED(n);
}
void ISSnoopDevice(XMLEle *root)
{
INDI_UNUSED(root);
}
|