TelescopeClientDirectNexStar.cpp   TelescopeClientDirectNexStar.cpp 
skipping to change at line 36 skipping to change at line 36
#include "TelescopeClientDirectNexStar.hpp" #include "TelescopeClientDirectNexStar.hpp"
#include "NexStarConnection.hpp" #include "NexStarConnection.hpp"
#include "NexStarCommand.hpp" #include "NexStarCommand.hpp"
#include "LogFile.hpp" #include "LogFile.hpp"
#include <QRegExp> #include <QRegExp>
#include <QStringList> #include <QStringList>
TelescopeClientDirectNexStar::TelescopeClientDirectNexStar TelescopeClientDirectNexStar::TelescopeClientDirectNexStar(const QString &n
(const QString &name, const QString &parameters ame, 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 TelescopeClientDirectNexStar: time_delay not valid (should be less than 10000000)"; qWarning() << "ERROR creating TelescopeClientDirectNexStar: time_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
nexstar = new NexStarConnection(*this, qPrintable(serialDeviceName)) ; nexstar = new NexStarConnection(*this, qPrintable(serialDeviceName)) ;
if (nexstar->isClosed()) if (nexstar->isClosed())
{ {
qWarning() << "ERROR creating TelescopeClientDirectNexStar: cannot open serial device" << serialDeviceName; qWarning() << "ERROR creating TelescopeClientDirectNexStar: cannot open serial device" << serialDeviceName;
return; return;
} }
//This connection will be deleted in the destructor of Server //This connection will be deleted in the destructor of Server
addConnection(nexstar); addConnection(nexstar);
last_ra = 0; last_ra = 0;
queue_get_position = true; queue_get_position = true;
next_pos_time = -0x8000000000000000LL; next_pos_time = -0x8000000000000000LL;
} }
//! resets/initializes the array of positions kept for position interpolati //! queues a GOTO command
on. void TelescopeClientDirectNexStar::telescopeGoto(const Vec3d &j2000Pos)
void TelescopeClientDirectNexStar::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 TelescopeClientDirectNexStar::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 TelescopeClientDirectNexStar::gotoReceived(unsigned int ra_int, int de c_int) void TelescopeClientDirectNexStar::gotoReceived(unsigned int ra_int, int de c_int)
{ {
nexstar->sendGoto(ra_int, dec_int); nexstar->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 TelescopeClientDirectNexStar::getJ2000EquatorialPos(const StelNavigat or*) const Vec3d TelescopeClientDirectNexStar::getJ2000EquatorialPos(const StelNavigat or*) 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 TelescopeClientDirectNexStar::prepareCommunication() bool TelescopeClientDirectNexStar::prepareCommunication()
{ {
//TODO: Nothing to prepare? //TODO: Nothing to prepare?
return true; return true;
} }
void TelescopeClientDirectNexStar::performCommunication() void TelescopeClientDirectNexStar::performCommunication()
{ {
skipping to change at line 244 skipping to change at line 207
bool TelescopeClientDirectNexStar::isInitialized(void) const bool TelescopeClientDirectNexStar::isInitialized(void) const
{ {
return (!nexstar->isClosed()); return (!nexstar->isClosed());
} }
//Merged from Connection::sendPosition() and TelescopeTCP::performReading() //Merged from Connection::sendPosition() and TelescopeTCP::performReading()
void TelescopeClientDirectNexStar::sendPosition(unsigned int ra_int, int de c_int, int status) void TelescopeClientDirectNexStar::sendPosition(unsigned int ra_int, int de c_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/