From c80e78aff9abcca7f5f67a224339ee6164f2f892 Mon Sep 17 00:00:00 2001 From: Anjo Krank Date: Thu, 10 Feb 2022 04:59:57 +0100 Subject: [PATCH] added OpenAstroTech driver --- CMakeLists.txt | 2 + drivers.xml | 4 + drivers/telescope/lx200_OpenAstroTech.cpp | 202 ++++++++++++++++++++++ drivers/telescope/lx200_OpenAstroTech.h | 52 ++++++ drivers/telescope/lx200generic.cpp | 6 + 5 files changed, 266 insertions(+) create mode 100644 drivers/telescope/lx200_OpenAstroTech.cpp create mode 100644 drivers/telescope/lx200_OpenAstroTech.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3faf2836b1..0ec68be3a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -664,6 +664,7 @@ SET(lx200generic_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/drivers/telescope/lx200fs2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drivers/telescope/lx200ss2000pc.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drivers/telescope/lx200_OnStep.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/telescope/lx200_OpenAstroTech.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drivers/telescope/lx200_10micron.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drivers/telescope/ioptronHC8406.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drivers/telescope/eq500x.cpp) @@ -696,6 +697,7 @@ exec_program(\"${CMAKE_COMMAND}\" ARGS -E create_symlink indi_lx200generic \$ENV exec_program(\"${CMAKE_COMMAND}\" ARGS -E create_symlink indi_lx200generic \$ENV{DESTDIR}${BIN_INSTALL_DIR}/indi_lx200fs2)\n exec_program(\"${CMAKE_COMMAND}\" ARGS -E create_symlink indi_lx200generic \$ENV{DESTDIR}${BIN_INSTALL_DIR}/indi_lx200ss2000pc)\n exec_program(\"${CMAKE_COMMAND}\" ARGS -E create_symlink indi_lx200generic \$ENV{DESTDIR}${BIN_INSTALL_DIR}/indi_lx200_OnStep)\n +exec_program(\"${CMAKE_COMMAND}\" ARGS -E create_symlink indi_lx200generic \$ENV{DESTDIR}${BIN_INSTALL_DIR}/indi_lx200_OpenAstroTech)\n exec_program(\"${CMAKE_COMMAND}\" ARGS -E create_symlink indi_lx200generic \$ENV{DESTDIR}${BIN_INSTALL_DIR}/indi_lx200_10micron)\n exec_program(\"${CMAKE_COMMAND}\" ARGS -E create_symlink indi_lx200generic \$ENV{DESTDIR}${BIN_INSTALL_DIR}/indi_ioptronHC8406)\n exec_program(\"${CMAKE_COMMAND}\" ARGS -E create_symlink indi_lx200generic \$ENV{DESTDIR}${BIN_INSTALL_DIR}/indi_eq500x_telescope)\n diff --git a/drivers.xml b/drivers.xml index 7991e233e8..8298f90265 100644 --- a/drivers.xml +++ b/drivers.xml @@ -21,6 +21,10 @@ indi_lx200_OnStep 1.13 + + indi_lx200_OpenAstroTech + 0.9 + indi_lx200_TeenAstro 1.2 diff --git a/drivers/telescope/lx200_OpenAstroTech.cpp b/drivers/telescope/lx200_OpenAstroTech.cpp new file mode 100644 index 0000000000..608e6bea4b --- /dev/null +++ b/drivers/telescope/lx200_OpenAstroTech.cpp @@ -0,0 +1,202 @@ +/* + OpenAstroTech + Copyright (C) 2021 Anjo Krank + + 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 + +*/ + +#include "lx200_OpenAstroTech.h" + +#include "indicom.h" +#include "lx200driver.h" + +#include +#include + +#include +#include +#include + +#define RB_MAX_LEN 64 + +LX200_OpenAstroTech::LX200_OpenAstroTech(void) : LX200GPS() +{ + setVersion(MAJOR_VERSION, MINOR_VERSION); +} + +bool LX200_OpenAstroTech::Handshake() +{ + bool result = LX200GPS::Handshake(); + return result; +} + +#define OAT_MEADE_COMMAND "OAT_MEADE_COMMAND" +#define OAT_DEC_LOWER_LIMIT "OAT_DEC_LOWER_LIMIT" +#define OAT_DEC_UPPER_LIMIT "OAT_DEC_UPPER_LIMIT" +#define OAT_GET_DEBUG_LEVEL "OAT_GET_DEBUG_LEVEL" +#define OAT_GET_ENABLED_DEBUG_LEVEL "OAT_GET_ENABLED_DEBUG_LEVEL" +#define OAT_SET_DEBUG_LEVEL "OAT_GET_DEBUG_LEVEL" + +const char *OAT_TAB = "Open Astro Tech"; + +bool LX200_OpenAstroTech::initProperties() +{ + LX200GPS::initProperties(); + + IUFillText(&MeadeCommandT, OAT_MEADE_COMMAND, "Result / Command", ""); + IUFillTextVector(&MeadeCommandTP, &MeadeCommandT, 1, getDeviceName(), "Meade", "", OPTIONS_TAB, IP_RW, 0, IPS_IDLE); + + return true; +} + +bool LX200_OpenAstroTech::updateProperties() +{ + LX200GPS::updateProperties(); + + if (isConnected()) + { + defineProperty(&MeadeCommandTP); + } + else + { + deleteProperty(MeadeCommandTP.name); + } + + return true; +} + +bool LX200_OpenAstroTech::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) +{ + if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) + { + if (!strcmp(name, MeadeCommandTP.name)) + { + if(!isSimulation()) { + // we're using the "Set" field for the command and the actual field for the result + // we need to: + // - get the value + // - check if it's a command + // - if so, execute it, then set the result to the control + // the client side needs to + // - push ":somecmd#" + // - listen to change on MeadeCommand and log it + char * cmd = texts[0]; + size_t len = strlen(cmd); + DEBUGFDEVICE(getDeviceName(), DBG_SCOPE, "Meade Command <%s>", cmd); + if(len > 2 && cmd[0] == ':' && cmd[len-1] == '#') { + IText *tp = IUFindText(&MeadeCommandTP, names[0]); + int err = executeMeadeCommand(texts[0]); + DEBUGFDEVICE(getDeviceName(), DBG_SCOPE, "Meade Command Result %d <%s>", err, MeadeCommandResult); + if(err == 0) { + MeadeCommandTP.s = IPS_OK; + IUSaveText(tp, MeadeCommandResult); + IDSetText(&MeadeCommandTP, MeadeCommandResult); + return true; + } else { + MeadeCommandTP.s = IPS_ALERT; + IDSetText(&MeadeCommandTP, nullptr); + return true; + } + } + } + } + } + + return INDI::Telescope::ISNewText(dev, name, texts, names, n); +} + +bool LX200_OpenAstroTech::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) +{ + if (strcmp(dev, getDeviceName()) == 0) + { + /* left in for later use + if (!strcmp(name, SlewAccuracyNP.name)) + { + if (IUUpdateNumber(&SlewAccuracyNP, values, names, n) < 0) + return false; + + SlewAccuracyNP.s = IPS_OK; + + if (SlewAccuracyN[0].value < 3 || SlewAccuracyN[1].value < 3) + IDSetNumber(&SlewAccuracyNP, "Warning: Setting the slew accuracy too low may result in a dead lock"); + + IDSetNumber(&SlewAccuracyNP, nullptr); + return true; + }*/ + } + + return LX200GPS::ISNewNumber(dev, name, values, names, n); +} + +bool LX200_OpenAstroTech::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) +{ + int index = 0; + + if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) + { + /* + //Intercept Before inditelescope base can set TrackState + //Next one modification of inditelescope.cpp function + if (!strcmp(name, TrackStateSP.name)) + { + // int previousState = IUFindOnSwitchIndex(&TrackStateSP); + IUUpdateSwitch(&TrackStateSP, states, names, n); + int targetState = IUFindOnSwitchIndex(&TrackStateSP); + // LOG_DEBUG("OnStep driver TrackStateSP override called"); + // if (previousState == targetState) + // { + // IDSetSwitch(&TrackStateSP, nullptr); + // return true; + // } + + if (TrackState == SCOPE_PARKED) + { + LOG_WARN("Telescope is Parked, Unpark before tracking."); + return false; + } + + bool rc = SetTrackEnabled((targetState == TRACK_ON) ? true : false); + + if (rc) + { + return true; + //TrackStateSP moved to Update + } + else + { + //This is the case for an error on sending the command, so change TrackStateSP + TrackStateSP.s = IPS_ALERT; + IUResetSwitch(&TrackStateSP); + return false; + } + + LOG_DEBUG("TrackStateSP intercept, OnStep driver, should never get here"); + return false; + } + */ + } + return LX200GPS::ISNewSwitch(dev, name, states, names, n); +} + +const char *LX200_OpenAstroTech::getDefaultName(void) +{ + return const_cast("LX200 OpenAstroTech"); +} + +int LX200_OpenAstroTech::executeMeadeCommand(char *cmd) +{ + return getCommandString(PortFD, MeadeCommandResult, cmd); +} diff --git a/drivers/telescope/lx200_OpenAstroTech.h b/drivers/telescope/lx200_OpenAstroTech.h new file mode 100644 index 0000000000..a390690fa8 --- /dev/null +++ b/drivers/telescope/lx200_OpenAstroTech.h @@ -0,0 +1,52 @@ +/* + OpenAstroTech + Copyright (C) 2021 Anjo Krank + + 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 + +*/ + +#pragma once + +#include "lx200gps.h" + +#define MAJOR_VERSION 0 +#define MINOR_VERSION 9 + +class LX200_OpenAstroTech : public LX200GPS +{ + public: + LX200_OpenAstroTech(void); + + virtual bool Handshake() override; + virtual const char *getDefaultName(void) override; + virtual bool initProperties() override; + virtual bool updateProperties() override; + virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; + virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; + virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override; + + protected: +// virtual void getBasicData(void) override; + + private: + virtual int executeMeadeCommand(char *cmd); + + private: + IText MeadeCommandT; + ITextVectorProperty MeadeCommandTP; + char MeadeCommandResult[1024]; +}; + diff --git a/drivers/telescope/lx200generic.cpp b/drivers/telescope/lx200generic.cpp index 0f410bc1b1..bcd2318afc 100644 --- a/drivers/telescope/lx200generic.cpp +++ b/drivers/telescope/lx200generic.cpp @@ -32,6 +32,7 @@ Updated driver to use INDI::Telescope (JM) #include "lx200_10micron.h" #include "lx200_16.h" #include "lx200_OnStep.h" +#include "lx200_OpenAstroTech.h" #include "lx200ap.h" #include "lx200ap_gtocp2.h" #include "lx200classic.h" @@ -145,6 +146,11 @@ static class Loader IDLog("initializing for EQ500X mount...\n"); telescope.reset(new EQ500X()); } + else if (strstr(__progname, "indi_lx200_OpenAstroTech")) + { + IDLog("initializing for OpenAstroTech mount...\n"); + telescope.reset(new LX200_OpenAstroTech()); + } // be nice and give them a generic device else telescope.reset(new LX200Generic());