Commit add84795 authored by Jasem Mutlaq's avatar Jasem Mutlaq
Browse files

Adding support to remote INDI server in Ekos and ability to preload...

Adding support to remote INDI server in Ekos and ability to preload configuration settings of devices
parent d1ef4542
......@@ -26,6 +26,8 @@
#include "indi/indilistener.h"
#include "indi/guimanager.h"
#define MAX_REMOTE_INDI_TIMEOUT 15000
EkosManager::EkosManager()
: QDialog(KStars::Instance())
{
......@@ -48,11 +50,81 @@ EkosManager::EkosManager()
guider_di = NULL;
focuser_di = NULL;
filter_di = NULL;
remote_indi= NULL;
captureProcess = NULL;
focusProcess = NULL;
guideProcess = NULL;
kcfg_localMode->setChecked(Options::localMode());
kcfg_remoteMode->setChecked(Options::remoteMode());
connect(toolsWidget, SIGNAL(currentChanged(int)), this, SLOT(updateLog()));
toolsWidget->setTabEnabled(1, false);
connect(processINDIB, SIGNAL(clicked()), this, SLOT(processINDI()));
connect(connectB, SIGNAL(clicked()), this, SLOT(connectDevices()));
connect(disconnectB, SIGNAL(clicked()), this, SLOT(disconnectDevices()));
connect(controlPanelB, SIGNAL(clicked()), GUIManager::Instance(), SLOT(show()));
connect(optionsB, SIGNAL(clicked()), KStars::Instance(), SLOT(slotViewOps()));
connect(clearB, SIGNAL(clicked()), this, SLOT(clearLog()));
connect(kcfg_localMode, SIGNAL(toggled(bool)), this, SLOT(processINDIModeChange()));
localMode = Options::localMode();
if (localMode)
initLocalDrivers();
else
initRemoteDrivers();
}
EkosManager::~EkosManager()
{
delete captureProcess;
delete focusProcess;
delete guideProcess;
}
void EkosManager::processINDIModeChange()
{
Options::setLocalMode(kcfg_localMode->isChecked());
Options::setRemoteMode(kcfg_remoteMode->isChecked());
bool newLocalMode = kcfg_localMode->isChecked();
if (newLocalMode == localMode)
return;
localMode = newLocalMode;
reset();
if (localMode)
initLocalDrivers();
else
initRemoteDrivers();
}
void EkosManager::initLocalDrivers()
{
telescopeCombo->clear();
ccdCombo->clear();
guiderCombo->clear();
focuserCombo->clear();
filterCombo->clear();
auxCombo->clear();
telescopeCombo->addItem("--");
ccdCombo->addItem("--");
guiderCombo->addItem("--");
......@@ -96,27 +168,50 @@ EkosManager::EkosManager()
loadDefaultDrivers();
connect(toolsWidget, SIGNAL(currentChanged(int)), this, SLOT(updateLog()));
toolsWidget->setTabEnabled(1, false);
}
connect(processINDIB, SIGNAL(clicked()), this, SLOT(processINDI()));
void EkosManager::initRemoteDrivers()
{
connect(connectB, SIGNAL(clicked()), this, SLOT(connectDevices()));
telescopeCombo->clear();
ccdCombo->clear();
guiderCombo->clear();
focuserCombo->clear();
filterCombo->clear();
auxCombo->clear();
connect(disconnectB, SIGNAL(clicked()), this, SLOT(disconnectDevices()));
if (Options::remoteScopeName().isEmpty() == false)
telescopeCombo->addItem(Options::remoteScopeName());
else
telescopeCombo->addItem("--");
connect(controlPanelB, SIGNAL(clicked()), GUIManager::Instance(), SLOT(show()));
connect(clearB, SIGNAL(clicked()), this, SLOT(clearLog()));
if (Options::remoteCCDName().isEmpty() == false)
ccdCombo->addItem(Options::remoteCCDName());
else
ccdCombo->addItem("--");
}
if (Options::remoteGuiderName().isEmpty() == false)
guiderCombo->addItem(Options::remoteGuiderName());
else
guiderCombo->addItem("--");
if (Options::remoteFocuserName().isEmpty() == false)
focuserCombo->addItem(Options::remoteFocuserName());
else
focuserCombo->addItem("--");
if (Options::remoteFilterName().isEmpty() == false)
filterCombo->addItem(Options::remoteFilterName());
else
filterCombo->addItem("--");
if (Options::remoteAuxName().isEmpty() == false)
auxCombo->addItem(Options::remoteAuxName());
else
auxCombo->addItem("--");
EkosManager::~EkosManager()
{
delete captureProcess;
delete focusProcess;
delete guideProcess;
}
void EkosManager::reset()
......@@ -147,6 +242,13 @@ void EkosManager::reset()
captureProcess = NULL;
focusProcess = NULL;
guideProcess = NULL;
connectB->setEnabled(false);
disconnectB->setEnabled(false);
controlPanelB->setEnabled(false);
processINDIB->setEnabled(true);
processINDIB->setText(i18n("Start INDI"));
}
void EkosManager::loadDefaultDrivers()
......@@ -240,7 +342,7 @@ void EkosManager::saveDefaultDrivers()
void EkosManager::processINDI()
{
if (managedDevices.count() > 0)
if (managedDevices.count() > 0 || remote_indi != NULL)
{
cleanDevices();
return;
......@@ -249,61 +351,99 @@ void EkosManager::processINDI()
managedDevices.clear();
reset();
scope_di = driversList.value(telescopeCombo->currentText());
ccd_di = driversList.value(ccdCombo->currentText());
guider_di = driversList.value(guiderCombo->currentText());
filter_di = driversList.value(filterCombo->currentText());
focuser_di = driversList.value(focuserCombo->currentText());
aux_di = driversList.value(auxCombo->currentText());
if (guider_di)
if (localMode)
{
if (guider_di == ccd_di)
scope_di = driversList.value(telescopeCombo->currentText());
ccd_di = driversList.value(ccdCombo->currentText());
guider_di = driversList.value(guiderCombo->currentText());
filter_di = driversList.value(filterCombo->currentText());
focuser_di = driversList.value(focuserCombo->currentText());
aux_di = driversList.value(auxCombo->currentText());
if (guider_di)
{
useGuiderFromCCD = true;
guider_di = NULL;
if (guider_di == ccd_di)
{
useGuiderFromCCD = true;
guider_di = NULL;
}
}
}
if (filter_di)
{
if (filter_di == ccd_di)
if (filter_di)
{
useFilterFromCCD = true;
filter_di = NULL;
if (filter_di == ccd_di)
{
useFilterFromCCD = true;
filter_di = NULL;
}
}
}
if (scope_di != NULL)
managedDevices.append(scope_di);
if (ccd_di != NULL)
managedDevices.append(ccd_di);
if (guider_di != NULL)
managedDevices.append(guider_di);
if (filter_di != NULL)
managedDevices.append(filter_di);
if (scope_di != NULL)
managedDevices.append(scope_di);
if (ccd_di != NULL)
managedDevices.append(ccd_di);
if (guider_di != NULL)
managedDevices.append(guider_di);
if (filter_di != NULL)
managedDevices.append(filter_di);
if (focuser_di != NULL)
managedDevices.append(focuser_di);
if (aux_di != NULL)
managedDevices.append(aux_di);
if (managedDevices.empty())
return;
if (ccd_di == NULL && guider_di == NULL)
{
KMessageBox::error(this, i18n("Ekos requires at least one CCD or Guider to operate."));
managedDevices.clear();
return;
}
if (focuser_di != NULL)
managedDevices.append(focuser_di);
nDevices = managedDevices.count();
saveDefaultDrivers();
if (aux_di != NULL)
managedDevices.append(aux_di);
if (managedDevices.empty()) return;
if (ccd_di == NULL && guider_di == NULL)
{
KMessageBox::error(this, i18n("Ekos requires at least one CCD or Guider to operate."));
managedDevices.clear();
return;
}
else
{
delete (remote_indi);
nDevices = managedDevices.count();
remote_indi = new DriverInfo(QString("Ekos Remote Host"));
saveDefaultDrivers();
remote_indi->setHostParameters(Options::remoteHost(), Options::remotePort());
if (DriverManager::Instance()->startDevices(managedDevices) == false)
return;
remote_indi->setDriverSource(HOST_SOURCE);
if (telescopeCombo->currentText() != "--")
nDevices++;
if (ccdCombo->currentText() != "--")
nDevices++;
if (guiderCombo->currentText() != "--")
{
if (guiderCombo->currentText() != ccdCombo->currentText())
nDevices++;
else
useGuiderFromCCD = true;
}
if (focuserCombo->currentText() != "--")
nDevices++;
if (filterCombo->currentText() != "--")
{
if (filterCombo->currentText() != ccdCombo->currentText())
nDevices++;
else
useFilterFromCCD = true;
}
if (auxCombo->currentText() != "--")
nDevices++;
}
connect(INDIListener::Instance(), SIGNAL(newDevice(ISD::GDInterface*)), this, SLOT(processNewDevice(ISD::GDInterface*)));
connect(INDIListener::Instance(), SIGNAL(newTelescope(ISD::GDInterface*)), this, SLOT(setTelescope(ISD::GDInterface*)));
......@@ -313,13 +453,53 @@ void EkosManager::processINDI()
connect(INDIListener::Instance(), SIGNAL(newST4(ISD::ST4*)), this, SLOT(setST4(ISD::ST4*)));
connect(INDIListener::Instance(), SIGNAL(deviceRemoved(ISD::GDInterface*)), this, SLOT(removeDevice(ISD::GDInterface*)));
if (localMode)
{
if (DriverManager::Instance()->startDevices(managedDevices) == false)
{
INDIListener::Instance()->disconnect(this);
return;
}
appendLogText(i18n("INDI services started. Please connect devices."));
}
else
{
if (DriverManager::Instance()->connectRemoteHost(remote_indi) == false)
{
INDIListener::Instance()->disconnect(this);
return;
}
appendLogText(i18n("INDI services started. Connection to %1 at %2 is successful.", Options::remoteHost(), Options::remotePort()));
QTimer::singleShot(MAX_REMOTE_INDI_TIMEOUT, this, SLOT(checkINDITimeout()));
}
connectB->setEnabled(false);
disconnectB->setEnabled(false);
controlPanelB->setEnabled(false);
processINDIB->setText(i18n("Stop INDI"));
appendLogText(i18n("INDI services started. Please connect devices."));
}
void EkosManager::checkINDITimeout()
{
if (localMode)
return;
if (nDevices != 0)
KMessageBox::error(this, i18np("Unable to completely establish remote devices. %1 device remaining.", "Unable to completely establish remote devices. %1 devices remaining.", nDevices));
}
void EkosManager::refreshRemoteDrivers()
{
if (localMode == false)
initRemoteDrivers();
}
void EkosManager::connectDevices()
......@@ -394,7 +574,14 @@ void EkosManager::cleanDevices()
INDIListener::Instance()->disconnect(this);
DriverManager::Instance()->stopDevices(managedDevices);
if (localMode)
DriverManager::Instance()->stopDevices(managedDevices);
else if (remote_indi)
{
DriverManager::Instance()->disconnectRemoteHost(remote_indi);
delete (remote_indi);
remote_indi = 0;
}
nDevices = 0;
......@@ -412,6 +599,16 @@ void EkosManager::cleanDevices()
}
void EkosManager::processNewDevice(ISD::GDInterface *devInterface)
{
if (localMode)
processLocalDevice(devInterface);
else
processRemoteDevice(devInterface);
}
void EkosManager::processLocalDevice(ISD::GDInterface *devInterface)
{
foreach(DriverInfo *di, driversList.values())
{
......@@ -421,8 +618,6 @@ void EkosManager::processNewDevice(ISD::GDInterface *devInterface)
{
case KSTARS_TELESCOPE:
scope = devInterface;
connect(scope, SIGNAL(Connected()), this, SLOT(deviceConnected()));
connect(scope, SIGNAL(Disconnected()), this, SLOT(deviceDisconnected()));
break;
......@@ -430,42 +625,27 @@ void EkosManager::processNewDevice(ISD::GDInterface *devInterface)
if (guider_di == di)
{
guider = devInterface;
connect(guider, SIGNAL(Connected()), this, SLOT(deviceConnected()));
connect(guider, SIGNAL(Disconnected()), this, SLOT(deviceDisconnected()));
guiderName = devInterface->getDeviceName();
}
else
{
ccd = devInterface;
connect(ccd, SIGNAL(Connected()), this, SLOT(deviceConnected()));
connect(ccd, SIGNAL(Disconnected()), this, SLOT(deviceDisconnected()));
}
break;
case KSTARS_FOCUSER:
focuser = devInterface;
connect(focuser, SIGNAL(Connected()), this, SLOT(deviceConnected()));
connect(focuser, SIGNAL(Disconnected()), this, SLOT(deviceDisconnected()));
break;
case KSTARS_FILTER:
if (filter_di == di)
{
filter = devInterface;
connect(filter, SIGNAL(Connected()), this, SLOT(deviceConnected()));
connect(filter, SIGNAL(Disconnected()), this, SLOT(deviceDisconnected()));
}
break;
case KSTARS_AUXILIARY:
if (aux_di == di)
{
aux = devInterface;
connect(aux, SIGNAL(Connected()), this, SLOT(deviceConnected()));
connect(aux, SIGNAL(Disconnected()), this, SLOT(deviceDisconnected()));
}
default:
return;
break;
}
......@@ -474,6 +654,10 @@ void EkosManager::processNewDevice(ISD::GDInterface *devInterface)
}
}
connect(devInterface, SIGNAL(Connected()), this, SLOT(deviceConnected()));
connect(devInterface, SIGNAL(Disconnected()), this, SLOT(deviceDisconnected()));
if (nDevices == 0)
{
connectB->setEnabled(true);
......@@ -483,12 +667,103 @@ void EkosManager::processNewDevice(ISD::GDInterface *devInterface)
}
void EkosManager::processRemoteDevice(ISD::GDInterface *devInterface)
{
if (!strcmp(devInterface->getDeviceName(), Options::remoteScopeName().toLatin1()))
scope = devInterface;
else if (!strcmp(devInterface->getDeviceName(), Options::remoteCCDName().toLatin1()))
{
ccd = devInterface;
if (useGuiderFromCCD)
guider = ccd;
}
else if (!strcmp(devInterface->getDeviceName(), Options::remoteGuiderName().toLatin1()))
{
guider = devInterface;
guiderName = devInterface->getDeviceName();
}
else if (!strcmp(devInterface->getDeviceName(), Options::remoteFocuserName().toLatin1()))
focuser = devInterface;
else if (!strcmp(devInterface->getDeviceName(), Options::remoteFilterName().toLatin1()))
filter = devInterface;
else if (!strcmp(devInterface->getDeviceName(), Options::remoteAuxName().toLatin1()))
aux = devInterface;
else
return;
nDevices--;
connect(devInterface, SIGNAL(Connected()), this, SLOT(deviceConnected()));
connect(devInterface, SIGNAL(Disconnected()), this, SLOT(deviceDisconnected()));
if (nDevices == 0)
{
connectB->setEnabled(true);
disconnectB->setEnabled(false);
controlPanelB->setEnabled(true);
appendLogText(i18n("Remote devices established. Please connect devices."));
}
}
void EkosManager::deviceConnected()
{
connectB->setEnabled(false);
disconnectB->setEnabled(true);
processINDIB->setEnabled(false);
if (Options::neverLoadConfig())
return;
INDIConfig tConfig = Options::loadConfigOnConnection() ? LOAD_LAST_CONFIG : LOAD_DEFAULT_CONFIG;
ISwitchVectorProperty *configProp = NULL;
if (scope && scope->isConnected())
{
configProp = scope->getBaseDevice()->getSwitch("CONFIG_PROCESS");
if (configProp && configProp->s != IPS_OK)
scope->setConfig(tConfig);
}
if (ccd && ccd->isConnected())
{
configProp = ccd->getBaseDevice()->getSwitch("CONFIG_PROCESS");
if (configProp && configProp->s != IPS_OK)
ccd->setConfig(tConfig);
}
if (guider && guider != ccd && guider->isConnected())
{
configProp = guider->getBaseDevice()->getSwitch("CONFIG_PROCESS");
if (configProp && configProp->s != IPS_OK)
guider->setConfig(tConfig);
}
if (focuser && focuser->isConnected())
{
configProp = focuser->getBaseDevice()->getSwitch("CONFIG_PROCESS");
if (configProp && configProp->s != IPS_OK)
focuser->setConfig(tConfig);
}
if (filter && filter->isConnected())
{
configProp = filter->getBaseDevice()->getSwitch("CONFIG_PROCESS");
if (configProp && configProp->s != IPS_OK)
filter->setConfig(tConfig);
}
if (aux && aux->isConnected())
{
configProp = aux->getBaseDevice()->getSwitch("CONFIG_PROCESS");
if (configProp && configProp->s != IPS_OK)
aux->setConfig(tConfig);
}
}
void EkosManager::deviceDisconnected()
......@@ -513,7 +788,8 @@ void EkosManager::setTelescope(ISD::GDInterface *scopeDevice)
void EkosManager::setCCD(ISD::GDInterface *ccdDevice)
{
// If we have a guider and it's the same as the CCD driver, then let's establish it separately.
if (useGuiderFromCCD == false && guider_di && (!strcmp(guider_di->getBaseDevice()->getDeviceName(), ccdDevice->getDeviceName())))
//if (useGuiderFromCCD == false && guider_di && (!strcmp(guider_di->getBaseDevice()->getDeviceName(), ccdDevice->getDeviceName())))
if (useGuiderFromCCD == false && guiderName == QString(ccdDevice->getDeviceName()))
{
guider = ccdDevice;
appendLogText(i18n("%1 is online.", ccdDevice->getDeviceName()));
......@@ -741,7 +1017,7 @@ void EkosManager::initGuide()
void EkosManager::setST4(ISD::ST4 * st4Driver)
{
appendLogText(i18n("Guider port from %1 is ready.", st4Driver->getDeviceName()));
appendLogText(i18n("Guider port from %1 is ready.", st4Driver->getDeviceName()));
useST4=true;
initGuide();
......
......@@ -35,6 +35,7 @@ public:
~EkosManager();
void appendLogText(const QString &);
void refreshRemoteDrivers();
public slots:
void processINDI();
......@@ -53,6 +54,9 @@ public slots:
void deviceConnected();
void deviceDisconnected();
void processINDIModeChange();
void checkINDITimeout();
void setTelescope(ISD::GDInterface *);
void setCCD(ISD::GDInterface *);
void setFilter(ISD::GDInterface *);
......@@ -68,6 +72,13 @@ public slots:
void initCapture();
void initFocus();
void initGuide();
void initLocalDrivers();
void initRemoteDrivers();
void processLocalDevice(ISD::GDInterface*);
void processRemoteDevice(ISD::GDInterface*);
bool useGuiderFromCCD;
bool useFilterFromCCD;
bool useST4;
......@@ -75,13 +86,16 @@ public slots:
bool ccdStarted;