From 5d2c87dd6ff51ede86cdef7818648afe0ff20cf8 Mon Sep 17 00:00:00 2001 From: Orestes Sanchez Date: Tue, 7 Nov 2023 20:15:05 +0100 Subject: [PATCH 1/7] Add TCP connection. --- drivers/auxiliary/snapcap.cpp | 69 ++++++++++++++++++++++++++++++----- drivers/auxiliary/snapcap.h | 31 +++++++++++++++- 2 files changed, 89 insertions(+), 11 deletions(-) diff --git a/drivers/auxiliary/snapcap.cpp b/drivers/auxiliary/snapcap.cpp index 006f6917fa..50942ad4f1 100644 --- a/drivers/auxiliary/snapcap.cpp +++ b/drivers/auxiliary/snapcap.cpp @@ -28,6 +28,7 @@ #include "indicom.h" #include "connectionplugins/connectionserial.h" +#include "connectionplugins/connectiontcp.h" #include #include @@ -44,7 +45,13 @@ std::unique_ptr snapcap(new SnapCap()); SnapCap::SnapCap() : LightBoxInterface(this, true) { - setVersion(1, 2); + setVersion(1, 3); +} + +SnapCap::~SnapCap(){ + + delete serialConnection; + delete tcpConnection; } bool SnapCap::initProperties() @@ -82,13 +89,27 @@ bool SnapCap::initProperties() addAuxControls(); - serialConnection = new Connection::Serial(this); - serialConnection->registerHandshake([&]() + if (dustcapConnection & CONNECTION_SERIAL) + { + serialConnection = new Connection::Serial(this); + serialConnection->registerHandshake([&]() + { + return callHandshake(); + }); + registerConnection(serialConnection); + } + + if (dustcapConnection & CONNECTION_TCP) { - return Handshake(); - }); - registerConnection(serialConnection); - serialConnection->setDefaultBaudRate(Connection::Serial::B_38400); + tcpConnection = new Connection::TCP(this); + tcpConnection->registerHandshake([&]() + { + return callHandshake(); + }); + registerConnection(tcpConnection); + } + + return true; } @@ -152,8 +173,6 @@ bool SnapCap::Handshake() return true; } - PortFD = serialConnection->getPortFD(); - if (!ping()) { LOG_ERROR("Device ping failed."); @@ -163,6 +182,19 @@ bool SnapCap::Handshake() return true; } +bool SnapCap::callHandshake() +{ + if (dustcapConnection > 0) + { + if (getActiveConnection() == serialConnection) + PortFD = serialConnection->getPortFD(); + else if (getActiveConnection() == tcpConnection) + PortFD = tcpConnection->getPortFD(); + } + + return Handshake(); +} + bool SnapCap::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) { if (!dev || strcmp(dev, getDeviceName())) @@ -642,3 +674,22 @@ bool SnapCap::SetLightBoxBrightness(uint16_t value) return true; } + +uint8_t SnapCap::getDustcapConnection() const +{ + return dustcapConnection; +} + +void SnapCap::setDustcapConnection(const uint8_t &value) +{ + uint8_t mask = CONNECTION_SERIAL | CONNECTION_TCP | CONNECTION_NONE; + + if (value == 0 || (mask & value) == 0) + { + LOGF_ERROR( "Invalid connection mode %d", value); + return; + } + + dustcapConnection = value; +} + diff --git a/drivers/auxiliary/snapcap.h b/drivers/auxiliary/snapcap.h index 3b09b7d3ed..8826265a03 100644 --- a/drivers/auxiliary/snapcap.h +++ b/drivers/auxiliary/snapcap.h @@ -35,6 +35,7 @@ namespace Connection { class Serial; +class TCP; } class SnapCap : public INDI::DefaultDevice, public INDI::LightBoxInterface, public INDI::DustCapInterface @@ -52,6 +53,28 @@ class SnapCap : public INDI::DefaultDevice, public INDI::LightBoxInterface, publ virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; virtual bool ISSnoopDevice(XMLEle *root) override; + /** \struct SnapcapConnection + \brief Holds the connection mode of the Dome. + */ + enum + { + CONNECTION_NONE = 1 << 0, /** Do not use any connection plugin */ + CONNECTION_SERIAL = 1 << 1, /** For regular serial and bluetooth connections */ + CONNECTION_TCP = 1 << 2 /** For Wired and WiFI connections */ + } DustcapConnection; + + /** + * @brief setDustcapConnection Set Dustcap connection mode. Child class should call this in the constructor before Dustcap registers + * any connection interfaces + * @param value ORed combination of DustcapConnection values. + */ + void setDustcapConnection(const uint8_t &value); + + /** + * @return Get current Dustcap connection mode + */ + uint8_t getDustcapConnection() const; + protected: const char *getDefaultName() override; @@ -100,5 +123,9 @@ class SnapCap : public INDI::DefaultDevice, public INDI::LightBoxInterface, publ uint8_t prevMotorStatus{ 0xFF }; uint8_t prevBrightness{ 0xFF }; - Connection::Serial *serialConnection{ nullptr }; -}; + Connection::Serial *serialConnection = nullptr; + Connection::TCP *tcpConnection = nullptr; + + private: + bool callHandshake(); + uint8_t dustcapConnection = CONNECTION_SERIAL | CONNECTION_TCP;}; From 30770b954c78811e687e677326a31085b8d7f158 Mon Sep 17 00:00:00 2001 From: Orestes Sanchez Date: Tue, 7 Nov 2023 20:22:27 +0100 Subject: [PATCH 2/7] Update driver version --- drivers.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers.xml b/drivers.xml index 5e27eb13cc..a8a9dd7bf7 100644 --- a/drivers.xml +++ b/drivers.xml @@ -667,7 +667,7 @@ indi_snapcap - 1.2 + 1.3 indi_Excalibur From 0c9c891aa5865842df592bf270dd7855c32a38be Mon Sep 17 00:00:00 2001 From: Orestes Sanchez Date: Wed, 8 Nov 2023 19:09:40 +0100 Subject: [PATCH 3/7] fix: Solve wrong name of ForceSP property. --- drivers/auxiliary/snapcap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/auxiliary/snapcap.cpp b/drivers/auxiliary/snapcap.cpp index 50942ad4f1..2e9ff9dd2d 100644 --- a/drivers/auxiliary/snapcap.cpp +++ b/drivers/auxiliary/snapcap.cpp @@ -231,8 +231,8 @@ bool SnapCap::ISNewSwitch(const char *dev, const char *name, ISState *states, ch } if (ForceSP.isNameMatch(name)) { - AbortSP.update(states, names, n); - AbortSP.apply(); + ForceSP.update(states, names, n); + ForceSP.apply(); return true; } From 91530654fb4b56a6ed8bf928256936beec6d3608 Mon Sep 17 00:00:00 2001 From: Orestes Sanchez Date: Wed, 8 Nov 2023 19:10:06 +0100 Subject: [PATCH 4/7] Set not default destructor --- drivers/auxiliary/snapcap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/auxiliary/snapcap.h b/drivers/auxiliary/snapcap.h index 8826265a03..469445a67b 100644 --- a/drivers/auxiliary/snapcap.h +++ b/drivers/auxiliary/snapcap.h @@ -42,7 +42,7 @@ class SnapCap : public INDI::DefaultDevice, public INDI::LightBoxInterface, publ { public: SnapCap(); - virtual ~SnapCap() = default; + virtual ~SnapCap(); virtual bool initProperties() override; virtual void ISGetProperties(const char *dev) override; From b326fe2571bf41778114f2bb74ea9504a8d74fae Mon Sep 17 00:00:00 2001 From: Orestes Sanchez Date: Wed, 8 Nov 2023 19:11:10 +0100 Subject: [PATCH 5/7] fix: wrong parsing of firmware version in SnapCap. --- drivers/auxiliary/snapcap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/auxiliary/snapcap.cpp b/drivers/auxiliary/snapcap.cpp index 2e9ff9dd2d..1a40794eb8 100644 --- a/drivers/auxiliary/snapcap.cpp +++ b/drivers/auxiliary/snapcap.cpp @@ -591,7 +591,7 @@ bool SnapCap::getFirmwareVersion() return false; char versionString[4] = { 0 }; - snprintf(versionString, 4, "%s", response + 2); + snprintf(versionString, 3, "%s", response + 4); FirmwareTP[0].setText(versionString); FirmwareTP.apply(); From 153381da8a4e46db330bf6606d2e7fc29828ae79 Mon Sep 17 00:00:00 2001 From: Orestes Sanchez Date: Wed, 8 Nov 2023 22:36:20 +0100 Subject: [PATCH 6/7] lint: change tabs to space --- drivers/auxiliary/snapcap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/auxiliary/snapcap.h b/drivers/auxiliary/snapcap.h index 469445a67b..b69850f234 100644 --- a/drivers/auxiliary/snapcap.h +++ b/drivers/auxiliary/snapcap.h @@ -127,5 +127,5 @@ class SnapCap : public INDI::DefaultDevice, public INDI::LightBoxInterface, publ Connection::TCP *tcpConnection = nullptr; private: - bool callHandshake(); + bool callHandshake(); uint8_t dustcapConnection = CONNECTION_SERIAL | CONNECTION_TCP;}; From 7b3c672f4774d79e2394f2079ebc62c3e2330182 Mon Sep 17 00:00:00 2001 From: Orestes Sanchez Date: Wed, 8 Nov 2023 22:37:55 +0100 Subject: [PATCH 7/7] Revert "fix: wrong parsing of firmware version in SnapCap." This reverts commit b326fe2571bf41778114f2bb74ea9504a8d74fae. --- drivers/auxiliary/snapcap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/auxiliary/snapcap.cpp b/drivers/auxiliary/snapcap.cpp index 1a40794eb8..2e9ff9dd2d 100644 --- a/drivers/auxiliary/snapcap.cpp +++ b/drivers/auxiliary/snapcap.cpp @@ -591,7 +591,7 @@ bool SnapCap::getFirmwareVersion() return false; char versionString[4] = { 0 }; - snprintf(versionString, 3, "%s", response + 4); + snprintf(versionString, 4, "%s", response + 2); FirmwareTP[0].setText(versionString); FirmwareTP.apply();