TelescopeClientDirectLx200.cpp   TelescopeClientDirectLx200.cpp 
skipping to change at line 36 skipping to change at line 36
#include "TelescopeClientDirectLx200.hpp" #include "TelescopeClientDirectLx200.hpp"
#include "Lx200Connection.hpp" #include "Lx200Connection.hpp"
#include "Lx200Command.hpp" #include "Lx200Command.hpp"
#include "LogFile.hpp" #include "LogFile.hpp"
#include <QRegExp> #include <QRegExp>
#include <QStringList> #include <QStringList>
TelescopeClientDirectLx200::TelescopeClientDirectLx200 TelescopeClientDirectLx200::TelescopeClientDirectLx200 (const QString &name
(const QString &name, const QString &parameters , const QString &parameters, Equinox eq) :
) : TelescopeClient(name),
TelescopeClient(name), equinox(eq)
end_position(positions + (sizeof(positions)/si
zeof(positions[0])))
{ {
resetPositions(); interpolatedPosition.reset();
//Extract parameters //Extract parameters
//Format: "serial_port_name:time_delay" //Format: "serial_port_name:time_delay"
QRegExp paramRx("^([^:]*):(\\d+)$"); QRegExp paramRx("^([^:]*):(\\d+)$");
QString serialDeviceName; QString serialDeviceName;
if (paramRx.exactMatch(parameters)) if (paramRx.exactMatch(parameters))
{ {
// This QRegExp only matches valid integers // This QRegExp only matches valid integers
serialDeviceName = paramRx.capturedTexts().at(1).trimmed(); serialDeviceName = paramRx.capturedTexts().at(1).trimmed();
time_delay = paramRx.capturedTexts().at(2).toInt(); time_delay = paramRx.capturedTexts().at(2).toInt();
skipping to change at line 72 skipping to change at line 71
if (time_delay <= 0 || time_delay > 10000000) if (time_delay <= 0 || time_delay > 10000000)
{ {
qWarning() << "ERROR creating TelescopeClientDirectLx200: ti me_delay not valid (should be less than 10000000)"; qWarning() << "ERROR creating TelescopeClientDirectLx200: ti me_delay not valid (should be less than 10000000)";
return; return;
} }
//end_of_timeout = -0x8000000000000000LL; //end_of_timeout = -0x8000000000000000LL;
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
if(serialDeviceName.right(serialDeviceName.size() - 3).toInt() > 9) if(serialDeviceName.right(serialDeviceName.size() - 3).toInt() > 9)
serialDeviceName = "\\\\.\\" + serialDeviceName + ":";//"\\. \COMxx", not sure if it will work serialDeviceName = "\\\\.\\" + serialDeviceName;//"\\.\COMxx ", not sure if it will work
else else
serialDeviceName = serialDeviceName + ":"; serialDeviceName = serialDeviceName;
#endif //Q_OS_WIN32 #endif //Q_OS_WIN32
//Try to establish a connection to the telescope //Try to establish a connection to the telescope
lx200 = new Lx200Connection(*this, qPrintable(serialDeviceName)); lx200 = new Lx200Connection(*this, qPrintable(serialDeviceName));
if (lx200->isClosed()) if (lx200->isClosed())
{ {
qWarning() << "ERROR creating TelescopeClientDirectLx200: ca nnot open serial device" << serialDeviceName; qWarning() << "ERROR creating TelescopeClientDirectLx200: ca nnot open serial device" << serialDeviceName;
return; return;
} }
// lx200 will be deleted in the destructor of Server // lx200 will be deleted in the destructor of Server
addConnection(lx200); addConnection(lx200);
long_format_used = false; // unknown long_format_used = false; // unknown
last_ra = 0; last_ra = 0;
queue_get_position = true; queue_get_position = true;
next_pos_time = -0x8000000000000000LL; next_pos_time = -0x8000000000000000LL;
answers_received = false; answers_received = false;
} }
//! resets/initializes the array of positions kept for position interpolati //! queues a GOTO command
on void TelescopeClientDirectLx200::telescopeGoto(const Vec3d &j2000Pos)
void TelescopeClientDirectLx200::resetPositions()
{ {
for (position_pointer = positions; position_pointer < end_position; if (!isConnected())
position_pointer++) return;
Vec3d position = j2000Pos;
if (equinox == EquinoxJNow)
{ {
position_pointer->server_micros = 0x7FFFFFFFFFFFFFFFLL; const StelNavigator* navigator = StelApp::getInstance().getC
position_pointer->client_micros = 0x7FFFFFFFFFFFFFFFLL; ore()->getNavigator();
position_pointer->pos[0] = 0.0; position = navigator->j2000ToEquinoxEqu(j2000Pos);
position_pointer->pos[1] = 0.0;
position_pointer->pos[2] = 0.0;
position_pointer->status = 0;
} }
position_pointer = positions;
}
//! queues a GOTO command with the specified position to the write buffer. //if (writeBufferEnd - writeBuffer + 20 < (int)sizeof(writeBuffer))
//! For the data format of the command see the //TODO: See the else clause, think how to do the same thing
//! "Stellarium telescope control protocol" text file
void TelescopeClientDirectLx200::telescopeGoto(const Vec3d &j2000Pos)
{
if (isConnected())//TODO: See the else clause, think how to do the s
ame thing
{ {
//if (writeBufferEnd - writeBuffer + 20 < (int)sizeof(writeB const double ra_signed = atan2(position[1], position[0]);
uffer)) //Workaround for the discrepancy in precision between Window
{ s/Linux/PPC Macs and Intel Macs:
const double ra_signed = atan2(j2000Pos[1], j2000Pos const double ra = (ra_signed >= 0) ? ra_signed : (ra_signed
[0]); + 2.0 * M_PI);
//Workaround for the discrepancy in precision betwee const double dec = atan2(position[2], sqrt(position[0]*posit
n Windows/Linux/PPC Macs and Intel Macs: ion[0]+position[1]*position[1]));
const double ra = (ra_signed >= 0) ? ra_signed : (ra unsigned int ra_int = (unsigned int)floor(0.5 + ra*(((unsign
_signed + 2.0 * M_PI); ed int)0x80000000)/M_PI));
const double dec = atan2(j2000Pos[2], sqrt(j2000Pos[ int dec_int = (int)floor(0.5 + dec*(((unsigned int)0x8000000
0]*j2000Pos[0]+j2000Pos[1]*j2000Pos[1])); 0)/M_PI));
unsigned int ra_int = (unsigned int)floor(0.5 + ra*(
((unsigned int)0x80000000)/M_PI));
int dec_int = (int)floor(0.5 + dec*(((unsigned int)0
x80000000)/M_PI));
gotoReceived(ra_int, dec_int); gotoReceived(ra_int, dec_int);
} }
/* /*
else else
{ {
qDebug() << "TelescopeTCP(" << name << ")::telescope Goto: "<< "communication is too slow, I will ignore this command"; qDebug() << "TelescopeTCP(" << name << ")::telescope Goto: "<< "communication is too slow, I will ignore this command";
} }
*/ */
}
} }
void TelescopeClientDirectLx200::gotoReceived(unsigned int ra_int, int dec_ int) void TelescopeClientDirectLx200::gotoReceived(unsigned int ra_int, int dec_ int)
{ {
lx200->sendGoto(ra_int, dec_int); lx200->sendGoto(ra_int, dec_int);
} }
//! estimates where the telescope is by interpolation in the stored //! estimates where the telescope is by interpolation in the stored
//! telescope positions: //! telescope positions:
Vec3d TelescopeClientDirectLx200::getJ2000EquatorialPos(const StelNavigator *) const Vec3d TelescopeClientDirectLx200::getJ2000EquatorialPos(const StelNavigator *) const
{ {
if (position_pointer->client_micros == 0x7FFFFFFFFFFFFFFFLL)
{
return Vec3d(0,0,0);
}
const qint64 now = getNow() - time_delay; const qint64 now = getNow() - time_delay;
const Position *p = position_pointer; return interpolatedPosition.get(now);
do
{
const Position *pp = p;
if (pp == positions) pp = end_position;
pp--;
if (pp->client_micros == 0x7FFFFFFFFFFFFFFFLL) break;
if (pp->client_micros <= now && now <= p->client_micros)
{
if (pp->client_micros != p->client_micros)
{
Vec3d rval = p->pos * (now - pp->client_micr
os) + pp->pos * (p->client_micros - now);
double f = rval.lengthSquared();
if (f > 0.0)
{
return (1.0/sqrt(f))*rval;
}
}
break;
}
p = pp;
}
while (p != position_pointer);
return p->pos;
} }
bool TelescopeClientDirectLx200::prepareCommunication() bool TelescopeClientDirectLx200::prepareCommunication()
{ {
//TODO: Nothing to prepare? //TODO: Nothing to prepare?
return true; return true;
} }
void TelescopeClientDirectLx200::performCommunication() void TelescopeClientDirectLx200::performCommunication()
{ {
skipping to change at line 267 skipping to change at line 230
bool TelescopeClientDirectLx200::isInitialized(void) const bool TelescopeClientDirectLx200::isInitialized(void) const
{ {
return (!lx200->isClosed()); return (!lx200->isClosed());
} }
//Merged from Connection::sendPosition() and TelescopeTCP::performReading() //Merged from Connection::sendPosition() and TelescopeTCP::performReading()
void TelescopeClientDirectLx200::sendPosition(unsigned int ra_int, int dec_ int, int status) void TelescopeClientDirectLx200::sendPosition(unsigned int ra_int, int dec_ int, int status)
{ {
//Server time is "now", because this class is the server //Server time is "now", because this class is the server
const qint64 server_micros = (qint64) getNow(); const qint64 server_micros = (qint64) getNow();
// remember the time and received position so that later we
// will know where the telescope is pointing to:
position_pointer++;
if (position_pointer >= end_position)
position_pointer = positions;
position_pointer->server_micros = server_micros;
position_pointer->client_micros = getNow();
const double ra = ra_int * (M_PI/(unsigned int)0x80000000); const double ra = ra_int * (M_PI/(unsigned int)0x80000000);
const double dec = dec_int * (M_PI/(unsigned int)0x80000000); const double dec = dec_int * (M_PI/(unsigned int)0x80000000);
const double cdec = cos(dec); const double cdec = cos(dec);
position_pointer->pos[0] = cos(ra)*cdec; Vec3d position(cos(ra)*cdec, sin(ra)*cdec, sin(dec));
position_pointer->pos[1] = sin(ra)*cdec; Vec3d j2000Position = position;
position_pointer->pos[2] = sin(dec); if (equinox == EquinoxJNow)
position_pointer->status = status; {
const StelNavigator* navigator = StelApp::getInstance().getC
ore()->getNavigator();
j2000Position = navigator->equinoxEquToJ2000(position);
}
interpolatedPosition.add(j2000Position, getNow(), server_micros, sta
tus);
} }
 End of changes. 16 change blocks. 
90 lines changed or deleted 45 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/