1 /***************************************************************************
2 * Copyright (C) 2006 by Michal Sojka *
3 * sojkam1@fel.cvut.cz *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #include "osccommthread.h"
29 ostream& operator<<(ostream& s, OscImage& im)
34 s << "Size: " << im.size() << " Data " << (void *)im.data() << ": ";
37 for (i=0; i<(im.size() > 32 ? 32 : im.size()); i++)
38 s << setw(2) << setfill('0') << (unsigned int)(unsigned char)im.at(i) << ' ';
40 if (im.size() >= i) s << "...";
44 OscCommThread::OscCommThread( const string &tty)
46 m_fd = open(tty.c_str(), O_RDWR);
55 /* Flush input and output queues. */
56 if (tcflush(m_fd, TCIOFLUSH) != 0) {
57 cerr << "Error in tcflush" << endl;
61 /* Fetch the current terminal parameters. */
62 if (tcgetattr(m_fd, &ts) != 0) {
63 cerr << "Error in tcfgetattr" << endl;
67 /* Sets hardware control flags: */
70 /* Ignore CD (local connection) */
71 ts.c_cflag = CS8 | CREAD | CLOCAL;
72 //ts.c_cflag |= CRTSCTS; /* CCTS_OFLOW | CRTS_IFLOW */
74 ts.c_oflag = NL0 | CR0 | TAB0 | BS0 | VT0 | FF0;
77 cfsetispeed (&ts, B19200);
78 cfsetospeed (&ts, B19200);
80 /* Sets the new terminal parameters. */
81 if (tcsetattr(m_fd, TCSANOW, &ts) != 0) {
82 cerr << "Error in tcsetattr" << endl;
88 OscCommThread::~OscCommThread()
92 \fn OscCommThread::run()
94 void OscCommThread::run()
105 ret = poll(&pfd, 1, 1000/*ms*/);
107 if (m_img->size() == 0) newImage();
108 n = read(m_fd, buf, sizeof(buf)-1);
109 QByteArray ba = QByteArray::fromRawData(buf, n);
111 bytesReceived( m_img->size() );
120 void OscCommThread::processImage()
122 imageAvailable( m_img );
123 m_img = new OscImage;