2
The stellarium telescope library helps building
3
telescope server programs, that can communicate with stellarium
4
by means of the stellarium TCP telescope protocol.
5
It also contains smaple server classes (dummy, Meade LX200).
7
Author and Copyright of this file and of the stellarium telescope library:
8
Johannes Gajdosik, 2006, modified for NexStar telescopes by Michael Heinz.
10
This library is free software; you can redistribute it and/or
11
modify it under the terms of the GNU Lesser General Public
12
License as published by the Free Software Foundation; either
13
version 2.1 of the License, or (at your option) any later version.
15
This library is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
Lesser General Public License for more details.
20
You should have received a copy of the GNU Lesser General Public
21
License along with this library; if not, write to the Free Software
22
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25
#include "NexStarConnection.hpp"
26
#include "NexStarCommand.hpp"
27
#include "TelescopeClientDirectNexStar.hpp"
28
#include "LogFile.hpp"
33
NexStarConnection::NexStarConnection(Server &server, const char *serial_device) : SerialPort(server, serial_device)
37
void NexStarConnection::resetCommunication(void)
39
while (!command_list.empty())
41
delete command_list.front();
42
command_list.pop_front();
45
read_buff_end = read_buff;
46
write_buff_end = write_buff;
48
*log_file << Now() << "NexStarConnection::resetCommunication" << endl;
52
void NexStarConnection::sendGoto(unsigned int ra_int, int dec_int)
54
sendCommand(new NexStarCommandGotoPosition(server, ra_int, dec_int));
57
void NexStarConnection::dataReceived(const char *&p,const char *read_buff_end)
61
*log_file << Now() << "NexStarConnection::dataReceived: strange: fd is closed" << endl;
63
else if (command_list.empty())
66
*log_file << Now() << "NexStarConnection::dataReceived: "
67
"error: command_list is empty" << endl;
70
static_cast<TelescopeClientDirectNexStar*>(&server)->communicationResetReceived();
72
else if (command_list.front()->needsNoAnswer())
74
*log_file << Now() << "NexStarConnection::dataReceived: "
75
"strange: command(" << *command_list.front()
76
<< ") needs no answer" << endl;
82
const int rc=command_list.front()->readAnswerFromBuffer(p, read_buff_end);
83
//*log_file << Now() << "NexStarConnection::dataReceived: "
84
// << *command_list.front() << "->readAnswerFromBuffer returned "
91
static_cast<TelescopeClientDirectNexStar*>(&server)->communicationResetReceived();
95
delete command_list.front();
96
command_list.pop_front();
97
if (command_list.empty())
99
if (!command_list.front()->writeCommandToBuffer(
101
write_buff+sizeof(write_buff)))
107
void NexStarConnection::sendCommand(NexStarCommand *command)
112
*log_file << Now() << "NexStarConnection::sendCommand(" << *command
115
command_list.push_back(command);
116
while (!command_list.front()->hasBeenWrittenToBuffer())
118
if (command_list.front()->writeCommandToBuffer(
120
write_buff+sizeof(write_buff)))
122
//*log_file << Now() << "NexStarConnection::sendCommand: "
123
// << (*command_list.front())
124
// << "::writeCommandToBuffer ok" << endl;
125
if (command_list.front()->needsNoAnswer())
127
delete command_list.front();
128
command_list.pop_front();
129
if (command_list.empty())
139
//*log_file << Now() << "NexStarConnection::sendCommand: "
140
// << (*command_list.front())
141
// << "::writeCommandToBuffer failed" << endl;
145
//*log_file << Now() << "NexStarConnection::sendCommand(" << *command << ") end"