| 1 | #if 0
|
|---|
| 2 | Intelliscope INDI driver
|
|---|
| 3 | Copyright (C) 2005 Douglas Philipson (dougp AT intermind DOT net)
|
|---|
| 4 |
|
|---|
| 5 | Based on code by Jasem Mutlaq (mutlaqja@ikarustech.com)
|
|---|
| 6 |
|
|---|
| 7 | This library is free software; 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; either
|
|---|
| 10 | version 2.1 of the License, or (at your option) any later version.
|
|---|
| 11 |
|
|---|
| 12 | This library is distributed in the hope that it will be useful,
|
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 15 | Lesser General Public License for more details.
|
|---|
| 16 |
|
|---|
| 17 | You should have received a copy of the GNU Lesser General Public
|
|---|
| 18 | License along with this library; if not, write to the Free Software
|
|---|
| 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|---|
| 20 |
|
|---|
| 21 | #endif
|
|---|
| 22 |
|
|---|
| 23 | #include <config.h>
|
|---|
| 24 |
|
|---|
| 25 | #include <stdio.h>
|
|---|
| 26 | #include <stdlib.h>
|
|---|
| 27 | #include <string.h>
|
|---|
| 28 | #include <stdarg.h>
|
|---|
| 29 | #include <math.h>
|
|---|
| 30 | #include <unistd.h>
|
|---|
| 31 | #include <time.h>
|
|---|
| 32 |
|
|---|
| 33 | #include "indidevapi.h"
|
|---|
| 34 | #include "indicom.h"
|
|---|
| 35 | #include "lx200driver.h"
|
|---|
| 36 |
|
|---|
| 37 | #define mydev "Intelliscope"
|
|---|
| 38 | #define BASIC_GROUP "Main Control"
|
|---|
| 39 | #define POLLMS 1000
|
|---|
| 40 | #define currentRA eq[0].value
|
|---|
| 41 | #define currentDEC eq[1].value
|
|---|
| 42 |
|
|---|
| 43 | static void ISPoll(void *);
|
|---|
| 44 | static void ISInit(void);
|
|---|
| 45 | static void connectTelescope(void);
|
|---|
| 46 |
|
|---|
| 47 | int fd;
|
|---|
| 48 |
|
|---|
| 49 | static ISwitch PowerS[] = {{"CONNECT" , "Connect" , ISS_OFF, 0, 0},{"DISCONNECT", "Disconnect", ISS_ON, 0, 0}};
|
|---|
| 50 | ISwitchVectorProperty PowerSP = { mydev, "CONNECTION" , "Connection", BASIC_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, PowerS, NARRAY(PowerS), "", 0};
|
|---|
| 51 |
|
|---|
| 52 | static IText PortT[] = {{"PORT", "Port", 0, 0, 0, 0}};
|
|---|
| 53 | static ITextVectorProperty PortTP = { mydev, "DEVICE_PORT", "Ports", BASIC_GROUP, IP_RW, 0, IPS_IDLE, PortT, NARRAY(PortT), "", 0};
|
|---|
| 54 |
|
|---|
| 55 | /* equatorial position */
|
|---|
| 56 | INumber eq[] = {
|
|---|
| 57 | {"RA", "RA H:M:S", "%10.6m", 0., 24., 0., 0., 0, 0, 0},
|
|---|
| 58 | {"DEC", "Dec D:M:S", "%10.6m", -90., 90., 0., 0., 0, 0, 0},
|
|---|
| 59 | };
|
|---|
| 60 | INumberVectorProperty eqNum = {
|
|---|
| 61 | mydev, "EQUATORIAL_EOD_COORD", "Equatorial JNow", BASIC_GROUP, IP_RO, 0, IPS_IDLE,
|
|---|
| 62 | eq, NARRAY(eq), "", 0};
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 | void ISInit(void)
|
|---|
| 66 | {
|
|---|
| 67 | static int isInit=0;
|
|---|
| 68 |
|
|---|
| 69 | if (isInit) return;
|
|---|
| 70 |
|
|---|
| 71 | isInit = 1;
|
|---|
| 72 | fd = -1;
|
|---|
| 73 |
|
|---|
| 74 | IEAddTimer (POLLMS, ISPoll, NULL);
|
|---|
| 75 |
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | void ISGetProperties (const char *dev)
|
|---|
| 79 | {
|
|---|
| 80 |
|
|---|
| 81 | ISInit();
|
|---|
| 82 |
|
|---|
| 83 | dev=dev;
|
|---|
| 84 |
|
|---|
| 85 | IDDefSwitch(&PowerSP, NULL);
|
|---|
| 86 | IDDefText(&PortTP, NULL);
|
|---|
| 87 | IDDefNumber(&eqNum, NULL);
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | void ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
|
|---|
| 91 | {
|
|---|
| 92 | ISInit();
|
|---|
| 93 |
|
|---|
| 94 | dev = dev;
|
|---|
| 95 |
|
|---|
| 96 | if (!strcmp(name, PowerSP.name))
|
|---|
| 97 | {
|
|---|
| 98 | IUResetSwitch(&PowerSP);
|
|---|
| 99 | IUUpdateSwitch(&PowerSP, states, names, n);
|
|---|
| 100 | connectTelescope();
|
|---|
| 101 | return;
|
|---|
| 102 | }
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | void ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
|
|---|
| 106 | {
|
|---|
| 107 |
|
|---|
| 108 | ISInit();
|
|---|
| 109 |
|
|---|
| 110 | dev=dev; names=names; n=n;
|
|---|
| 111 |
|
|---|
| 112 | if (!strcmp(name, PortTP.name))
|
|---|
| 113 | {
|
|---|
| 114 | IUSaveText(&PortT[0], texts[0]);
|
|---|
| 115 | PortTP.s = IPS_OK;
|
|---|
| 116 | IDSetText(&PortTP, NULL);
|
|---|
| 117 | return;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | }
|
|---|
| 121 | void ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
|
|---|
| 122 | {
|
|---|
| 123 | dev=dev;name=name;values=values;names=names;n=n;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | void ISNewBLOB (const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
|
|---|
| 127 | {
|
|---|
| 128 | INDI_UNUSED(dev);
|
|---|
| 129 | INDI_UNUSED(name);
|
|---|
| 130 | INDI_UNUSED(sizes);
|
|---|
| 131 | INDI_UNUSED(blobsizes);
|
|---|
| 132 | INDI_UNUSED(blobs);
|
|---|
| 133 | INDI_UNUSED(formats);
|
|---|
| 134 | INDI_UNUSED(names);
|
|---|
| 135 | INDI_UNUSED(n);
|
|---|
| 136 | }
|
|---|
| 137 | void ISSnoopDevice (XMLEle *root)
|
|---|
| 138 | {
|
|---|
| 139 | INDI_UNUSED(root);
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | void ISPoll (void *p)
|
|---|
| 143 | {
|
|---|
| 144 | p=p;
|
|---|
| 145 |
|
|---|
| 146 | if (PowerS[0].s == ISS_ON)
|
|---|
| 147 | {
|
|---|
| 148 | switch (eqNum.s)
|
|---|
| 149 | {
|
|---|
| 150 | case IPS_IDLE:
|
|---|
| 151 | case IPS_OK:
|
|---|
| 152 | case IPS_BUSY:
|
|---|
| 153 | if (updateIntelliscopeCoord(fd, ¤tRA, ¤tDEC) < 0)
|
|---|
| 154 | {
|
|---|
| 155 | eqNum.s = IPS_ALERT;
|
|---|
| 156 | IDSetNumber(&eqNum, "Unknown error while reading telescope coordinates");
|
|---|
| 157 | IDLog("Unknown error while reading telescope coordinates\n");
|
|---|
| 158 | break;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | IDSetNumber(&eqNum, NULL);
|
|---|
| 162 | break;
|
|---|
| 163 |
|
|---|
| 164 | case IPS_ALERT:
|
|---|
| 165 | break;
|
|---|
| 166 | }
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | IEAddTimer(POLLMS, ISPoll, NULL);
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | void connectTelescope(void)
|
|---|
| 173 | {
|
|---|
| 174 |
|
|---|
| 175 | switch (PowerS[0].s)
|
|---|
| 176 | {
|
|---|
| 177 | case ISS_ON:
|
|---|
| 178 | if (tty_connect(PortT[0].text, 9600, 8, 0, 1, &fd) != TTY_OK)
|
|---|
| 179 | {
|
|---|
| 180 | PowerSP.s = IPS_ALERT;
|
|---|
| 181 | IUResetSwitch(&PowerSP);
|
|---|
| 182 | IDSetSwitch(&PowerSP, "Error connecting to port %s", PortT[0].text);
|
|---|
| 183 | return;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | PowerSP.s = IPS_OK;
|
|---|
| 187 | IDSetSwitch(&PowerSP, "Intelliscope is online.");
|
|---|
| 188 | break;
|
|---|
| 189 |
|
|---|
| 190 | case ISS_OFF:
|
|---|
| 191 | tty_disconnect(fd);
|
|---|
| 192 | IUResetSwitch(&PowerSP);
|
|---|
| 193 | eqNum.s = PortTP.s = PowerSP.s = IPS_IDLE;
|
|---|
| 194 | IDSetSwitch(&PowerSP, "Intelliscope is offline.");
|
|---|
| 195 | IDSetText(&PortTP, NULL);
|
|---|
| 196 | IDSetNumber(&eqNum, NULL);
|
|---|
| 197 | break;
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|