2 True Technology Filter Wheel
3 Copyright (C) 2006 Jasem Mutlaq (mutlaqja AT ikarustech DOT com)
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.
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.
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
32 #include <sys/types.h>
33 #include <sys/socket.h>
51 static int targetFilter;
57 #define mydev "TruTech Wheel"
58 #define MAIN_GROUP "Main Control"
59 #define currentFilter FilterPositionN[0].value
61 #define DEFAULT_FILTER_COUNT 5
62 #define MAX_FILTER_COUNT 10
63 #define ERRMSG_SIZE 1024
69 #define FILTER_TIMEOUT 15
70 #define FIRST_FILTER 1
73 #define SIMULATION_ON 0
78 static ISwitch PowerS[] = { {
"CONNECT",
"Connect",
ISS_OFF, 0, 0 }, {
"DISCONNECT",
"Disconnect",
ISS_ON, 0, 0 } };
83 static IText PortT[] = { {
"PORT",
"Port", 0, 0, 0, 0 } };
95 FilterCountN,
NARRAY(FilterCountN),
"", 0 };
101 mydev,
"FILTER_SLOT",
"Filter",
MAIN_GROUP,
IP_RW, 0,
IPS_IDLE, FilterPositionN,
NARRAY(FilterPositionN),
"", 0
107 static int isInit = 0;
122 if (dev !=
nullptr && strcmp(
mydev, dev))
133 void ISNewBLOB(
const char *dev,
const char *name,
int sizes[],
int blobsizes[],
char *blobs[],
char *formats[],
134 char *names[],
int n)
153 if (dev !=
nullptr && strcmp(dev,
mydev))
167 if (!strcmp(name, HomeSP.
name))
171 unsigned char type = 0x03;
173 unsigned char filter_command[
CMD_SIZE];
196 IDSetSwitch(&HomeSP,
"Sending command Home to filter failed. %s", error_message);
197 IDLog(
"Sending command Home to filter failed. %s\n", error_message);
202 FilterPositionN[0].value = 1;
210 void ISNewText(
const char *dev,
const char *name,
char *texts[],
char *names[],
int n)
215 if (dev !=
nullptr && strcmp(
mydev, dev))
228 void ISNewNumber(
const char *dev,
const char *name,
double values[],
char *names[],
int n)
234 if (dev !=
nullptr && strcmp(dev,
mydev))
239 if (!strcmp(FilterPositionNP.
name, name))
250 if (np == &FilterPositionN[0])
252 targetFilter = values[0];
254 unsigned char type = 0x01;
255 unsigned char chksum =
COMM_INIT +
type + (
unsigned char)targetFilter;
257 unsigned char filter_command[
CMD_SIZE];
259 if (targetFilter < FilterPositionN[0].
min || targetFilter > FilterPositionN[0].
max)
262 IDSetNumber(&FilterPositionNP,
"Error: valid range of filter is from %d to %d",
263 (
int)FilterPositionN[0].
min, (
int)FilterPositionN[0].
max);
274 IDLog(
"Filter Position Command (int): #%d#%d#%d#%d#\n",
COMM_INIT,
type, targetFilter, chksum);
275 IDLog(
"Filter Position Command (char): #%c#%c#%c#%c#\n",
COMM_INIT,
type, targetFilter, chksum);
282 IDSetNumber(&FilterPositionNP,
"Setting current filter to slot %d", targetFilter);
293 if (!strcmp(FilterCountNP.
name, name))
304 if (np == &FilterCountN[0])
309 FilterPositionN[0].min = 1;
310 FilterPositionN[0].max = (int)FilterCountN[0].value;
314 IDSetNumber(&FilterCountNP,
"Updated number of available filters to %d", ((
int)FilterCountN[0].value));
329 for (i = 0; i < sp->
nsp; i++)
342 if (!strcmp(sp->
label,
""))
359 if (!strcmp(np->
label,
""))
376 if (!strcmp(tp->
label,
""))
409 "Error: cannot connect to %s. Make sure the filter is connected and you have access to the port.",
412 IDLog(
"Error: %s\n", errmsg);
417 IDSetSwitch(&
PowerSP,
"Filter Wheel is online. True Technology filter wheel suffers from several bugs. "
418 "Please refer to http://indi.sf.net/profiles/trutech.html for more details.");
434 IDLog(
"Error: %s\n", errmsg);
447 return ((PowerS[0].s ==
ISS_ON) ? 1 : 0);
Public interface to INDI's eventloop mechanism.
#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_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
int tty_disconnect(int fd)
Closes a tty connection and flushes the bus.
void IDLog(const char *fmt,...)
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
Implementations for common driver routines.
INumber * IUFindNumber(const INumberVectorProperty *nvp, const char *name)
Find an INumber member in a number text property.
Interface to the reference INDI C API device implementation on the Device Driver side.
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,...)
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
void IUUpdateMinMax(const INumberVectorProperty *nvp)
Function to update the min and max elements of a number in the client.
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,...)
ISwitchVectorProperty PowerSP
ITextVectorProperty PortTP
Number vector property descriptor.
Switch vector property descriptor.
Text vector property descriptor.
const unsigned char COMM_FILL
int manageDefaults(char errmsg[])
#define DEFAULT_FILTER_COUNT
void ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
Update data of an existing blob vector property.
void handleExposure(void *)
void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Update the value of an existing switch vector property.
void ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Update the value of an existing text vector property.
int checkPowerS(ISwitchVectorProperty *sp)
void ISGetProperties(const char *dev)
Get Device Properties.
int checkPowerN(INumberVectorProperty *np)
const unsigned char COMM_PRE
int getOnSwitch(ISwitchVectorProperty *sp)
void ISSnoopDevice(XMLEle *root)
Function defined by Drivers that is called when another Driver it is snooping (by having previously c...
void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
const unsigned char COMM_INIT
int isFilterConnected(void)
int checkPowerT(ITextVectorProperty *tp)