8#include <gtest/gtest.h>
19char _me[] =
"MockScopeSimDriver";
36 const char *types[] = {
"ALTAZ",
"EQ_FORK",
"EQ_GEM" };
39 for (
int i = 0; i < 3; i++)
42 names[i] =
const_cast<char *
>(types[i]);
78 void snoop(
const std::string &xml)
82 std::string buffer = xml;
84 ASSERT_NE(nodes,
nullptr) << errmsg;
85 for (
int i = 0; nodes[i] !=
nullptr; i++)
96 char *texts[] = {
const_cast<char *
>(
device) };
97 char *names[] = {
const_cast<char *
>(
"PAC_DEVICE") };
103 double values[] = { ma,
me };
104 char *names[] = {
const_cast<char *
>(
"MM_MA"),
const_cast<char *
>(
"MM_ME") };
114TEST(TelescopeSimulatorTest, switchingBetweenAltAzAndEquatorialClearsSyncPoints)
133TEST(TelescopeSimulatorTest, switchingBetweenEquatorialTypesKeepsSyncPoints)
149static void checkResyncReplacesOlderPoint(
const char *mountType)
155 ASSERT_TRUE(sim.
syncAt(9.50, 45.00));
159 ASSERT_TRUE(sim.
syncAt(9.51, 45.05));
165TEST(TelescopeSimulatorTest, resyncReplacesOlderSyncPointEquatorial)
167 checkResyncReplacesOlderPoint(
"EQ_GEM");
180const char *PAC =
"Alignment Correction Simulator";
182std::string manualAdjustment(
const char *state,
double azStep,
double altStep)
184 return std::string(
"<setNumberVector device='") + PAC +
"' name='PAC_MANUAL_ADJUSTMENT' state='" + state +
"'>"
185 "<oneNumber name='MANUAL_AZ_STEP'>" + std::to_string(azStep) +
"</oneNumber>"
186 "<oneNumber name='MANUAL_ALT_STEP'>" + std::to_string(altStep) +
"</oneNumber>"
187 "</setNumberVector>";
190std::string correctionGain(
double percent)
192 return std::string(
"<setNumberVector device='") + PAC +
"' name='CORRECTION_GAIN' state='Ok'>"
193 "<oneNumber name='GAIN'>" + std::to_string(percent) +
"</oneNumber></setNumberVector>";
196constexpr double LATITUDE = 51.4683;
201TEST(TelescopeSimulatorTest, pacMoveCorrectsThePolarAxis)
211 const double azStep = 30.0 / std::cos(LATITUDE *
M_PI / 180) / 60.0;
212 sim.
snoop(manualAdjustment(
"Busy", azStep, -20.0 / 60));
213 EXPECT_NEAR(sim.
mountModel(
"MM_MA"), 0, 1e-4);
214 EXPECT_NEAR(sim.
mountModel(
"MM_ME"), 0, 1e-4);
219TEST(TelescopeSimulatorTest, pacMoveIsAppliedOnceWhenItStarts)
227 sim.
snoop(manualAdjustment(
"Busy", 0, 0.5));
228 EXPECT_NEAR(sim.
mountModel(
"MM_ME"), -30, 1e-4);
231 sim.
snoop(manualAdjustment(
"Busy", 0, 0.5));
232 sim.
snoop(manualAdjustment(
"Ok", 0, 0.5));
233 EXPECT_NEAR(sim.
mountModel(
"MM_ME"), -30, 1e-4);
236 sim.
snoop(manualAdjustment(
"Ok", 0, 0.5));
237 EXPECT_NEAR(sim.
mountModel(
"MM_ME"), -30, 1e-4);
240 sim.
snoop(manualAdjustment(
"Busy", 0, -0.5));
241 EXPECT_NEAR(sim.
mountModel(
"MM_ME"), 0, 1e-4);
245TEST(TelescopeSimulatorTest, pacMoveFollowsTheCorrectionGain)
252 sim.
snoop(correctionGain(50));
253 sim.
snoop(manualAdjustment(
"Busy", 0, 0.5));
254 EXPECT_NEAR(sim.
mountModel(
"MM_ME"), -15, 1e-4);
255 sim.
snoop(manualAdjustment(
"Ok", 0, 0.5));
260 sim.
snoop(manualAdjustment(
"Busy", 0, 0.5));
261 EXPECT_NEAR(sim.
mountModel(
"MM_ME"), -45, 1e-4);
268 const std::string configFile =
"/tmp/test_telescope_simulator_" + std::to_string(getpid()) +
"_config.xml";
269 setenv(
"INDICONFIG", configFile.c_str(), 1);
272 ::testing::InitGoogleTest(&argc, argv);
273 int rc = RUN_ALL_TESTS();
274 std::remove(configFile.c_str());
275 std::remove((configFile +
".default").c_str());
AlignmentDatabaseType & GetAlignmentDatabase()
Get a reference to the in memory database.
INDI::PropertyNumber getNumber(const char *name) const
static const loggerConf file_off
void configure(const std::string &outputFile, const loggerConf configuration, const int fileVerbosityLevel, const int screenVerbosityLevel)
Method to configure the logger. Called by the DEBUG_CONF() macro. To make implementation easier,...
static Logger & getInstance()
Method to get a reference to the object (i.e., Singleton) It is a static method.
WidgetView< T > * findWidgetByName(const char *name) const
void setActivePAC(const char *device)
double mountModel(const char *element)
bool syncAt(double ra, double dec)
void setLocation(double latitude, double longitude)
void snoop(const std::string &xml)
void setPolarError(double ma, double me)
void selectMountType(const char *type)
const AlignmentDatabaseEntry & lastSyncPoint()
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
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 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.
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 initProperties() override
Called to initialize basic properties required all the time.
LilXML * newLilXML()
Create a new lilxml parser.
XMLEle ** parseXMLChunk(LilXML *lp, char *buf, int size, char ynot[])
Process an XML chunk.
void delXMLEle(XMLEle *ep)
delXMLEle Delete XML element.
void delLilXML(LilXML *lp)
Delete a lilxml parser.
A little DOM-style library to handle parsing and processing an XML file.
Entry in the in memory alignment database.
double RightAscension
Right ascension in decimal hours. N.B. libnova works in decimal degrees so conversion is always neede...
double ObservationJulianDate
double Declination
Declination in decimal degrees.
int PrivateDataSize
This size in bytes of any private data.
TEST(TelescopeSimulatorTest, switchingBetweenAltAzAndEquatorialClearsSyncPoints)