From be74cf0f54f2c77e64c7d09d7023386e7f4654cc Mon Sep 17 00:00:00 2001 From: Stephane Fillod Date: Sun, 21 Aug 2011 18:28:14 +0200 Subject: [PATCH] add rotator Celestron/Orion Teletrack Az-G telescope mount --- AUTHORS | 4 + Makefile.am | 2 +- NEWS | 4 + bindings/ignore.swg | 4 + celestron/Makefile.am | 7 ++ celestron/celestron.c | 248 +++++++++++++++++++++++++++++++++++++++ celestron/celestron.h | 25 ++++ configure.ac | 3 +- include/hamlib/rotlist.h | 12 ++ 9 files changed, 307 insertions(+), 2 deletions(-) create mode 100644 celestron/Makefile.am create mode 100644 celestron/celestron.c create mode 100644 celestron/celestron.h diff --git a/AUTHORS b/AUTHORS index 780ac1bf7..157d64cd2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -211,6 +211,10 @@ M: Jacob Heder Rotators +[celestron] +M: Stephane Fillod, F8CFE +C: Eric/N3KQX + [easycomm] M: Luc Langehegermann, LX2GT C: Francois Retief diff --git a/Makefile.am b/Makefile.am index 5db784f51..2d648bd78 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,7 +18,7 @@ DIST_SUBDIRS = macros include lib $(subdirs) src c++ bindings tests doc \ icom kenwood aor yaesu dummy pcr alinco uniden tentec kachina jrc \ rpcrig winradio easycomm fodtrack rpcrot drake rotorez \ flexradio sartek lowe rft rs tapr kit skanti prm80 wj racal tuner \ - gs232a heathkit spid ars m2 amsat scripts ts7400 + gs232a heathkit spid ars m2 amsat scripts ts7400 celestron rpm: Makefile dist $(RPMBUILD) -ta $(PACKAGE)-$(VERSION).tar.gz diff --git a/NEWS b/NEWS index cb0c773eb..a0c56b11a 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,10 @@ Copyright (C) 2000-2011 Stephane Fillod, and others Please send Hamlib bug reports to hamlib-developer@lists.sourceforge.net +Version 1.2.15 + * New rotator backends: Celestron (telescope mount) + * Fixes and features: K3 + Version 1.2.14 2011-08-01 * New models: SigFox Transfox, TH-D72A, IC-7410, IC-9100, IC-R9500, KX3, diff --git a/bindings/ignore.swg b/bindings/ignore.swg index fe370f14d..7247fc5a0 100644 --- a/bindings/ignore.swg +++ b/bindings/ignore.swg @@ -91,6 +91,10 @@ %ignore ROT_BACKEND_ARS; %ignore ROT_AMSAT; %ignore ROT_BACKEND_AMSAT; +%ignore ROT_TS7400; +%ignore ROT_BACKEND_TS7400; +%ignore ROT_CELESTRON; +%ignore ROT_BACKEND_CELESTRON; %ignore PRIfreq; %ignore SCNfreq; diff --git a/celestron/Makefile.am b/celestron/Makefile.am new file mode 100644 index 000000000..f501a1b5b --- /dev/null +++ b/celestron/Makefile.am @@ -0,0 +1,7 @@ + +pkglib_LTLIBRARIES = hamlib-celestron.la +hamlib_celestron_la_SOURCES = celestron.c +hamlib_celestron_la_LDFLAGS = -no-undefined -module -avoid-version +hamlib_celestron_la_LIBADD = $(top_builddir)/src/libhamlib.la + +noinst_HEADERS = celestron.h diff --git a/celestron/celestron.c b/celestron/celestron.c new file mode 100644 index 000000000..6b5bc6094 --- /dev/null +++ b/celestron/celestron.c @@ -0,0 +1,248 @@ +/* + * Hamlib Rotator backend - Celestron + * Copyright (c) 2011 by Stephane Fillod + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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 Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include + +#include "hamlib/rotator.h" +#include "serial.h" +#include "misc.h" +#include "register.h" + +#include "celestron.h" + +#define ACK "#" + +#define BUFSZ 128 + +/** + * celestron_transaction + * + * cmdstr - Command to be sent to the rig. + * data - Buffer for reply string. Can be NULL, indicating that no reply is + * is needed, but answer will still be read. + * data_len - in: Size of buffer. It is the caller's responsibily to provide + * a large enough buffer for all possible replies for a command. + * + * returns: + * RIG_OK - if no error occured. + * RIG_EIO - if an I/O error occured while sending/receiving data. + * RIG_ETIMEOUT - if timeout expires without any characters received. + */ +static int +celestron_transaction (ROT *rot, const char *cmdstr, + char *data, size_t data_len) +{ + struct rot_state *rs; + int retval; + int retry_read = 0; + char replybuf[BUFSZ]; + + rs = &rot->state; + +transaction_write: + + serial_flush(&rs->rotport); + + if (cmdstr) { + retval = write_block(&rs->rotport, cmdstr, strlen(cmdstr)); + if (retval != RIG_OK) + goto transaction_quit; + } + + /* Always read the reply to know whether the cmd went OK */ + if (!data) + data = replybuf; + if (!data_len) + data_len = BUFSZ; + + /* the answer */ + memset(data,0,data_len); + retval = read_string(&rs->rotport, data, data_len, ACK, strlen(ACK)); + if (retval < 0) { + if (retry_read++ < rot->state.rotport.retry) + goto transaction_write; + goto transaction_quit; + } + + /* check for acknowledge */ + if (retval < 1 || data[retval-1] != '#') { + rig_debug(RIG_DEBUG_ERR, "%s: unexpected response, len %d: '%s'\n", __func__, retval, data); + return -RIG_EPROTO; + } + + data[retval-1] = '\0'; + + retval = RIG_OK; +transaction_quit: + return retval; +} + + +static int +celestron_set_position(ROT *rot, azimuth_t az, elevation_t el) +{ + char cmdstr[32]; + int retval; + + rig_debug(RIG_DEBUG_TRACE, "%s called: %f %f\n", __func__, az, el); + + /* + Note: if the telescope has not been aligned, the RA/DEC values will not be meaningful and the AZM-ALT values will + be relative to where the telescope was powered on. After alignment, RA/DEC values will reflect the actual sky, + azimuth will be indexed to North equals 0 and altitude will be indexed with 0 equal to the orientation where the optical + tube is perpendicular to the azimuth axis. + */ + + sprintf(cmdstr, "B%04X,%04X", + (unsigned)((az/360.)*65535), + (unsigned)((el/360.)*65535)); + + retval = celestron_transaction(rot, cmdstr, NULL, 0); + + return retval; +} + +static int +celestron_get_position(ROT *rot, azimuth_t *az, elevation_t *el) +{ + char posbuf[32]; + int retval; + unsigned w; + + rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__); + + /* Get Azm-Alt */ + retval = celestron_transaction(rot, "Z" , posbuf, sizeof(posbuf)); + if (retval != RIG_OK || strlen(posbuf) < 9 || posbuf[4] != ',') { + return retval < 0 ? retval : -RIG_EPROTO; + } + + if (sscanf(posbuf, "%04X", &w) != 1) + return -RIG_EPROTO; + + *az = ((azimuth_t)w*360.)/65536.; + + if (sscanf(posbuf+5, "%04X", &w) != 1) + return -RIG_EPROTO; + + *el = ((elevation_t)w*360.)/65536.; + + rig_debug(RIG_DEBUG_TRACE, "%s: (az, el) = (%.1f, %.1f)\n", + __func__, *az, *el); + + return RIG_OK; +} + +static int +celestron_stop(ROT *rot) +{ + int retval; + + rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__); + + /* Cancel Goto */ + retval = celestron_transaction(rot, "M", NULL, 0); + + return retval; +} + +static const char * +celestron_get_info(ROT *rot) +{ + static char info[16]; + char str[8]; + + rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__); + + if (celestron_transaction(rot, "V", str, sizeof(str)) != RIG_OK) + return NULL; + + sprintf(info, "V%c.%c", str[0], str[1]); + + return info; +} + + + +/* ************************************************************************* */ +/* + * Celestron Nexstar telescope(rotator) capabilities. + * + * Protocol documentation: + * from Celestron: + * http://www.celestron.com/c3/images/files/downloads/1154108406_nexstarcommprot.pdf + * from Orion Teletrack Az-G: + * http://content.telescope.com/rsc/img/catalog/product/instructions/29295.pdf + */ + +const struct rot_caps nexstar_rot_caps = { + .rot_model = ROT_MODEL_NEXSTAR, + .model_name = "NexStar", // Any Celestron starting with version 1.2 + .mfg_name = "Celestron", + .version = "0.1", + .copyright = "LGPL", + .status = RIG_STATUS_UNTESTED, + .rot_type = ROT_TYPE_AZEL, + .port_type = RIG_PORT_SERIAL, + .serial_rate_min = 9600, + .serial_rate_max = 9600, + .serial_data_bits = 8, + .serial_stop_bits = 1, + .serial_parity = RIG_PARITY_NONE, + .serial_handshake = RIG_HANDSHAKE_NONE, + .write_delay = 0, + .post_write_delay = 0, + .timeout = 3500, /* worst case scenario */ + .retry = 1, + + .min_az = 0.0, + .max_az = 360.0, + .min_el = 0.0, + .max_el = 180.0, + + .get_position = celestron_get_position, + .set_position = celestron_set_position, + .stop = celestron_stop, + .get_info = celestron_get_info, +}; + +/* ************************************************************************* */ + +DECLARE_INITROT_BACKEND(celestron) +{ + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__); + + rot_register(&nexstar_rot_caps); + + return RIG_OK; +} + +/* ************************************************************************* */ +/* end of file */ + diff --git a/celestron/celestron.h b/celestron/celestron.h new file mode 100644 index 000000000..6e7b9f76b --- /dev/null +++ b/celestron/celestron.h @@ -0,0 +1,25 @@ +/* + * Hamlib Rotator backend - Celestron interface protocol + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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 Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef _ROT_CELESTRON_H +#define _ROT_CELESTRON_H 1 + +extern const struct rot_caps nexstar_rot_caps; + +#endif /* _ROT_CELESTRON_H */ diff --git a/configure.ac b/configure.ac index cd424a14a..1eca4ec12 100644 --- a/configure.ac +++ b/configure.ac @@ -259,7 +259,7 @@ AC_SUBST(RIGMATRIX) BACKEND_LIST="icom kenwood aor yaesu dummy pcr alinco uniden tentec kachina jrc drake lowe rft rs kit skanti prm80 tapr flexradio wj racal tuner" -ROT_BACKEND_LIST="dummy easycomm fodtrack gs232a heathkit kit rotorez sartek spid ars m2 amsat ts7400" +ROT_BACKEND_LIST="dummy easycomm fodtrack gs232a heathkit kit rotorez sartek spid ars m2 amsat ts7400 celestron" BINDINGS="" BINDING_ALL="" BINDING_CHECK="" @@ -540,6 +540,7 @@ flexradio/Makefile m2/Makefile amsat/Makefile ts7400/Makefile +celestron/Makefile scripts/Makefile hamlib.pc hamlib.spec] diff --git a/include/hamlib/rotlist.h b/include/hamlib/rotlist.h index 86bb7863d..b2871256b 100644 --- a/include/hamlib/rotlist.h +++ b/include/hamlib/rotlist.h @@ -100,6 +100,7 @@ #define ROT_BACKEND_EASYCOMM "easycomm" #define ROT_MODEL_EASYCOMM1 ROT_MAKE_MODEL(ROT_EASYCOMM, 1) #define ROT_MODEL_EASYCOMM2 ROT_MAKE_MODEL(ROT_EASYCOMM, 2) +#define ROT_MODEL_TRAKBOX ROT_MAKE_MODEL(ROT_EASYCOMM, 3) /*! \def ROT_MODEL_FODTRACK * \brief A macro that returns the model number of the Fodtrack backend. @@ -264,6 +265,16 @@ #define ROT_BACKEND_TS7400 "ts7400" #define ROT_MODEL_TS7400 ROT_MAKE_MODEL(ROT_TS7400, 1) +/*! \def ROT_MODEL_NEXSTAR + * \brief A macro that returns the model number of the NEXSTAR backend. + * + * The CELESTRON backend can be used with rotators that support the Celestron + * protocol and alike. + */ +#define ROT_CELESTRON 14 +#define ROT_BACKEND_CELESTRON "celestron" +#define ROT_MODEL_NEXSTAR ROT_MAKE_MODEL(ROT_CELESTRON, 1) + /*! \typedef typedef int rot_model_t \brief Convenience type definition for rotator model. @@ -292,6 +303,7 @@ typedef int rot_model_t; { ROT_ARS, ROT_BACKEND_ARS }, \ { ROT_AMSAT, ROT_BACKEND_AMSAT }, \ { ROT_TS7400, ROT_BACKEND_TS7400 }, \ + { ROT_CELESTRON, ROT_BACKEND_CELESTRON }, \ { 0, NULL }, /* end */ \ }