summaryrefslogtreecommitdiffstats
path: root/kstars/kstars/indistd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kstars/kstars/indistd.cpp')
-rw-r--r--kstars/kstars/indistd.cpp296
1 files changed, 148 insertions, 148 deletions
diff --git a/kstars/kstars/indistd.cpp b/kstars/kstars/indistd.cpp
index b2c9b2c6..6bfe8ef9 100644
--- a/kstars/kstars/indistd.cpp
+++ b/kstars/kstars/indistd.cpp
@@ -5,10 +5,10 @@
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
-
+
2004-01-18: This class handles INDI Standard properties.
*/
-
+
#include "indistd.h"
#include "Options.h"
#include "indielement.h"
@@ -26,7 +26,7 @@
#include "streamwg.h"
#include "ccdpreviewwg.h"
#include "fitsviewer.h"
-
+
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -34,13 +34,13 @@
#include <ctype.h>
#include <zlib.h>
#include <stdlib.h>
-
+
#include <tqtimer.h>
#include <tqlabel.h>
#include <tqfont.h>
#include <tqeventloop.h>
#include <tqsocketnotifier.h>
-
+
#include <tdelocale.h>
#include <kdebug.h>
#include <kpushbutton.h>
@@ -52,40 +52,40 @@
#include <kurl.h>
#include <kdirlister.h>
#include <tdeaction.h>
-
-
+
+
#define STD_BUFFER_SIZ 1024000
#define FRAME_ILEN 1024
-
+
INDIStdDevice::INDIStdDevice(INDI_D *associatedDevice, KStars * kswPtr)
{
-
+
dp = associatedDevice;
ksw = kswPtr;
initDevCounter = 0;
setCount = 0;
batchMode = false;
ISOMode = false;
-
- currentObject = NULL;
+
+ currentObject = NULL;
streamWindow = new StreamWG(this, ksw);
CCDPreviewWindow = new CCDPreviewWG(this, ksw);
-
+
devTimer = new TQTimer(this);
seqLister = new KDirLister();
-
+
telescopeSkyObject = new SkyObject(0, 0, 0, 0, i18n("Telescope"));
ksw->data()->appendTelescopeObject(telescopeSkyObject);
-
+
connect( devTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(timerDone()) );
connect( seqLister, TQT_SIGNAL(newItems (const KFileItemList & )), this, TQT_SLOT(checkSeqBoundary(const KFileItemList &)));
-
+
downloadDialog = new KProgressDialog(NULL, 0, i18n("INDI"), i18n("Downloading Data..."));
downloadDialog->cancel();
-
+
parser = newLilXML();
}
-
+
INDIStdDevice::~INDIStdDevice()
{
streamWindow->enableStream(false);
@@ -95,29 +95,29 @@
streamDisabled();
delete (seqLister);
}
-
+
void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString dataFormat)
{
if (dataFormat == ".fits") dataType = DATA_FITS;
else if (dataFormat == ".stream") dataType = DATA_STREAM;
- else if (dataFormat == ".ccdpreview") dataType = DATA_CCDPREVIEW;
+ else if (dataFormat == ".ccdpreview") dataType = DATA_CCDPREVIEW;
else dataType = DATA_OTHER;
if (dataType == DATA_STREAM)
{
if (!streamWindow->processStream)
return;
-
- streamWindow->show();
- streamWindow->streamFrame->newFrame( buffer, bufferSize, streamWindow->streamWidth, streamWindow->streamHeight);
+
+ streamWindow->show();
+ streamWindow->streamFrame->newFrame( buffer, bufferSize, streamWindow->streamWidth, streamWindow->streamHeight);
}
else if (dataType == DATA_CCDPREVIEW)
{
if (!CCDPreviewWindow->processStream)
return;
- CCDPreviewWindow->show();
- CCDPreviewWindow->streamFrame->newFrame( buffer, bufferSize, CCDPreviewWindow->streamWidth, CCDPreviewWindow->streamHeight);
+ CCDPreviewWindow->show();
+ CCDPreviewWindow->streamFrame->newFrame( buffer, bufferSize, CCDPreviewWindow->streamWidth, CCDPreviewWindow->streamHeight);
}
else if (dataType == DATA_FITS || dataType == DATA_OTHER)
{
@@ -125,14 +125,14 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
FILE *fitsTempFile;
int fd, nr, n=0;
TQString currentDir = Options::fitsSaveDirectory();
-
+
streamWindow->close();
-
+
if (dataType == DATA_FITS && !batchMode && Options::indiFITSDisplay())
{
strcpy(filename, "/tmp/fitsXXXXXX");
if ((fd = mkstemp(filename)) < 0)
- {
+ {
KMessageBox::error(NULL, "Error making temporary filename.");
return;
}
@@ -145,18 +145,18 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
time_t t;
time (&t);
tp = gmtime (&t);
-
+
if (currentDir[currentDir.length() -1] == '/')
currentDir.truncate(currentDir.length() - 1);
-
+
strncpy(filename, currentDir.ascii(), currentDir.length());
filename[currentDir.length()] = '\0';
-
+
if (dataType == DATA_FITS)
{
char tempFileStr[256];
strncpy(tempFileStr, filename, 256);
-
+
if ( batchMode && !ISOMode)
snprintf(filename, sizeof(filename), "%s/%s_%02d.fits", tempFileStr, seqPrefix.ascii(), setCount);
else if (!batchMode && !Options::indiFITSDisplay())
@@ -169,7 +169,7 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
strftime (ts, sizeof(ts), "%Y-%m-%dT%H:%M:%S", tp);
snprintf(filename, sizeof(filename), "%s/%s_%02d_%s.fits", tempFileStr, seqPrefix.ascii(), setCount, ts);
}
-
+
setCount++;
}
else
@@ -179,16 +179,16 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
strncat(filename, dataFormat.ascii(), 10);
}
}
-
+
fitsTempFile = fopen(filename, "w");
-
+
if (fitsTempFile == NULL) return;
-
+
for (nr=0; nr < (int) bufferSize; nr += n)
n = fwrite( ((unsigned char *) buffer) + nr, 1, bufferSize - nr, fitsTempFile);
-
+
fclose(fitsTempFile);
-
+
// We're done if we have DATA_OTHER
if (dataType == DATA_OTHER)
{
@@ -200,15 +200,15 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
ksw->statusBar()->changeItem( i18n("FITS file saved to %1").arg(filename), 0);
emit FITSReceived(dp->label);
return;
- }
-
+ }
+
KURL fileURL(filename);
-
+
FITSViewer * fv = new FITSViewer(&fileURL, ksw);
fv->fitsChange();
fv->show();
}
-
+
}
/* Process standard Text and Number properties arrives from the driver */
@@ -222,44 +222,44 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
ExtDate indiDate;
TQTime indiTime;
KStarsDateTime indiDateTime;
-
+
switch (pp->stdID)
{
case TIME:
if ( Options::indiAutoTime() )
handleDevCounter();
-
+
// Update KStars time once we receive update from INDI
el = pp->findElement("UTC");
if (!el) return;
-
+
sscanf(el->text.ascii(), "%d%*[^0-9]%d%*[^0-9]%dT%d%*[^0-9]%d%*[^0-9]%d", &y, &m, &d, &hour, &min, &sec);
indiDate.setYMD(y, m, d);
indiTime.setHMS(hour, min, sec);
indiDateTime.setDate(indiDate);
indiDateTime.setTime(indiTime);
-
+
ksw->data()->changeDateTime(indiDateTime);
ksw->data()->syncLST();
-
+
break;
-
+
case SDTIME:
if ( Options::indiAutoTime())
handleDevCounter();
break;
-
+
case GEOGRAPHIC_COORD:
if ( Options::indiAutoGeo() )
handleDevCounter();
break;
-
+
case CCD_EXPOSE_DURATION:
if (pp->state == PS_IDLE || pp->state == PS_OK)
pp->set_w->setText(i18n("Start"));
break;
-
+
case CCD_FRAME:
el = pp->findElement("WIDTH");
if (!el) return;
@@ -267,11 +267,11 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
el = pp->findElement("HEIGHT");
if (!el) return;
ht = (int) el->value;
-
+
streamWindow->setSize(wd, ht);
//streamWindow->allocateStreamBuffer();
break;
- case CCDPREVIEW_CTRL:
+ case CCDPREVIEW_CTRL:
el = pp->findElement("WIDTH");
if (!el) return;
wd = (int) el->value;
@@ -283,12 +283,12 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
bo = (int) el->value;
el = pp->findElement("BYTESPERPIXEL");
if (!el) return;
- bpp = (int) el->value;
+ bpp = (int) el->value;
el = pp->findElement("MAXGOODDATA");
if (!el) return;
mgd = (long) el->value;
CCDPreviewWindow->setCtrl(wd, ht, bo ,bpp,mgd);
-
+
break;
case CCD_INFO:
@@ -311,10 +311,10 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
if (!el) return;
telescopeSkyObject->setDec(el->value);
telescopeSkyObject->EquatorialToHorizontal(ksw->LST(), ksw->geo()->lat());
- // Force immediate update of skymap if the focus object is our telescope.
+ // Force immediate update of skymap if the focus object is our telescope.
if (ksw->map()->focusObject() == telescopeSkyObject)
ksw->map()->updateFocus();
- else
+ else
ksw->map()->update();
break;
@@ -327,7 +327,7 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
if (!el) return;
telescopeSkyObject->setAz(el->value);
telescopeSkyObject->HorizontalToEquatorial(ksw->LST(), ksw->geo()->lat());
- // Force immediate update of skymap if the focus object is our telescope.
+ // Force immediate update of skymap if the focus object is our telescope.
if (ksw->map()->focusObject() == telescopeSkyObject)
ksw->map()->updateFocus();
else
@@ -336,9 +336,9 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
default:
break;
-
+
}
-
+
}
void INDIStdDevice::setLabelState(INDI_P *pp)
@@ -348,13 +348,13 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
TDEAction *tmpAction;
INDIDriver *drivers = ksw->getINDIDriver();
TQFont buttonFont;
-
+
switch (pp->stdID)
{
case CONNECTION:
lp = pp->findElement("CONNECT");
if (!lp) return;
-
+
if (lp->state == PS_ON)
{
initDeviceOptions();
@@ -378,10 +378,10 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
//dp->parentMgr->sNotifier->disconnect();
streamWindow->enableStream(false);
streamWindow->close();
-
+
//close(streamFD);
}
-
+
if (ksw->map()->focusObject() == telescopeSkyObject)
{
ksw->map()->stopTracking();
@@ -393,7 +393,7 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
emit linkRejected();
}
break;
-
+
case VIDEO_STREAM:
lp = pp->findElement("ON");
if (!lp) return;
@@ -402,7 +402,7 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
else
streamWindow->enableStream(false);
break;
-
+
case CCDPREVIEW_STREAM:
lp = pp->findElement("ON");
if (!lp) return;
@@ -411,101 +411,101 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
else
CCDPreviewWindow->enableStream(false);
break;
-
+
default:
break;
}
-
+
}
void INDIStdDevice::streamDisabled()
{
INDI_P *pp;
INDI_E *el;
-
+
//pp = dp->findProp("CONNECTION");
//if (!pp) return;
//if (pp->state == PS_OFF) return;
-
+
pp = dp->findProp("VIDEO_STREAM");
if (!pp) return;
-
+
el = pp->findElement("OFF");
if (!el) return;
-
+
if (el->state == PS_ON)
return;
-
+
// Turn stream off
- pp->newSwitch(1);
-
+ pp->newSwitch(1);
+
}
-
+
void INDIStdDevice::updateSequencePrefix(TQString newPrefix)
{
seqPrefix = newPrefix;
-
+
seqLister->setNameFilter(TQString("%1_*.fits").arg(seqPrefix));
-
+
setCount = 0;
-
+
if (ISOMode) return;
-
+
seqLister->openURL(Options::fitsSaveDirectory());
-
+
checkSeqBoundary(seqLister->items());
-
+
}
-
+
void INDIStdDevice::checkSeqBoundary(const KFileItemList & items)
{
int newFileIndex;
TQString tempName;
char *tempPrefix = new char[64];
-
+
// No need to check when in ISO mode
if (ISOMode)
return;
-
+
for ( KFileItemListIterator it( items ) ; it.current() ; ++it )
{
tempName = it.current()->name();
-
+
// find the prefix first
if (tempName.find(seqPrefix) == -1)
continue;
-
+
strncpy(tempPrefix, tempName.ascii(), 64);
tempPrefix[63] = '\0';
-
+
char * t = tempPrefix;
-
+
// skip chars
while (*t) { if (isdigit(*t)) break; t++; }
//tempPrefix = t;
-
+
newFileIndex = strtol(t, NULL, 10);
-
+
if (newFileIndex >= setCount)
setCount = newFileIndex + 1;
}
-
+
delete [] (tempPrefix);
-
+
}
-
+
void INDIStdDevice::updateTime()
{
INDI_P *pp;
INDI_E *lp;
-
+
pp = dp->findProp("TIME");
if (!pp) return;
-
+
lp = pp->findElement("UTC");
-
+
if (!lp) return;
-
+
TQTime newTime( ksw->data()->ut().time());
ExtDate newDate( ksw->data()->ut().date());
@@ -513,12 +513,12 @@ void INDIStdDevice::handleBLOB(unsigned char *buffer, int bufferSize, TQString d
.arg(newDate.day()).arg(newTime.hour())
.arg(newTime.minute()).arg(newTime.second()));
pp->newText();
-
+
pp = dp->findProp("SDTIME");
if (!pp) return;
lp = pp->findElement("LST");
if (!lp) return;
-
+
lp->write_w->setText(ksw->LST()->toHMSString());
pp->newText();
}
@@ -531,7 +531,7 @@ void INDIStdDevice::updateLocation()
pp = dp->findProp("GEOGRAPHIC_COORD");
if (!pp) return;
-
+
dms tempLong (geo->lng()->degree(), geo->lng()->arcmin(), geo->lng()->arcsec());
dms fullCir(360,0,0);
@@ -542,26 +542,26 @@ void INDIStdDevice::updateLocation()
if (!latEle) return;
longEle = pp->findElement("LONG");
if (!longEle) return;
-
+
longEle->write_w->setText(TQString("%1:%2:%3").arg(tempLong.degree()).arg(tempLong.arcmin()).arg(tempLong.arcsec()));
latEle->write_w->setText(TQString("%1:%2:%3").arg(geo->lat()->degree()).arg(geo->lat()->arcmin()).arg(geo->lat()->arcsec()));
-
+
pp->newText();
}
-
+
void INDIStdDevice::registerProperty(INDI_P *pp)
{
INDI_E * portEle;
INDIDriver *drivers = ksw->getINDIDriver();
TQString str;
-
+
switch (pp->stdID)
{
case DEVICE_PORT:
portEle = pp->findElement("PORT");
if (!portEle) return;
-
+
if (drivers)
{
for (unsigned int i=0; i < drivers->devices.size(); i++)
@@ -583,14 +583,14 @@ void INDIStdDevice::updateLocation()
break;
}
}
- }
+ }
}
break;
-
+
}
-
+
}
-
+
void INDIStdDevice::initDeviceOptions()
{
@@ -678,7 +678,7 @@ bool INDIStdDevice::handleNonSidereal()
{
prop->newSwitch(i);
setMode->newSwitch(trackIndex);
-
+
/* Send object name if available */
nameEle = dp->findElem("OBJECT_NAME");
if (nameEle && nameEle->pp->perm != PP_RO)
@@ -693,7 +693,7 @@ bool INDIStdDevice::handleNonSidereal()
kdDebug() << "Device doesn't support SOLAR_SYSTEM property, issuing a timer" << endl;
kdDebug() << "Starting timer for object of type " << currentObject->typeName() << endl;
-
+
switch (currentObject->type())
{
@@ -735,21 +735,21 @@ void INDIStdDevice::timerDone()
el = prop->findElement("TRACK");
if (!el) return;
-
+
if (el->state != PS_ON)
{
devTimer->stop();
return;
}
-
+
prop = dp->findProp("EQUATORIAL_EOD_COORD");
-
+
if (prop == NULL)
{
prop = dp->findProp("EQUATORIAL_COORD");
if (prop) useJ2000 = true;
}
-
+
if (prop == NULL || !currentObject)
return;
@@ -760,7 +760,7 @@ void INDIStdDevice::timerDone()
kdDebug() << "Timer called, starting processing" << endl;
SkyPoint sp(currentObject->ra(), currentObject->dec());
-
+
kdDebug() << "RA: " << currentObject->ra()->toHMSString() << " - DEC: " << currentObject->dec()->toDMSString() << endl;
kdDebug() << "Az: " << currentObject->az()->toHMSString() << " - Alt " << currentObject->alt()->toDMSString() << endl;
@@ -778,7 +778,7 @@ void INDIStdDevice::timerDone()
if (!RAEle) return;
DecEle = prop->findElement("DEC");
if (!DecEle) return;
-
+
RAEle->write_w->setText(TQString("%1:%2:%3").arg(sp.ra()->hour())
.arg(sp.ra()->minute())
.arg(sp.ra()->second()));
@@ -795,29 +795,29 @@ INDIStdProperty::INDIStdProperty(INDI_P *associatedProperty, KStars * kswPtr, IN
ksw = kswPtr;
stdDev = stdDevPtr;
}
-
- INDIStdProperty::~INDIStdProperty()
+
+ INDIStdProperty::~INDIStdProperty()
{
-
+
}
-
+
void INDIStdProperty::newText()
{
INDI_E *lp;
INDIDriver *drivers = ksw->getINDIDriver();
-
+
switch (pp->stdID)
{
/* Set expose duration button to 'cancel' when busy */
case CCD_EXPOSE_DURATION:
pp->set_w->setText(i18n("Cancel"));
break;
-
+
/* Save Port name in KStars options */
case DEVICE_PORT:
lp = pp->findElement("PORT");
-
- if (lp && drivers)
+
+ if (lp && drivers)
{
for (unsigned int i=0; i < drivers->devices.size(); i++)
{
@@ -837,21 +837,21 @@ INDIStdProperty::INDIStdProperty(INDI_P *associatedProperty, KStars * kswPtr, IN
}
}
}
-
+
break;
}
-
+
}
-
+
bool INDIStdProperty::convertSwitch(int switchIndex, INDI_E *lp)
{
-
+
INDI_E *RAEle(NULL), *DecEle(NULL), *AzEle(NULL), *AltEle(NULL), *nameEle(NULL);
INDI_P * prop;
SkyPoint sp;
- int selectedCoord=0; /* 0 for Equatorial, 1 forQt::Horizontal */
+ int selectedCoord=0; /* 0 for Equatorial, 1 for Horizontal */
bool useJ2000 (false);
-
+
switch (pp->stdID)
{
/* Handle Slew/Track/Sync */
@@ -889,7 +889,7 @@ INDIStdProperty::INDIStdProperty(INDI_P *associatedProperty, KStars * kswPtr, IN
if (!DecEle) return false;
break;
- //Qt::Horizontal
+ // Horizontal
case 1:
if (prop->perm == PP_RO) return false;
AzEle = prop->findElement("AZ");
@@ -898,7 +898,7 @@ INDIStdProperty::INDIStdProperty(INDI_P *associatedProperty, KStars * kswPtr, IN
if (!AltEle) return false;
break;
}
-
+
stdDev->currentObject = ksw->map()->clickedObject();
// Track is similar to slew, except that for non-sidereal objects
// it tracks the objects automatically via a timer.
@@ -953,10 +953,10 @@ INDIStdProperty::INDIStdProperty(INDI_P *associatedProperty, KStars * kswPtr, IN
pp->newSwitch(switchIndex);
prop->newText();
-
+
return true;
break;
-
+
/* Handle Abort */
case ABORT_MOTION:
kdDebug() << "Stopping timer." << endl;
@@ -964,33 +964,33 @@ INDIStdProperty::INDIStdProperty(INDI_P *associatedProperty, KStars * kswPtr, IN
pp->newSwitch(switchIndex);
return true;
break;
-
+
case MOVEMENT:
pp->newSwitch(switchIndex);
break;
-
+
default:
return false;
break;
}
-
+
return false;
-
+
}
-
+
// Return true if the complete operation is done here, or false if the operation is to be completed in the properties newSwitch()
bool INDIStdProperty::newSwitch(int id, INDI_E* el)
{
INDI_P *prop;
- el=el;
+ el=el;
switch (pp->stdID)
{
- case CONNECTION:
+ case CONNECTION:
if (id == 1)
stdDev->streamDisabled();
else
- {
+ {
prop = pp->pg->dp->findProp("DEVICE_PORT");
if (prop)
prop->newText();
@@ -1005,7 +1005,7 @@ bool INDIStdProperty::newSwitch(int id, INDI_E* el)
default:
break;
}
-
+
return false;
}
@@ -1014,10 +1014,10 @@ void INDIStdProperty::newTime()
{
INDI_E * timeEle;
INDI_P *SDProp;
-
+
timeEle = pp->findElement("UTC");
if (!timeEle) return;
-
+
TimeDialog timedialog ( ksw->data()->ut(), ksw );
if ( timedialog.exec() == TQDialog::Accepted )
@@ -1032,12 +1032,12 @@ void INDIStdProperty::newTime()
pp->newText();
}
else return;
-
+
SDProp = pp->pg->dp->findProp("SDTIME");
if (!SDProp) return;
timeEle = SDProp->findElement("LST");
if (!timeEle) return;
-
+
timeEle->write_w->setText(ksw->LST()->toHMSString());
SDProp->newText();
}