summaryrefslogtreecommitdiffstats
path: root/kstars/kstars/indi/skycommander.c
blob: 261b6808d478401844fab95279e05d41407d15a0 (plain)
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
#if 0
    Sky Commander INDI driver
    Copyright (C) 2005 Jasem Mutlaq (mutlaqja@ikarustech.com)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA

#endif

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <math.h>
#include <unistd.h>
#include <time.h>

#include "indidevapi.h"
#include "indicom.h"
#include "lx200driver.h"

#define mydev		"Sky Commander"
#define BASIC_GROUP	"Main Control"
#define POLLMS		1000
#define currentRA	eq[0].value
#define currentDEC	eq[1].value

static void ISPoll(void *);
static void ISInit(void);
static void connectTelescope(void);

static ISwitch PowerS[]          = {{"CONNECT" , "Connect" , ISS_OFF, 0, 0},{"DISCONNECT", "Disconnect", ISS_ON, 0, 0}};
ISwitchVectorProperty PowerSP		= { mydev, "CONNECTION" , "Connection", BASIC_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE, PowerS, NARRAY(PowerS), "", 0};

static IText PortT[]			= {{"PORT", "Port", 0, 0, 0, 0}};
static ITextVectorProperty PortTP		= { mydev, "DEVICE_PORT", "Ports", BASIC_GROUP, IP_RW, 0, IPS_IDLE, PortT, NARRAY(PortT), "", 0};

/* equatorial position */
INumber eq[] = {
    {"RA",  "RA  H:M:S", "%10.6m",  0., 24., 0., 0., 0, 0, 0},
    {"DEC", "Dec D:M:S", "%10.6m", -90., 90., 0., 0., 0, 0, 0},
};
INumberVectorProperty eqNum = {
    mydev, "EQUATORIAL_EOD_COORD", "Equatorial JNow", BASIC_GROUP, IP_RO, 0, IPS_IDLE,
    eq, NARRAY(eq), "", 0};


void ISInit(void)
{
  static int isInit=0;

  if (isInit) return;

  isInit = 1;

  IEAddTimer (POLLMS, ISPoll, NULL);

}

void ISGetProperties (const char *dev)
{
  
  ISInit(); 

  dev=dev;

  IDDefSwitch(&PowerSP, NULL);
  IDDefText(&PortTP, NULL);
  IDDefNumber(&eqNum, NULL);
}

void ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
{
   ISInit();

   dev = dev;

   if (!strcmp(name, PowerSP.name))
   {
      IUResetSwitches(&PowerSP);
      IUUpdateSwitches(&PowerSP, states, names, n);
      connectTelescope();
      return;
   }
}

void ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
{

  ISInit();

  dev=dev; names=names; n=n;

  if (!strcmp(name, PortTP.name))
  {
    IUSaveText(&PortT[0], texts[0]);
    PortTP.s = IPS_OK;
    IDSetText(&PortTP, NULL);
    return;
  }

}
void ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
{
 dev=dev;name=name;values=values;names=names;n=n;
}

void ISNewBLOB (const char *dev, const char *name, int sizes[], char *blobs[], char *formats[], char *names[], int n)
{
  dev=dev;name=name;sizes=sizes;blobs=blobs;formats=formats;names=names;n=n;
}

void ISPoll (void *p)
{
  p=p;

  if (PowerS[0].s == ISS_ON)
  {
  	switch (eqNum.s)
		{
		case IPS_IDLE:
	        case IPS_OK:
	        case IPS_BUSY:
	        if (updateSkyCommanderCoord(&currentRA, &currentDEC) < 0)
                 {
                   eqNum.s = IPS_ALERT;
                   IDSetNumber(&eqNum, "Unknown error while reading telescope coordinates");
                   IDLog("Unknown error while reading telescope coordinates\n");
                   break;
                 }

	        IDSetNumber(&eqNum, NULL);
	        break;
	        
	        case IPS_ALERT:
	    	break;
		}
  }

  IEAddTimer(POLLMS, ISPoll, NULL);
}

void connectTelescope(void)
{

  switch (PowerS[0].s)
  {
    case ISS_ON:
     if (Connect(PortT[0].text) < 0)
     {
       PowerSP.s = IPS_ALERT;
       IUResetSwitches(&PowerSP);
       IDSetSwitch(&PowerSP, "Error connecting to port %s", PortT[0].text);
       return;
     }

     PowerSP.s = IPS_OK;
     IDSetSwitch(&PowerSP, "Sky Commander is online.");
     break;

   case ISS_OFF:
	Disconnect();
	IUResetSwitches(&PowerSP);
        eqNum.s = PortTP.s = PowerSP.s = IPS_IDLE;
	IDSetSwitch(&PowerSP, "Sky Commander is offline.");
        IDSetText(&PortTP, NULL);
	IDSetNumber(&eqNum, NULL);
	break;
  }

}