From: Michal Sojka Date: Thu, 9 Nov 2006 16:56:43 +0000 (+0100) Subject: Initial import. X-Git-Url: http://rtime.felk.cvut.cz/gitweb/sojka/tekpic.git/commitdiff_plain/80cf1f70e42f1989381bb287a925c4685a70d246 Initial import. darcs-hash:20061109165643-f2ef6-1206dad5960f0cd36ceef9e159e4774be8b8fc59.gz --- 80cf1f70e42f1989381bb287a925c4685a70d246 diff --git a/README b/README new file mode 100644 index 0000000..183a111 --- /dev/null +++ b/README @@ -0,0 +1,18 @@ +This is a very stupid QT4 based program that is able to read pictures +from Tektronix oscilloscope through serial line. Currently, there are +no configuration options. The configuration is hardcoded in sources +and is: + +Serial line: /dev/ttyS0 +Speed: 19200 +No handshake +Image format: TIFF + +The osciloscope must be setup to the same format. + +If you want the program to display images and copy them to clipboard +automatically, TIFF image plugin for QT must be installed. There is +one available at http://artis.imag.fr/Software/TiffIO/. + + +Author: Michal Sojka diff --git a/src/main.ui b/src/main.ui new file mode 100644 index 0000000..8944c4e --- /dev/null +++ b/src/main.ui @@ -0,0 +1,146 @@ + + MainWin + + + + 0 + 0 + 430 + 352 + + + + TekPic + + + + 9 + + + 6 + + + + + 0 + + + 6 + + + + + + 5 + 5 + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + + + + + 24 + + + Qt::Horizontal + + + + + + + + + 0 + + + 6 + + + + + &File name prefix: + + + prefixLine + + + + + + + + 1 + 0 + 0 + 0 + + + + osc- + + + + + + + Full file &name: + + + fileLine + + + + + + + + + + Qt::Vertical + + + + 201 + 71 + + + + + + + + &Save + + + + + + + &Quit + + + + + + + + + + QScrollArea + QFrame +
QScrollArea
+
+
+ + +
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp new file mode 100644 index 0000000..6895675 --- /dev/null +++ b/src/mainwindow.cpp @@ -0,0 +1,99 @@ +/*************************************************************************** + * Copyright (C) 2006 by Michal Sojka * + * sojkam1@fel.cvut.cz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "mainwindow.h" +#include +#include +#include +#include + +MainWindow::MainWindow(const string &tty) + : QDialog(), m_commThread(tty), m_fileNum(0), m_image() +{ + ui.setupUi(this); + + imageLabel = new QLabel; + ui.scrollArea->setWidget(imageLabel); + ui.progressBar->setValue(0); + ui.progressBar->setMaximum(15000); + ui.saveButton->setDisabled(true); + + connect(ui.quitButton, SIGNAL(clicked()), this, SLOT(close())); + connect(&m_commThread, SIGNAL(bytesReceived(int)), ui.progressBar, SLOT(setValue(int))); + connect(&m_commThread, SIGNAL(imageAvailable(OscImage*)), this, SLOT(processImage(OscImage*))); + connect(ui.prefixLine, SIGNAL(textChanged(const QString&)), this, SLOT(generateFileName(const QString&))); + connect(ui.saveButton, SIGNAL(clicked()), this, SLOT(saveImage())); + + m_commThread.start(); +} + + +MainWindow::~MainWindow() +{ +} + +void MainWindow::processImage( OscImage * img ) +{ + bool ret; + ui.saveButton->setEnabled(true); + ui.progressBar->setMaximum(img->size()); + ui.progressBar->setValue(img->size()); + ui.progressBar->update(); + + m_fileNum++; + generateFileName( ui.prefixLine->text()); + + if (m_image) delete m_image; + m_image = img; + + QPixmap pixmap; + ret = pixmap.loadFromData(*m_image); + if (!ret) cerr << "Can't display image!"<setPixmap(pixmap); + imageLabel->setPixmap(pixmap); + imageLabel->adjustSize(); +} + + + +void MainWindow::resetFileCounter( ) +{ + m_fileNum = 0; +} + +void MainWindow::generateFileName( const QString & prefix ) +{ + QString fname; + QTextStream ts(&fname); + + ts.setFieldWidth(3); + ts.setPadChar('0') ; + ts << prefix << m_fileNum << ".tif"; + ui.fileLine->setText(fname); +} + +void MainWindow::saveImage() +{ + QFile file(ui.fileLine->text()); + QDataStream ds(&file); + + file.open(QIODevice::WriteOnly); + ds.writeRawData(m_image->data(), m_image->size()); + file.close(); +} diff --git a/src/mainwindow.h b/src/mainwindow.h new file mode 100644 index 0000000..0d42c6f --- /dev/null +++ b/src/mainwindow.h @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (C) 2006 by Michal Sojka * + * sojkam1@fel.cvut.cz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include "ui_main.h" +#include "osccommthread.h" +#include +#include "mainwindow.h" + +using namespace std; +/** + @author Michal Sojka +*/ +class MainWindow : public QDialog +{ + Q_OBJECT +public: + MainWindow(const string &tty); + + ~MainWindow(); +private: + Ui::MainWin ui; + OscCommThread m_commThread; + int m_fileNum; + OscImage *m_image; + QLabel *imageLabel; +private slots: + void processImage(OscImage *img); + void saveImage(); + void resetFileCounter(); + void generateFileName(const QString& prefix); + +}; + +#endif diff --git a/src/osccommthread.cpp b/src/osccommthread.cpp new file mode 100644 index 0000000..e1056d2 --- /dev/null +++ b/src/osccommthread.cpp @@ -0,0 +1,123 @@ +/*************************************************************************** + * Copyright (C) 2006 by Michal Sojka * + * sojkam1@fel.cvut.cz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "osccommthread.h" +#include +#include +#include +#include +#include +#include +using namespace std; + +ostream& operator<<(ostream& s, OscImage& im) +{ + int i; + ios::fmtflags f; + + s << "Size: " << im.size() << " Data " << (void *)im.data() << ": "; + f = s.flags(); + s << hex; + for (i=0; i<(im.size() > 32 ? 32 : im.size()); i++) + s << setw(2) << setfill('0') << (unsigned int)(unsigned char)im.at(i) << ' '; + s.flags(f); + if (im.size() >= i) s << "..."; + return s; +} + +OscCommThread::OscCommThread( const string &tty) +{ + m_fd = open(tty.c_str(), O_RDWR); + if (m_fd<0) { + perror(tty.c_str()); + exit(1); + } + m_img = new OscImage; + + struct termios ts; + + /* Flush input and output queues. */ + if (tcflush(m_fd, TCIOFLUSH) != 0) { + cerr << "Error in tcflush" << endl; + exit(1); + } + + /* Fetch the current terminal parameters. */ + if (tcgetattr(m_fd, &ts) != 0) { + cerr << "Error in tcfgetattr" << endl; + exit(1); + } + + /* Sets hardware control flags: */ + /* 8 data bits */ + /* Enable receiver */ + /* Ignore CD (local connection) */ + ts.c_cflag = CS8 | CREAD | CLOCAL; + //ts.c_cflag |= CRTSCTS; /* CCTS_OFLOW | CRTS_IFLOW */ + ts.c_iflag = 0; + ts.c_oflag = NL0 | CR0 | TAB0 | BS0 | VT0 | FF0; + ts.c_lflag = 0; + + cfsetispeed (&ts, B19200); + cfsetospeed (&ts, B19200); + + /* Sets the new terminal parameters. */ + if (tcsetattr(m_fd, TCSANOW, &ts) != 0) { + cerr << "Error in tcsetattr" << endl; + exit(1); + } +} + + +OscCommThread::~OscCommThread() +{} + +/*! + \fn OscCommThread::run() + */ +void OscCommThread::run() +{ + char buf[100]; + int n; + struct pollfd pfd; + int ret; + + pfd.fd = m_fd; + pfd.events = POLLIN; + + while (1) { + ret = poll(&pfd, 1, 1000/*ms*/); + if (ret>0) { + n = read(m_fd, buf, sizeof(buf)-1); + QByteArray ba = QByteArray::fromRawData(buf, n); + m_img->append(ba); + bytesReceived( m_img->size() ); + } else if (ret==0) { + if (m_img->size()) { + processImage(); + } + } + } +} + +void OscCommThread::processImage() +{ + imageAvailable( m_img ); + m_img = new OscImage; +} diff --git a/src/osccommthread.h b/src/osccommthread.h new file mode 100644 index 0000000..4ab2a1a --- /dev/null +++ b/src/osccommthread.h @@ -0,0 +1,68 @@ +/*************************************************************************** + * Copyright (C) 2006 by Michal Sojka * + * sojkam1@fel.cvut.cz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef OSCCOMMTHREAD_H +#define OSCCOMMTHREAD_H + +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +class OscImage : public QByteArray +{ +public: + OscImage() + { +// cout << "Img created" << (void*)this->data() << endl; + reserve(1000); + } + virtual ~OscImage() { +// cout << "Img destroyed" << this << endl; + } +}; + +ostream& operator<<(ostream& s, OscImage& im); + + +/** + @author Michal Sojka +*/ +class OscCommThread : public QThread +{ + Q_OBJECT +public: + OscCommThread(const string &tty); + ~OscCommThread(); +private: + int m_fd; + OscImage *m_img; + + void run(); + void processImage(); +signals: + void imageAvailable(OscImage *img); + void bytesReceived(int bytes); +}; + +#endif diff --git a/src/serial.cpp b/src/serial.cpp new file mode 100644 index 0000000..81bdb58 --- /dev/null +++ b/src/serial.cpp @@ -0,0 +1,34 @@ +/*************************************************************************** + * Copyright (C) 2006 by Michal Sojka * + * sojkam1@fel.cvut.cz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "serial.h" + +Serial::Serial(QObject *parent) + : QIODevice(parent) +{ +} + + +Serial::~Serial() +{ +} + + + + diff --git a/src/serial.h b/src/serial.h new file mode 100644 index 0000000..bb5f48f --- /dev/null +++ b/src/serial.h @@ -0,0 +1,38 @@ +/*************************************************************************** + * Copyright (C) 2006 by Michal Sojka * + * sojkam1@fel.cvut.cz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef SERIAL_H +#define SERIAL_H + +#include + +/** + @author Michal Sojka +*/ +class Serial : public QIODevice +{ +Q_OBJECT +public: + Serial(QObject *parent = 0); + + ~Serial(); + +}; + +#endif diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 0000000..e8b107f --- /dev/null +++ b/src/src.pro @@ -0,0 +1,17 @@ +# File generated by kdevelop's qmake manager. +# ------------------------------------------- +# Subdir relative project main directory: ./src +# Target is an application: ../bin/tekpic + +TARGET = ../bin/tekpic +CONFIG += debug \ + warn_on +TEMPLATE = app +FORMS += main.ui +HEADERS += mainwindow.h \ + serial.h \ + osccommthread.h +SOURCES += tekpic.cpp \ + mainwindow.cpp \ + serial.cpp \ + osccommthread.cpp diff --git a/src/tekpic.cpp b/src/tekpic.cpp new file mode 100644 index 0000000..008da2f --- /dev/null +++ b/src/tekpic.cpp @@ -0,0 +1,38 @@ +/*************************************************************************** + * Copyright (C) 2006 by Michal Sojka * + * sojkam1@fel.cvut.cz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow *window = new MainWindow(string("/dev/ttyS0")); + + window->show(); + return app.exec(); +} diff --git a/tekpic.pro b/tekpic.pro new file mode 100644 index 0000000..8feb4aa --- /dev/null +++ b/tekpic.pro @@ -0,0 +1,2 @@ +TEMPLATE=subdirs +SUBDIRS=src diff --git a/templates/cpp b/templates/cpp new file mode 100644 index 0000000..7eb98e9 --- /dev/null +++ b/templates/cpp @@ -0,0 +1,19 @@ +/*************************************************************************** + * Copyright (C) 2006 by Michal Sojka * + * sojkam1@fel.cvut.cz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ diff --git a/templates/h b/templates/h new file mode 100644 index 0000000..7eb98e9 --- /dev/null +++ b/templates/h @@ -0,0 +1,19 @@ +/*************************************************************************** + * Copyright (C) 2006 by Michal Sojka * + * sojkam1@fel.cvut.cz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/