SerialPort.cpp   SerialPort.cpp 
/* /*
The stellarium telescope library helps building The stellarium telescope library helps building
telescope server programs, that can communicate with stellarium telescope server programs, that can communicate with stellarium
by means of the stellarium TCP telescope protocol. by means of the stellarium TCP telescope protocol.
It also contains smaple server classes (dummy, Meade LX200). It also contains smaple server classes (dummy, Meade LX200).
Author and Copyright of this file and of the stellarium telescope library: Author and Copyright of this file and of the stellarium telescope library:
Johannes Gajdosik, 2006 Johannes Gajdosik, 2006
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU General Public License
License as published by the Free Software Foundation; either as published by the Free Software Foundation; either version 2
version 2.1 of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Lesser General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU General Public License
License along with this library; if not, write to the Free Software along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA USA.
*/ */
#include "SerialPort.hpp" #include "SerialPort.hpp"
#include "LogFile.hpp" #include "LogFile.hpp"
#ifndef WIN32 #ifndef Q_OS_WIN32
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <string.h> // memset #include <string.h> // memset
using namespace std; using namespace std;
SerialPort::SerialPort(Server &server, const char *serial_device) : Connect ion(server, INVALID_SOCKET) SerialPort::SerialPort(Server &server, const char *serial_device) : Connect ion(server, INVALID_SOCKET)
{ {
#ifdef WIN32 #ifdef Q_OS_WIN32
handle = CreateFile(serial_device, GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); handle = CreateFile(serial_device, GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
if (handle == INVALID_HANDLE_VALUE) if (handle == INVALID_HANDLE_VALUE)
{ {
*log_file << Now() << "SerialPort::SerialPort(" << serial_de vice << "): " *log_file << Now() << "SerialPort::SerialPort(" << serial_de vice << "): "
"CreateFile() failed: " << GetLastErro r() << endl; "CreateFile() failed: " << GetLastErro r() << endl;
} }
else else
{ {
COMMTIMEOUTS timeouts; COMMTIMEOUTS timeouts;
timeouts.ReadIntervalTimeout = MAXDWORD; timeouts.ReadIntervalTimeout = MAXDWORD;
skipping to change at line 141 skipping to change at line 141
else else
{ {
// success // success
return; return;
} }
} }
} }
close(fd); close(fd);
fd = -1; fd = -1;
} }
#endif //WIN32 #endif //Q_OS_WIN32
} }
SerialPort::~SerialPort(void) SerialPort::~SerialPort(void)
{ {
#ifdef WIN32 #ifdef Q_OS_WIN32
if (handle == INVALID_HANDLE_VALUE) if (handle != INVALID_HANDLE_VALUE)
{ {
// restore original settings // restore original settings
SetCommState(handle, &dcb_original); SetCommState(handle, &dcb_original);
CloseHandle(handle); CloseHandle(handle);
} }
#else #else
if (fd >= 0) if (fd >= 0)
{ {
// restore original settings // restore original settings
tcsetattr(fd, TCSANOW, &termios_original); tcsetattr(fd, TCSANOW, &termios_original);
close(fd); close(fd);
} }
#endif #endif
} }
#ifdef WIN32 #ifdef Q_OS_WIN32
int SerialPort::readNonblocking(char *buf, int count) int SerialPort::readNonblocking(char *buf, int count)
{ {
DWORD rval; DWORD rval;
if (ReadFile(handle, buf, count, &rval, 0)) if (ReadFile(handle, buf, count, &rval, 0))
return (int)rval; return (int)rval;
if (GetLastError() == ERROR_IO_PENDING) if (GetLastError() == ERROR_IO_PENDING)
return 0; return 0;
return -1; return -1;
} }
skipping to change at line 191 skipping to change at line 191
return 0; return 0;
return -1; return -1;
} }
#endif #endif
void SerialPort::prepareSelectFds(fd_set &read_fds, void SerialPort::prepareSelectFds(fd_set &read_fds,
fd_set &write_fds, fd_set &write_fds,
int &fd_max) int &fd_max)
{ {
#ifdef WIN32 #ifdef Q_OS_WIN32
// handle all IO here // handle all IO here
if (write_buff_end > write_buff) if (write_buff_end > write_buff)
performWriting(); performWriting();
performReading(); performReading();
#else #else
Connection::prepareSelectFds(read_fds, write_fds, fd_max); Connection::prepareSelectFds(read_fds, write_fds, fd_max);
#endif //WIN32 #endif //Q_OS_WIN32
} }
 End of changes. 10 change blocks. 
17 lines changed or deleted 17 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/