diff --git a/libs/indibase/connectionplugins/connectionserial.cpp b/libs/indibase/connectionplugins/connectionserial.cpp index 4e2b2ef43e..8efa7eab60 100644 --- a/libs/indibase/connectionplugins/connectionserial.cpp +++ b/libs/indibase/connectionplugins/connectionserial.cpp @@ -34,7 +34,7 @@ namespace Connection { extern const char *CONNECTION_TAB; -Serial::Serial(INDI::DefaultDevice *dev) : Interface(dev, CONNECTION_SERIAL) +Serial::Serial(INDI::DefaultDevice *dev, IPerm permission) : Interface(dev, CONNECTION_SERIAL), m_Permission(permission) { char configPort[256] = {0}; // Try to load the port from the config file. If that fails, use default port. @@ -51,7 +51,7 @@ Serial::Serial(INDI::DefaultDevice *dev) : Interface(dev, CONNECTION_SERIAL) IUFillText(&PortT[0], "PORT", "Port", "/dev/ttyUSB0"); #endif } - IUFillTextVector(&PortTP, PortT, 1, dev->getDeviceName(), INDI::SP::DEVICE_PORT, "Ports", CONNECTION_TAB, IP_RW, 60, + IUFillTextVector(&PortTP, PortT, 1, dev->getDeviceName(), INDI::SP::DEVICE_PORT, "Ports", CONNECTION_TAB, m_Permission, 60, IPS_IDLE); int autoSearchIndex = 0; @@ -75,7 +75,7 @@ Serial::Serial(INDI::DefaultDevice *dev) : Interface(dev, CONNECTION_SERIAL) IUFillSwitch(&BaudRateS[4], "115200", "", ISS_OFF); IUFillSwitch(&BaudRateS[5], "230400", "", ISS_OFF); IUFillSwitchVector(&BaudRateSP, BaudRateS, 6, dev->getDeviceName(), INDI::SP::DEVICE_BAUD_RATE, "Baud Rate", CONNECTION_TAB, - IP_RW, ISR_1OFMANY, 60, IPS_IDLE); + m_Permission, ISR_1OFMANY, 60, IPS_IDLE); // Try to load the port from the config file. If that fails, use default port. IUGetConfigOnSwitchIndex(dev->getDeviceName(), INDI::SP::DEVICE_BAUD_RATE, &m_ConfigBaudRate); @@ -330,11 +330,15 @@ bool Serial::Disconnect() void Serial::Activated() { - Refresh(true); + if (m_Permission != IP_RO) + Refresh(true); m_Device->defineProperty(&PortTP); m_Device->defineProperty(&BaudRateSP); - m_Device->defineProperty(&AutoSearchSP); - m_Device->defineProperty(&RefreshSP); + if (m_Permission != IP_RO) + { + m_Device->defineProperty(&AutoSearchSP); + m_Device->defineProperty(&RefreshSP); + } } void Serial::Deactivated() @@ -344,15 +348,21 @@ void Serial::Deactivated() SystemPortS = nullptr; m_Device->deleteProperty(PortTP.name); m_Device->deleteProperty(BaudRateSP.name); - m_Device->deleteProperty(AutoSearchSP.name); - m_Device->deleteProperty(RefreshSP.name); + if (m_Permission != IP_RO) + { + m_Device->deleteProperty(AutoSearchSP.name); + m_Device->deleteProperty(RefreshSP.name); + } } bool Serial::saveConfigItems(FILE *fp) { - IUSaveConfigText(fp, &PortTP); - IUSaveConfigSwitch(fp, &BaudRateSP); - IUSaveConfigSwitch(fp, &AutoSearchSP); + if (m_Permission != IP_RO) + { + IUSaveConfigText(fp, &PortTP); + IUSaveConfigSwitch(fp, &BaudRateSP); + IUSaveConfigSwitch(fp, &AutoSearchSP); + } return true; } diff --git a/libs/indibase/connectionplugins/connectionserial.h b/libs/indibase/connectionplugins/connectionserial.h index 112f5b0048..2a0aa8e4f7 100644 --- a/libs/indibase/connectionplugins/connectionserial.h +++ b/libs/indibase/connectionplugins/connectionserial.h @@ -46,7 +46,7 @@ class Serial : public Interface */ typedef enum { B_9600, B_19200, B_38400, B_57600, B_115200, B_230400 } BaudRate; - Serial(INDI::DefaultDevice *dev); + Serial(INDI::DefaultDevice *dev, IPerm permission = IP_RW); virtual ~Serial(); virtual bool Connect() override; @@ -192,6 +192,8 @@ class Serial : public Interface uint8_t parity = 0; uint8_t stopBits = 1; + IPerm m_Permission = IP_RW; + std::string m_ConfigPort; int m_ConfigBaudRate {-1}; std::vector m_SystemPorts; diff --git a/libs/indibase/connectionplugins/connectiontcp.cpp b/libs/indibase/connectionplugins/connectiontcp.cpp index 73ffd59d96..9108f4c325 100644 --- a/libs/indibase/connectionplugins/connectiontcp.cpp +++ b/libs/indibase/connectionplugins/connectiontcp.cpp @@ -41,7 +41,7 @@ extern const char *CONNECTION_TAB; ////////////////////////////////////////////////////////////////////////////////////////////////// /// ////////////////////////////////////////////////////////////////////////////////////////////////// -TCP::TCP(INDI::DefaultDevice *dev) : Interface(dev, CONNECTION_TCP) +TCP::TCP(INDI::DefaultDevice *dev, IPerm permission) : Interface(dev, CONNECTION_TCP), m_Permission(permission) { char defaultHostname[MAXINDINAME] = {0}; char defaultPort[MAXINDINAME] = {0}; @@ -56,7 +56,7 @@ TCP::TCP(INDI::DefaultDevice *dev) : Interface(dev, CONNECTION_TCP) IUFillText(&AddressT[0], "ADDRESS", "Address", defaultHostname); IUFillText(&AddressT[1], "PORT", "Port", defaultPort); IUFillTextVector(&AddressTP, AddressT, 2, getDeviceName(), "DEVICE_ADDRESS", "Server", CONNECTION_TAB, - IP_RW, 60, IPS_IDLE); + m_Permission, 60, IPS_IDLE); int connectionTypeIndex = 0; if (IUGetConfigOnSwitchIndex(dev->getDeviceName(), "CONNECTION_TYPE", &connectionTypeIndex) == 0) @@ -359,8 +359,11 @@ bool TCP::Disconnect() void TCP::Activated() { m_Device->defineProperty(&AddressTP); - m_Device->defineProperty(&TcpUdpSP); - m_Device->defineProperty(&LANSearchSP); + if (m_Permission != IP_RO) + { + m_Device->defineProperty(&TcpUdpSP); + m_Device->defineProperty(&LANSearchSP); + } } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -369,8 +372,11 @@ void TCP::Activated() void TCP::Deactivated() { m_Device->deleteProperty(AddressTP.name); - m_Device->deleteProperty(TcpUdpSP.name); - m_Device->deleteProperty(LANSearchSP.name); + if (m_Permission != IP_RO) + { + m_Device->deleteProperty(TcpUdpSP.name); + m_Device->deleteProperty(LANSearchSP.name); + } } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -378,9 +384,12 @@ void TCP::Deactivated() ////////////////////////////////////////////////////////////////////////////////////////////////// bool TCP::saveConfigItems(FILE * fp) { - IUSaveConfigText(fp, &AddressTP); - IUSaveConfigSwitch(fp, &TcpUdpSP); - IUSaveConfigSwitch(fp, &LANSearchSP); + if (m_Permission != IP_RO) + { + IUSaveConfigText(fp, &AddressTP); + IUSaveConfigSwitch(fp, &TcpUdpSP); + IUSaveConfigSwitch(fp, &LANSearchSP); + } return true; } diff --git a/libs/indibase/connectionplugins/connectiontcp.h b/libs/indibase/connectionplugins/connectiontcp.h index 321e2d7525..807347f110 100644 --- a/libs/indibase/connectionplugins/connectiontcp.h +++ b/libs/indibase/connectionplugins/connectiontcp.h @@ -43,7 +43,7 @@ class TCP : public Interface TYPE_UDP }; - TCP(INDI::DefaultDevice *dev); + TCP(INDI::DefaultDevice *dev, IPerm permission = IP_RW); virtual ~TCP() = default; virtual bool Connect() override; @@ -115,6 +115,7 @@ class TCP : public Interface ISwitchVectorProperty LANSearchSP; // Variables + IPerm m_Permission = IP_RW; std::string m_ConfigHost; std::string m_ConfigPort; int m_ConfigConnectionType {-1};