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