3 Copyright (C) 2011 Nacho Mas (mas.ignacio@gmail.com). Only litle changes
4 from lx200basic made it by Jasem Mutlaq (mutlaqja@ikarustech.com)
6 This library is free software;
7 you can redistribute it and / or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation;
11 version 2.1 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT
ANY WARRANTY;
15 without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License
for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with
this library;
21 if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301 USA
47 #define currentRA EquatorialCoordsRN[0].value
48 #define currentDEC EquatorialCoordsRN[1].value
50 static void ISPoll(
void *);
51 static void retry_connection(
void *);
55 std::unique_ptr<IEQ45Basic> telescope;
89 IDLog(
"Initializing from IEQ45 device...\n");
90 IDLog(
"Driver Version: 0.1 (2011-11-07)\n");
92 enable_simulation(
false);
105 void IEQ45Basic::init_properties()
134 IUFillText(&PortT[0],
"PORT",
"Port",
"/dev/ttyS0");
138 IUFillNumber(&EquatorialCoordsRN[0],
"RA",
"RA H:M:S",
"%10.6m", 0., 24., 0., 0.);
139 IUFillNumber(&EquatorialCoordsRN[1],
"DEC",
"Dec D:M:S",
"%10.6m", -90., 90., 0., 0.);
149 if (dev !=
nullptr && strcmp(
mydev, dev))
167 if (strcmp(dev,
mydev))
173 if (!strcmp(name, PortTP.
name))
183 if (is_connected() ==
false)
185 IDMessage(
mydev,
"IEQ45 is offline. Please connect before issuing any commands.");
186 reset_all_properties();
197 if (strcmp(dev,
mydev))
200 if (is_connected() ==
false)
202 IDMessage(
mydev,
"IEQ45 is offline. Please connect before issuing any commands.");
203 reset_all_properties();
210 if (!strcmp(name, EquatorialCoordsRNP.
name))
212 int i = 0, nset = 0, error_code = 0;
213 double newRA = 0, newDEC = 0;
215 for (nset = i = 0; i < n; i++)
218 if (eqp == &EquatorialCoordsRN[0])
221 nset += newRA >= 0 && newRA <= 24.0;
223 else if (eqp == &EquatorialCoordsRN[1])
226 nset += newDEC >= -90.0 && newDEC <= 90.0;
232 char RAStr[32], DecStr[32];
234 fs_sexa(RAStr, newRA, 2, 3600);
235 fs_sexa(DecStr, newDEC, 2, 3600);
238 IDLog(
"We received JNow RA %g - DEC %g\n", newRA, newDEC);
239 IDLog(
"We received JNow RA %s - DEC %s\n", RAStr, DecStr);
245 handle_error(&EquatorialCoordsRNP, error_code,
"Setting RA/DEC");
252 if (process_coords() ==
false)
261 IDSetNumber(&EquatorialCoordsRNP,
"RA or Dec missing or invalid");
274 if (strcmp(
mydev, dev))
280 if (!strcmp(name, ConnectSP.
name))
289 if (is_connected() ==
false)
291 IDMessage(
mydev,
"IEQ45 is offline. Please connect before issuing any commands.");
292 reset_all_properties();
299 if (!strcmp(name, OnCoordSetSP.
name))
312 if (!strcmp(name, TrackModeSP.
name))
317 int trackMode = get_switch_index(&TrackModeSP);
326 if (!strcmp(name, AbortSlewSP.
name))
357 IDSetSwitch(&ConnectSP,
"Telescope is not responding to commands, will retry in 10 seconds.");
368 IDSetNumber(nvp,
"Device timed out. Current device may be busy or does not support %s. Will retry again.", msg);
380 void IEQ45Basic::reset_all_properties()
393 OnCoordSetS[0].s =
ISS_ON;
409 void IEQ45Basic::correct_fault()
418 bool IEQ45Basic::is_connected()
423 return (ConnectSP.
sp[0].s ==
ISS_ON);
429 static void retry_connection(
void *p)
431 int fd = *((
int *)p);
434 telescope->connection_lost();
436 telescope->connection_resumed();
450 switch (EquatorialCoordsRNP.
s)
460 IDLog(
"IDLE update coord\n");
471 if (fabs(dx) <= (3 / (900.0)) && fabs(dy) <= (3 / 60.0))
477 EquatorialCoordsRNP.
s =
IPS_OK;
483 OnCoordSetSP.
sp[IEQ45_SLEW].s =
ISS_ON;
499 handle_error(&EquatorialCoordsRNP, error_code,
"Getting RA/DEC");
523 bool IEQ45Basic::process_coords()
526 char syncString[256];
527 char RAStr[32], DecStr[32];
537 IDLog(
"Aborting Slew\n");
546 slew_error(error_code);
553 IDSetNumber(&EquatorialCoordsRNP,
"Slewing to JNow RA %s - DEC %s", RAStr, DecStr);
554 IDLog(
"Slewing to JNow RA %s - DEC %s\n", RAStr, DecStr);
564 IDSetNumber(&EquatorialCoordsRNP,
"Synchronization failed.");
570 EquatorialCoordsRN[0].value = EquatorialCoordsRN[0].value;
571 EquatorialCoordsRN[1].value = EquatorialCoordsRN[1].value;
574 EquatorialCoordsRNP.
s =
IPS_OK;
575 IDLog(
"Synchronization successful %s\n", syncString);
576 IDSetNumber(&EquatorialCoordsRNP,
"Synchronization successful.");
588 for (
int i = 0; i < sp->
nsp; i++)
598 void IEQ45Basic::connect_telescope()
600 switch (ConnectSP.
sp[0].s)
607 IDSetSwitch(&ConnectSP,
"Simulated telescope is online.");
617 "Error connecting to port %s. Make sure you have BOTH read and write permission to the port.",
626 IDSetSwitch(&ConnectSP,
"Error connecting to Telescope. Telescope is offline.");
631 IDSetSwitch(&ConnectSP,
"Telescope is online. Retrieving basic data...");
641 IDSetSwitch(&ConnectSP,
"Simulated Telescope is offline.");
645 IDLog(
"Telescope is offline.");
655 void IEQ45Basic::get_initial_data()
670 void IEQ45Basic::slew_error(
int slewCode)
673 IDLog(
"Aborting Slew\n");
676 IDSetSwitch(&OnCoordSetSP,
"Object below horizon.");
677 else if (slewCode == 2)
678 IDSetSwitch(&OnCoordSetSP,
"Object below the minimum elevation limit.");
686 void IEQ45Basic::enable_simulation(
bool enable)
691 IDLog(
"Warning: Simulation is activated.\n");
693 IDLog(
"Simulation is disabled.\n");
702 IDSetSwitch(&ConnectSP,
"The connection to the telescope is lost.");
715 IDSetSwitch(&ConnectSP,
"The connection to the telescope has been resumed.");
void ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
void ISGetProperties(const char *dev)
void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
void connection_resumed()
int IEAddTimer(int millisecs, IE_TCF *fp, void *p)
Register a new single-shot timer function, fp, to be called with ud as argument after ms.
const char * OPTIONS_GROUP
const int POLLMS_OVERRIDE
#define getIEQ45DEC(fd, x)
int check_IEQ45_connection(int fd)
#define getIEQ45RA(fd, x)
int checkIEQ45Format(int fd)
#define NARRAY(a)
Handy macro to find the number of elements in array a[]. Must be used with actual array,...
int tty_connect(const char *device, int bit_rate, int word_size, int parity, int stop_bits, int *fd)
Establishes a tty connection to a terminal device.
int tty_disconnect(int fd)
Closes a tty connection and flushes the bus.
void IDLog(const char *fmt,...)
int fs_sexa(char *out, double a, int w, int fracbase)
Converts a sexagesimal number to a string. sprint the variable a in sexagesimal format into out[].
Implementations for common driver routines.
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
INumber * IUFindNumber(const INumberVectorProperty *nvp, const char *name)
Find an INumber member in a number text property.
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
void IUFillTextVector(ITextVectorProperty *tvp, IText *tp, int ntp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a text vector property. The vector's auxiliary elements will be set to NULL.
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
void IUFillText(IText *tp, const char *name, const char *label, const char *initialText)
Assign attributes for a text property. The text's auxiliary elements will be set to NULL.
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
int IUUpdateText(ITextVectorProperty *tvp, char *texts[], char *names[], int n)
Update all text members in a text vector property.
void IDMessage(const char *dev, const char *fmt,...)
void IDDefNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDDefText(const ITextVectorProperty *tvp, const char *fmt,...)
void IDSetText(const ITextVectorProperty *tvp, const char *fmt,...)
void IDDefSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
int selectTrackingMode(int fd, int trackMode)
int setObjectRA(int fd, double ra, bool addSpace)
int setObjectDEC(int fd, double dec, bool addSpace)
int Sync(int fd, char *matchedObject)
Number vector property descriptor.
Switch vector property descriptor.