TelescopeControl.cpp   TelescopeControl.cpp 
skipping to change at line 64 skipping to change at line 64
#include <QFileInfo> #include <QFileInfo>
#include <QMapIterator> #include <QMapIterator>
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QDir> #include <QDir>
#include <QSignalMapper> #include <QSignalMapper>
#include <QDebug> #include <QDebug>
#define DEFAULT_RTS2_REFRESH 500000
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
// //
StelModule* TelescopeControlStelPluginInterface::getStelModule() const StelModule* TelescopeControlStelPluginInterface::getStelModule() const
{ {
return new TelescopeControl(); return new TelescopeControl();
} }
StelPluginInfo TelescopeControlStelPluginInterface::getPluginInfo() const StelPluginInfo TelescopeControlStelPluginInterface::getPluginInfo() const
{ {
// Allow to load the resources when used as a static plugin // Allow to load the resources when used as a static plugin
Q_INIT_RESOURCE(TelescopeControl); Q_INIT_RESOURCE(TelescopeControl);
StelPluginInfo info; StelPluginInfo info;
info.id = "TelescopeControl"; info.id = "TelescopeControl";
info.displayedName = N_("Telescope Control"); info.displayedName = N_("Telescope Control");
info.authors = "Bogdan Marinov, Johannes Gajdosik"; info.authors = "Bogdan Marinov, Johannes Gajdosik";
info.contact = "http://stellarium.org"; info.contact = "http://stellarium.org";
info.description = N_("This plug-in allows Stellarium to send \"slew \" commands to a telescope on a computerized mount (a \"GoTo telescope\")." ); info.description = N_("This plug-in allows Stellarium to send \"slew \" commands to a telescope on a computerized mount (a \"GoTo telescope\")." );
info.version = TELESCOPE_CONTROL_VERSION; info.version = TELESCOPE_CONTROL_PLUGIN_VERSION;
info.license = TELESCOPE_CONTROL_PLUGIN_LICENSE;
return info; return info;
} }
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
// Constructor and destructor // Constructor and destructor
TelescopeControl::TelescopeControl() TelescopeControl::TelescopeControl()
: toolbarButton(Q_NULLPTR) : toolbarButton(Q_NULLPTR)
, useTelescopeServerLogs(false) , useTelescopeServerLogs(false)
, useServerExecutables(false) , useServerExecutables(false)
, telescopeDialog(Q_NULLPTR) , telescopeDialog(Q_NULLPTR)
skipping to change at line 624 skipping to change at line 627
return; return;
} }
QFile telescopesJsonFile(telescopesJsonPath); QFile telescopesJsonFile(telescopesJsonPath);
if(!telescopesJsonFile.open(QFile::WriteOnly|QFile::Text)) if(!telescopesJsonFile.open(QFile::WriteOnly|QFile::Text))
{ {
qWarning() << "[TelescopeControl] Telescopes can not be save d. A file can not be open for writing:" << QDir::toNativeSeparators(telesco pesJsonPath); qWarning() << "[TelescopeControl] Telescopes can not be save d. A file can not be open for writing:" << QDir::toNativeSeparators(telesco pesJsonPath);
return; return;
} }
//Add the version: //Add the version:
telescopeDescriptions.insert("version", QString(TELESCOPE_CONTROL_VE RSION)); telescopeDescriptions.insert("version", QString(TELESCOPE_CONTROL_PL UGIN_VERSION));
//Convert the tree to JSON //Convert the tree to JSON
StelJsonParser::write(telescopeDescriptions, &telescopesJsonFile); StelJsonParser::write(telescopeDescriptions, &telescopesJsonFile);
telescopesJsonFile.flush();//Is this necessary? telescopesJsonFile.flush();//Is this necessary?
telescopesJsonFile.close(); telescopesJsonFile.close();
} }
void TelescopeControl::loadTelescopes() void TelescopeControl::loadTelescopes()
{ {
QVariantMap result; QVariantMap result;
skipping to change at line 673 skipping to change at line 676
} }
//File contains any telescopes? //File contains any telescopes?
if(map.isEmpty()) if(map.isEmpty())
{ {
telescopeDescriptions = result; telescopeDescriptions = result;
return; return;
} }
QString version = map.value("version", "0.0.0").toString(); QString version = map.value("version", "0.0.0").toString();
if(StelUtils::compareVersions(version, QString(TELESCOPE_CONTROL_VER SION))!=0) if(StelUtils::compareVersions(version, QString(TELESCOPE_CONTROL_PLU GIN_VERSION))!=0)
{ {
QString newName = telescopesJsonPath + ".backup." + QDateTim e::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss"); QString newName = telescopesJsonPath + ".backup." + QDateTim e::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss");
if(telescopesJsonFile.rename(newName)) if(telescopesJsonFile.rename(newName))
{ {
qWarning() << "[TelescopeControl] The existing versi on of telescopes.json is obsolete. Backing it up as" << QDir::toNativeSepar ators(newName); qWarning() << "[TelescopeControl] The existing versi on of telescopes.json is obsolete. Backing it up as" << QDir::toNativeSepar ators(newName);
qWarning() << "[TelescopeControl] A blank telescopes .json file will have to be created."; qWarning() << "[TelescopeControl] A blank telescopes .json file will have to be created.";
telescopeDescriptions = result; telescopeDescriptions = result;
return; return;
} }
else else
skipping to change at line 751 skipping to change at line 754
} }
QString hostName("localhost"); QString hostName("localhost");
int portTCP = 0; int portTCP = 0;
int delay = 0; int delay = 0;
QString deviceModelName; QString deviceModelName;
QString portSerial; QString portSerial;
QString rts2Url("localhost"); QString rts2Url("localhost");
QString rts2Username(""); QString rts2Username("");
QString rts2Password(""); QString rts2Password("");
int rts2Refresh = DEFAULT_RTS2_REFRESH;
if (connectionType == ConnectionInternal) if (connectionType == ConnectionInternal)
{ {
//Serial port and device model //Serial port and device model
deviceModelName = telescope.value("device_model").to String(); deviceModelName = telescope.value("device_model").to String();
portSerial = telescope.value("serial_port").toString (); portSerial = telescope.value("serial_port").toString ();
if(deviceModelName.isEmpty()) if(deviceModelName.isEmpty())
{ {
qDebug() << "[TelescopeControl] Unable to lo ad telescope: No device model specified at slot" << key; qDebug() << "[TelescopeControl] Unable to lo ad telescope: No device model specified at slot" << key;
skipping to change at line 806 skipping to change at line 810
//Validation: Host name //Validation: Host name
rts2Url = telescope.value("url").toString(); rts2Url = telescope.value("url").toString();
if(rts2Url.isEmpty()) if(rts2Url.isEmpty())
{ {
qDebug() << "[TelescopeControl] loadTelescop es(): No URL at slot" << key; qDebug() << "[TelescopeControl] loadTelescop es(): No URL at slot" << key;
map.remove(key); map.remove(key);
continue; continue;
} }
rts2Username = telescope.value("username").toString( ); rts2Username = telescope.value("username").toString( );
rts2Password = telescope.value("password").toString( ); rts2Password = telescope.value("password").toString( );
rts2Refresh = telescope.value("refresh", DEFAULT_RTS 2_REFRESH).toInt();
} }
if (connectionType != ConnectionVirtual) if (connectionType != ConnectionVirtual)
{ {
if (connectionType != ConnectionRTS2) if (connectionType != ConnectionRTS2)
{ {
//Validation: TCP port //Validation: TCP port
portTCP = telescope.value("tcp_port").toInt( ); portTCP = telescope.value("tcp_port").toInt( );
if(!telescope.contains("tcp_port") || !isVal idPort(portTCP)) if(!telescope.contains("tcp_port") || !isVal idPort(portTCP))
{ {
skipping to change at line 901 skipping to change at line 906
{ {
qDebug() << "[TelescopeContr ol] Unable to create a telescope client at slot" << slot; qDebug() << "[TelescopeContr ol] Unable to create a telescope client at slot" << slot;
//Unnecessary due to if-else construction; //Unnecessary due to if-else construction;
//also, causes bug #608533 //also, causes bug #608533
//continue; //continue;
} }
} }
} }
else else
{ {
if(!startClientAtSlot(slot, connectionType, name, equinox, hostName, portTCP, delay, internalCircles, deviceModelName, portSerial, rts2Url, rts2Username, rts2Password)) if(!startClientAtSlot(slot, connectionType, name, equinox, hostName, portTCP, delay, internalCircles, deviceModelName, portSerial, rts2Url, rts2Username, rts2Password, rts2Refresh))
{ {
qDebug() << "[TelescopeControl] Unab le to create a telescope client at slot" << slot; qDebug() << "[TelescopeControl] Unab le to create a telescope client at slot" << slot;
//Unnecessary due to if-else constru ction; //Unnecessary due to if-else constru ction;
//also, causes bug #608533 //also, causes bug #608533
//continue; //continue;
} }
} }
} }
//If this line is reached, the telescope at this slot has be en loaded successfully //If this line is reached, the telescope at this slot has be en loaded successfully
skipping to change at line 925 skipping to change at line 930
if(telescopesCount > 0) if(telescopesCount > 0)
{ {
result = map; result = map;
qDebug() << "[TelescopeControl] Loaded successfully" << tele scopesCount qDebug() << "[TelescopeControl] Loaded successfully" << tele scopesCount
<< "telescopes."; << "telescopes.";
} }
telescopeDescriptions = result; telescopeDescriptions = result;
} }
bool TelescopeControl::addTelescopeAtSlot(int slot, ConnectionType connecti onType, QString name, QString equinox, QString host, int portTCP, int delay , bool connectAtStartup, QList<double> circles, QString deviceModelName, QS tring portSerial, QString rts2Url, QString rts2Username, QString rts2Passwo rd) bool TelescopeControl::addTelescopeAtSlot(int slot, ConnectionType connecti onType, QString name, QString equinox, QString host, int portTCP, int delay , bool connectAtStartup, QList<double> circles, QString deviceModelName, QS tring portSerial, QString rts2Url, QString rts2Username, QString rts2Passwo rd, int rts2Refresh)
{ {
//Validation //Validation
if(!isValidSlotNumber(slot) || name.isEmpty() || equinox.isEmpty() | | connectionType <= ConnectionNA || connectionType >= ConnectionCount) if(!isValidSlotNumber(slot) || name.isEmpty() || equinox.isEmpty() | | connectionType <= ConnectionNA || connectionType >= ConnectionCount)
return false; return false;
//Create a new map node and fill it with parameters //Create a new map node and fill it with parameters
QVariantMap telescope; QVariantMap telescope;
telescope.insert("name", name); telescope.insert("name", name);
telescope.insert("connection", connectionTypeNames.value(connectionT ype)); telescope.insert("connection", connectionTypeNames.value(connectionT ype));
telescope.insert("equinox", equinox);//TODO: Validation! telescope.insert("equinox", equinox);//TODO: Validation!
skipping to change at line 952 skipping to change at line 957
telescope.insert("host_name", host); telescope.insert("host_name", host);
} }
if(connectionType == ConnectionRTS2) if(connectionType == ConnectionRTS2)
{ {
if (rts2Url.isEmpty()) if (rts2Url.isEmpty())
return false; return false;
telescope.insert("url", rts2Url); telescope.insert("url", rts2Url);
telescope.insert("username", rts2Username); telescope.insert("username", rts2Username);
telescope.insert("password", rts2Password); telescope.insert("password", rts2Password);
telescope.insert("refresh", rts2Refresh);
} }
if(connectionType == ConnectionInternal) if(connectionType == ConnectionInternal)
{ {
if (!deviceModels.contains(deviceModelName)) if (!deviceModels.contains(deviceModelName))
return false; return false;
telescope.insert("device_model", deviceModelName); telescope.insert("device_model", deviceModelName);
if (portSerial.isEmpty()) if (portSerial.isEmpty())
return false; return false;
skipping to change at line 994 skipping to change at line 1000
for(int i = 0; i < circles.size(); i++) for(int i = 0; i < circles.size(); i++)
circleList.append(circles[i]); circleList.append(circles[i]);
telescope.insert("circles", circleList); telescope.insert("circles", circleList);
} }
telescopeDescriptions.insert(QString::number(slot), telescope); telescopeDescriptions.insert(QString::number(slot), telescope);
return true; return true;
} }
bool TelescopeControl::getTelescopeAtSlot(int slot, ConnectionType& connect ionType, QString& name, QString& equinox, QString& host, int& portTCP, int& delay, bool& connectAtStartup, QList<double>& circles, QString& deviceMode lName, QString& portSerial, QString& rts2Url, QString& rts2Username, QStrin g& rts2Password) bool TelescopeControl::getTelescopeAtSlot(int slot, ConnectionType& connect ionType, QString& name, QString& equinox, QString& host, int& portTCP, int& delay, bool& connectAtStartup, QList<double>& circles, QString& deviceMode lName, QString& portSerial, QString& rts2Url, QString& rts2Username, QStrin g& rts2Password, int& rts2Refresh)
{ {
//Validation //Validation
if(!isValidSlotNumber(slot)) if(!isValidSlotNumber(slot))
return false; return false;
//Read the node at that slot //Read the node at that slot
QVariantMap telescope = telescopeDescriptions.value(QString::number( slot)).toMap(); QVariantMap telescope = telescopeDescriptions.value(QString::number( slot)).toMap();
if(telescope.isEmpty()) if(telescope.isEmpty())
{ {
telescopeDescriptions.remove(QString::number(slot)); telescopeDescriptions.remove(QString::number(slot));
skipping to change at line 1035 skipping to change at line 1041
if(connectionType == ConnectionInternal) if(connectionType == ConnectionInternal)
{ {
deviceModelName = telescope.value("device_model").toString() ; deviceModelName = telescope.value("device_model").toString() ;
portSerial = telescope.value("serial_port").toString(); portSerial = telescope.value("serial_port").toString();
} }
if(connectionType == ConnectionRTS2) if(connectionType == ConnectionRTS2)
{ {
rts2Url = telescope.value("url").toString(); rts2Url = telescope.value("url").toString();
rts2Username = telescope.value("username").toString(); rts2Username = telescope.value("username").toString();
rts2Password = telescope.value("password").toString(); rts2Password = telescope.value("password").toString();
rts2Refresh = telescope.value("refresh", DEFAULT_RTS2_REFRES H).toInt();
} }
return true; return true;
} }
bool TelescopeControl::removeTelescopeAtSlot(int slot) bool TelescopeControl::removeTelescopeAtSlot(int slot)
{ {
//Validation //Validation
if(!isValidSlotNumber(slot)) if(!isValidSlotNumber(slot))
return false; return false;
skipping to change at line 1069 skipping to change at line 1076
ConnectionType connectionType; ConnectionType connectionType;
int portTCP; int portTCP;
int delay; int delay;
bool connectAtStartup; bool connectAtStartup;
QList<double> circles; QList<double> circles;
QString deviceModelName; QString deviceModelName;
QString portSerial; QString portSerial;
QString rts2Url; QString rts2Url;
QString rts2Username; QString rts2Username;
QString rts2Password; QString rts2Password;
if(!getTelescopeAtSlot(slot, connectionType, name, equinox, host, po int rts2Refresh;
rtTCP, delay, connectAtStartup, circles, deviceModelName, portSerial, rts2U if(!getTelescopeAtSlot(slot, connectionType, name, equinox, host, po
rl, rts2Username, rts2Password)) rtTCP, delay, connectAtStartup, circles, deviceModelName, portSerial, rts2U
rl, rts2Username, rts2Password, rts2Refresh))
{ {
//TODO: Add debug //TODO: Add debug
return false; return false;
} }
if(connectionType == ConnectionInternal && !deviceModelName.isEmpty( )) if(connectionType == ConnectionInternal && !deviceModelName.isEmpty( ))
{ {
if(deviceModels[deviceModelName].useExecutable) if(deviceModels[deviceModelName].useExecutable)
{ {
if (startClientAtSlot(slot, connectionType, name, eq uinox, host, portTCP, delay, circles)) if (startClientAtSlot(slot, connectionType, name, eq uinox, host, portTCP, delay, circles))
skipping to change at line 1105 skipping to change at line 1113
logAtSlot(slot); logAtSlot(slot);
if (startClientAtSlot(slot, connectionType, name, eq uinox, QString(), 0, delay, circles, deviceModelName, portSerial)) if (startClientAtSlot(slot, connectionType, name, eq uinox, QString(), 0, delay, circles, deviceModelName, portSerial))
{ {
emit clientConnected(slot, name); emit clientConnected(slot, name);
return true; return true;
} }
} }
} }
else else
{ {
if (startClientAtSlot(slot, connectionType, name, equinox, h ost, portTCP, delay, circles, deviceModelName, portSerial, rts2Url, rts2Use rname, rts2Password)) if (startClientAtSlot(slot, connectionType, name, equinox, h ost, portTCP, delay, circles, deviceModelName, portSerial, rts2Url, rts2Use rname, rts2Password, rts2Refresh))
{ {
emit clientConnected(slot, name); emit clientConnected(slot, name);
return true; return true;
} }
} }
return false; return false;
} }
bool TelescopeControl::stopTelescopeAtSlot(int slot) bool TelescopeControl::stopTelescopeAtSlot(int slot)
skipping to change at line 1241 skipping to change at line 1249
telescopeServerProcess[slotNumber]->terminate(); telescopeServerProcess[slotNumber]->terminate();
#endif //Q_OS_WIN #endif //Q_OS_WIN
telescopeServerProcess[slotNumber]->waitForFinished(); telescopeServerProcess[slotNumber]->waitForFinished();
delete telescopeServerProcess[slotNumber]; delete telescopeServerProcess[slotNumber];
telescopeServerProcess.remove(slotNumber); telescopeServerProcess.remove(slotNumber);
return true; return true;
} }
bool TelescopeControl::startClientAtSlot(int slotNumber, ConnectionType con nectionType, QString name, QString equinox, QString host, int portTCP, int delay, QList<double> circles, QString deviceModelName, QString portSerial, QString rts2Url, QString rts2Username, QString rts2Password) bool TelescopeControl::startClientAtSlot(int slotNumber, ConnectionType con nectionType, QString name, QString equinox, QString host, int portTCP, int delay, QList<double> circles, QString deviceModelName, QString portSerial, QString rts2Url, QString rts2Username, QString rts2Password, int rts2Refres h)
{ {
//Validation //Validation
if(!isValidSlotNumber(slotNumber)) if(!isValidSlotNumber(slotNumber))
return false; return false;
//Check if it's not already running //Check if it's not already running
//Should it return, or should it remove the old one and proceed? //Should it return, or should it remove the old one and proceed?
if(telescopeClients.contains(slotNumber)) if(telescopeClients.contains(slotNumber))
{ {
//TODO: Add debug. Update logic? //TODO: Add debug. Update logic?
skipping to change at line 1274 skipping to change at line 1282
initString = QString("%1:%2:%3:%4:%5").arg(n ame, deviceModels[deviceModelName].server, equinox, portSerial, QString::nu mber(delay)); initString = QString("%1:%2:%3:%4:%5").arg(n ame, deviceModels[deviceModelName].server, equinox, portSerial, QString::nu mber(delay));
break; break;
case ConnectionLocal: case ConnectionLocal:
if (isValidPort(portTCP)) if (isValidPort(portTCP))
initString = QString("%1:TCP:%2:%3:%4:%5").a rg(name, equinox, "localhost", QString::number(portTCP), QString::number(de lay)); initString = QString("%1:TCP:%2:%3:%4:%5").a rg(name, equinox, "localhost", QString::number(portTCP), QString::number(de lay));
break; break;
case ConnectionRTS2: case ConnectionRTS2:
if (!rts2Url.isEmpty()) if (!rts2Url.isEmpty())
initString = QString("%1:RTS2:%2:http://%3:% 4@%5").arg(name, equinox, rts2Username, rts2Password, rts2Url); initString = QString("%1:RTS2:%2:%3:http://% 4:%5@%6").arg(name, equinox, QString::number(rts2Refresh), rts2Username, rt s2Password, rts2Url);
break; break;
case ConnectionRemote: case ConnectionRemote:
default: default:
if (isValidPort(portTCP) && !host.isEmpty()) if (isValidPort(portTCP) && !host.isEmpty())
initString = QString("%1:TCP:%2:%3:%4:%5").a rg(name, equinox, host, QString::number(portTCP), QString::number(delay)); initString = QString("%1:TCP:%2:%3:%4:%5").a rg(name, equinox, host, QString::number(portTCP), QString::number(delay));
} }
qDebug() << "connectionType:" << connectionType << " initString:" << initString; qDebug() << "connectionType:" << connectionType << " initString:" << initString;
skipping to change at line 1356 skipping to change at line 1364
{ {
qWarning() << "[TelescopeControl] Can't open for rea ding " << QDir::toNativeSeparators(deviceModelsJsonPath); qWarning() << "[TelescopeControl] Can't open for rea ding " << QDir::toNativeSeparators(deviceModelsJsonPath);
useDefaultList = true; useDefaultList = true;
} }
else else
{ {
//Check the version and move the old file if necessa ry //Check the version and move the old file if necessa ry
QVariantMap deviceModelsJsonMap; QVariantMap deviceModelsJsonMap;
deviceModelsJsonMap = StelJsonParser::parse(&deviceM odelsJsonFile).toMap(); deviceModelsJsonMap = StelJsonParser::parse(&deviceM odelsJsonFile).toMap();
QString version = deviceModelsJsonMap.value("version ", "0.0.0").toString(); QString version = deviceModelsJsonMap.value("version ", "0.0.0").toString();
if(StelUtils::compareVersions(version, QString(TELES COPE_CONTROL_VERSION))!=0) if(StelUtils::compareVersions(version, QString(TELES COPE_CONTROL_PLUGIN_VERSION))!=0)
{ {
deviceModelsJsonFile.close(); deviceModelsJsonFile.close();
QString newName = deviceModelsJsonPath + ".b ackup." + QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss"); QString newName = deviceModelsJsonPath + ".b ackup." + QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss");
if(deviceModelsJsonFile.rename(newName)) if(deviceModelsJsonFile.rename(newName))
{ {
qWarning() << "[TelescopeControl] Th e existing version of device_models.json is obsolete. Backing it up as " << QDir::toNativeSeparators(newName); qWarning() << "[TelescopeControl] Th e existing version of device_models.json is obsolete. Backing it up as " << QDir::toNativeSeparators(newName);
if(!restoreDeviceModelsListTo(device ModelsJsonPath)) if(!restoreDeviceModelsListTo(device ModelsJsonPath))
{ {
useDefaultList = true; useDefaultList = true;
} }
 End of changes. 16 change blocks. 
13 lines changed or deleted 21 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/