Skip to content

Commit

Permalink
Add ability to configure serial or network devices that are read-only
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed Jan 21, 2024
1 parent 7837566 commit 8e24b43
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
32 changes: 21 additions & 11 deletions libs/indibase/connectionplugins/connectionserial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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()
Expand All @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion libs/indibase/connectionplugins/connectionserial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::string> m_SystemPorts;
Expand Down
27 changes: 18 additions & 9 deletions libs/indibase/connectionplugins/connectiontcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -369,18 +372,24 @@ 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);
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////
///
//////////////////////////////////////////////////////////////////////////////////////////////////
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;
}
Expand Down
3 changes: 2 additions & 1 deletion libs/indibase/connectionplugins/connectiontcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit 8e24b43

Please sign in to comment.