hrs-svn Mailing List for Ham Radio Studio
Status: Inactive
Brought to you by:
csete
You can subscribe to this list here.
2007 |
Jan
(2) |
Feb
(4) |
Mar
(1) |
Apr
(4) |
May
(15) |
Jun
|
Jul
(39) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(23) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(4) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <cs...@us...> - 2008-01-06 00:38:00
|
Revision: 92 http://hrs.svn.sourceforge.net/hrs/?rev=92&view=rev Author: csete Date: 2008-01-05 16:37:58 -0800 (Sat, 05 Jan 2008) Log Message: ----------- Sync Modified Paths: -------------- trunk/src/main.cpp Modified: trunk/src/main.cpp =================================================================== --- trunk/src/main.cpp 2008-01-04 21:53:36 UTC (rev 91) +++ trunk/src/main.cpp 2008-01-06 00:37:58 UTC (rev 92) @@ -30,6 +30,11 @@ { QApplication app(argc, argv); + /* set application settings domain */ + QCoreApplication::setOrganizationName("HRS"); + QCoreApplication::setOrganizationDomain("hrs.sf.net"); + //QCoreApplication::setApplicationName("hrs"); + MainWindow *mainWin = new MainWindow; mainWin->show(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-01-04 21:53:38
|
Revision: 91 http://hrs.svn.sourceforge.net/hrs/?rev=91&view=rev Author: csete Date: 2008-01-04 13:53:36 -0800 (Fri, 04 Jan 2008) Log Message: ----------- Added files. Added Paths: ----------- trunk/src/RadioSelector.cpp trunk/src/RadioSelector.h Added: trunk/src/RadioSelector.cpp =================================================================== --- trunk/src/RadioSelector.cpp (rev 0) +++ trunk/src/RadioSelector.cpp 2008-01-04 21:53:36 UTC (rev 91) @@ -0,0 +1,168 @@ +/*************************************************************************** + * * + * Ham Radio Studio http://hrs.sf.net/ * + * * + * Copyright (C) 2007-2008 by Alexandru Csete OZ9AEC * + * * + * 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 <QtGui> +#include "RadioSelector.h" + + + +RadioSelector::RadioSelector(QWidget *parent) + : QDialog(parent) +{ + QVBoxLayout *layout; + QHBoxLayout *buttons; + QFrame *line; + QDialogButtonBox *butBox; + QLabel *label = new QLabel("Radio Selector"); + + + // create dialog button layout + butBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, + Qt::Horizontal, parent); + connect(butBox, SIGNAL(accepted()), this, SLOT(okClicked())); + connect(butBox, SIGNAL(rejected()), this, SLOT(cancelClicked())); + + // create radio list + createRadioList(); + + // create tool buttons + createToolButtons(); + buttons = new QHBoxLayout; + buttons->addWidget(addButton); + buttons->addWidget(editButton); + buttons->addWidget(deleteButton); + + // horizontal line + line = new QFrame(this); + line->setFrameStyle(QFrame::HLine|QFrame::Sunken); + + // vertical box layout + layout = new QVBoxLayout; + layout->addWidget(radios); + layout->addLayout(buttons); + layout->addWidget(line); + layout->addWidget(butBox); + setLayout(layout); + + setWindowTitle(tr("Select a radio configuration")); +} + + +/*! \brief Create radio list. + * + * This memeber function creates a list showing the available radio + * configurations. + */ +void RadioSelector::createRadioList() +{ + radios = new QTreeWidget; + + radios->setColumnCount(10); + radios->setHeaderLabels(QStringList() << + tr("Name") << tr("Backend") << tr("Company") << tr("Model") << tr("ID") << + tr("Port") << tr("Speed") << tr("CI-V") << tr("DTR") << tr("RTS")); + radios->header()->setResizeMode(QHeaderView::Stretch); + + // make it look like a simple list + radios->setRootIsDecorated(false); +} + +/*! \brief Create tool buttons. + * + * This member function creates the Add, Edit, and Delete tool buttons + * that are located below the list of radio configurations. + */ +void RadioSelector::createToolButtons() +{ + // FIXME: button icons + + addButton = new QPushButton(tr("Add new"), this); + addButton->setToolTip(tr("Add a new radio configuration to the list.")); + + editButton = new QPushButton(tr("Edit"), this); + editButton->setToolTip(tr("Edit the selected radio configuration.")); + + deleteButton = new QPushButton(tr("Delete"), this); + deleteButton->setToolTip(tr("Delete the selected radio configuration.")); +} + + +/*! \brief OK button clicked. + * + * This slot is activated when the user clicks on the OK button. The function + * retrieves the selected radio from the list, emits the radioSelected() + * signal and closes the radio selector dialog. + */ +void RadioSelector::okClicked() +{ + QSettings *conf = new QSettings(); + + emit radioSelected(conf); + + close(); +} + +/*! \brief Cancel button clicked. + * + * This slot is activated when the user clicks on the Cancel button. The + * function closes the radio selector dialog without emitting the + * radioSelected() signal. + * + * \note The main window remains open so that functions other than radio + * control are available. Moreover, the user can always reopen the + * radio selector dialog from the main menubar. + */ +void RadioSelector::cancelClicked() +{ + close(); +} + + +/*! \brief Add a new radio configuration. + * + * This slot is activated when the user clicks on the Add new button. + * A new,empty radio configuration dialog is created. + */ +void RadioSelector::addRadio() +{ +} + + +/*! \brief Edit the selected radio configuration. + * + * This slot is activated when the user clicks on the Edit button. + * A new radio configuration dialog is created with the currently selected + * radio. + */ +void RadioSelector::editRadio() +{ +} + +/*! \brief Delete the selected radio configuration. + * + * This slot is activated when the user clicks on the Delete button. + * The currently selected radio is removed from the list and the corresponding + * configuration file is deleted from the disk. No undo or cancel is possible. + */ +void RadioSelector::deleteRadio() +{ +} Added: trunk/src/RadioSelector.h =================================================================== --- trunk/src/RadioSelector.h (rev 0) +++ trunk/src/RadioSelector.h 2008-01-04 21:53:36 UTC (rev 91) @@ -0,0 +1,72 @@ +/*************************************************************************** + * * + * Ham Radio Studio http://hrs.sf.net/ * + * * + * Copyright (C) 2007-2008 by Alexandru Csete OZ9AEC * + * * + * 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 RADIOSELECTOR_H +#define RADIOSELECTOR_H +#include <QDialog> +#include <QString> +#include <QTreeWidget> +#include <QSettings> + + +/*! \brief The radio selector window + * + * The radio selector window is the first window that shows up when HRS is + * started. It shows a list of configured radios so that the user can + * conveniently select which radio to connect to in this instance of HRS. + * + * The radio selector also allows to edit the existing configurations and to + * add new radio configurations. + */ +class RadioSelector : public QDialog +{ + Q_OBJECT + + public: + RadioSelector(QWidget *parent = 0); + + + signals: + void radioSelected(QSettings *conf); + + private slots: + void okClicked(); + void cancelClicked(); + void addRadio(); + void editRadio(); + void deleteRadio(); + + private: + QPushButton *addButton; + QPushButton *editButton; + QPushButton *deleteButton; + + QTreeWidget *radios; + + void createRadioList(); + void readRadios(); + void createToolButtons(); + + +}; + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-01-04 21:53:13
|
Revision: 90 http://hrs.svn.sourceforge.net/hrs/?rev=90&view=rev Author: csete Date: 2008-01-04 13:53:11 -0800 (Fri, 04 Jan 2008) Log Message: ----------- Work on radio selector Modified Paths: -------------- trunk/src/MainWindow.cpp trunk/src/MainWindow.h trunk/src/main.cpp trunk/src/src.pro Modified: trunk/src/MainWindow.cpp =================================================================== --- trunk/src/MainWindow.cpp 2008-01-03 20:13:18 UTC (rev 89) +++ trunk/src/MainWindow.cpp 2008-01-04 21:53:11 UTC (rev 90) @@ -21,6 +21,7 @@ * * ***************************************************************************/ #include <QtGui> +#include <QtDebug> #include "MainWindow.h" #include "version.h" @@ -55,6 +56,9 @@ //setWindowIcon(QIcon(":/icons/radio.png")); + // restore window state, se also documentation for QWidget::setWindowState + //setWindowState(Qt::WindowMaximized); + //disp = new QFreqDisp(this); //setCentralWidget(disp); @@ -62,14 +66,15 @@ /*! \brief Open a new radio. - * \param RadioConf[in] Radio configuration + * \param rigfile[in] Radio configuration file * * This slot is used to receive notifications when the user requests to * open a new radio. If there already is a radio open it is closed and * the new radio is created and added as central widget to the main window. */ -void MainWindow::openRadio() +void MainWindow::openRadio(QSettings *conf) { + } @@ -150,6 +155,12 @@ } +/*! \brief Main window close event handler. + * \param event[in] TBW + * + * This overrides the closeEvent of the QMainWindow (TBC) + * TBW... + */ void MainWindow::closeEvent(QCloseEvent *event) { //if (okToContinue()) { Modified: trunk/src/MainWindow.h =================================================================== --- trunk/src/MainWindow.h 2008-01-03 20:13:18 UTC (rev 89) +++ trunk/src/MainWindow.h 2008-01-04 21:53:11 UTC (rev 90) @@ -23,6 +23,7 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> +#include <QSettings> /*! \brief The HRS main window @@ -38,7 +39,7 @@ MainWindow(); public slots: - void openRadio(); + void openRadio(QSettings *conf); protected: void closeEvent(QCloseEvent *event); Modified: trunk/src/main.cpp =================================================================== --- trunk/src/main.cpp 2008-01-03 20:13:18 UTC (rev 89) +++ trunk/src/main.cpp 2008-01-04 21:53:11 UTC (rev 90) @@ -21,17 +21,24 @@ * * ***************************************************************************/ #include <QApplication> +#include <QtGui> #include "MainWindow.h" +#include "RadioSelector.h" int main(int argc, char *argv[]) { - QApplication app(argc, argv); + MainWindow *mainWin = new MainWindow; - mainWin->show(); + // Execute radio selector + RadioSelector *sel = new RadioSelector(mainWin); + QObject::connect(sel, SIGNAL(radioSelected(QSettings *)), + mainWin, SLOT(openRadio(QSettings *))); + sel->exec(); + return app.exec(); } Modified: trunk/src/src.pro =================================================================== --- trunk/src/src.pro 2008-01-03 20:13:18 UTC (rev 89) +++ trunk/src/src.pro 2008-01-04 21:53:11 UTC (rev 90) @@ -1,9 +1,11 @@ SOURCES += MainWindow.cpp \ main.cpp \ - QFreqDisp.cpp + QFreqDisp.cpp \ + RadioSelector.cpp HEADERS += MainWindow.h \ QFreqDisp.h \ + RadioSelector.h \ version.h TEMPLATE = app This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2008-01-03 20:13:20
|
Revision: 89 http://hrs.svn.sourceforge.net/hrs/?rev=89&view=rev Author: csete Date: 2008-01-03 12:13:18 -0800 (Thu, 03 Jan 2008) Log Message: ----------- Started finalisation of UI framework. Added doxygen comments for existing classes. Modified Paths: -------------- trunk/src/MainWindow.cpp trunk/src/MainWindow.h trunk/src/QFreqDisp.cpp trunk/src/QFreqDisp.h trunk/src/main.cpp trunk/src/src.pro Added Paths: ----------- trunk/src/version.h Modified: trunk/src/MainWindow.cpp =================================================================== --- trunk/src/MainWindow.cpp 2007-12-29 19:34:48 UTC (rev 88) +++ trunk/src/MainWindow.cpp 2008-01-03 20:13:18 UTC (rev 89) @@ -2,7 +2,7 @@ * * * Ham Radio Studio http://hrs.sf.net/ * * * - * Copyright (C) 2007 by Alexandru Csete OZ9AEC * + * Copyright (C) 2007-2008 by Alexandru Csete OZ9AEC * * * * 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 * @@ -22,31 +22,61 @@ ***************************************************************************/ #include <QtGui> #include "MainWindow.h" -#include "QFreqDisp.h" +#include "version.h" +/*! \brief Default main window constructor. + * + * This is the default constructor for the HRS main window. The contructor + * performs the following actions: + * - Read HRS settings (user settings) + * - Create actions + * - Create the menubar + * - Create the status bar + * - Restore the previous session by recreating the dock widgets + * No central widget is set by the constructor. The central widget contains + * the radio control widgets; however, this is first created later when the + * user has selected a valid radio configuration. The central widget will be + * set by the openRadio() slot. + * + * \sa openRadio() + */ MainWindow::MainWindow() { - QFreqDisp *disp; + //readSettings(); - //spreadsheet = new Spreadsheet; - //setCentralWidget(spreadsheet); createActions(); createMenus(); - //createContextMenu(); + //createToolBars(); //createStatusBar(); - //readSettings(); - //setWindowIcon(QIcon(":/images/icon.png")); + //createContextMenu(); + + //setWindowIcon(QIcon(":/icons/radio.png")); - disp = new QFreqDisp(this); - setCentralWidget(disp); + //disp = new QFreqDisp(this); + //setCentralWidget(disp); } +/*! \brief Open a new radio. + * \param RadioConf[in] Radio configuration + * + * This slot is used to receive notifications when the user requests to + * open a new radio. If there already is a radio open it is closed and + * the new radio is created and added as central widget to the main window. + */ +void MainWindow::openRadio() +{ +} + +/*! \brief Create the menubar entries. + * + * \sa createActions() + */ void MainWindow::createMenus() { fileMenu = menuBar()->addMenu(tr("&File")); @@ -54,8 +84,10 @@ fileMenu->addSeparator(); fileMenu->addAction(exitAction); - menuBar()->addSeparator(); + editMenu = menuBar()->addMenu(tr("&Edit")); + toolsMenu = menuBar()->addMenu(tr("&Tools")); + helpMenu = menuBar()->addMenu(tr("&Help")); helpMenu->addAction(umAction); helpMenu->addSeparator(); @@ -65,8 +97,9 @@ -/** \brief Create menu and toolbar actions +/** \brief Create actions for the menubar and the toolbar. * + * \sa createMenus() */ void MainWindow::createActions() { @@ -90,9 +123,9 @@ umAction->setShortcut(tr("F1")); /* Help -> About */ - aboutAction = new QAction(tr("&About"), this); + aboutAction = new QAction(tr("&About HRS"), this); aboutAction->setIcon(QIcon(":/icon/about.png")); - aboutAction->setStatusTip(tr("Ahow about box")); + aboutAction->setStatusTip(tr("Show information about Ham Radio Studio")); connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); /* Help -> About Qt */ @@ -107,7 +140,7 @@ { QString fileName = QFileDialog::getSaveFileName(this, tr("Save Spreadsheet"), ".", - tr("Spreadsheet files (*.sp)")); + tr("Spreadsheet files (*)")); if (fileName.isEmpty()) return false; @@ -129,12 +162,21 @@ } - +/*! \brief Show About HRS box. */ void MainWindow::about() { QMessageBox::about(this, tr("About HRS"), - tr("<h2>Ham Radio Studio 1.0</h2>" - "<p>Copyright © 2007 Alexandru Csete OZ9AEC." - "<p>Description")); + tr("<h2>Ham Radio Studio (HRS) %1.%2 %3</h2>" + "<p>Copyright © 2007-2008 Alexandru Csete OZ9AEC." + "<p>HRS is a ham radio and rotator control application for " + "Linux, Mac OS X, and Windows." + "<p>HRS is free software licensed under the terms and " + "conditions of the " + "<a href=\"http://www.fsf.org/licensing/licenses/gpl.html\">" + "GNU General Public Licence</a>." + "<p>Ham Radio Studio is avaialble <b>free of charge</b> from " + "<a href=\"http://hrs.sf.net/\">http://hrs.sf.net/</a>" + "<p>Build date: %4 %5") + .arg(HRS_MAJOR_VERSION).arg(HRS_MINOR_VERSION) + .arg(HRS_BETA_STRING).arg(__DATE__).arg(__TIME__)); } - Modified: trunk/src/MainWindow.h =================================================================== --- trunk/src/MainWindow.h 2007-12-29 19:34:48 UTC (rev 88) +++ trunk/src/MainWindow.h 2008-01-03 20:13:18 UTC (rev 89) @@ -2,7 +2,7 @@ * * * Ham Radio Studio http://hrs.sf.net/ * * * - * Copyright (C) 2007 by Alexandru Csete OZ9AEC * + * Copyright (C) 2007-2008 by Alexandru Csete OZ9AEC * * * * 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 * @@ -25,12 +25,20 @@ #include <QMainWindow> - +/*! \brief The HRS main window + * + * The HRS main window is the top level window that comes up when HRS is + * started. It contains a menu bar, the central radio control widget surrounded + * by the optional dock widgets, and a status bar in the bottom of the window. + */ class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(); + + public slots: + void openRadio(); protected: void closeEvent(QCloseEvent *event); @@ -51,16 +59,22 @@ //void writeSettings(); /* File Menu */ - QMenu *fileMenu; - QAction *saveAsAction; - QAction *exitAction; + QMenu *fileMenu; /*!< The File menu. */ + QAction *saveAsAction; /*!< The Save As menu item. */ + QAction *exitAction; /*!< The Exit menu item. */ QAction *separatorAction; + /* Edit Menu */ + QMenu *editMenu; /*!< The Edit menu. */ + + /* Tools Menu */ + QMenu *toolsMenu; /*!< The Tools menu. */ + /* Help menu */ - QMenu *helpMenu; - QAction *umAction; - QAction *aboutAction; - QAction *aboutQtAction; + QMenu *helpMenu; /*!< The Help menu. */ + QAction *umAction; /*!< The User Manual menu item. */ + QAction *aboutAction; /*!< The About HRS menu item. */ + QAction *aboutQtAction; /*!< The About Qt menu item. */ }; Modified: trunk/src/QFreqDisp.cpp =================================================================== --- trunk/src/QFreqDisp.cpp 2007-12-29 19:34:48 UTC (rev 88) +++ trunk/src/QFreqDisp.cpp 2008-01-03 20:13:18 UTC (rev 89) @@ -2,7 +2,7 @@ * * * Ham Radio Studio http://hrs.sf.net/ * * * - * Copyright (C) 2007 by Alexandru Csete OZ9AEC * + * Copyright (C) 2007-2008 by Alexandru Csete OZ9AEC * * * * 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 * Modified: trunk/src/QFreqDisp.h =================================================================== --- trunk/src/QFreqDisp.h 2007-12-29 19:34:48 UTC (rev 88) +++ trunk/src/QFreqDisp.h 2008-01-03 20:13:18 UTC (rev 89) @@ -2,7 +2,7 @@ * * * Ham Radio Studio http://hrs.sf.net/ * * * - * Copyright (C) 2007 by Alexandru Csete OZ9AEC * + * Copyright (C) 2007-2008 by Alexandru Csete OZ9AEC * * * * 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 * Modified: trunk/src/main.cpp =================================================================== --- trunk/src/main.cpp 2007-12-29 19:34:48 UTC (rev 88) +++ trunk/src/main.cpp 2008-01-03 20:13:18 UTC (rev 89) @@ -2,7 +2,7 @@ * * * Ham Radio Studio http://hrs.sf.net/ * * * - * Copyright (C) 2007 by Alexandru Csete OZ9AEC * + * Copyright (C) 2007-2008 by Alexandru Csete OZ9AEC * * * * 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 * Modified: trunk/src/src.pro =================================================================== --- trunk/src/src.pro 2007-12-29 19:34:48 UTC (rev 88) +++ trunk/src/src.pro 2008-01-03 20:13:18 UTC (rev 89) @@ -2,8 +2,9 @@ main.cpp \ QFreqDisp.cpp -HEADERS += MainWindow.h \ - QFreqDisp.h +HEADERS += MainWindow.h \ + QFreqDisp.h \ + version.h TEMPLATE = app Added: trunk/src/version.h =================================================================== --- trunk/src/version.h (rev 0) +++ trunk/src/version.h 2008-01-03 20:13:18 UTC (rev 89) @@ -0,0 +1,11 @@ +#ifndef COMMON_H +#define COMMON_H + + +#define HRS_MAJOR_VERSION 1 +#define HRS_MINOR_VERSION 0 +#define HRS_MICRO_VERSION 0 +#define HRS_VERSION "1.0.0" +#define HRS_BETA_STRING "beta1" + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-29 19:34:49
|
Revision: 88 http://hrs.svn.sourceforge.net/hrs/?rev=88&view=rev Author: csete Date: 2007-12-29 11:34:48 -0800 (Sat, 29 Dec 2007) Log Message: ----------- Updated. Modified Paths: -------------- trunk/src/MainWindow.cpp trunk/src/src.pro trunk/tests/testserial/QSerTest.h Added Paths: ----------- trunk/src/QFreqDisp.cpp trunk/src/QFreqDisp.h Modified: trunk/src/MainWindow.cpp =================================================================== --- trunk/src/MainWindow.cpp 2007-12-28 23:21:25 UTC (rev 87) +++ trunk/src/MainWindow.cpp 2007-12-29 19:34:48 UTC (rev 88) @@ -22,11 +22,12 @@ ***************************************************************************/ #include <QtGui> #include "MainWindow.h" +#include "QFreqDisp.h" MainWindow::MainWindow() { - + QFreqDisp *disp; //spreadsheet = new Spreadsheet; @@ -39,6 +40,8 @@ //readSettings(); //setWindowIcon(QIcon(":/images/icon.png")); + disp = new QFreqDisp(this); + setCentralWidget(disp); } Added: trunk/src/QFreqDisp.cpp =================================================================== --- trunk/src/QFreqDisp.cpp (rev 0) +++ trunk/src/QFreqDisp.cpp 2007-12-29 19:34:48 UTC (rev 88) @@ -0,0 +1,142 @@ +/*************************************************************************** + * * + * Ham Radio Studio http://hrs.sf.net/ * + * * + * Copyright (C) 2007 by Alexandru Csete OZ9AEC * + * * + * 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 <QtGui> +#include <QtDebug> +#include "qextserialport.h" +#include "QFreqDisp.h" + + +QFreqDisp::QFreqDisp(QWidget *parent) : QWidget(parent) +{ + QHBoxLayout *hLay; + + // display label */ + freq = new QLabel("FREQ", this); + + hLay = new QHBoxLayout; + hLay->addWidget(freq); + + setLayout(hLay); + + lastfreq = 0; + + // serial comm + port = new QextSerialPort("/dev/ttyUSB0"); + port->setBaudRate(BAUD9600); + port->setFlowControl(FLOW_OFF); + port->setParity(PAR_NONE); + port->setDataBits(DATA_8); + port->setStopBits(STOP_1); + port->setTimeout(0,0); + port->open(QIODevice::ReadWrite); + port->setDtr(FALSE); + port->setRts(FALSE); + + + // timer + fast = FALSE; + timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(updateFreq())); + timer->start(500); + +} + + +QFreqDisp::~QFreqDisp() +{ + if (port->isOpen()) { + port->close(); + } + delete port; + port = NULL; +} + +unsigned long long from_bcd(const char bcd_data[], unsigned bcd_len) +{ + int i; + unsigned long long f = 0; + + if (bcd_len&1) + f = bcd_data[bcd_len/2] & 0x0f; + + for (i=(bcd_len/2)-1; i >= 0; i--) { + f *= 10; + f += bcd_data[i]>>4; + f *= 10; + f += bcd_data[i] & 0x0f; + } + + return f; +} + + +void QFreqDisp::updateFreq() +{ + const char *tx = "\xFE\xFE\x2C\xE0\x03\xFD"; + int num,i; + QByteArray rx1,rx2; + QString str; + qulonglong f; + +// tx = new QByteArray("\xFE\xFE\x2C\xE0\x03\xFD"); + i = port->write(tx,6); + + //qDebug() << "WROTE " << i; + + num = port->bytesAvailable(); + if (num > 1024) num = 1024; + + + + if (num > 6) { + rx1 = port->read(6); + rx2 = port->read(num-6); + rx2.chop(1); + rx2.remove(0,5); + f = from_bcd(rx2.data(), 10); + + if (f != lastfreq) { + lastfreq = f; + str.setNum(f); + freq->setText(str); + + // check if we need to resched + if (!fast) { + timer->setInterval(100); + fast = TRUE; + } + } + else { + // check if we need to resched + if (fast) { + timer->setInterval(500); + fast = FALSE; + } + } + } + + //qDebug() << "READ: " << i << "/" << num; + +} + + Added: trunk/src/QFreqDisp.h =================================================================== --- trunk/src/QFreqDisp.h (rev 0) +++ trunk/src/QFreqDisp.h 2007-12-29 19:34:48 UTC (rev 88) @@ -0,0 +1,53 @@ +/*************************************************************************** + * * + * Ham Radio Studio http://hrs.sf.net/ * + * * + * Copyright (C) 2007 by Alexandru Csete OZ9AEC * + * * + * 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 QFREQDISP_H +#define QFREQDISP_H 1 + +#include <QtGui> + +class QextSerialPort; + + +class QFreqDisp : public QWidget +{ + Q_OBJECT + + public: + QFreqDisp(QWidget *parent=0); + ~QFreqDisp(); + + private: + QextSerialPort *port; + QLabel *freq; + QTimer *timer; + + qulonglong lastfreq; + + bool fast; + + + private slots: + void updateFreq(); +}; + +#endif Modified: trunk/src/src.pro =================================================================== --- trunk/src/src.pro 2007-12-28 23:21:25 UTC (rev 87) +++ trunk/src/src.pro 2007-12-29 19:34:48 UTC (rev 88) @@ -1,7 +1,9 @@ SOURCES += MainWindow.cpp \ - main.cpp + main.cpp \ + QFreqDisp.cpp -HEADERS += MainWindow.h +HEADERS += MainWindow.h \ + QFreqDisp.h TEMPLATE = app Modified: trunk/tests/testserial/QSerTest.h =================================================================== --- trunk/tests/testserial/QSerTest.h 2007-12-28 23:21:25 UTC (rev 87) +++ trunk/tests/testserial/QSerTest.h 2007-12-29 19:34:48 UTC (rev 88) @@ -21,7 +21,7 @@ * * ***************************************************************************/ #ifndef QSERTEST_H -#define QSERTEST_H +#define QSERTEST_H 1 #include <QtGui> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-28 23:21:31
|
Revision: 87 http://hrs.svn.sourceforge.net/hrs/?rev=87&view=rev Author: csete Date: 2007-12-28 15:21:25 -0800 (Fri, 28 Dec 2007) Log Message: ----------- Added file Added Paths: ----------- trunk/CREDITS Added: trunk/CREDITS =================================================================== --- trunk/CREDITS (rev 0) +++ trunk/CREDITS 2007-12-28 23:21:25 UTC (rev 87) @@ -0,0 +1,10 @@ + +Serial IO: +Stefan Sander, Michal Policht +http://qextserialport.sf.net/ + +Maidenhead locator functions: +TBD... +http://hamlib.sf.net/ + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-28 23:11:10
|
Revision: 86 http://hrs.svn.sourceforge.net/hrs/?rev=86&view=rev Author: csete Date: 2007-12-28 15:11:09 -0800 (Fri, 28 Dec 2007) Log Message: ----------- Remove test class. Modified Paths: -------------- trunk/src/MainWindow.cpp trunk/src/src.pro Modified: trunk/src/MainWindow.cpp =================================================================== --- trunk/src/MainWindow.cpp 2007-12-28 23:07:38 UTC (rev 85) +++ trunk/src/MainWindow.cpp 2007-12-28 23:11:09 UTC (rev 86) @@ -22,12 +22,11 @@ ***************************************************************************/ #include <QtGui> #include "MainWindow.h" -#include "QSerTest.h" MainWindow::MainWindow() { - QSerTest *test; + //spreadsheet = new Spreadsheet; @@ -40,8 +39,7 @@ //readSettings(); //setWindowIcon(QIcon(":/images/icon.png")); - test = new QSerTest(this); - setCentralWidget(test); + } Modified: trunk/src/src.pro =================================================================== --- trunk/src/src.pro 2007-12-28 23:07:38 UTC (rev 85) +++ trunk/src/src.pro 2007-12-28 23:11:09 UTC (rev 86) @@ -1,9 +1,7 @@ SOURCES += MainWindow.cpp \ - main.cpp \ - QSerTest.cpp + main.cpp -HEADERS += MainWindow.h \ - QSerTest.h +HEADERS += MainWindow.h TEMPLATE = app This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-28 23:07:39
|
Revision: 85 http://hrs.svn.sourceforge.net/hrs/?rev=85&view=rev Author: csete Date: 2007-12-28 15:07:38 -0800 (Fri, 28 Dec 2007) Log Message: ----------- Added CTS readback. Modified Paths: -------------- trunk/tests/testserial/QSerTest.cpp trunk/tests/testserial/testserial.pro Modified: trunk/tests/testserial/QSerTest.cpp =================================================================== --- trunk/tests/testserial/QSerTest.cpp 2007-12-28 22:26:19 UTC (rev 84) +++ trunk/tests/testserial/QSerTest.cpp 2007-12-28 23:07:38 UTC (rev 85) @@ -94,22 +94,26 @@ { port->setDtr(true); qDebug() << "dtrOn"; + qDebug() << "CTS: " << (port->lineStatus() & LS_CTS); } void QSerTest::dtrOff() { port->setDtr(false); qDebug() << "dtrOff"; + qDebug() << "CTS: " << (port->lineStatus() & LS_CTS); } void QSerTest::rtsOn() { port->setRts(TRUE); qDebug() << "rtsOn"; + qDebug() << "CTS: " << (port->lineStatus() & LS_CTS); } void QSerTest::rtsOff() { port->setRts(FALSE); qDebug() << "rtsOff"; + qDebug() << "CTS: " << (port->lineStatus() & LS_CTS); } Modified: trunk/tests/testserial/testserial.pro =================================================================== --- trunk/tests/testserial/testserial.pro 2007-12-28 22:26:19 UTC (rev 84) +++ trunk/tests/testserial/testserial.pro 2007-12-28 23:07:38 UTC (rev 85) @@ -15,6 +15,7 @@ unix:DEFINES += _TTY_POSIX_ win32:DEFINES += _TTY_WIN_ -TARGET = ../testserial + +TARGET = testserial INCLUDEPATH += ../../src/serial LIBS += ../../build/libqextserialport.a This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-28 22:26:20
|
Revision: 84 http://hrs.svn.sourceforge.net/hrs/?rev=84&view=rev Author: csete Date: 2007-12-28 14:26:19 -0800 (Fri, 28 Dec 2007) Log Message: ----------- Converted to unix EOL Modified Paths: -------------- trunk/src/serial/posix_qextserialport.cpp trunk/src/serial/posix_qextserialport.h trunk/src/serial/qextserialbase.cpp trunk/src/serial/qextserialbase.h trunk/src/serial/qextserialport.cpp trunk/src/serial/qextserialport.h trunk/src/serial/serial.pro trunk/src/serial/win_qextserialport.cpp trunk/src/serial/win_qextserialport.h Modified: trunk/src/serial/posix_qextserialport.cpp =================================================================== --- trunk/src/serial/posix_qextserialport.cpp 2007-12-28 22:19:40 UTC (rev 83) +++ trunk/src/serial/posix_qextserialport.cpp 2007-12-28 22:26:19 UTC (rev 84) @@ -1,1117 +1,1117 @@ - -/*! -\class Posix_QextSerialPort -\version 1.0.0 -\author Stefan Sander - -A cross-platform serial port class. -This class encapsulates the POSIX portion of QextSerialPort. The user will be notified of errors -and possible portability conflicts at run-time by default - this behavior can be turned off by -defining _TTY_NOWARN_ (to turn off all warnings) or _TTY_NOWARN_PORT_ (to turn off portability -warnings) in the project. Note that _TTY_NOWARN_ will also turn off portability warnings. -*/ - -#include <stdio.h> -#include "posix_qextserialport.h" - -/*! -\fn Posix_QextSerialPort::Posix_QextSerialPort() -Default constructor. Note that the name of the device used by a QextSerialPort constructed with -this constructor will be determined by #defined constants, or lack thereof - the default behavior -is the same as _TTY_LINUX_. Possible naming conventions and their associated constants are: - -\verbatim - -Constant Used By Naming Convention ----------- ------------- ------------------------ -_TTY_WIN_ Windows COM1, COM2 -_TTY_IRIX_ SGI/IRIX /dev/ttyf1, /dev/ttyf2 -_TTY_HPUX_ HP-UX /dev/tty1p0, /dev/tty2p0 -_TTY_SUN_ SunOS/Solaris /dev/ttya, /dev/ttyb -_TTY_DIGITAL_ Digital UNIX /dev/tty01, /dev/tty02 -_TTY_FREEBSD_ FreeBSD /dev/ttyd0, /dev/ttyd1 -_TTY_LINUX_ Linux /dev/ttyS0, /dev/ttyS1 -<none> Linux /dev/ttyS0, /dev/ttyS1 -\endverbatim - -This constructor assigns the device name to the name of the first port on the specified system. -See the other constructors if you need to open a different port. -*/ -Posix_QextSerialPort::Posix_QextSerialPort() -: QextSerialBase() -{ - Posix_File=new QFile(); -} - -/*! -\fn Posix_QextSerialPort::Posix_QextSerialPort(const Posix_QextSerialPort&) -Copy constructor. -*/ -Posix_QextSerialPort::Posix_QextSerialPort(const Posix_QextSerialPort& s) - : QextSerialBase(s.port) -{ - setOpenMode(s.openMode()); - port = s.port; - Settings.BaudRate=s.Settings.BaudRate; - Settings.DataBits=s.Settings.DataBits; - Settings.Parity=s.Settings.Parity; - Settings.StopBits=s.Settings.StopBits; - Settings.FlowControl=s.Settings.FlowControl; - lastErr=s.lastErr; - - Posix_File=new QFile(); - Posix_File=s.Posix_File; - memcpy(&Posix_Timeout, &s.Posix_Timeout, sizeof(struct timeval)); - memcpy(&Posix_Copy_Timeout, &s.Posix_Copy_Timeout, sizeof(struct timeval)); - memcpy(&Posix_CommConfig, &s.Posix_CommConfig, sizeof(struct termios)); -} - -/*! -\fn Posix_QextSerialPort::Posix_QextSerialPort(const QString & name) -Constructs a serial port attached to the port specified by name. -name is the name of the device, which is windowsystem-specific, -e.g."COM1" or "/dev/ttyS0". -*/ -Posix_QextSerialPort::Posix_QextSerialPort(const QString & name) - : QextSerialBase(name) -{ - Posix_File=new QFile(); -} - -/*! -\fn Posix_QextSerialPort::Posix_QextSerialPort(const PortSettings& settings) -Constructs a port with default name and specified settings. -*/ -Posix_QextSerialPort::Posix_QextSerialPort(const PortSettings& settings) - : QextSerialBase() -{ - setBaudRate(settings.BaudRate); - setDataBits(settings.DataBits); - setParity(settings.Parity); - setStopBits(settings.StopBits); - setFlowControl(settings.FlowControl); - - Posix_File=new QFile(); - setTimeout(settings.Timeout_Sec, settings.Timeout_Millisec); -} - -/*! -\fn Posix_QextSerialPort::Posix_QextSerialPort(const QString & name, const PortSettings& settings) -Constructs a port with specified name and settings. -*/ -Posix_QextSerialPort::Posix_QextSerialPort(const QString & name, const PortSettings& settings) - : QextSerialBase(name) -{ - setBaudRate(settings.BaudRate); - setDataBits(settings.DataBits); - setParity(settings.Parity); - setStopBits(settings.StopBits); - setFlowControl(settings.FlowControl); - - Posix_File=new QFile(); - setTimeout(settings.Timeout_Sec, settings.Timeout_Millisec); -} - -/*! -\fn Posix_QextSerialPort& Posix_QextSerialPort::operator=(const Posix_QextSerialPort& s) -Override the = operator. -*/ -Posix_QextSerialPort& Posix_QextSerialPort::operator=(const Posix_QextSerialPort& s) -{ - setOpenMode(s.openMode()); - port = s.port; - Settings.BaudRate=s.Settings.BaudRate; - Settings.DataBits=s.Settings.DataBits; - Settings.Parity=s.Settings.Parity; - Settings.StopBits=s.Settings.StopBits; - Settings.FlowControl=s.Settings.FlowControl; - lastErr=s.lastErr; - - Posix_File=s.Posix_File; - memcpy(&Posix_Timeout, &(s.Posix_Timeout), sizeof(struct timeval)); - memcpy(&Posix_Copy_Timeout, &(s.Posix_Copy_Timeout), sizeof(struct timeval)); - memcpy(&Posix_CommConfig, &(s.Posix_CommConfig), sizeof(struct termios)); - return *this; -} - -/*! -\fn Posix_QextSerialPort::~Posix_QextSerialPort() -Standard destructor. -*/ -Posix_QextSerialPort::~Posix_QextSerialPort() -{ - if (isOpen()) { - close(); - } - Posix_File->close(); - delete Posix_File; -} - -/*! -\fn void Posix_QextSerialPort::setBaudRate(BaudRateType baudRate) -Sets the baud rate of the serial port. Note that not all rates are applicable on -all platforms. The following table shows translations of the various baud rate -constants on Windows(including NT/2000) and POSIX platforms. Speeds marked with an * -are speeds that are usable on both Windows and POSIX. - -\note -BAUD76800 may not be supported on all POSIX systems. SGI/IRIX systems do not support -BAUD1800. - -\verbatim - - RATE Windows Speed POSIX Speed - ----------- ------------- ----------- - BAUD50 110 50 - BAUD75 110 75 - *BAUD110 110 110 - BAUD134 110 134.5 - BAUD150 110 150 - BAUD200 110 200 - *BAUD300 300 300 - *BAUD600 600 600 - *BAUD1200 1200 1200 - BAUD1800 1200 1800 - *BAUD2400 2400 2400 - *BAUD4800 4800 4800 - *BAUD9600 9600 9600 - BAUD14400 14400 9600 - *BAUD19200 19200 19200 - *BAUD38400 38400 38400 - BAUD56000 56000 38400 - *BAUD57600 57600 57600 - BAUD76800 57600 76800 - *BAUD115200 115200 115200 - BAUD128000 128000 115200 - BAUD256000 256000 115200 -\endverbatim -*/ -void Posix_QextSerialPort::setBaudRate(BaudRateType baudRate) -{ - LOCK_MUTEX(); - if (Settings.BaudRate!=baudRate) { - switch (baudRate) { - case BAUD14400: - Settings.BaudRate=BAUD9600; - break; - - case BAUD56000: - Settings.BaudRate=BAUD38400; - break; - - case BAUD76800: - -#ifndef B76800 - Settings.BaudRate=BAUD57600; -#else - Settings.BaudRate=baudRate; -#endif - break; - - case BAUD128000: - case BAUD256000: - Settings.BaudRate=BAUD115200; - break; - - default: - Settings.BaudRate=baudRate; - break; - } - } - if (isOpen()) { - switch (baudRate) { - - /*50 baud*/ - case BAUD50: - TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 50 baud operation."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B50; -#else - cfsetispeed(&Posix_CommConfig, B50); - cfsetospeed(&Posix_CommConfig, B50); -#endif - break; - - /*75 baud*/ - case BAUD75: - TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 75 baud operation."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B75; -#else - cfsetispeed(&Posix_CommConfig, B75); - cfsetospeed(&Posix_CommConfig, B75); -#endif - break; - - /*110 baud*/ - case BAUD110: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B110; -#else - cfsetispeed(&Posix_CommConfig, B110); - cfsetospeed(&Posix_CommConfig, B110); -#endif - break; - - /*134.5 baud*/ - case BAUD134: - TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 134.5 baud operation."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B134; -#else - cfsetispeed(&Posix_CommConfig, B134); - cfsetospeed(&Posix_CommConfig, B134); -#endif - break; - - /*150 baud*/ - case BAUD150: - TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 150 baud operation."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B150; -#else - cfsetispeed(&Posix_CommConfig, B150); - cfsetospeed(&Posix_CommConfig, B150); -#endif - break; - - /*200 baud*/ - case BAUD200: - TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 200 baud operation."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B200; -#else - cfsetispeed(&Posix_CommConfig, B200); - cfsetospeed(&Posix_CommConfig, B200); -#endif - break; - - /*300 baud*/ - case BAUD300: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B300; -#else - cfsetispeed(&Posix_CommConfig, B300); - cfsetospeed(&Posix_CommConfig, B300); -#endif - break; - - /*600 baud*/ - case BAUD600: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B600; -#else - cfsetispeed(&Posix_CommConfig, B600); - cfsetospeed(&Posix_CommConfig, B600); -#endif - break; - - /*1200 baud*/ - case BAUD1200: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B1200; -#else - cfsetispeed(&Posix_CommConfig, B1200); - cfsetospeed(&Posix_CommConfig, B1200); -#endif - break; - - /*1800 baud*/ - case BAUD1800: - TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows and IRIX do not support 1800 baud operation."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B1800; -#else - cfsetispeed(&Posix_CommConfig, B1800); - cfsetospeed(&Posix_CommConfig, B1800); -#endif - break; - - /*2400 baud*/ - case BAUD2400: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B2400; -#else - cfsetispeed(&Posix_CommConfig, B2400); - cfsetospeed(&Posix_CommConfig, B2400); -#endif - break; - - /*4800 baud*/ - case BAUD4800: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B4800; -#else - cfsetispeed(&Posix_CommConfig, B4800); - cfsetospeed(&Posix_CommConfig, B4800); -#endif - break; - - /*9600 baud*/ - case BAUD9600: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B9600; -#else - cfsetispeed(&Posix_CommConfig, B9600); - cfsetospeed(&Posix_CommConfig, B9600); -#endif - break; - - /*14400 baud*/ - case BAUD14400: - TTY_WARNING("Posix_QextSerialPort: POSIX does not support 14400 baud operation. Switching to 9600 baud."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B9600; -#else - cfsetispeed(&Posix_CommConfig, B9600); - cfsetospeed(&Posix_CommConfig, B9600); -#endif - break; - - /*19200 baud*/ - case BAUD19200: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B19200; -#else - cfsetispeed(&Posix_CommConfig, B19200); - cfsetospeed(&Posix_CommConfig, B19200); -#endif - break; - - /*38400 baud*/ - case BAUD38400: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B38400; -#else - cfsetispeed(&Posix_CommConfig, B38400); - cfsetospeed(&Posix_CommConfig, B38400); -#endif - break; - - /*56000 baud*/ - case BAUD56000: - TTY_WARNING("Posix_QextSerialPort: POSIX does not support 56000 baud operation. Switching to 38400 baud."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B38400; -#else - cfsetispeed(&Posix_CommConfig, B38400); - cfsetospeed(&Posix_CommConfig, B38400); -#endif - break; - - /*57600 baud*/ - case BAUD57600: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B57600; -#else - cfsetispeed(&Posix_CommConfig, B57600); - cfsetospeed(&Posix_CommConfig, B57600); -#endif - break; - - /*76800 baud*/ - case BAUD76800: - TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows and some POSIX systems do not support 76800 baud operation."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - -#ifdef B76800 - Posix_CommConfig.c_cflag|=B76800; -#else - TTY_WARNING("Posix_QextSerialPort: Posix_QextSerialPort was compiled without 76800 baud support. Switching to 57600 baud."); - Posix_CommConfig.c_cflag|=B57600; -#endif //B76800 -#else //CBAUD -#ifdef B76800 - cfsetispeed(&Posix_CommConfig, B76800); - cfsetospeed(&Posix_CommConfig, B76800); -#else - TTY_WARNING("Posix_QextSerialPort: Posix_QextSerialPort was compiled without 76800 baud support. Switching to 57600 baud."); - cfsetispeed(&Posix_CommConfig, B57600); - cfsetospeed(&Posix_CommConfig, B57600); -#endif //B76800 -#endif //CBAUD - break; - - /*115200 baud*/ - case BAUD115200: -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B115200; -#else - cfsetispeed(&Posix_CommConfig, B115200); - cfsetospeed(&Posix_CommConfig, B115200); -#endif - break; - - /*128000 baud*/ - case BAUD128000: - TTY_WARNING("Posix_QextSerialPort: POSIX does not support 128000 baud operation. Switching to 115200 baud."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B115200; -#else - cfsetispeed(&Posix_CommConfig, B115200); - cfsetospeed(&Posix_CommConfig, B115200); -#endif - break; - - /*256000 baud*/ - case BAUD256000: - TTY_WARNING("Posix_QextSerialPort: POSIX does not support 256000 baud operation. Switching to 115200 baud."); -#ifdef CBAUD - Posix_CommConfig.c_cflag&=(~CBAUD); - Posix_CommConfig.c_cflag|=B115200; -#else - cfsetispeed(&Posix_CommConfig, B115200); - cfsetospeed(&Posix_CommConfig, B115200); -#endif - break; - } - tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Posix_QextSerialPort::setDataBits(DataBitsType dataBits) -Sets the number of data bits used by the serial port. Possible values of dataBits are: -\verbatim - DATA_5 5 data bits - DATA_6 6 data bits - DATA_7 7 data bits - DATA_8 8 data bits -\endverbatim - -\note -This function is subject to the following restrictions: -\par - 5 data bits cannot be used with 2 stop bits. -\par - 8 data bits cannot be used with space parity on POSIX systems. - -*/ -void Posix_QextSerialPort::setDataBits(DataBitsType dataBits) -{ - LOCK_MUTEX(); - if (Settings.DataBits!=dataBits) { - if ((Settings.StopBits==STOP_2 && dataBits==DATA_5) || - (Settings.StopBits==STOP_1_5 && dataBits!=DATA_5) || - (Settings.Parity==PAR_SPACE && dataBits==DATA_8)) { - } - else { - Settings.DataBits=dataBits; - } - } - if (isOpen()) { - switch(dataBits) { - - /*5 data bits*/ - case DATA_5: - if (Settings.StopBits==STOP_2) { - TTY_WARNING("Posix_QextSerialPort: 5 Data bits cannot be used with 2 stop bits."); - } - else { - Settings.DataBits=dataBits; - Posix_CommConfig.c_cflag&=(~CSIZE); - Posix_CommConfig.c_cflag|=CS5; - tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); - } - break; - - /*6 data bits*/ - case DATA_6: - if (Settings.StopBits==STOP_1_5) { - TTY_WARNING("Posix_QextSerialPort: 6 Data bits cannot be used with 1.5 stop bits."); - } - else { - Settings.DataBits=dataBits; - Posix_CommConfig.c_cflag&=(~CSIZE); - Posix_CommConfig.c_cflag|=CS6; - tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); - } - break; - - /*7 data bits*/ - case DATA_7: - if (Settings.StopBits==STOP_1_5) { - TTY_WARNING("Posix_QextSerialPort: 7 Data bits cannot be used with 1.5 stop bits."); - } - else { - Settings.DataBits=dataBits; - Posix_CommConfig.c_cflag&=(~CSIZE); - Posix_CommConfig.c_cflag|=CS7; - tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); - } - break; - - /*8 data bits*/ - case DATA_8: - if (Settings.StopBits==STOP_1_5) { - TTY_WARNING("Posix_QextSerialPort: 8 Data bits cannot be used with 1.5 stop bits."); - } - else { - Settings.DataBits=dataBits; - Posix_CommConfig.c_cflag&=(~CSIZE); - Posix_CommConfig.c_cflag|=CS8; - tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); - } - break; - } - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Posix_QextSerialPort::setParity(ParityType parity) -Sets the parity associated with the serial port. The possible values of parity are: -\verbatim - PAR_SPACE Space Parity - PAR_MARK Mark Parity - PAR_NONE No Parity - PAR_EVEN Even Parity - PAR_ODD Odd Parity -\endverbatim - -\note -This function is subject to the following limitations: -\par -POSIX systems do not support mark parity. -\par -POSIX systems support space parity only if tricked into doing so, and only with - fewer than 8 data bits. Use space parity very carefully with POSIX systems. - -*/ -void Posix_QextSerialPort::setParity(ParityType parity) -{ - LOCK_MUTEX(); - if (Settings.Parity!=parity) { - if (parity==PAR_MARK || (parity==PAR_SPACE && Settings.DataBits==DATA_8)) { - } - else { - Settings.Parity=parity; - } - } - if (isOpen()) { - switch (parity) { - - /*space parity*/ - case PAR_SPACE: - if (Settings.DataBits==DATA_8) { - TTY_PORTABILITY_WARNING("Posix_QextSerialPort: Space parity is only supported in POSIX with 7 or fewer data bits"); - } - else { - - /*space parity not directly supported - add an extra data bit to simulate it*/ - Posix_CommConfig.c_cflag&=~(PARENB|CSIZE); - switch(Settings.DataBits) { - case DATA_5: - Settings.DataBits=DATA_6; - Posix_CommConfig.c_cflag|=CS6; - break; - - case DATA_6: - Settings.DataBits=DATA_7; - Posix_CommConfig.c_cflag|=CS7; - break; - - case DATA_7: - Settings.DataBits=DATA_8; - Posix_CommConfig.c_cflag|=CS8; - break; - - case DATA_8: - break; - } - tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); - } - break; - - /*mark parity - WINDOWS ONLY*/ - case PAR_MARK: - TTY_WARNING("Posix_QextSerialPort: Mark parity is not supported by POSIX."); - break; - - /*no parity*/ - case PAR_NONE: - Posix_CommConfig.c_cflag&=(~PARENB); - tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); - break; - - /*even parity*/ - case PAR_EVEN: - Posix_CommConfig.c_cflag&=(~PARODD); - Posix_CommConfig.c_cflag|=PARENB; - tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); - break; - - /*odd parity*/ - case PAR_ODD: - Posix_CommConfig.c_cflag|=(PARENB|PARODD); - tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); - break; - } - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Posix_QextSerialPort::setStopBits(StopBitsType stopBits) -Sets the number of stop bits used by the serial port. Possible values of stopBits are: -\verbatim - STOP_1 1 stop bit - STOP_1_5 1.5 stop bits - STOP_2 2 stop bits -\endverbatim -\note -This function is subject to the following restrictions: -\par - 2 stop bits cannot be used with 5 data bits. -\par - POSIX does not support 1.5 stop bits. - -*/ -void Posix_QextSerialPort::setStopBits(StopBitsType stopBits) -{ - LOCK_MUTEX(); - if (Settings.StopBits!=stopBits) { - if ((Settings.DataBits==DATA_5 && stopBits==STOP_2) || stopBits==STOP_1_5) {} - else { - Settings.StopBits=stopBits; - } - } - if (isOpen()) { - switch (stopBits) { - - /*one stop bit*/ - case STOP_1: - Settings.StopBits=stopBits; - Posix_CommConfig.c_cflag&=(~CSTOPB); - tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); - break; - - /*1.5 stop bits*/ - case STOP_1_5: - TTY_WARNING("Posix_QextSerialPort: 1.5 stop bit operation is not supported by POSIX."); - break; - - /*two stop bits*/ - case STOP_2: - if (Settings.DataBits==DATA_5) { - TTY_WARNING("Posix_QextSerialPort: 2 stop bits cannot be used with 5 data bits"); - } - else { - Settings.StopBits=stopBits; - Posix_CommConfig.c_cflag|=CSTOPB; - tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); - } - break; - } - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Posix_QextSerialPort::setFlowControl(FlowType flow) -Sets the flow control used by the port. Possible values of flow are: -\verbatim - FLOW_OFF No flow control - FLOW_HARDWARE Hardware (RTS/CTS) flow control - FLOW_XONXOFF Software (XON/XOFF) flow control -\endverbatim -\note -FLOW_HARDWARE may not be supported on all versions of UNIX. In cases where it is -unsupported, FLOW_HARDWARE is the same as FLOW_OFF. - -*/ -void Posix_QextSerialPort::setFlowControl(FlowType flow) -{ - LOCK_MUTEX(); - if (Settings.FlowControl!=flow) { - Settings.FlowControl=flow; - } - if (isOpen()) { - switch(flow) { - - /*no flow control*/ - case FLOW_OFF: - Posix_CommConfig.c_cflag&=(~CRTSCTS); - Posix_CommConfig.c_iflag&=(~(IXON|IXOFF|IXANY)); - tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); - break; - - /*software (XON/XOFF) flow control*/ - case FLOW_XONXOFF: - Posix_CommConfig.c_cflag&=(~CRTSCTS); - Posix_CommConfig.c_iflag|=(IXON|IXOFF|IXANY); - tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); - break; - - case FLOW_HARDWARE: - Posix_CommConfig.c_cflag|=CRTSCTS; - Posix_CommConfig.c_iflag&=(~(IXON|IXOFF|IXANY)); - tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); - break; - } - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Posix_QextSerialPort::setTimeout(ulong sec, ulong millisec); -Sets the read and write timeouts for the port to sec seconds and millisec milliseconds. -Note that this is a per-character timeout, i.e. the port will wait this long for each -individual character, not for the whole read operation. This timeout also applies to the -bytesWaiting() function. - -\note -POSIX does not support millisecond-level control for I/O timeout values. Any -timeout set using this function will be set to the next lowest tenth of a second for -the purposes of detecting read or write timeouts. For example a timeout of 550 milliseconds -will be seen by the class as a timeout of 500 milliseconds for the purposes of reading and -writing the port. However millisecond-level control is allowed by the select() system call, -so for example a 550-millisecond timeout will be seen as 550 milliseconds on POSIX systems for -the purpose of detecting available bytes in the read buffer. - -*/ -void Posix_QextSerialPort::setTimeout(ulong sec, ulong millisec) -{ - LOCK_MUTEX(); - Settings.Timeout_Sec=sec; - Settings.Timeout_Millisec=millisec; - Posix_Copy_Timeout.tv_sec=sec; - Posix_Copy_Timeout.tv_usec=millisec; - if (isOpen()) { - tcgetattr(Posix_File->handle(), &Posix_CommConfig); - Posix_CommConfig.c_cc[VTIME]=sec*10+millisec/100; - tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); - } - UNLOCK_MUTEX(); -} - -/*! -\fn bool Posix_QextSerialPort::open(OpenMode mode) -Opens the serial port associated to this class. -This function has no effect if the port associated with the class is already open. -The port is also configured to the current settings, as stored in the Settings structure. -*/ -bool Posix_QextSerialPort::open(OpenMode mode) -{ - LOCK_MUTEX(); - if (mode == QIODevice::NotOpen) - return isOpen(); - if (!isOpen()) { - /*open the port*/ - Posix_File->setFileName(port); - qDebug("Trying to open File"); - if (Posix_File->open(QIODevice::ReadWrite|QIODevice::Unbuffered)) { - qDebug("Opened File succesfully"); - /*set open mode*/ - QIODevice::open(mode); - - /*configure port settings*/ - tcgetattr(Posix_File->handle(), &Posix_CommConfig); - - /*set up other port settings*/ - Posix_CommConfig.c_cflag|=CREAD|CLOCAL; - Posix_CommConfig.c_lflag&=(~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|ISIG)); - Posix_CommConfig.c_iflag&=(~(INPCK|IGNPAR|PARMRK|ISTRIP|ICRNL|IXANY)); - Posix_CommConfig.c_oflag&=(~OPOST); - Posix_CommConfig.c_cc[VMIN]=0; - Posix_CommConfig.c_cc[VINTR] = _POSIX_VDISABLE; - Posix_CommConfig.c_cc[VQUIT] = _POSIX_VDISABLE; - Posix_CommConfig.c_cc[VSTART] = _POSIX_VDISABLE; - Posix_CommConfig.c_cc[VSTOP] = _POSIX_VDISABLE; - Posix_CommConfig.c_cc[VSUSP] = _POSIX_VDISABLE; - setBaudRate(Settings.BaudRate); - setDataBits(Settings.DataBits); - setParity(Settings.Parity); - setStopBits(Settings.StopBits); - setFlowControl(Settings.FlowControl); - setTimeout(Settings.Timeout_Sec, Settings.Timeout_Millisec); - tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); - } else { - qDebug("Could not open File! Error code : %d", Posix_File->error()); - } - } - UNLOCK_MUTEX(); - return isOpen(); -} - -/*! -\fn void Posix_QextSerialPort::close() -Closes a serial port. This function has no effect if the serial port associated with the class -is not currently open. -*/ -void Posix_QextSerialPort::close() -{ - LOCK_MUTEX(); - Posix_File->close(); - QIODevice::close(); - UNLOCK_MUTEX(); -} - -/*! -\fn void Posix_QextSerialPort::flush() -Flushes all pending I/O to the serial port. This function has no effect if the serial port -associated with the class is not currently open. -*/ -void Posix_QextSerialPort::flush() -{ - LOCK_MUTEX(); - if (isOpen()) { - Posix_File->flush(); - } - UNLOCK_MUTEX(); -} - -/*! -\fn qint64 Posix_QextSerialPort::size() const -This function will return the number of bytes waiting in the receive queue of the serial port. -It is included primarily to provide a complete QIODevice interface, and will not record errors -in the lastErr member (because it is const). This function is also not thread-safe - in -multithreading situations, use Posix_QextSerialPort::bytesWaiting() instead. -*/ -qint64 Posix_QextSerialPort::size() const -{ - int numBytes; - if (ioctl(Posix_File->handle(), FIONREAD, &numBytes)<0) { - numBytes=0; - } - return (qint64)numBytes; -} - -/*! -\fn qint64 Posix_QextSerialPort::bytesAvailable() -Returns the number of bytes waiting in the port's receive queue. This function will return 0 if -the port is not currently open, or -1 on error. Error information can be retrieved by calling -Posix_QextSerialPort::getLastError(). -*/ -qint64 Posix_QextSerialPort::bytesAvailable() -{ - LOCK_MUTEX(); - if (isOpen()) { - int bytesQueued; - fd_set fileSet; - FD_ZERO(&fileSet); - FD_SET(Posix_File->handle(), &fileSet); - - /*on Linux systems the Posix_Timeout structure will be altered by the select() call. - Make sure we use the right timeout values*/ - //memcpy(&Posix_Timeout, &Posix_Copy_Timeout, sizeof(struct timeval)); - Posix_Timeout = Posix_Copy_Timeout; - int n=select(Posix_File->handle()+1, &fileSet, NULL, &fileSet, &Posix_Timeout); - if (!n) { - lastErr=E_PORT_TIMEOUT; - UNLOCK_MUTEX(); - return -1; - } - if (n==-1 || ioctl(Posix_File->handle(), FIONREAD, &bytesQueued)==-1) { - translateError(errno); - UNLOCK_MUTEX(); - return -1; - } - lastErr=E_NO_ERROR; - UNLOCK_MUTEX(); - return bytesQueued + QIODevice::bytesAvailable(); - } - UNLOCK_MUTEX(); - return 0; -} - -/*! -\fn void Posix_QextSerialPort::ungetChar(char) -This function is included to implement the full QIODevice interface, and currently has no -purpose within this class. This function is meaningless on an unbuffered device and currently -only prints a warning message to that effect. -*/ -void Posix_QextSerialPort::ungetChar(char) -{ - /*meaningless on unbuffered sequential device - return error and print a warning*/ - TTY_WARNING("Posix_QextSerialPort: ungetChar() called on an unbuffered sequential device - operation is meaningless"); -} - -/*! -\fn void Posix_QextSerialPort::translateError(ulong error) -Translates a system-specific error code to a QextSerialPort error code. Used internally. -*/ -void Posix_QextSerialPort::translateError(ulong error) -{ - switch (error) { - case EBADF: - case ENOTTY: - lastErr=E_INVALID_FD; - break; - - case EINTR: - lastErr=E_CAUGHT_NON_BLOCKED_SIGNAL; - break; - - case ENOMEM: - lastErr=E_NO_MEMORY; - break; - } -} - -/*! -\fn void Posix_QextSerialPort::setDtr(bool set) -Sets DTR line to the requested state (high by default). This function will have no effect if -the port associated with the class is not currently open. -*/ -void Posix_QextSerialPort::setDtr(bool set) -{ - LOCK_MUTEX(); - if (isOpen()) { - int status; - ioctl(Posix_File->handle(), TIOCMGET, &status); - if (set) { - status|=TIOCM_DTR; - } - else { - status&=~TIOCM_DTR; - } - ioctl(Posix_File->handle(), TIOCMSET, &status); - } - UNLOCK_MUTEX(); -} - -/*! -\fn void Posix_QextSerialPort::setRts(bool set) -Sets RTS line to the requested state (high by default). This function will have no effect if -the port associated with the class is not currently open. -*/ -void Posix_QextSerialPort::setRts(bool set) -{ - LOCK_MUTEX(); - if (isOpen()) { - int status; - ioctl(Posix_File->handle(), TIOCMGET, &status); - if (set) { - status|=TIOCM_RTS; - } - else { - status&=~TIOCM_RTS; - } - ioctl(Posix_File->handle(), TIOCMSET, &status); - } - UNLOCK_MUTEX(); -} - -/*! -\fn unsigned long Posix_QextSerialPort::lineStatus() -returns the line status as stored by the port function. This function will retrieve the states -of the following lines: DCD, CTS, DSR, and RI. On POSIX systems, the following additional lines -can be monitored: DTR, RTS, Secondary TXD, and Secondary RXD. The value returned is an unsigned -long with specific bits indicating which lines are high. The following constants should be used -to examine the states of individual lines: - -\verbatim -Mask Line ------- ---- -LS_CTS CTS -LS_DSR DSR -LS_DCD DCD -LS_RI RI -LS_RTS RTS (POSIX only) -LS_DTR DTR (POSIX only) -LS_ST Secondary TXD (POSIX only) -LS_SR Secondary RXD (POSIX only) -\endverbatim - -This function will return 0 if the port associated with the class is not currently open. -*/ -unsigned long Posix_QextSerialPort::lineStatus() -{ - unsigned long Status=0, Temp=0; - LOCK_MUTEX(); - if (isOpen()) { - ioctl(Posix_File->handle(), TIOCMGET, &Temp); - if (Temp&TIOCM_CTS) { - Status|=LS_CTS; - } - if (Temp&TIOCM_DSR) { - Status|=LS_DSR; - } - if (Temp&TIOCM_RI) { - Status|=LS_RI; - } - if (Temp&TIOCM_CD) { - Status|=LS_DCD; - } - if (Temp&TIOCM_DTR) { - Status|=LS_DTR; - } - if (Temp&TIOCM_RTS) { - Status|=LS_RTS; - } - if (Temp&TIOCM_ST) { - Status|=LS_ST; - } - if (Temp&TIOCM_SR) { - Status|=LS_SR; - } - } - UNLOCK_MUTEX(); - return Status; -} - -/*! -\fn qint64 Posix_QextSerialPort::readData(char * data, qint64 maxSize) -Reads a block of data from the serial port. This function will read at most maxSize bytes from -the serial port and place them in the buffer pointed to by data. Return value is the number of -bytes actually read, or -1 on error. - -\warning before calling this function ensure that serial port associated with this class -is currently open (use isOpen() function to check if port is open). -*/ -qint64 Posix_QextSerialPort::readData(char * data, qint64 maxSize) -{ - LOCK_MUTEX(); - int retVal=0; - retVal=Posix_File->read(data, maxSize); - if (retVal==-1) - lastErr=E_READ_FAILED; - UNLOCK_MUTEX(); - - return retVal; -} - -/*! -\fn qint64 Posix_QextSerialPort::writeData(const char * data, qint64 maxSize) -Writes a block of data to the serial port. This function will write maxSize bytes -from the buffer pointed to by data to the serial port. Return value is the number -of bytes actually written, or -1 on error. - -\warning before calling this function ensure that serial port associated with this class -is currently open (use isOpen() function to check if port is open). -*/ -qint64 Posix_QextSerialPort::writeData(const char * data, qint64 maxSize) -{ - LOCK_MUTEX(); - int retVal=0; - retVal=Posix_File->write(data, maxSize); - if (retVal==-1) - lastErr=E_WRITE_FAILED; - UNLOCK_MUTEX(); - - flush(); - return retVal; -} + +/*! +\class Posix_QextSerialPort +\version 1.0.0 +\author Stefan Sander + +A cross-platform serial port class. +This class encapsulates the POSIX portion of QextSerialPort. The user will be notified of errors +and possible portability conflicts at run-time by default - this behavior can be turned off by +defining _TTY_NOWARN_ (to turn off all warnings) or _TTY_NOWARN_PORT_ (to turn off portability +warnings) in the project. Note that _TTY_NOWARN_ will also turn off portability warnings. +*/ + +#include <stdio.h> +#include "posix_qextserialport.h" + +/*! +\fn Posix_QextSerialPort::Posix_QextSerialPort() +Default constructor. Note that the name of the device used by a QextSerialPort constructed with +this constructor will be determined by #defined constants, or lack thereof - the default behavior +is the same as _TTY_LINUX_. Possible naming conventions and their associated constants are: + +\verbatim + +Constant Used By Naming Convention +---------- ------------- ------------------------ +_TTY_WIN_ Windows COM1, COM2 +_TTY_IRIX_ SGI/IRIX /dev/ttyf1, /dev/ttyf2 +_TTY_HPUX_ HP-UX /dev/tty1p0, /dev/tty2p0 +_TTY_SUN_ SunOS/Solaris /dev/ttya, /dev/ttyb +_TTY_DIGITAL_ Digital UNIX /dev/tty01, /dev/tty02 +_TTY_FREEBSD_ FreeBSD /dev/ttyd0, /dev/ttyd1 +_TTY_LINUX_ Linux /dev/ttyS0, /dev/ttyS1 +<none> Linux /dev/ttyS0, /dev/ttyS1 +\endverbatim + +This constructor assigns the device name to the name of the first port on the specified system. +See the other constructors if you need to open a different port. +*/ +Posix_QextSerialPort::Posix_QextSerialPort() +: QextSerialBase() +{ + Posix_File=new QFile(); +} + +/*! +\fn Posix_QextSerialPort::Posix_QextSerialPort(const Posix_QextSerialPort&) +Copy constructor. +*/ +Posix_QextSerialPort::Posix_QextSerialPort(const Posix_QextSerialPort& s) + : QextSerialBase(s.port) +{ + setOpenMode(s.openMode()); + port = s.port; + Settings.BaudRate=s.Settings.BaudRate; + Settings.DataBits=s.Settings.DataBits; + Settings.Parity=s.Settings.Parity; + Settings.StopBits=s.Settings.StopBits; + Settings.FlowControl=s.Settings.FlowControl; + lastErr=s.lastErr; + + Posix_File=new QFile(); + Posix_File=s.Posix_File; + memcpy(&Posix_Timeout, &s.Posix_Timeout, sizeof(struct timeval)); + memcpy(&Posix_Copy_Timeout, &s.Posix_Copy_Timeout, sizeof(struct timeval)); + memcpy(&Posix_CommConfig, &s.Posix_CommConfig, sizeof(struct termios)); +} + +/*! +\fn Posix_QextSerialPort::Posix_QextSerialPort(const QString & name) +Constructs a serial port attached to the port specified by name. +name is the name of the device, which is windowsystem-specific, +e.g."COM1" or "/dev/ttyS0". +*/ +Posix_QextSerialPort::Posix_QextSerialPort(const QString & name) + : QextSerialBase(name) +{ + Posix_File=new QFile(); +} + +/*! +\fn Posix_QextSerialPort::Posix_QextSerialPort(const PortSettings& settings) +Constructs a port with default name and specified settings. +*/ +Posix_QextSerialPort::Posix_QextSerialPort(const PortSettings& settings) + : QextSerialBase() +{ + setBaudRate(settings.BaudRate); + setDataBits(settings.DataBits); + setParity(settings.Parity); + setStopBits(settings.StopBits); + setFlowControl(settings.FlowControl); + + Posix_File=new QFile(); + setTimeout(settings.Timeout_Sec, settings.Timeout_Millisec); +} + +/*! +\fn Posix_QextSerialPort::Posix_QextSerialPort(const QString & name, const PortSettings& settings) +Constructs a port with specified name and settings. +*/ +Posix_QextSerialPort::Posix_QextSerialPort(const QString & name, const PortSettings& settings) + : QextSerialBase(name) +{ + setBaudRate(settings.BaudRate); + setDataBits(settings.DataBits); + setParity(settings.Parity); + setStopBits(settings.StopBits); + setFlowControl(settings.FlowControl); + + Posix_File=new QFile(); + setTimeout(settings.Timeout_Sec, settings.Timeout_Millisec); +} + +/*! +\fn Posix_QextSerialPort& Posix_QextSerialPort::operator=(const Posix_QextSerialPort& s) +Override the = operator. +*/ +Posix_QextSerialPort& Posix_QextSerialPort::operator=(const Posix_QextSerialPort& s) +{ + setOpenMode(s.openMode()); + port = s.port; + Settings.BaudRate=s.Settings.BaudRate; + Settings.DataBits=s.Settings.DataBits; + Settings.Parity=s.Settings.Parity; + Settings.StopBits=s.Settings.StopBits; + Settings.FlowControl=s.Settings.FlowControl; + lastErr=s.lastErr; + + Posix_File=s.Posix_File; + memcpy(&Posix_Timeout, &(s.Posix_Timeout), sizeof(struct timeval)); + memcpy(&Posix_Copy_Timeout, &(s.Posix_Copy_Timeout), sizeof(struct timeval)); + memcpy(&Posix_CommConfig, &(s.Posix_CommConfig), sizeof(struct termios)); + return *this; +} + +/*! +\fn Posix_QextSerialPort::~Posix_QextSerialPort() +Standard destructor. +*/ +Posix_QextSerialPort::~Posix_QextSerialPort() +{ + if (isOpen()) { + close(); + } + Posix_File->close(); + delete Posix_File; +} + +/*! +\fn void Posix_QextSerialPort::setBaudRate(BaudRateType baudRate) +Sets the baud rate of the serial port. Note that not all rates are applicable on +all platforms. The following table shows translations of the various baud rate +constants on Windows(including NT/2000) and POSIX platforms. Speeds marked with an * +are speeds that are usable on both Windows and POSIX. + +\note +BAUD76800 may not be supported on all POSIX systems. SGI/IRIX systems do not support +BAUD1800. + +\verbatim + + RATE Windows Speed POSIX Speed + ----------- ------------- ----------- + BAUD50 110 50 + BAUD75 110 75 + *BAUD110 110 110 + BAUD134 110 134.5 + BAUD150 110 150 + BAUD200 110 200 + *BAUD300 300 300 + *BAUD600 600 600 + *BAUD1200 1200 1200 + BAUD1800 1200 1800 + *BAUD2400 2400 2400 + *BAUD4800 4800 4800 + *BAUD9600 9600 9600 + BAUD14400 14400 9600 + *BAUD19200 19200 19200 + *BAUD38400 38400 38400 + BAUD56000 56000 38400 + *BAUD57600 57600 57600 + BAUD76800 57600 76800 + *BAUD115200 115200 115200 + BAUD128000 128000 115200 + BAUD256000 256000 115200 +\endverbatim +*/ +void Posix_QextSerialPort::setBaudRate(BaudRateType baudRate) +{ + LOCK_MUTEX(); + if (Settings.BaudRate!=baudRate) { + switch (baudRate) { + case BAUD14400: + Settings.BaudRate=BAUD9600; + break; + + case BAUD56000: + Settings.BaudRate=BAUD38400; + break; + + case BAUD76800: + +#ifndef B76800 + Settings.BaudRate=BAUD57600; +#else + Settings.BaudRate=baudRate; +#endif + break; + + case BAUD128000: + case BAUD256000: + Settings.BaudRate=BAUD115200; + break; + + default: + Settings.BaudRate=baudRate; + break; + } + } + if (isOpen()) { + switch (baudRate) { + + /*50 baud*/ + case BAUD50: + TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 50 baud operation."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B50; +#else + cfsetispeed(&Posix_CommConfig, B50); + cfsetospeed(&Posix_CommConfig, B50); +#endif + break; + + /*75 baud*/ + case BAUD75: + TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 75 baud operation."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B75; +#else + cfsetispeed(&Posix_CommConfig, B75); + cfsetospeed(&Posix_CommConfig, B75); +#endif + break; + + /*110 baud*/ + case BAUD110: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B110; +#else + cfsetispeed(&Posix_CommConfig, B110); + cfsetospeed(&Posix_CommConfig, B110); +#endif + break; + + /*134.5 baud*/ + case BAUD134: + TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 134.5 baud operation."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B134; +#else + cfsetispeed(&Posix_CommConfig, B134); + cfsetospeed(&Posix_CommConfig, B134); +#endif + break; + + /*150 baud*/ + case BAUD150: + TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 150 baud operation."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B150; +#else + cfsetispeed(&Posix_CommConfig, B150); + cfsetospeed(&Posix_CommConfig, B150); +#endif + break; + + /*200 baud*/ + case BAUD200: + TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 200 baud operation."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B200; +#else + cfsetispeed(&Posix_CommConfig, B200); + cfsetospeed(&Posix_CommConfig, B200); +#endif + break; + + /*300 baud*/ + case BAUD300: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B300; +#else + cfsetispeed(&Posix_CommConfig, B300); + cfsetospeed(&Posix_CommConfig, B300); +#endif + break; + + /*600 baud*/ + case BAUD600: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B600; +#else + cfsetispeed(&Posix_CommConfig, B600); + cfsetospeed(&Posix_CommConfig, B600); +#endif + break; + + /*1200 baud*/ + case BAUD1200: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B1200; +#else + cfsetispeed(&Posix_CommConfig, B1200); + cfsetospeed(&Posix_CommConfig, B1200); +#endif + break; + + /*1800 baud*/ + case BAUD1800: + TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows and IRIX do not support 1800 baud operation."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B1800; +#else + cfsetispeed(&Posix_CommConfig, B1800); + cfsetospeed(&Posix_CommConfig, B1800); +#endif + break; + + /*2400 baud*/ + case BAUD2400: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B2400; +#else + cfsetispeed(&Posix_CommConfig, B2400); + cfsetospeed(&Posix_CommConfig, B2400); +#endif + break; + + /*4800 baud*/ + case BAUD4800: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B4800; +#else + cfsetispeed(&Posix_CommConfig, B4800); + cfsetospeed(&Posix_CommConfig, B4800); +#endif + break; + + /*9600 baud*/ + case BAUD9600: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B9600; +#else + cfsetispeed(&Posix_CommConfig, B9600); + cfsetospeed(&Posix_CommConfig, B9600); +#endif + break; + + /*14400 baud*/ + case BAUD14400: + TTY_WARNING("Posix_QextSerialPort: POSIX does not support 14400 baud operation. Switching to 9600 baud."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B9600; +#else + cfsetispeed(&Posix_CommConfig, B9600); + cfsetospeed(&Posix_CommConfig, B9600); +#endif + break; + + /*19200 baud*/ + case BAUD19200: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B19200; +#else + cfsetispeed(&Posix_CommConfig, B19200); + cfsetospeed(&Posix_CommConfig, B19200); +#endif + break; + + /*38400 baud*/ + case BAUD38400: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B38400; +#else + cfsetispeed(&Posix_CommConfig, B38400); + cfsetospeed(&Posix_CommConfig, B38400); +#endif + break; + + /*56000 baud*/ + case BAUD56000: + TTY_WARNING("Posix_QextSerialPort: POSIX does not support 56000 baud operation. Switching to 38400 baud."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B38400; +#else + cfsetispeed(&Posix_CommConfig, B38400); + cfsetospeed(&Posix_CommConfig, B38400); +#endif + break; + + /*57600 baud*/ + case BAUD57600: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B57600; +#else + cfsetispeed(&Posix_CommConfig, B57600); + cfsetospeed(&Posix_CommConfig, B57600); +#endif + break; + + /*76800 baud*/ + case BAUD76800: + TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows and some POSIX systems do not support 76800 baud operation."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + +#ifdef B76800 + Posix_CommConfig.c_cflag|=B76800; +#else + TTY_WARNING("Posix_QextSerialPort: Posix_QextSerialPort was compiled without 76800 baud support. Switching to 57600 baud."); + Posix_CommConfig.c_cflag|=B57600; +#endif //B76800 +#else //CBAUD +#ifdef B76800 + cfsetispeed(&Posix_CommConfig, B76800); + cfsetospeed(&Posix_CommConfig, B76800); +#else + TTY_WARNING("Posix_QextSerialPort: Posix_QextSerialPort was compiled without 76800 baud support. Switching to 57600 baud."); + cfsetispeed(&Posix_CommConfig, B57600); + cfsetospeed(&Posix_CommConfig, B57600); +#endif //B76800 +#endif //CBAUD + break; + + /*115200 baud*/ + case BAUD115200: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B115200; +#else + cfsetispeed(&Posix_CommConfig, B115200); + cfsetospeed(&Posix_CommConfig, B115200); +#endif + break; + + /*128000 baud*/ + case BAUD128000: + TTY_WARNING("Posix_QextSerialPort: POSIX does not support 128000 baud operation. Switching to 115200 baud."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B115200; +#else + cfsetispeed(&Posix_CommConfig, B115200); + cfsetospeed(&Posix_CommConfig, B115200); +#endif + break; + + /*256000 baud*/ + case BAUD256000: + TTY_WARNING("Posix_QextSerialPort: POSIX does not support 256000 baud operation. Switching to 115200 baud."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B115200; +#else + cfsetispeed(&Posix_CommConfig, B115200); + cfsetospeed(&Posix_CommConfig, B115200); +#endif + break; + } + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + } + UNLOCK_MUTEX(); +} + +/*! +\fn void Posix_QextSerialPort::setDataBits(DataBitsType dataBits) +Sets the number of data bits used by the serial port. Possible values of dataBits are: +\verbatim + DATA_5 5 data bits + DATA_6 6 data bits + DATA_7 7 data bits + DATA_8 8 data bits +\endverbatim + +\note +This function is subject to the following restrictions: +\par + 5 data bits cannot be used with 2 stop bits. +\par + 8 data bits cannot be used with space parity on POSIX systems. + +*/ +void Posix_QextSerialPort::setDataBits(DataBitsType dataBits) +{ + LOCK_MUTEX(); + if (Settings.DataBits!=dataBits) { + if ((Settings.StopBits==STOP_2 && dataBits==DATA_5) || + (Settings.StopBits==STOP_1_5 && dataBits!=DATA_5) || + (Settings.Parity==PAR_SPACE && dataBits==DATA_8)) { + } + else { + Settings.DataBits=dataBits; + } + } + if (isOpen()) { + switch(dataBits) { + + /*5 data bits*/ + case DATA_5: + if (Settings.StopBits==STOP_2) { + TTY_WARNING("Posix_QextSerialPort: 5 Data bits cannot be used with 2 stop bits."); + } + else { + Settings.DataBits=dataBits; + Posix_CommConfig.c_cflag&=(~CSIZE); + Posix_CommConfig.c_cflag|=CS5; + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + } + break; + + /*6 data bits*/ + case DATA_6: + if (Settings.StopBits==STOP_1_5) { + TTY_WARNING("Posix_QextSerialPort: 6 Data bits cannot be used with 1.5 stop bits."); + } + else { + Settings.DataBits=dataBits; + Posix_CommConfig.c_cflag&=(~CSIZE); + Posix_CommConfig.c_cflag|=CS6; + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + } + break; + + /*7 data bits*/ + case DATA_7: + if (Settings.StopBits==STOP_1_5) { + TTY_WARNING("Posix_QextSerialPort: 7 Data bits cannot be used with 1.5 stop bits."); + } + else { + Settings.DataBits=dataBits; + Posix_CommConfig.c_cflag&=(~CSIZE); + Posix_CommConfig.c_cflag|=CS7; + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + } + break; + + /*8 data bits*/ + case DATA_8: + if (Settings.StopBits==STOP_1_5) { + TTY_WARNING("Posix_QextSerialPort: 8 Data bits cannot be used with 1.5 stop bits."); + } + else { + Settings.DataBits=dataBits; + Posix_CommConfig.c_cflag&=(~CSIZE); + Posix_CommConfig.c_cflag|=CS8; + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + } + break; + } + } + UNLOCK_MUTEX(); +} + +/*! +\fn void Posix_QextSerialPort::setParity(ParityType parity) +Sets the parity associated with the serial port. The possible values of parity are: +\verbatim + PAR_SPACE Space Parity + PAR_MARK Mark Parity + PAR_NONE No Parity + PAR_EVEN Even Parity + PAR_ODD Odd Parity +\endverbatim + +\note +This function is subject to the following limitations: +\par +POSIX systems do not support mark parity. +\par +POSIX systems support space parity only if tricked into doing so, and only with + fewer than 8 data bits. Use space parity very carefully with POSIX systems. + +*/ +void Posix_QextSerialPort::setParity(ParityType parity) +{ + LOCK_MUTEX(); + if (Settings.Parity!=parity) { + if (parity==PAR_MARK || (parity==PAR_SPACE && Settings.DataBits==DATA_8)) { + } + else { + Settings.Parity=parity; + } + } + if (isOpen()) { + switch (parity) { + + /*space parity*/ + case PAR_SPACE: + if (Settings.DataBits==DATA_8) { + TTY_PORTABILITY_WARNING("Posix_QextSerialPort: Space parity is only supported in POSIX with 7 or fewer data bits"); + } + else { + + /*space parity not directly supported - add an extra data bit to simulate it*/ + Posix_CommConfig.c_cflag&=~(PARENB|CSIZE); + switch(Settings.DataBits) { + case DATA_5: + Settings.DataBits=DATA_6; + Posix_CommConfig.c_cflag|=CS6; + break; + + case DATA_6: + Settings.DataBits=DATA_7; + Posix_CommConfig.c_cflag|=CS7; + break; + + case DATA_7: + Settings.DataBits=DATA_8; + Posix_C... [truncated message content] |
From: <cs...@us...> - 2007-12-28 22:19:41
|
Revision: 83 http://hrs.svn.sourceforge.net/hrs/?rev=83&view=rev Author: csete Date: 2007-12-28 14:19:40 -0800 (Fri, 28 Dec 2007) Log Message: ----------- Updated. Modified Paths: -------------- trunk/hrs.pro trunk/src/MainWindow.cpp trunk/src/MainWindow.h trunk/src/main.cpp trunk/src/serial/serial.pro trunk/src/src.pro trunk/tests/tests.pro trunk/tests/testserial/testserial.pro Modified: trunk/hrs.pro =================================================================== --- trunk/hrs.pro 2007-12-28 22:15:42 UTC (rev 82) +++ trunk/hrs.pro 2007-12-28 22:19:40 UTC (rev 83) @@ -1,5 +1,5 @@ SUBDIRS += src/serial \ - src + src TEMPLATE = subdirs CONFIG += debug Modified: trunk/src/MainWindow.cpp =================================================================== --- trunk/src/MainWindow.cpp 2007-12-28 22:15:42 UTC (rev 82) +++ trunk/src/MainWindow.cpp 2007-12-28 22:19:40 UTC (rev 83) @@ -1,7 +1,9 @@ /*************************************************************************** + * * + * Ham Radio Studio http://hrs.sf.net/ * + * * * Copyright (C) 2007 by Alexandru Csete OZ9AEC * * * - * * * 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 * @@ -16,13 +18,18 @@ * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * * ***************************************************************************/ #include <QtGui> #include "MainWindow.h" +#include "QSerTest.h" MainWindow::MainWindow() { + QSerTest *test; + + //spreadsheet = new Spreadsheet; //setCentralWidget(spreadsheet); createActions(); @@ -32,7 +39,9 @@ //createStatusBar(); //readSettings(); //setWindowIcon(QIcon(":/images/icon.png")); - + + test = new QSerTest(this); + setCentralWidget(test); } Modified: trunk/src/MainWindow.h =================================================================== --- trunk/src/MainWindow.h 2007-12-28 22:15:42 UTC (rev 82) +++ trunk/src/MainWindow.h 2007-12-28 22:19:40 UTC (rev 83) @@ -1,7 +1,9 @@ /*************************************************************************** + * * + * Ham Radio Studio http://hrs.sf.net/ * + * * * Copyright (C) 2007 by Alexandru Csete OZ9AEC * * * - * * * 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 * @@ -16,6 +18,7 @@ * 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 Modified: trunk/src/main.cpp =================================================================== --- trunk/src/main.cpp 2007-12-28 22:15:42 UTC (rev 82) +++ trunk/src/main.cpp 2007-12-28 22:19:40 UTC (rev 83) @@ -1,3 +1,25 @@ +/*************************************************************************** + * * + * Ham Radio Studio http://hrs.sf.net/ * + * * + * Copyright (C) 2007 by Alexandru Csete OZ9AEC * + * * + * 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 <QApplication> #include "MainWindow.h" Modified: trunk/src/serial/serial.pro =================================================================== --- trunk/src/serial/serial.pro 2007-12-28 22:15:42 UTC (rev 82) +++ trunk/src/serial/serial.pro 2007-12-28 22:19:40 UTC (rev 83) @@ -23,5 +23,7 @@ win32:DEFINES += _TTY_WIN_ DESTDIR = ../../build +OBJECTS_DIR = $(DESTDIR)/obj +MOC_DIR = $(DESTDIR)/moc TARGET = qextserialport unix:VERSION = 1.0.0 Modified: trunk/src/src.pro =================================================================== --- trunk/src/src.pro 2007-12-28 22:15:42 UTC (rev 82) +++ trunk/src/src.pro 2007-12-28 22:19:40 UTC (rev 83) @@ -1,10 +1,24 @@ SOURCES += MainWindow.cpp \ - main.cpp -HEADERS += MainWindow.h + main.cpp \ + QSerTest.cpp + +HEADERS += MainWindow.h \ + QSerTest.h + TEMPLATE = app + CONFIG += warn_on \ debug \ thread \ qt -TARGET = hrs -RESOURCES = ../icons/icons.qrc + +unix:DEFINES += _TTY_POSIX_ +win32:DEFINES += _TTY_WIN_ + +DESTDIR = ../build +OBJECTS_DIR = $(DESTDIR)/obj +MOC_DIR = $(DESTDIR)/moc +TARGET = hrs +RESOURCES = ../icons/icons.qrc +INCLUDEPATH += serial +LIBS += $(DESTDIR)/libqextserialport.a Modified: trunk/tests/tests.pro =================================================================== --- trunk/tests/tests.pro 2007-12-28 22:15:42 UTC (rev 82) +++ trunk/tests/tests.pro 2007-12-28 22:19:40 UTC (rev 83) @@ -1,6 +1,4 @@ -SUBDIRS += src/serial \ - src \ - tests/testserial +SUBDIRS += testserial TEMPLATE = subdirs CONFIG += debug @@ -9,6 +7,4 @@ qt \ thread -DESTDIR = build -OBJECTS_DIR = build/obj -MOC_DIR = build/moc + Modified: trunk/tests/testserial/testserial.pro =================================================================== --- trunk/tests/testserial/testserial.pro 2007-12-28 22:15:42 UTC (rev 82) +++ trunk/tests/testserial/testserial.pro 2007-12-28 22:19:40 UTC (rev 83) @@ -15,7 +15,6 @@ unix:DEFINES += _TTY_POSIX_ win32:DEFINES += _TTY_WIN_ -unix:TARGET = testserial -win32:TARGET =testserial.exe +TARGET = ../testserial INCLUDEPATH += ../../src/serial LIBS += ../../build/libqextserialport.a This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-28 22:15:44
|
Revision: 82 http://hrs.svn.sourceforge.net/hrs/?rev=82&view=rev Author: csete Date: 2007-12-28 14:15:42 -0800 (Fri, 28 Dec 2007) Log Message: ----------- Moved serial test program to separate directory. Added Paths: ----------- trunk/tests/ trunk/tests/tests.pro trunk/tests/testserial/ trunk/tests/testserial/MainWindow.cpp trunk/tests/testserial/MainWindow.h trunk/tests/testserial/QSerTest.cpp trunk/tests/testserial/QSerTest.h trunk/tests/testserial/main.cpp trunk/tests/testserial/testserial.pro Added: trunk/tests/tests.pro =================================================================== --- trunk/tests/tests.pro (rev 0) +++ trunk/tests/tests.pro 2007-12-28 22:15:42 UTC (rev 82) @@ -0,0 +1,14 @@ +SUBDIRS += src/serial \ + src \ + tests/testserial + +TEMPLATE = subdirs +CONFIG += debug +#CONFIG += release +CONFIG += warn_on \ + qt \ + thread + +DESTDIR = build +OBJECTS_DIR = build/obj +MOC_DIR = build/moc Added: trunk/tests/testserial/MainWindow.cpp =================================================================== --- trunk/tests/testserial/MainWindow.cpp (rev 0) +++ trunk/tests/testserial/MainWindow.cpp 2007-12-28 22:15:42 UTC (rev 82) @@ -0,0 +1,139 @@ +/*************************************************************************** + * * + * Ham Radio Studio http://hrs.sf.net/ * + * * + * Copyright (C) 2007 by Alexandru Csete OZ9AEC * + * * + * 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 <QtGui> +#include "MainWindow.h" +#include "QSerTest.h" + + +MainWindow::MainWindow() +{ + QSerTest *test; + + + //spreadsheet = new Spreadsheet; + //setCentralWidget(spreadsheet); + createActions(); + createMenus(); + //createContextMenu(); + //createToolBars(); + //createStatusBar(); + //readSettings(); + //setWindowIcon(QIcon(":/images/icon.png")); + + test = new QSerTest(this); + setCentralWidget(test); +} + + + +void MainWindow::createMenus() +{ + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(saveAsAction); + fileMenu->addSeparator(); + fileMenu->addAction(exitAction); + + menuBar()->addSeparator(); + + helpMenu = menuBar()->addMenu(tr("&Help")); + helpMenu->addAction(umAction); + helpMenu->addSeparator(); + helpMenu->addAction(aboutAction); + helpMenu->addAction(aboutQtAction); +} + + + +/** \brief Create menu and toolbar actions + * + */ +void MainWindow::createActions() +{ + + /* File -> Save As */ + saveAsAction = new QAction(tr("Save &As..."), this); + saveAsAction->setIcon(QIcon(":/icon/save-as.png")); + saveAsAction->setStatusTip(tr("Save the logbook to a new file")); + connect(saveAsAction, SIGNAL(triggered()), this, SLOT(saveAs())); + + exitAction = new QAction(tr("E&xit"), this); + exitAction->setIcon(QIcon(":/icon/quit.png")); + exitAction->setShortcut(tr("Ctrl+Q")); + exitAction->setStatusTip(tr("Exit the application")); + connect(exitAction, SIGNAL(triggered()), + qApp, SLOT(closeAllWindows())); + + /* Help -> contents */ + umAction = new QAction(tr("&Contents"), this); + umAction->setIcon(QIcon(":/icon/help.png")); + umAction->setShortcut(tr("F1")); + + /* Help -> About */ + aboutAction = new QAction(tr("&About"), this); + aboutAction->setIcon(QIcon(":/icon/about.png")); + aboutAction->setStatusTip(tr("Ahow about box")); + connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); + + /* Help -> About Qt */ + aboutQtAction = new QAction(tr("About &Qt"), this); + aboutQtAction->setStatusTip(tr("Show the Qt library's About box")); + connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + +} + + +bool MainWindow::saveAs() +{ + QString fileName = QFileDialog::getSaveFileName(this, + tr("Save Spreadsheet"), ".", + tr("Spreadsheet files (*.sp)")); + + if (fileName.isEmpty()) + return false; + + return true; + //return saveFile(fileName); +} + + +void MainWindow::closeEvent(QCloseEvent *event) +{ + //if (okToContinue()) { + //writeSettings(); + event->accept(); + + //} else { + // event->ignore(); + //} +} + + + +void MainWindow::about() +{ + QMessageBox::about(this, tr("About HRS"), + tr("<h2>Ham Radio Studio 1.0</h2>" + "<p>Copyright © 2007 Alexandru Csete OZ9AEC." + "<p>Description")); +} + Added: trunk/tests/testserial/MainWindow.h =================================================================== --- trunk/tests/testserial/MainWindow.h (rev 0) +++ trunk/tests/testserial/MainWindow.h 2007-12-28 22:15:42 UTC (rev 82) @@ -0,0 +1,67 @@ +/*************************************************************************** + * * + * Ham Radio Studio http://hrs.sf.net/ * + * * + * Copyright (C) 2007 by Alexandru Csete OZ9AEC * + * * + * 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 <QMainWindow> + + + +class MainWindow : public QMainWindow +{ + Q_OBJECT + public: + MainWindow(); + + protected: + void closeEvent(QCloseEvent *event); + + private slots: + bool saveAs(); + void about(); + + + + private: + void createActions(); + void createMenus(); + //void createContextMenu(); + //void createToolBars(); + //void createStatusBar(); + //void readSettings(); + //void writeSettings(); + + /* File Menu */ + QMenu *fileMenu; + QAction *saveAsAction; + QAction *exitAction; + QAction *separatorAction; + + /* Help menu */ + QMenu *helpMenu; + QAction *umAction; + QAction *aboutAction; + QAction *aboutQtAction; + +}; + +#endif Added: trunk/tests/testserial/QSerTest.cpp =================================================================== --- trunk/tests/testserial/QSerTest.cpp (rev 0) +++ trunk/tests/testserial/QSerTest.cpp 2007-12-28 22:15:42 UTC (rev 82) @@ -0,0 +1,115 @@ +/*************************************************************************** + * * + * Ham Radio Studio http://hrs.sf.net/ * + * * + * Copyright (C) 2007 by Alexandru Csete OZ9AEC * + * * + * 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 <QtGui> +#include <QtDebug> +#include <qextserialport.h> +#include "QSerTest.h" + + +QSerTest::QSerTest(QWidget *parent) : QWidget(parent) +{ + QVBoxLayout *myVBox; // main vertical box + QHBoxLayout *txHBox; // hbox with DTR and RTS buttons + + + port = new QextSerialPort("/dev/ttyUSB0"); + port->setBaudRate(BAUD9600); + port->setFlowControl(FLOW_OFF); + port->setParity(PAR_NONE); + port->setDataBits(DATA_8); + port->setStopBits(STOP_1); + + opnButton = new QPushButton("OPEN", this); + opnButton->setCheckable(true); + connect(opnButton, SIGNAL(toggled(bool)), this, SLOT(toggle(bool))); + + // DTR and RTS buttons + dtrButton = new QPushButton("DTR", this); + connect(dtrButton, SIGNAL(pressed()), this, SLOT(dtrOn())); + connect(dtrButton, SIGNAL(released()), this, SLOT(dtrOff())); + + rtsButton = new QPushButton("RTS", this); + connect(rtsButton, SIGNAL(pressed()), this, SLOT(rtsOn())); + connect(rtsButton, SIGNAL(released()), this, SLOT(rtsOff())); + + txHBox = new QHBoxLayout; + txHBox->addWidget(rtsButton); + txHBox->addWidget(dtrButton); + + // main vertical container + myVBox = new QVBoxLayout; + myVBox->addWidget(opnButton); + myVBox->addLayout(txHBox); + + setLayout(myVBox); +} + + +QSerTest::~QSerTest() +{ + if (port->isOpen()) { + port->close(); + } + delete port; + port = NULL; +} + + +void QSerTest::toggle(bool on) +{ + if (on) { + port->open(QIODevice::ReadWrite); + port->setDtr(FALSE); + port->setRts(FALSE); + qDebug() << "PORT: " << port->isOpen(); + } + else { + port->close(); + qDebug() << "PORT: " << port->isOpen(); + } +} + + +void QSerTest::dtrOn() +{ + port->setDtr(true); + qDebug() << "dtrOn"; +} + +void QSerTest::dtrOff() +{ + port->setDtr(false); + qDebug() << "dtrOff"; +} + +void QSerTest::rtsOn() +{ + port->setRts(TRUE); + qDebug() << "rtsOn"; +} + +void QSerTest::rtsOff() +{ + port->setRts(FALSE); + qDebug() << "rtsOff"; +} Added: trunk/tests/testserial/QSerTest.h =================================================================== --- trunk/tests/testserial/QSerTest.h (rev 0) +++ trunk/tests/testserial/QSerTest.h 2007-12-28 22:15:42 UTC (rev 82) @@ -0,0 +1,61 @@ +/*************************************************************************** + * * + * Ham Radio Studio http://hrs.sf.net/ * + * * + * Copyright (C) 2007 by Alexandru Csete OZ9AEC * + * * + * 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 QSERTEST_H +#define QSERTEST_H + +#include <QtGui> + +class QextSerialPort; + + +class QSerTest : public QWidget +{ + Q_OBJECT + + public: + QSerTest(QWidget *parent=0); + ~QSerTest(); + + private: + QextSerialPort *port; + + QLineEdit *device; + QLineEdit *speed; + QLabel *freq; + + QPushButton *dtrButton; + QPushButton *rtsButton; + QPushButton *opnButton; + + private slots: + void toggle(bool on); + + void dtrOn(); + void dtrOff(); + void rtsOn(); + void rtsOff(); + +}; + + +#endif Added: trunk/tests/testserial/main.cpp =================================================================== --- trunk/tests/testserial/main.cpp (rev 0) +++ trunk/tests/testserial/main.cpp 2007-12-28 22:15:42 UTC (rev 82) @@ -0,0 +1,37 @@ +/*************************************************************************** + * * + * Ham Radio Studio http://hrs.sf.net/ * + * * + * Copyright (C) 2007 by Alexandru Csete OZ9AEC * + * * + * 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 <QApplication> +#include "MainWindow.h" + + +int main(int argc, char *argv[]) +{ + + QApplication app(argc, argv); + MainWindow *mainWin = new MainWindow; + + mainWin->show(); + + return app.exec(); + +} Added: trunk/tests/testserial/testserial.pro =================================================================== --- trunk/tests/testserial/testserial.pro (rev 0) +++ trunk/tests/testserial/testserial.pro 2007-12-28 22:15:42 UTC (rev 82) @@ -0,0 +1,21 @@ +SOURCES += MainWindow.cpp \ + main.cpp \ + QSerTest.cpp + +HEADERS += MainWindow.h \ + QSerTest.h + +TEMPLATE = app + +CONFIG += warn_on \ + debug \ + thread \ + qt + +unix:DEFINES += _TTY_POSIX_ +win32:DEFINES += _TTY_WIN_ + +unix:TARGET = testserial +win32:TARGET =testserial.exe +INCLUDEPATH += ../../src/serial +LIBS += ../../build/libqextserialport.a This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-28 19:15:54
|
Revision: 81 http://hrs.svn.sourceforge.net/hrs/?rev=81&view=rev Author: csete Date: 2007-12-28 11:15:50 -0800 (Fri, 28 Dec 2007) Log Message: ----------- Added directories. Added Paths: ----------- trunk/build/moc/ trunk/build/obj/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-28 18:26:10
|
Revision: 80 http://hrs.svn.sourceforge.net/hrs/?rev=80&view=rev Author: csete Date: 2007-12-28 10:26:09 -0800 (Fri, 28 Dec 2007) Log Message: ----------- Updated. Modified Paths: -------------- trunk/hrs.pro trunk/hrslogbook/MainWindow.cpp trunk/hrslogbook/MainWindow.h trunk/src/serial/serial.pro trunk/src/src.pro Modified: trunk/hrs.pro =================================================================== --- trunk/hrs.pro 2007-12-28 18:18:19 UTC (rev 79) +++ trunk/hrs.pro 2007-12-28 18:26:09 UTC (rev 80) @@ -1,9 +1,13 @@ -SUBDIRS += hrscluster \ - hrslogbook \ - hrsmap \ - hrsrig \ - hrsrot +SUBDIRS += src/serial \ + src + TEMPLATE = subdirs +CONFIG += debug +#CONFIG += release CONFIG += warn_on \ qt \ thread + +DESTDIR = build +OBJECTS_DIR = build/obj +MOC_DIR = build/moc Modified: trunk/hrslogbook/MainWindow.cpp =================================================================== --- trunk/hrslogbook/MainWindow.cpp 2007-12-28 18:18:19 UTC (rev 79) +++ trunk/hrslogbook/MainWindow.cpp 2007-12-28 18:26:09 UTC (rev 80) @@ -39,6 +39,15 @@ //readSettings(); //setWindowIcon(QIcon(":/images/icon.png")); + + /* Create log browsers */ + nBook = new QTabWidget (this); + setCentralWidget (nBook); + + setWindowTitle (tr("HRS Map %1.%2 %3") + .arg(HRS_MAJOR_VERSION) + .arg(HRS_MINOR_VERSION) + .arg(HRS_BETA_STRING)); } Modified: trunk/hrslogbook/MainWindow.h =================================================================== --- trunk/hrslogbook/MainWindow.h 2007-12-28 18:18:19 UTC (rev 79) +++ trunk/hrslogbook/MainWindow.h 2007-12-28 18:26:09 UTC (rev 80) @@ -20,6 +20,7 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> +#include <QTabWidget> @@ -67,6 +68,8 @@ QAction *aboutAction; //!< The 'About' menu item QAction *aboutQtAction; //!< The 'About Qt' menu item + QTabWidget *nBook; //!< Notebook widget containing log browsers + }; #endif Modified: trunk/src/serial/serial.pro =================================================================== --- trunk/src/serial/serial.pro 2007-12-28 18:18:19 UTC (rev 79) +++ trunk/src/serial/serial.pro 2007-12-28 18:26:09 UTC (rev 80) @@ -1,5 +1,5 @@ -PROJECT = qextserialport +#PROJECT = qextserialport TEMPLATE = lib CONFIG -= debug_and_release @@ -7,8 +7,6 @@ CONFIG += staticlib QT -= gui -OBJECTS_DIR = ../../build/obj -MOC_DIR = ../../build/moc DEPENDDIR = . INCLUDEDIR = . HEADERS = qextserialbase.h \ Modified: trunk/src/src.pro =================================================================== --- trunk/src/src.pro 2007-12-28 18:18:19 UTC (rev 79) +++ trunk/src/src.pro 2007-12-28 18:26:09 UTC (rev 80) @@ -6,5 +6,5 @@ debug \ thread \ qt -TARGET = ../dist/linux/bin/hrs +TARGET = hrs RESOURCES = ../icons/icons.qrc This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-28 18:18:21
|
Revision: 79 http://hrs.svn.sourceforge.net/hrs/?rev=79&view=rev Author: csete Date: 2007-12-28 10:18:19 -0800 (Fri, 28 Dec 2007) Log Message: ----------- Added files. Added Paths: ----------- trunk/src/serial/posix_qextserialport.cpp trunk/src/serial/posix_qextserialport.h trunk/src/serial/qextserialbase.cpp trunk/src/serial/qextserialbase.h trunk/src/serial/qextserialport.cpp trunk/src/serial/qextserialport.h trunk/src/serial/serial.pro trunk/src/serial/win_qextserialport.cpp trunk/src/serial/win_qextserialport.h Added: trunk/src/serial/posix_qextserialport.cpp =================================================================== --- trunk/src/serial/posix_qextserialport.cpp (rev 0) +++ trunk/src/serial/posix_qextserialport.cpp 2007-12-28 18:18:19 UTC (rev 79) @@ -0,0 +1,1117 @@ + +/*! +\class Posix_QextSerialPort +\version 1.0.0 +\author Stefan Sander + +A cross-platform serial port class. +This class encapsulates the POSIX portion of QextSerialPort. The user will be notified of errors +and possible portability conflicts at run-time by default - this behavior can be turned off by +defining _TTY_NOWARN_ (to turn off all warnings) or _TTY_NOWARN_PORT_ (to turn off portability +warnings) in the project. Note that _TTY_NOWARN_ will also turn off portability warnings. +*/ + +#include <stdio.h> +#include "posix_qextserialport.h" + +/*! +\fn Posix_QextSerialPort::Posix_QextSerialPort() +Default constructor. Note that the name of the device used by a QextSerialPort constructed with +this constructor will be determined by #defined constants, or lack thereof - the default behavior +is the same as _TTY_LINUX_. Possible naming conventions and their associated constants are: + +\verbatim + +Constant Used By Naming Convention +---------- ------------- ------------------------ +_TTY_WIN_ Windows COM1, COM2 +_TTY_IRIX_ SGI/IRIX /dev/ttyf1, /dev/ttyf2 +_TTY_HPUX_ HP-UX /dev/tty1p0, /dev/tty2p0 +_TTY_SUN_ SunOS/Solaris /dev/ttya, /dev/ttyb +_TTY_DIGITAL_ Digital UNIX /dev/tty01, /dev/tty02 +_TTY_FREEBSD_ FreeBSD /dev/ttyd0, /dev/ttyd1 +_TTY_LINUX_ Linux /dev/ttyS0, /dev/ttyS1 +<none> Linux /dev/ttyS0, /dev/ttyS1 +\endverbatim + +This constructor assigns the device name to the name of the first port on the specified system. +See the other constructors if you need to open a different port. +*/ +Posix_QextSerialPort::Posix_QextSerialPort() +: QextSerialBase() +{ + Posix_File=new QFile(); +} + +/*! +\fn Posix_QextSerialPort::Posix_QextSerialPort(const Posix_QextSerialPort&) +Copy constructor. +*/ +Posix_QextSerialPort::Posix_QextSerialPort(const Posix_QextSerialPort& s) + : QextSerialBase(s.port) +{ + setOpenMode(s.openMode()); + port = s.port; + Settings.BaudRate=s.Settings.BaudRate; + Settings.DataBits=s.Settings.DataBits; + Settings.Parity=s.Settings.Parity; + Settings.StopBits=s.Settings.StopBits; + Settings.FlowControl=s.Settings.FlowControl; + lastErr=s.lastErr; + + Posix_File=new QFile(); + Posix_File=s.Posix_File; + memcpy(&Posix_Timeout, &s.Posix_Timeout, sizeof(struct timeval)); + memcpy(&Posix_Copy_Timeout, &s.Posix_Copy_Timeout, sizeof(struct timeval)); + memcpy(&Posix_CommConfig, &s.Posix_CommConfig, sizeof(struct termios)); +} + +/*! +\fn Posix_QextSerialPort::Posix_QextSerialPort(const QString & name) +Constructs a serial port attached to the port specified by name. +name is the name of the device, which is windowsystem-specific, +e.g."COM1" or "/dev/ttyS0". +*/ +Posix_QextSerialPort::Posix_QextSerialPort(const QString & name) + : QextSerialBase(name) +{ + Posix_File=new QFile(); +} + +/*! +\fn Posix_QextSerialPort::Posix_QextSerialPort(const PortSettings& settings) +Constructs a port with default name and specified settings. +*/ +Posix_QextSerialPort::Posix_QextSerialPort(const PortSettings& settings) + : QextSerialBase() +{ + setBaudRate(settings.BaudRate); + setDataBits(settings.DataBits); + setParity(settings.Parity); + setStopBits(settings.StopBits); + setFlowControl(settings.FlowControl); + + Posix_File=new QFile(); + setTimeout(settings.Timeout_Sec, settings.Timeout_Millisec); +} + +/*! +\fn Posix_QextSerialPort::Posix_QextSerialPort(const QString & name, const PortSettings& settings) +Constructs a port with specified name and settings. +*/ +Posix_QextSerialPort::Posix_QextSerialPort(const QString & name, const PortSettings& settings) + : QextSerialBase(name) +{ + setBaudRate(settings.BaudRate); + setDataBits(settings.DataBits); + setParity(settings.Parity); + setStopBits(settings.StopBits); + setFlowControl(settings.FlowControl); + + Posix_File=new QFile(); + setTimeout(settings.Timeout_Sec, settings.Timeout_Millisec); +} + +/*! +\fn Posix_QextSerialPort& Posix_QextSerialPort::operator=(const Posix_QextSerialPort& s) +Override the = operator. +*/ +Posix_QextSerialPort& Posix_QextSerialPort::operator=(const Posix_QextSerialPort& s) +{ + setOpenMode(s.openMode()); + port = s.port; + Settings.BaudRate=s.Settings.BaudRate; + Settings.DataBits=s.Settings.DataBits; + Settings.Parity=s.Settings.Parity; + Settings.StopBits=s.Settings.StopBits; + Settings.FlowControl=s.Settings.FlowControl; + lastErr=s.lastErr; + + Posix_File=s.Posix_File; + memcpy(&Posix_Timeout, &(s.Posix_Timeout), sizeof(struct timeval)); + memcpy(&Posix_Copy_Timeout, &(s.Posix_Copy_Timeout), sizeof(struct timeval)); + memcpy(&Posix_CommConfig, &(s.Posix_CommConfig), sizeof(struct termios)); + return *this; +} + +/*! +\fn Posix_QextSerialPort::~Posix_QextSerialPort() +Standard destructor. +*/ +Posix_QextSerialPort::~Posix_QextSerialPort() +{ + if (isOpen()) { + close(); + } + Posix_File->close(); + delete Posix_File; +} + +/*! +\fn void Posix_QextSerialPort::setBaudRate(BaudRateType baudRate) +Sets the baud rate of the serial port. Note that not all rates are applicable on +all platforms. The following table shows translations of the various baud rate +constants on Windows(including NT/2000) and POSIX platforms. Speeds marked with an * +are speeds that are usable on both Windows and POSIX. + +\note +BAUD76800 may not be supported on all POSIX systems. SGI/IRIX systems do not support +BAUD1800. + +\verbatim + + RATE Windows Speed POSIX Speed + ----------- ------------- ----------- + BAUD50 110 50 + BAUD75 110 75 + *BAUD110 110 110 + BAUD134 110 134.5 + BAUD150 110 150 + BAUD200 110 200 + *BAUD300 300 300 + *BAUD600 600 600 + *BAUD1200 1200 1200 + BAUD1800 1200 1800 + *BAUD2400 2400 2400 + *BAUD4800 4800 4800 + *BAUD9600 9600 9600 + BAUD14400 14400 9600 + *BAUD19200 19200 19200 + *BAUD38400 38400 38400 + BAUD56000 56000 38400 + *BAUD57600 57600 57600 + BAUD76800 57600 76800 + *BAUD115200 115200 115200 + BAUD128000 128000 115200 + BAUD256000 256000 115200 +\endverbatim +*/ +void Posix_QextSerialPort::setBaudRate(BaudRateType baudRate) +{ + LOCK_MUTEX(); + if (Settings.BaudRate!=baudRate) { + switch (baudRate) { + case BAUD14400: + Settings.BaudRate=BAUD9600; + break; + + case BAUD56000: + Settings.BaudRate=BAUD38400; + break; + + case BAUD76800: + +#ifndef B76800 + Settings.BaudRate=BAUD57600; +#else + Settings.BaudRate=baudRate; +#endif + break; + + case BAUD128000: + case BAUD256000: + Settings.BaudRate=BAUD115200; + break; + + default: + Settings.BaudRate=baudRate; + break; + } + } + if (isOpen()) { + switch (baudRate) { + + /*50 baud*/ + case BAUD50: + TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 50 baud operation."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B50; +#else + cfsetispeed(&Posix_CommConfig, B50); + cfsetospeed(&Posix_CommConfig, B50); +#endif + break; + + /*75 baud*/ + case BAUD75: + TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 75 baud operation."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B75; +#else + cfsetispeed(&Posix_CommConfig, B75); + cfsetospeed(&Posix_CommConfig, B75); +#endif + break; + + /*110 baud*/ + case BAUD110: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B110; +#else + cfsetispeed(&Posix_CommConfig, B110); + cfsetospeed(&Posix_CommConfig, B110); +#endif + break; + + /*134.5 baud*/ + case BAUD134: + TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 134.5 baud operation."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B134; +#else + cfsetispeed(&Posix_CommConfig, B134); + cfsetospeed(&Posix_CommConfig, B134); +#endif + break; + + /*150 baud*/ + case BAUD150: + TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 150 baud operation."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B150; +#else + cfsetispeed(&Posix_CommConfig, B150); + cfsetospeed(&Posix_CommConfig, B150); +#endif + break; + + /*200 baud*/ + case BAUD200: + TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows does not support 200 baud operation."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B200; +#else + cfsetispeed(&Posix_CommConfig, B200); + cfsetospeed(&Posix_CommConfig, B200); +#endif + break; + + /*300 baud*/ + case BAUD300: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B300; +#else + cfsetispeed(&Posix_CommConfig, B300); + cfsetospeed(&Posix_CommConfig, B300); +#endif + break; + + /*600 baud*/ + case BAUD600: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B600; +#else + cfsetispeed(&Posix_CommConfig, B600); + cfsetospeed(&Posix_CommConfig, B600); +#endif + break; + + /*1200 baud*/ + case BAUD1200: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B1200; +#else + cfsetispeed(&Posix_CommConfig, B1200); + cfsetospeed(&Posix_CommConfig, B1200); +#endif + break; + + /*1800 baud*/ + case BAUD1800: + TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows and IRIX do not support 1800 baud operation."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B1800; +#else + cfsetispeed(&Posix_CommConfig, B1800); + cfsetospeed(&Posix_CommConfig, B1800); +#endif + break; + + /*2400 baud*/ + case BAUD2400: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B2400; +#else + cfsetispeed(&Posix_CommConfig, B2400); + cfsetospeed(&Posix_CommConfig, B2400); +#endif + break; + + /*4800 baud*/ + case BAUD4800: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B4800; +#else + cfsetispeed(&Posix_CommConfig, B4800); + cfsetospeed(&Posix_CommConfig, B4800); +#endif + break; + + /*9600 baud*/ + case BAUD9600: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B9600; +#else + cfsetispeed(&Posix_CommConfig, B9600); + cfsetospeed(&Posix_CommConfig, B9600); +#endif + break; + + /*14400 baud*/ + case BAUD14400: + TTY_WARNING("Posix_QextSerialPort: POSIX does not support 14400 baud operation. Switching to 9600 baud."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B9600; +#else + cfsetispeed(&Posix_CommConfig, B9600); + cfsetospeed(&Posix_CommConfig, B9600); +#endif + break; + + /*19200 baud*/ + case BAUD19200: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B19200; +#else + cfsetispeed(&Posix_CommConfig, B19200); + cfsetospeed(&Posix_CommConfig, B19200); +#endif + break; + + /*38400 baud*/ + case BAUD38400: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B38400; +#else + cfsetispeed(&Posix_CommConfig, B38400); + cfsetospeed(&Posix_CommConfig, B38400); +#endif + break; + + /*56000 baud*/ + case BAUD56000: + TTY_WARNING("Posix_QextSerialPort: POSIX does not support 56000 baud operation. Switching to 38400 baud."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B38400; +#else + cfsetispeed(&Posix_CommConfig, B38400); + cfsetospeed(&Posix_CommConfig, B38400); +#endif + break; + + /*57600 baud*/ + case BAUD57600: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B57600; +#else + cfsetispeed(&Posix_CommConfig, B57600); + cfsetospeed(&Posix_CommConfig, B57600); +#endif + break; + + /*76800 baud*/ + case BAUD76800: + TTY_PORTABILITY_WARNING("Posix_QextSerialPort Portability Warning: Windows and some POSIX systems do not support 76800 baud operation."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + +#ifdef B76800 + Posix_CommConfig.c_cflag|=B76800; +#else + TTY_WARNING("Posix_QextSerialPort: Posix_QextSerialPort was compiled without 76800 baud support. Switching to 57600 baud."); + Posix_CommConfig.c_cflag|=B57600; +#endif //B76800 +#else //CBAUD +#ifdef B76800 + cfsetispeed(&Posix_CommConfig, B76800); + cfsetospeed(&Posix_CommConfig, B76800); +#else + TTY_WARNING("Posix_QextSerialPort: Posix_QextSerialPort was compiled without 76800 baud support. Switching to 57600 baud."); + cfsetispeed(&Posix_CommConfig, B57600); + cfsetospeed(&Posix_CommConfig, B57600); +#endif //B76800 +#endif //CBAUD + break; + + /*115200 baud*/ + case BAUD115200: +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B115200; +#else + cfsetispeed(&Posix_CommConfig, B115200); + cfsetospeed(&Posix_CommConfig, B115200); +#endif + break; + + /*128000 baud*/ + case BAUD128000: + TTY_WARNING("Posix_QextSerialPort: POSIX does not support 128000 baud operation. Switching to 115200 baud."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B115200; +#else + cfsetispeed(&Posix_CommConfig, B115200); + cfsetospeed(&Posix_CommConfig, B115200); +#endif + break; + + /*256000 baud*/ + case BAUD256000: + TTY_WARNING("Posix_QextSerialPort: POSIX does not support 256000 baud operation. Switching to 115200 baud."); +#ifdef CBAUD + Posix_CommConfig.c_cflag&=(~CBAUD); + Posix_CommConfig.c_cflag|=B115200; +#else + cfsetispeed(&Posix_CommConfig, B115200); + cfsetospeed(&Posix_CommConfig, B115200); +#endif + break; + } + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + } + UNLOCK_MUTEX(); +} + +/*! +\fn void Posix_QextSerialPort::setDataBits(DataBitsType dataBits) +Sets the number of data bits used by the serial port. Possible values of dataBits are: +\verbatim + DATA_5 5 data bits + DATA_6 6 data bits + DATA_7 7 data bits + DATA_8 8 data bits +\endverbatim + +\note +This function is subject to the following restrictions: +\par + 5 data bits cannot be used with 2 stop bits. +\par + 8 data bits cannot be used with space parity on POSIX systems. + +*/ +void Posix_QextSerialPort::setDataBits(DataBitsType dataBits) +{ + LOCK_MUTEX(); + if (Settings.DataBits!=dataBits) { + if ((Settings.StopBits==STOP_2 && dataBits==DATA_5) || + (Settings.StopBits==STOP_1_5 && dataBits!=DATA_5) || + (Settings.Parity==PAR_SPACE && dataBits==DATA_8)) { + } + else { + Settings.DataBits=dataBits; + } + } + if (isOpen()) { + switch(dataBits) { + + /*5 data bits*/ + case DATA_5: + if (Settings.StopBits==STOP_2) { + TTY_WARNING("Posix_QextSerialPort: 5 Data bits cannot be used with 2 stop bits."); + } + else { + Settings.DataBits=dataBits; + Posix_CommConfig.c_cflag&=(~CSIZE); + Posix_CommConfig.c_cflag|=CS5; + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + } + break; + + /*6 data bits*/ + case DATA_6: + if (Settings.StopBits==STOP_1_5) { + TTY_WARNING("Posix_QextSerialPort: 6 Data bits cannot be used with 1.5 stop bits."); + } + else { + Settings.DataBits=dataBits; + Posix_CommConfig.c_cflag&=(~CSIZE); + Posix_CommConfig.c_cflag|=CS6; + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + } + break; + + /*7 data bits*/ + case DATA_7: + if (Settings.StopBits==STOP_1_5) { + TTY_WARNING("Posix_QextSerialPort: 7 Data bits cannot be used with 1.5 stop bits."); + } + else { + Settings.DataBits=dataBits; + Posix_CommConfig.c_cflag&=(~CSIZE); + Posix_CommConfig.c_cflag|=CS7; + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + } + break; + + /*8 data bits*/ + case DATA_8: + if (Settings.StopBits==STOP_1_5) { + TTY_WARNING("Posix_QextSerialPort: 8 Data bits cannot be used with 1.5 stop bits."); + } + else { + Settings.DataBits=dataBits; + Posix_CommConfig.c_cflag&=(~CSIZE); + Posix_CommConfig.c_cflag|=CS8; + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + } + break; + } + } + UNLOCK_MUTEX(); +} + +/*! +\fn void Posix_QextSerialPort::setParity(ParityType parity) +Sets the parity associated with the serial port. The possible values of parity are: +\verbatim + PAR_SPACE Space Parity + PAR_MARK Mark Parity + PAR_NONE No Parity + PAR_EVEN Even Parity + PAR_ODD Odd Parity +\endverbatim + +\note +This function is subject to the following limitations: +\par +POSIX systems do not support mark parity. +\par +POSIX systems support space parity only if tricked into doing so, and only with + fewer than 8 data bits. Use space parity very carefully with POSIX systems. + +*/ +void Posix_QextSerialPort::setParity(ParityType parity) +{ + LOCK_MUTEX(); + if (Settings.Parity!=parity) { + if (parity==PAR_MARK || (parity==PAR_SPACE && Settings.DataBits==DATA_8)) { + } + else { + Settings.Parity=parity; + } + } + if (isOpen()) { + switch (parity) { + + /*space parity*/ + case PAR_SPACE: + if (Settings.DataBits==DATA_8) { + TTY_PORTABILITY_WARNING("Posix_QextSerialPort: Space parity is only supported in POSIX with 7 or fewer data bits"); + } + else { + + /*space parity not directly supported - add an extra data bit to simulate it*/ + Posix_CommConfig.c_cflag&=~(PARENB|CSIZE); + switch(Settings.DataBits) { + case DATA_5: + Settings.DataBits=DATA_6; + Posix_CommConfig.c_cflag|=CS6; + break; + + case DATA_6: + Settings.DataBits=DATA_7; + Posix_CommConfig.c_cflag|=CS7; + break; + + case DATA_7: + Settings.DataBits=DATA_8; + Posix_CommConfig.c_cflag|=CS8; + break; + + case DATA_8: + break; + } + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + } + break; + + /*mark parity - WINDOWS ONLY*/ + case PAR_MARK: + TTY_WARNING("Posix_QextSerialPort: Mark parity is not supported by POSIX."); + break; + + /*no parity*/ + case PAR_NONE: + Posix_CommConfig.c_cflag&=(~PARENB); + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + break; + + /*even parity*/ + case PAR_EVEN: + Posix_CommConfig.c_cflag&=(~PARODD); + Posix_CommConfig.c_cflag|=PARENB; + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + break; + + /*odd parity*/ + case PAR_ODD: + Posix_CommConfig.c_cflag|=(PARENB|PARODD); + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + break; + } + } + UNLOCK_MUTEX(); +} + +/*! +\fn void Posix_QextSerialPort::setStopBits(StopBitsType stopBits) +Sets the number of stop bits used by the serial port. Possible values of stopBits are: +\verbatim + STOP_1 1 stop bit + STOP_1_5 1.5 stop bits + STOP_2 2 stop bits +\endverbatim +\note +This function is subject to the following restrictions: +\par + 2 stop bits cannot be used with 5 data bits. +\par + POSIX does not support 1.5 stop bits. + +*/ +void Posix_QextSerialPort::setStopBits(StopBitsType stopBits) +{ + LOCK_MUTEX(); + if (Settings.StopBits!=stopBits) { + if ((Settings.DataBits==DATA_5 && stopBits==STOP_2) || stopBits==STOP_1_5) {} + else { + Settings.StopBits=stopBits; + } + } + if (isOpen()) { + switch (stopBits) { + + /*one stop bit*/ + case STOP_1: + Settings.StopBits=stopBits; + Posix_CommConfig.c_cflag&=(~CSTOPB); + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + break; + + /*1.5 stop bits*/ + case STOP_1_5: + TTY_WARNING("Posix_QextSerialPort: 1.5 stop bit operation is not supported by POSIX."); + break; + + /*two stop bits*/ + case STOP_2: + if (Settings.DataBits==DATA_5) { + TTY_WARNING("Posix_QextSerialPort: 2 stop bits cannot be used with 5 data bits"); + } + else { + Settings.StopBits=stopBits; + Posix_CommConfig.c_cflag|=CSTOPB; + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + } + break; + } + } + UNLOCK_MUTEX(); +} + +/*! +\fn void Posix_QextSerialPort::setFlowControl(FlowType flow) +Sets the flow control used by the port. Possible values of flow are: +\verbatim + FLOW_OFF No flow control + FLOW_HARDWARE Hardware (RTS/CTS) flow control + FLOW_XONXOFF Software (XON/XOFF) flow control +\endverbatim +\note +FLOW_HARDWARE may not be supported on all versions of UNIX. In cases where it is +unsupported, FLOW_HARDWARE is the same as FLOW_OFF. + +*/ +void Posix_QextSerialPort::setFlowControl(FlowType flow) +{ + LOCK_MUTEX(); + if (Settings.FlowControl!=flow) { + Settings.FlowControl=flow; + } + if (isOpen()) { + switch(flow) { + + /*no flow control*/ + case FLOW_OFF: + Posix_CommConfig.c_cflag&=(~CRTSCTS); + Posix_CommConfig.c_iflag&=(~(IXON|IXOFF|IXANY)); + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + break; + + /*software (XON/XOFF) flow control*/ + case FLOW_XONXOFF: + Posix_CommConfig.c_cflag&=(~CRTSCTS); + Posix_CommConfig.c_iflag|=(IXON|IXOFF|IXANY); + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + break; + + case FLOW_HARDWARE: + Posix_CommConfig.c_cflag|=CRTSCTS; + Posix_CommConfig.c_iflag&=(~(IXON|IXOFF|IXANY)); + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + break; + } + } + UNLOCK_MUTEX(); +} + +/*! +\fn void Posix_QextSerialPort::setTimeout(ulong sec, ulong millisec); +Sets the read and write timeouts for the port to sec seconds and millisec milliseconds. +Note that this is a per-character timeout, i.e. the port will wait this long for each +individual character, not for the whole read operation. This timeout also applies to the +bytesWaiting() function. + +\note +POSIX does not support millisecond-level control for I/O timeout values. Any +timeout set using this function will be set to the next lowest tenth of a second for +the purposes of detecting read or write timeouts. For example a timeout of 550 milliseconds +will be seen by the class as a timeout of 500 milliseconds for the purposes of reading and +writing the port. However millisecond-level control is allowed by the select() system call, +so for example a 550-millisecond timeout will be seen as 550 milliseconds on POSIX systems for +the purpose of detecting available bytes in the read buffer. + +*/ +void Posix_QextSerialPort::setTimeout(ulong sec, ulong millisec) +{ + LOCK_MUTEX(); + Settings.Timeout_Sec=sec; + Settings.Timeout_Millisec=millisec; + Posix_Copy_Timeout.tv_sec=sec; + Posix_Copy_Timeout.tv_usec=millisec; + if (isOpen()) { + tcgetattr(Posix_File->handle(), &Posix_CommConfig); + Posix_CommConfig.c_cc[VTIME]=sec*10+millisec/100; + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + } + UNLOCK_MUTEX(); +} + +/*! +\fn bool Posix_QextSerialPort::open(OpenMode mode) +Opens the serial port associated to this class. +This function has no effect if the port associated with the class is already open. +The port is also configured to the current settings, as stored in the Settings structure. +*/ +bool Posix_QextSerialPort::open(OpenMode mode) +{ + LOCK_MUTEX(); + if (mode == QIODevice::NotOpen) + return isOpen(); + if (!isOpen()) { + /*open the port*/ + Posix_File->setFileName(port); + qDebug("Trying to open File"); + if (Posix_File->open(QIODevice::ReadWrite|QIODevice::Unbuffered)) { + qDebug("Opened File succesfully"); + /*set open mode*/ + QIODevice::open(mode); + + /*configure port settings*/ + tcgetattr(Posix_File->handle(), &Posix_CommConfig); + + /*set up other port settings*/ + Posix_CommConfig.c_cflag|=CREAD|CLOCAL; + Posix_CommConfig.c_lflag&=(~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|ISIG)); + Posix_CommConfig.c_iflag&=(~(INPCK|IGNPAR|PARMRK|ISTRIP|ICRNL|IXANY)); + Posix_CommConfig.c_oflag&=(~OPOST); + Posix_CommConfig.c_cc[VMIN]=0; + Posix_CommConfig.c_cc[VINTR] = _POSIX_VDISABLE; + Posix_CommConfig.c_cc[VQUIT] = _POSIX_VDISABLE; + Posix_CommConfig.c_cc[VSTART] = _POSIX_VDISABLE; + Posix_CommConfig.c_cc[VSTOP] = _POSIX_VDISABLE; + Posix_CommConfig.c_cc[VSUSP] = _POSIX_VDISABLE; + setBaudRate(Settings.BaudRate); + setDataBits(Settings.DataBits); + setParity(Settings.Parity); + setStopBits(Settings.StopBits); + setFlowControl(Settings.FlowControl); + setTimeout(Settings.Timeout_Sec, Settings.Timeout_Millisec); + tcsetattr(Posix_File->handle(), TCSAFLUSH, &Posix_CommConfig); + } else { + qDebug("Could not open File! Error code : %d", Posix_File->error()); + } + } + UNLOCK_MUTEX(); + return isOpen(); +} + +/*! +\fn void Posix_QextSerialPort::close() +Closes a serial port. This function has no effect if the serial port associated with the class +is not currently open. +*/ +void Posix_QextSerialPort::close() +{ + LOCK_MUTEX(); + Posix_File->close(); + QIODevice::close(); + UNLOCK_MUTEX(); +} + +/*! +\fn void Posix_QextSerialPort::flush() +Flushes all pending I/O to the serial port. This function has no effect if the serial port +associated with the class is not currently open. +*/ +void Posix_QextSerialPort::flush() +{ + LOCK_MUTEX(); + if (isOpen()) { + Posix_File->flush(); + } + UNLOCK_MUTEX(); +} + +/*! +\fn qint64 Posix_QextSerialPort::size() const +This function will return the number of bytes waiting in the receive queue of the serial port. +It is included primarily to provide a complete QIODevice interface, and will not record errors +in the lastErr member (because it is const). This function is also not thread-safe - in +multithreading situations, use Posix_QextSerialPort::bytesWaiting() instead. +*/ +qint64 Posix_QextSerialPort::size() const +{ + int numBytes; + if (ioctl(Posix_File->handle(), FIONREAD, &numBytes)<0) { + numBytes=0; + } + return (qint64)numBytes; +} + +/*! +\fn qint64 Posix_QextSerialPort::bytesAvailable() +Returns the number of bytes waiting in the port's receive queue. This function will return 0 if +the port is not currently open, or -1 on error. Error information can be retrieved by calling +Posix_QextSerialPort::getLastError(). +*/ +qint64 Posix_QextSerialPort::bytesAvailable() +{ + LOCK_MUTEX(); + if (isOpen()) { + int bytesQueued; + fd_set fileSet; + FD_ZERO(&fileSet); + FD_SET(Posix_File->handle(), &fileSet); + + /*on Linux systems the Posix_Timeout structure will be altered by the select() call. + Make sure we use the right timeout values*/ + //memcpy(&Posix_Timeout, &Posix_Copy_Timeout, sizeof(struct timeval)); + Posix_Timeout = Posix_Copy_Timeout; + int n=select(Posix_File->handle()+1, &fileSet, NULL, &fileSet, &Posix_Timeout); + if (!n) { + lastErr=E_PORT_TIMEOUT; + UNLOCK_MUTEX(); + return -1; + } + if (n==-1 || ioctl(Posix_File->handle(), FIONREAD, &bytesQueued)==-1) { + translateError(errno); + UNLOCK_MUTEX(); + return -1; + } + lastErr=E_NO_ERROR; + UNLOCK_MUTEX(); + return bytesQueued + QIODevice::bytesAvailable(); + } + UNLOCK_MUTEX(); + return 0; +} + +/*! +\fn void Posix_QextSerialPort::ungetChar(char) +This function is included to implement the full QIODevice interface, and currently has no +purpose within this class. This function is meaningless on an unbuffered device and currently +only prints a warning message to that effect. +*/ +void Posix_QextSerialPort::ungetChar(char) +{ + /*meaningless on unbuffered sequential device - return error and print a warning*/ + TTY_WARNING("Posix_QextSerialPort: ungetChar() called on an unbuffered sequential device - operation is meaningless"); +} + +/*! +\fn void Posix_QextSerialPort::translateError(ulong error) +Translates a system-specific error code to a QextSerialPort error code. Used internally. +*/ +void Posix_QextSerialPort::translateError(ulong error) +{ + switch (error) { + case EBADF: + case ENOTTY: + lastErr=E_INVALID_FD; + break; + + case EINTR: + lastErr=E_CAUGHT_NON_BLOCKED_SIGNAL; + break; + + case ENOMEM: + lastErr=E_NO_MEMORY; + break; + } +} + +/*! +\fn void Posix_QextSerialPort::setDtr(bool set) +Sets DTR line to the requested state (high by default). This function will have no effect if +the port associated with the class is not currently open. +*/ +void Posix_QextSerialPort::setDtr(bool set) +{ + LOCK_MUTEX(); + if (isOpen()) { + int status; + ioctl(Posix_File->handle(), TIOCMGET, &status); + if (set) { + status|=TIOCM_DTR; + } + else { + status&=~TIOCM_DTR; + } + ioctl(Posix_File->handle(), TIOCMSET, &status); + } + UNLOCK_MUTEX(); +} + +/*! +\fn void Posix_QextSerialPort::setRts(bool set) +Sets RTS line to the requested state (high by default). This function will have no effect if +the port associated with the class is not currently open. +*/ +void Posix_QextSerialPort::setRts(bool set) +{ + LOCK_MUTEX(); + if (isOpen()) { + int status; + ioctl(Posix_File->handle(), TIOCMGET, &status); + if (set) { + status|=TIOCM_RTS; + } + else { + status&=~TIOCM_RTS; + } + ioctl(Posix_File->handle(), TIOCMSET, &status); + } + UNLOCK_MUTEX(); +} + +/*! +\fn unsigned long Posix_QextSerialPort::lineStatus() +returns the line status as stored by the port function. This function will retrieve the states +of the following lines: DCD, CTS, DSR, and RI. On POSIX systems, the following additional lines +can be monitored: DTR, RTS, Secondary TXD, and Secondary RXD. The value returned is an unsigned +long with specific bits indicating which lines are high. The following constants should be used +to examine the states of individual lines: + +\verbatim +Mask Line +------ ---- +LS_CTS CTS +LS_DSR DSR +LS_DCD DCD +LS_RI RI +LS_RTS RTS (POSIX only) +LS_DTR DTR (POSIX only) +LS_ST Secondary TXD (POSIX only) +LS_SR Secondary RXD (POSIX only) +\endverbatim + +This function will return 0 if the port associated with the class is not currently open. +*/ +unsigned long Posix_QextSerialPort::lineStatus() +{ + unsigned long Status=0, Temp=0; + LOCK_MUTEX(); + if (isOpen()) { + ioctl(Posix_File->handle(), TIOCMGET, &Temp); + if (Temp&TIOCM_CTS) { + Status|=LS_CTS; + } + if (Temp&TIOCM_DSR) { + Status|=LS_DSR; + } + if (Temp&TIOCM_RI) { + Status|=LS_RI; + } + if (Temp&TIOCM_CD) { + Status|=LS_DCD; + } + if (Temp&TIOCM_DTR) { + Status|=LS_DTR; + } + if (Temp&TIOCM_RTS) { + Status|=LS_RTS; + } + if (Temp&TIOCM_ST) { + Status|=LS_ST; + } + if (Temp&TIOCM_SR) { + Status|=LS_SR; + } + } + UNLOCK_MUTEX(); + return Status; +} + +/*! +\fn qint64 Posix_QextSerialPort::readData(char * data, qint64 maxSize) +Reads a block of data from the serial port. This function will read at most maxSize bytes from +the serial port and place them in the buffer pointed to by data. Return value is the number of +bytes actually read, or -1 on error. + +\warning before calling this function ensure that serial port associated with this class +is currently open (use isOpen() function to check if port is open). +*/ +qint64 Posix_QextSerialPort::readData(char * data, qint64 maxSize) +{ + LOCK_MUTEX(); + int retVal=0; + retVal=Posix_File->read(data, maxSize); + if (retVal==-1) + lastErr=E_READ_FAILED; + UNLOCK_MUTEX(); + + return retVal; +} + +/*! +\fn qint64 Posix_QextSerialPort::writeData(const char * data, qint64 maxSize) +Writes a block of data to the serial port. This function will write maxSize bytes +from the buffer pointed to by data to the serial port. Return value is the number +of bytes actually written, or -1 on error. + +\warning before calling this function ensure that serial port associated with this class +is currently open (use isOpen() function to check if port is open). +*/ +qint64 Posix_QextSerialPort::writeData(const char * data, qint64 maxSize) +{ + LOCK_MUTEX(); + int retVal=0; + retVal=Posix_File->write(data, maxSize); + if (retVal==-1) + lastErr=E_WRITE_FAILED; + UNLOCK_MUTEX(); + + flush(); + return retVal; +} Added: trunk/src/serial/posix_qextserialport.h =================================================================== --- trunk/src/serial/posix_qextserialport.h (rev 0) +++ trunk/src/serial/posix_qextserialport.h 2007-12-28 18:18:19 UTC (rev 79) @@ -0,0 +1,56 @@ + +#ifndef _POSIX_QEXTSERIALPORT_H_ +#define _POSIX_QEXTSERIALPORT_H_ + +#include <stdio.h> +#include <termios.h> +#include <errno.h> +#include <unistd.h> +#include <sys/time.h> +#include <sys/ioctl.h> +#include <sys/select.h> +#include "qextserialbase.h" + +class Posix_QextSerialPort:public QextSerialBase { +public: + Posix_QextSerialPort(); + Posix_QextSerialPort(const Posix_QextSerialPort& s); + Posix_QextSerialPort(const QString & name); + Posix_QextSerialPort(const PortSettings& settings); + Posix_QextSerialPort(const QString & name, const PortSettings& settings); + Posix_QextSerialPort& operator=(const Posix_QextSerialPort& s); + virtual ~Posix_QextSerialPort(); + + virtual void setBaudRate(BaudRateType); + virtual void setDataBits(DataBitsType); + virtual void setParity(ParityType); + virtual void setStopBits(StopBitsType); + virtual void setFlowControl(FlowType); + virtual void setTimeout(ulong, ulong); + + virtual bool open(OpenMode mode=0); + virtual void close(); + virtual void flush(); + + virtual qint64 size() const; + virtual qint64 bytesAvailable(); + + virtual void ungetChar(char c); + + virtual void translateError(ulong error); + + virtual void setDtr(bool set=true); + virtual void setRts(bool set=true); + virtual ulong lineStatus(); + +protected: + QFile* Posix_File; + struct termios Posix_CommConfig; + struct timeval Posix_Timeout; + struct timeval Posix_Copy_Timeout; + + virtual qint64 readData(char * data, qint64 maxSize); + virtual qint64 writeData(const char * data, qint64 maxSize); +}; + +#endif Added: trunk/src/serial/qextserialbase.cpp =================================================================== --- trunk/src/serial/qextserialbase.cpp (rev 0) +++ trunk/src/serial/qextserialbase.cpp 2007-12-28 18:18:19 UTC (rev 79) @@ -0,0 +1,250 @@ + +#include "qextserialbase.h" + +/*! +\class QextSerialBase +\version 1.0.0 +\author Stefan Sander + +A common base class for Win_QextSerialBase, Posix_QextSerialBase and QextSerialPort. +*/ +#ifdef QT_THREAD_SUPPORT +QMutex* QextSerialBase::mutex=NULL; +unsigned long QextSerialBase::refCount=0; +#endif + +/*! +\fn QextSerialBase::QextSerialBase() +Default constructor. +*/ +QextSerialBase::QextSerialBase() + : QIODevice() +{ + +#ifdef _TTY_WIN_ + setPortName("COM1"); + +#elif defined(_TTY_IRIX_) + setPortName("/dev/ttyf1"); + +#elif defined(_TTY_HPUX_) + setPortName("/dev/tty1p0"); + +#elif defined(_TTY_SUN_) + setPortName("/dev/ttya"); + +#elif defined(_TTY_DIGITAL_) + setPortName("/dev/tty01"); + +#elif defined(_TTY_FREEBSD_) + setPortName("/dev/ttyd1"); + +#else + setPortName("/dev/ttyS0"); +#endif + + construct(); +} + +/*! +\fn QextSerialBase::QextSerialBase(const QString & name) +Construct a port and assign it to the device specified by the name parameter. +*/ +QextSerialBase::QextSerialBase(const QString & name) + : QIODevice() +{ + setPortName(name); + construct(); +} + +/*! +\fn QextSerialBase::~QextSerialBase() +Standard destructor. +*/ +QextSerialBase::~QextSerialBase() +{ + +#ifdef QT_THREAD_SUPPORT + refCount--; + if (mutex && refCount==0) { + delete mutex; + mutex=NULL; + } +#endif + +} + +/*! +\fn void QextSerialBase::construct() +Common constructor function for setting up default port settings. +(115200 Baud, 8N1, Hardware flow control where supported, otherwise no flow control, and 500 ms timeout). +*/ +void QextSerialBase::construct() +{ + Settings.BaudRate=BAUD115200; + Settings.DataBits=DATA_8; + Settings.Parity=PAR_NONE; + Settings.StopBits=STOP_1; + Settings.FlowControl=FLOW_HARDWARE; + Settings.Timeout_Sec=0; + Settings.Timeout_Millisec=500; + +#ifdef QT_THREAD_SUPPORT + if (!mutex) { + mutex=new QMutex( QMutex::Recursive ); + } + refCount++; +#endif + + setOpenMode(QIODevice::NotOpen); +} + +/*! +\fn void QextSerialBase::setPortName(const QString & name) +Sets the name of the device associated with the object, e.g. "COM1", or "/dev/ttyS0". +*/ +void QextSerialBase::setPortName(const QString & name) +{ + port = name; +} + +/*! +\fn QString QextSerialBase::portName() const +Returns the name set by setPortName(). +*/ +QString QextSerialBase::portName() const +{ + return port; +} + +/*! +\fn BaudRateType QextSerialBase::baudRate(void) const +Returns the baud rate of the serial port. For a list of possible return values see +the definition of the enum BaudRateType. +*/ +BaudRateType QextSerialBase::baudRate(void) const +{ + return Settings.BaudRate; +} + +/*! +\fn DataBitsType QextSerialBase::dataBits() const +Returns the number of data bits used by the port. For a list of possible values returned by +this function, see the definition of the enum DataBitsType. +*/ +DataBitsType QextSerialBase::dataBits() const +{ + return Settings.DataBits; +} + +/*! +\fn ParityType QextSerialBase::parity() const +Returns the type of parity used by the port. For a list of possible values returned by +this function, see the definition of the enum ParityType. +*/ +ParityType QextSerialBase::parity() const +{ + return Settings.Parity; +} + +/*! +\fn StopBitsType QextSerialBase::stopBits() const +Returns the number of stop bits used by the port. For a list of possible return values, see +the definition of the enum StopBitsType. +*/ +StopBitsType QextSerialBase::stopBits() const +{ + return Settings.StopBits; +} + +/*! +\fn FlowType QextSerialBase::flowControl() const +Returns the type of flow control used by the port. For a list of possible values returned +by this function, see the definition of the enum FlowType. +*/ +FlowType QextSerialBase::flowControl() const +{ + return Settings.FlowControl; +} + +/*! +\fn bool QextSerialBase::isSequential() const +Returns true if device is sequential, otherwise returns false. Serial port is sequential device +so this function always returns true. Check QIODevice::isSequential() documentation for more +information. +*/ +bool QextSerialBase::isSequential() const +{ + return true; +} + +/*! +\fn bool QextSerialBase::atEnd() const +This function will return true if the input buffer is empty (or on error), and false otherwise. +Call QextSerialBase::lastError() for error information. +*/ +bool QextSerialBase::atEnd() const +{ + if (size()) { + return true; + } + return false; +} + +/*! +\fn qint64 QextSerialBase::readLine(char * data, qint64 maxSize) +This function will read a line of buffered input from the port, stopping when either maxSize bytes +have been read, the port has no more data available, or a newline is encountered. +The value returned is the length of the string that was read. +*/ +qint64 QextSerialBase::readLine(char * data, qint64 maxSize) +{ + qint64 numBytes = bytesAvailable(); + char* pData = data; + + if (maxSize < 2) //maxSize must be larger than 1 + return -1; + + /*read a byte at a time for MIN(bytesAvail, maxSize - 1) iterations, or until a newline*/ + while (pData<(data+numBytes) && --maxSize) { + readData(pData, 1); + if (*pData++ == '\n') { + break; + } + } + *pData='\0'; + + /*return size of data read*/ + return (pData-data); +} + +/*! +\fn ulong QextSerialBase::lastError() const +Returns the code for the last error encountered by the port, or E_NO_ERROR if the last port +operation was successful. Possible error codes are: + +\verbatim +Error Explanation +--------------------------- ------------------------------------------------------------- +E_NO_ERROR No Error has occured +E_INVALID_FD Invalid file descriptor (port was not opened correctly) +E_NO_MEMORY Unable to allocate memory tables (POSIX) +E_CAUGHT_NON_BLOCKED_SIGNAL Caught a non-blocked signal (POSIX) +E_PORT_TIMEOUT Operation timed out (POSIX) +E_INVALID_DEVICE The file opened by the port is not a character device (POSIX) +E_BREAK_CONDITION The port detected a break condition +E_FRAMING_ERROR The port detected a framing error + (usually caused by incorrect baud rate settings) +E_IO_ERROR There was an I/O error while communicating with the port +E_BUFFER_OVERRUN Character buffer overrun +E_RECEIVE_OVERFLOW Receive buffer overflow +E_RECEIVE_PARITY_ERROR The port detected a parity error in the received data +E_TRANSMIT_OVERFLOW Transmit buffer overflow +E_READ_FAILED General read operation failure +E_WRITE_FAILED General write operation failure +\endverbatim +*/ +ulong QextSerialBase::lastError() const +{ + return lastErr; +} Added: trunk/src/serial/qextserialbase.h =================================================================== --- trunk/src/serial/qextserialbase.h (rev 0) +++ trunk/src/serial/qextserialbase.h 2007-12-28 18:18:19 UTC (rev 79) @@ -0,0 +1,196 @@ + +#ifndef _QEXTSERIALBASE_H_ +#define _QEXTSERIALBASE_H_ + +#include <QIODevice> +#include <QFile> + +#ifdef QT_THREAD_SUPPORT +#include <QThread> +#include <QMutex> +#endif + +/*if all warning messages are turned off, flag portability warnings to be turned off as well*/ +#ifdef _TTY_NOWARN_ +#define _TTY_NOWARN_PORT_ +#endif + +/*macros for thread support*/ +#ifdef QT_THREAD_SUPPORT +#define LOCK_MUTEX() mutex->lock() +#define UNLOCK_MUTEX() mutex->unlock() +#else +#define LOCK_MUTEX() +#define UNLOCK_MUTEX() +#endif + +/*macros for warning messages*/ +#ifdef _TTY_NOWARN_PORT_ +#define TTY_PORTABILITY_WARNING(s) +#else +#define TTY_PORTABILITY_WARNING(s) qWarning(s) +#endif +#ifdef _TTY_NOWARN_ +#define TTY_WARNING(s) +#else +#define TTY_WARNING(s) qWarning(s) +#endif + + +/*line status constants*/ +#define LS_CTS 0x01 +#define LS_DSR 0x02 +#define LS_DCD 0x04 +#define LS_RI 0x08 +#define LS_RTS 0x10 +#define LS_DTR 0x20 +#define LS_ST 0x40 +#define LS_SR 0x80 + +/*error constants*/ +#define E_NO_ERROR 0 +#define E_INVALID_FD 1 +#define E_NO_MEMORY 2 +#define E_CAUGHT_NON_BLOCKED_SIGNAL 3 +#define E_PORT_TIMEOUT 4 +#define E_INVALID_DEVICE 5 +#define E_BREAK_CONDITION 6 +#define E_FRAMING_ERROR 7 +#define E_IO_ERROR 8 +#define E_BUFFER_OVERRUN 9 +#define E_RECEIVE_OVERFLOW 10 +#define E_RECEIVE_PARITY_ERROR 11 +#define E_TRANSMIT_OVERFLOW 12 +#define E_READ_FAILED 13 +#define E_WRITE_FAILED 14 + +/*enums for port settings*/ +enum NamingConvention { + WIN_NAMES, + IRIX_NAMES, + HPUX_NAMES, + SUN_NAMES, + DIGITAL_NAMES, + FREEBSD_NAMES, + LINUX_NAMES +}; + +enum BaudRateType { + BAUD50, //POSIX ONLY + BAUD75, //POSIX ONLY + BAUD110, + BAUD134, //POSIX ONLY + BAUD150, //POSIX ONLY + BAUD200, //POSIX ONLY + BAUD300, + BAUD600, + BAUD1200, + BAUD1800, //POSIX ONLY + BAUD2400, + BAUD4800, + BAUD9600, + BAUD14400, //WINDOWS ONLY + BAUD19200, + BAUD38400, + BAUD56000, //WINDOWS ONLY + BAUD57600, + BAUD76800, //POSIX ONLY + BAUD115200, + BAUD128000, //WINDOWS ONLY + BAUD256000 //WINDOWS ONLY +}; + +enum DataBitsType { + DATA_5, + DATA_6, + DATA_7, + DATA_8 +}; + +enum ParityType { + PAR_NONE, + PAR_ODD, + PAR_EVEN, + PAR_MARK, //WINDOWS ONLY + PAR_SPACE +}; + +enum StopBitsType { + STOP_1, + STOP_1_5, //WINDOWS ONLY + STOP_2 +}; + +enum FlowType { + FLOW_OFF, + FLOW_HARDWARE, + FLOW_XONXOFF +}; + +/*structure to contain port settings*/ +struct PortSettings { + BaudRateType BaudRate; + DataBitsType DataBits; + ParityType Parity; + StopBitsType StopBits; + FlowType FlowControl; + ulong Timeout_Sec; + ulong Timeout_Millisec; +}; + +class QextSerialBase : public QIODevice { +public: + QextSerialBase(); + QextSerialBase(const QString & name); + virtual ~QextSerialBase(); + virtual void construct(); + virtual void setPortName(const QString & name); + virtual QString portName() const; + + virtual void setBaudRate(BaudRateType)=0; + virtual BaudRateType baudRate() const; + virtual void setDataBits(DataBitsType)=0; + virtual DataBitsType dataBits() const; + virtual void setParity(ParityType)=0; + virtual ParityType parity() const; + virtual void setStopBits(StopBitsType)=0; + virtual StopBitsType stopBits() const; + virtual void setFlowControl(FlowType)=0; + virtual FlowType flowControl() const; + virtual void setTimeout(ulong, ulong)=0; + + virtual bool open(OpenMode mode=0)=0; + virtual bool isSequential() const; + virtual void close()=0; + virtual void flush()=0; + + virtual qint64 size() const=0; + virtual qint64 bytesAvailable()=0; + virtual bool atEnd() const; + + virtual void ungetChar(char c)=0; + virtual qint64 readLine(char * data, qint64 maxSize); + + virtual ulong lastError() const; + virtual void translateError(ulong error)=0; + + virtual void setDtr(bool set=true)=0; + virtual void setRts(bool set=true)=0; + virtual ulong lineStatus()=0; + +protected: + QString port; + PortSettings Settings; + ulong lastErr; + +#ifdef QT_THREAD_SUPPORT + static QMutex* mutex; + static ulong refCount; +#endif + + virtual qint64 readData(char * data, qint64 maxSize)=0; + virtual qint64 writeData(const char * data, qint64 maxSize)=0; + +}; + +#endif Added: trunk/src/serial/qextserialport.cpp =================================================================== --- trunk/src/serial/qextserialport.cpp (rev 0) +++ trunk/src/serial/qextserialport.cpp 2007-12-28 18:18:19 UTC (rev 79) @@ -0,0 +1,98 @@ + +/*! +\class QextSerialPort +\version 1.0.0 +\author Stefan Sander + +A cross-platform serial port class. +This class encapsulates a serial port on both POSIX and Windows systems. The user will be +notified of errors and possible portability conflicts at run-time by default - this behavior can +be turned off by defining _TTY_NOWARN_ (to turn off all warnings) or _TTY_NOWARN_PORT_ (to turn +off portability warnings) in the project. + +\note +On Windows NT/2000/XP this class uses Win32 serial port functions by default. The user may +select POSIX behavior under NT, 2000, or XP ONLY by defining _TTY_POSIX_ in the project. I can +make no guarantees as to the quality of POSIX support under NT/2000 however. + +*/ + +#include <stdio.h> +#include "qextserialport.h" + +/*! +\fn QextSerialPort::QextSerialPort() +Default constructor. Note that the naming convention used by a QextSerialPort constructed with +this constructor will be determined by #defined constants, or lack thereof - the default behavior +is the same as _TTY_LINUX_. Possible naming conventions and their associated constants are: + +\verbatim + +Constant Used By Naming Convention +---------- ------------- ------------------------ +_TTY_WIN_ Windows COM1, COM2 +_TTY_IRIX_ SGI/IRIX /dev/ttyf1, /dev/ttyf2 +_TTY_HPUX_ HP-UX /dev/tty1p0, /dev/tty2p0 +_TTY_SUN_ SunOS/Solaris /dev/ttya, /dev/ttyb +_TTY_DIGITAL_ Digital UNIX /dev/tty01, /dev/tty02 +_TTY_FREEBSD_ FreeBSD /dev/ttyd0, /dev/ttyd1 +_TTY_LINUX_ Linux /dev/ttyS0, /dev/ttyS1 +<none> Linux /dev/ttyS0, /dev/ttyS1 +\endverbatim + +The object will be associated with the first port in the system, e.g. COM1 on Windows systems. +See the other constructors if you need to use a port other than the first. +*/ +QextSerialPort::QextSerialPort() + : QextBaseType() +{} + +/*! +\fn QextSerialPort::QextSerialPort(const QString & name) +Constructs a serial port attached to the port specified by name. +name is the name of the device, which is windowsystem-specific, +e.g."COM1" or "/dev/ttyS0". +*/ +QextSerialPort::QextSerialPort(const QString & name) + : QextBaseType(name) +{} + +/*! +\fn QextSerialPort::QextSerialPort(PortSettings const& settings) +Constructs a port with default name and settings specified by the settings parameter. +*/ +QextSerialPort::QextSerialPort(PortSettings const& settings) + : QextBaseType(settings) +{} + +/*! +\fn QextSerialPort::QextSerialPort(const QString & name, PortSettings const& settings) +Constructs a port with the name and settings specified. +*/ +QextSerialPort::QextSerialPort(const QString & name, PortSettings const& settings) + : QextBaseType(name, settings) +{} + +/*! +\fn QextSerialPort::QextSerialPort(const QextSerialPort& s) +Copy constructor. +*/ +QextSerialPort::QextSerialPort(const QextSerialPort& s) + : QextBaseType(s) +{} + +/*! +\fn QextSerialPort& QextSerialPort::operator=(const QextSerialPort& s) +Overrides the = operator. +*/ +QextSerialPort& QextSerialPort::operator=(const QextSerialPort& s) +{ + return (QextSerialPort&)QextBaseType::operator=(s); +} + +/*! +\fn QextSerialPort::~QextSerialPort() +Standard destructor. +*/ +QextSerialPort::~QextSerialPort() +{} Added: trunk/src/serial/qextserialport.h =================================================================== --- trunk/src/serial/qextserialport.h (rev 0) +++ trunk/src/serial/qextserialport.h 2007-12-28 18:18:19 UTC (rev 79) @@ -0,0 +1,27 @@ + +#ifndef _QEXTSERIALPORT_H_ +#define _QEXTSERIALPORT_H_ + +/*POSIX CODE*/ +#ifdef _TTY_POSIX_ +#include "posix_qextserialport.h" +#define QextBaseType Posix_QextSerialPort + +/*MS WINDOWS CODE*/ +#else +#include "win_qextserialport.h" +#define QextBaseType Win_QextSerialPort +#endif + +class QextSerialPort: public QextBaseType { +public: + QextSerialPort(); + QextSerialPort(const QString & name); + QextSerialPort(PortSettings const& s); + QextSerialPort(const QString & name, PortSettings const& s); + QextSerialPort(const QextSerialPort& s); + QextSerialPort& operator=(const QextSerialPort&); + virtual ~QextSerialPort(); +}; + +#endif Added: trunk/src/serial/serial.pro =================================================================== --- trunk/src/serial/serial.pro (rev 0) +++ trunk/src/serial/serial.pro 2007-12-28 18:18:19 UTC (rev 79) @@ -0,0 +1,29 @@ + +PROJECT = qextserialport +TEMPLATE = lib + +CONFIG -= debug_and_release +CONFIG += warn_on qt thread +CONFIG += staticlib +QT -= gui + +OBJECTS_DIR = ../../build/obj +MOC_DIR = ../../build/moc +DEPENDDIR = . +INCLUDEDIR = . +HEADERS = qextserialbase.h \ + qextserialport.h +SOURCES = qextserialbase.cpp \ + qextserialport.cpp + +unix:HEADERS += posix_qextserialport.h +unix:SOURCES += posix_qextserialport.cpp +unix:DEFINES += _TTY_POSIX_ + +win32:HEADERS += win_qextserialport.h +win32:SOURCES += win_qextserialport.cpp +win32:DEFINES += _TTY_WIN_ + +DESTDIR = ../../build +TARGET = qextserialport +unix:VERSION = 1.0.0 Added: trunk/src/serial/win_qextserialport.cpp =================================================================== --- trunk/src/serial/win_qextserialport.cpp (rev 0) +++ trunk/src/serial/win_qextserialport.cpp 2007-12-28 18:18:19 UTC (rev 79) @@ -0,0 +1,877 @@ +/*! +\class Win_QextSerialPort +\version 1.0.0 +\author Stefan Sander + +A cross-platform serial port class. +This class encapsulates the Windows portion of QextSerialPort. The user will be notified of +errors and possible portability conflicts at run-time by default - this behavior can be turned +off by defining _TTY_NOWARN_ (to turn off all warnings) or _TTY_NOWARN_PORT_ (to turn off +portability warnings) in the project. Note that defining _TTY_NOWARN_ also defines +_TTY_NOWARN_PORT_. + +\note +On Windows NT/2000/XP this class uses Win32 serial port functions by default. The user may +select POSIX behavior under NT, 2000, or XP ONLY by defining _TTY_POSIX_ in the project. I can +make no guarantees as to the quality of POSIX support under NT/2000 however. + +*/ + +#include <stdio.h> +#include "win_qextserialport.h" + +/*! +\fn Win_QextSerialPort::Win_QextSerialPort() +Default constructor. Note that the name of the device used by a Win_QextSerialPort constructed +with this constructor will be determined by #defined constants, or lack thereof - the default +behavior is the same as _TTY_LINUX_. Possible naming conventions and their associated constants +are: + +\verbatim + +Constant Used By Naming Convention +---------- ------------- ------------------------ +_TTY_WIN_ Windows COM1, COM2 +_TTY_IRIX_ SGI/IRIX /dev/ttyf1, /dev/ttyf2 +_TTY_HPUX_ HP-UX /dev/tty1p0, /dev/tty2p0 +_TTY_SUN_ SunOS/Solaris /dev/ttya, /dev/ttyb +_TTY_DIGITAL_ Digital UNIX /dev/tty01, /dev/tty02 +_TTY_FREEBSD_ FreeBSD /dev/ttyd0, /dev/ttyd1 +_TTY_LINUX_ Linux /dev/ttyS0, /dev/ttyS1 +<none> Linux /dev/ttyS0, /dev/ttyS1 +\endverb... [truncated message content] |
From: <cs...@us...> - 2007-12-28 18:14:58
|
Revision: 78 http://hrs.svn.sourceforge.net/hrs/?rev=78&view=rev Author: csete Date: 2007-12-28 10:14:56 -0800 (Fri, 28 Dec 2007) Log Message: ----------- Added directory. Added Paths: ----------- trunk/build/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-28 18:05:57
|
Revision: 77 http://hrs.svn.sourceforge.net/hrs/?rev=77&view=rev Author: csete Date: 2007-12-28 10:05:56 -0800 (Fri, 28 Dec 2007) Log Message: ----------- Added directory. Added Paths: ----------- trunk/src/serial/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-28 18:04:34
|
Revision: 76 http://hrs.svn.sourceforge.net/hrs/?rev=76&view=rev Author: csete Date: 2007-12-28 10:04:26 -0800 (Fri, 28 Dec 2007) Log Message: ----------- Added directory. Added Paths: ----------- trunk/src/ trunk/src/MainWindow.cpp trunk/src/MainWindow.h trunk/src/main.cpp trunk/src/src.pro Added: trunk/src/MainWindow.cpp =================================================================== --- trunk/src/MainWindow.cpp (rev 0) +++ trunk/src/MainWindow.cpp 2007-12-28 18:04:26 UTC (rev 76) @@ -0,0 +1,130 @@ +/*************************************************************************** + * Copyright (C) 2007 by Alexandru Csete OZ9AEC * + * * + * * + * 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 <QtGui> +#include "MainWindow.h" + + +MainWindow::MainWindow() +{ + //spreadsheet = new Spreadsheet; + //setCentralWidget(spreadsheet); + createActions(); + createMenus(); + //createContextMenu(); + //createToolBars(); + //createStatusBar(); + //readSettings(); + //setWindowIcon(QIcon(":/images/icon.png")); + +} + + + +void MainWindow::createMenus() +{ + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(saveAsAction); + fileMenu->addSeparator(); + fileMenu->addAction(exitAction); + + menuBar()->addSeparator(); + + helpMenu = menuBar()->addMenu(tr("&Help")); + helpMenu->addAction(umAction); + helpMenu->addSeparator(); + helpMenu->addAction(aboutAction); + helpMenu->addAction(aboutQtAction); +} + + + +/** \brief Create menu and toolbar actions + * + */ +void MainWindow::createActions() +{ + + /* File -> Save As */ + saveAsAction = new QAction(tr("Save &As..."), this); + saveAsAction->setIcon(QIcon(":/icon/save-as.png")); + saveAsAction->setStatusTip(tr("Save the logbook to a new file")); + connect(saveAsAction, SIGNAL(triggered()), this, SLOT(saveAs())); + + exitAction = new QAction(tr("E&xit"), this); + exitAction->setIcon(QIcon(":/icon/quit.png")); + exitAction->setShortcut(tr("Ctrl+Q")); + exitAction->setStatusTip(tr("Exit the application")); + connect(exitAction, SIGNAL(triggered()), + qApp, SLOT(closeAllWindows())); + + /* Help -> contents */ + umAction = new QAction(tr("&Contents"), this); + umAction->setIcon(QIcon(":/icon/help.png")); + umAction->setShortcut(tr("F1")); + + /* Help -> About */ + aboutAction = new QAction(tr("&About"), this); + aboutAction->setIcon(QIcon(":/icon/about.png")); + aboutAction->setStatusTip(tr("Ahow about box")); + connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); + + /* Help -> About Qt */ + aboutQtAction = new QAction(tr("About &Qt"), this); + aboutQtAction->setStatusTip(tr("Show the Qt library's About box")); + connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + +} + + +bool MainWindow::saveAs() +{ + QString fileName = QFileDialog::getSaveFileName(this, + tr("Save Spreadsheet"), ".", + tr("Spreadsheet files (*.sp)")); + + if (fileName.isEmpty()) + return false; + + return true; + //return saveFile(fileName); +} + + +void MainWindow::closeEvent(QCloseEvent *event) +{ + //if (okToContinue()) { + //writeSettings(); + event->accept(); + + //} else { + // event->ignore(); + //} +} + + + +void MainWindow::about() +{ + QMessageBox::about(this, tr("About HRS"), + tr("<h2>Ham Radio Studio 1.0</h2>" + "<p>Copyright © 2007 Alexandru Csete OZ9AEC." + "<p>Description")); +} + Added: trunk/src/MainWindow.h =================================================================== --- trunk/src/MainWindow.h (rev 0) +++ trunk/src/MainWindow.h 2007-12-28 18:04:26 UTC (rev 76) @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (C) 2007 by Alexandru Csete OZ9AEC * + * * + * * + * 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 <QMainWindow> + + + +class MainWindow : public QMainWindow +{ + Q_OBJECT + public: + MainWindow(); + + protected: + void closeEvent(QCloseEvent *event); + + private slots: + bool saveAs(); + void about(); + + + + private: + void createActions(); + void createMenus(); + //void createContextMenu(); + //void createToolBars(); + //void createStatusBar(); + //void readSettings(); + //void writeSettings(); + + /* File Menu */ + QMenu *fileMenu; + QAction *saveAsAction; + QAction *exitAction; + QAction *separatorAction; + + /* Help menu */ + QMenu *helpMenu; + QAction *umAction; + QAction *aboutAction; + QAction *aboutQtAction; + +}; + +#endif Added: trunk/src/main.cpp =================================================================== --- trunk/src/main.cpp (rev 0) +++ trunk/src/main.cpp 2007-12-28 18:04:26 UTC (rev 76) @@ -0,0 +1,15 @@ +#include <QApplication> +#include "MainWindow.h" + + +int main(int argc, char *argv[]) +{ + + QApplication app(argc, argv); + MainWindow *mainWin = new MainWindow; + + mainWin->show(); + + return app.exec(); + +} Added: trunk/src/src.pro =================================================================== --- trunk/src/src.pro (rev 0) +++ trunk/src/src.pro 2007-12-28 18:04:26 UTC (rev 76) @@ -0,0 +1,10 @@ +SOURCES += MainWindow.cpp \ + main.cpp +HEADERS += MainWindow.h +TEMPLATE = app +CONFIG += warn_on \ + debug \ + thread \ + qt +TARGET = ../dist/linux/bin/hrs +RESOURCES = ../icons/icons.qrc This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-26 16:51:58
|
Revision: 75 http://hrs.svn.sourceforge.net/hrs/?rev=75&view=rev Author: csete Date: 2007-12-26 08:51:54 -0800 (Wed, 26 Dec 2007) Log Message: ----------- Sync Modified Paths: -------------- trunk/hrslogbook/MainWindow.cpp trunk/hrsmap/MainWindow.cpp Modified: trunk/hrslogbook/MainWindow.cpp =================================================================== --- trunk/hrslogbook/MainWindow.cpp 2007-12-25 20:27:28 UTC (rev 74) +++ trunk/hrslogbook/MainWindow.cpp 2007-12-26 16:51:54 UTC (rev 75) @@ -18,6 +18,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include <QtGui> +#include "../common/version.h" +#include "../common/qra.h" #include "MainWindow.h" @@ -59,7 +61,6 @@ fileMenu->addSeparator(); fileMenu->addAction(exitAction); - menuBar()->addSeparator(); helpMenu = menuBar()->addMenu(tr("&Help")); helpMenu->addAction(umAction); @@ -158,10 +159,20 @@ void MainWindow::about() { - QMessageBox::about(this, tr("About HRS Logbook"), - tr("<h2>HRS Logbook 1.0</h2>" + QMessageBox::about(this, tr("About hrslogbook"), + tr("<h2>HRS Logbook %1.%2 %3</h2>" "<p>Copyright © 2007 Alexandru Csete OZ9AEC." - "<p>Hrs Logbook is a ham radio logbook application " - "... bla bla ...")); + "<p>HRS Logbook is a ham radio logbook editor and manager." + "<p>This is free software licensed under the terms and conditions " + "of the <a href=\"http://www.fsf.org/licensing/licenses/gpl.html\">" + "GNU General Public Licence</a>." + "<p>This application is part of Ham Radio Studio, which is " + "avaialble <b>free of charge</b> from " + "<a href=\"http://hrs.sf.net/\">http://hrs.sf.net/</a>" + "<p>Build date: %4 %5") + .arg(HRS_MAJOR_VERSION) + .arg(HRS_MINOR_VERSION) + .arg(HRS_BETA_STRING) + .arg(__DATE__).arg(__TIME__)); } Modified: trunk/hrsmap/MainWindow.cpp =================================================================== --- trunk/hrsmap/MainWindow.cpp 2007-12-25 20:27:28 UTC (rev 74) +++ trunk/hrsmap/MainWindow.cpp 2007-12-26 16:51:54 UTC (rev 75) @@ -224,21 +224,25 @@ borderAction = new QAction(tr("Country borders"), this); borderAction->setStatusTip(tr("Show the border lines between countries")); borderAction->setCheckable(true); + borderAction->setEnabled(FALSE); /* View -> Country prefix */ prefixAction = new QAction(tr("Country prefix"), this); prefixAction->setStatusTip(tr("Show country prefixes on the map")); prefixAction->setCheckable(true); + prefixAction->setEnabled(FALSE); /* View -> Grid lines */ gridAction = new QAction(tr("Lat/Lon grid"), this); gridAction->setStatusTip(tr("Show Lat/Lon grid lines")); gridAction->setCheckable (true); + gridAction->setEnabled(FALSE); /* View -> Maidenhead squares */ qraAction = new QAction(tr("Maidenhead locators"), this); qraAction->setStatusTip(tr("Show Maidenhead locator squares")); qraAction->setCheckable (true); + qraAction->setEnabled(FALSE); /* View -> Fullscreen */ fsAction = new QAction(tr("&Fullscreen"), this); @@ -297,7 +301,7 @@ QMessageBox::about(this, tr("About hrsmap"), tr("<h2>HRS Map %1.%2 %3</h2>" "<p>Copyright © 2007 Alexandru Csete OZ9AEC." - "<p>HRS Map is a small world map utility and greyline calculator." + "<p>HRS Map is a world map utility and greyline calculator." "<p>This is free software licensed under the terms and conditions " "of the <a href=\"http://www.fsf.org/licensing/licenses/gpl.html\">" "GNU General Public Licence</a>." This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-25 20:27:30
|
Revision: 74 http://hrs.svn.sourceforge.net/hrs/?rev=74&view=rev Author: csete Date: 2007-12-25 12:27:28 -0800 (Tue, 25 Dec 2007) Log Message: ----------- Added parameters for home location. Modified Paths: -------------- trunk/doc/um/hrsmap/xml/hrsmap.xml Modified: trunk/doc/um/hrsmap/xml/hrsmap.xml =================================================================== --- trunk/doc/um/hrsmap/xml/hrsmap.xml 2007-12-25 19:52:45 UTC (rev 73) +++ trunk/doc/um/hrsmap/xml/hrsmap.xml 2007-12-25 20:27:28 UTC (rev 74) @@ -40,7 +40,7 @@ <appendix id="cfg-param"> - <title>Configuration Parameters</title> + <title>Configuration Parameters Reference</title> <sect1 id="cfg-param-intro"> <title>Overview</title> <para>ref keeps the configuration data in TBD</para> @@ -52,7 +52,7 @@ </sect1> <sect1 id="cfg-param-ref"> - <title>Configuration Parameters Reference</title> + <title>Configuration Parameters</title> <para>List all configuration parameters</para> <!-- Table listing configuration parameters --> @@ -73,6 +73,22 @@ </thead> <tbody> <row> + <entry morerows='2'>Home</entry> + <entry>Lat</entry> + <entry>real</entry> + <entry>Latitude of the home location in decimal degrees North.</entry> + </row> + <row> + <entry>Lon</entry> + <entry>real</entry> + <entry>Longitude of the home location in decimal degrees East.</entry> + </row> + <row> + <entry>Name</entry> + <entry>string</entry> + <entry>The name of the home location.</entry> + </row> + <row> <entry morerows='1'>MainWindow</entry> <entry>pos</entry> <entry>(uint uint)</entry> @@ -83,6 +99,22 @@ <entry>(uint uint)</entry> <entry>Size of the main window in pixel units. Stored automatically when &app; is quit.</entry> </row> + <row> + <entry morerows='2'>StatusBar</entry> + <entry>dirVisible</entry> + <entry>bool</entry> + <entry>Show direction and bearing to the point under the mouse in the status bar.</entry> + </row> + <row> + <entry>latlonVisible</entry> + <entry>bool</entry> + <entry>Show the Latitude and Longitude of the point under the mouse in the status bar.</entry> + </row> + <row> + <entry>qraVisible</entry> + <entry>bool</entry> + <entry>Show Maidenhead square of the point under the mouse in the status bar.</entry> + </row> </tbody> </tgroup> </table> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-25 19:52:54
|
Revision: 73 http://hrs.svn.sourceforge.net/hrs/?rev=73&view=rev Author: csete Date: 2007-12-25 11:52:45 -0800 (Tue, 25 Dec 2007) Log Message: ----------- Implemented bearing and distance fields. Modified Paths: -------------- trunk/hrsmap/ChangeLog trunk/hrsmap/MainWindow.cpp trunk/hrsmap/MainWindow.h Modified: trunk/hrsmap/ChangeLog =================================================================== --- trunk/hrsmap/ChangeLog 2007-12-25 16:45:25 UTC (rev 72) +++ trunk/hrsmap/ChangeLog 2007-12-25 19:52:45 UTC (rev 73) @@ -1,7 +1,7 @@ 2007-12-25; Alexandru Csete <oz...@gm...> * MainWindow: - Implemented QRA field in the status bar. + Implemented QRA, bearing, adn distance fields in the status bar. 2007-12-24; Alexandru Csete <oz...@gm...> Modified: trunk/hrsmap/MainWindow.cpp =================================================================== --- trunk/hrsmap/MainWindow.cpp 2007-12-25 16:45:25 UTC (rev 72) +++ trunk/hrsmap/MainWindow.cpp 2007-12-25 19:52:45 UTC (rev 73) @@ -498,6 +498,7 @@ QString str; char qra[7]; qint32 retcode; + qreal dist,az; /* if Lat/Lon visible, set lat/lon label texts */ @@ -534,6 +535,17 @@ /* if bearing is visible, calculate bearing and set label text */ if (dirVisible) { + retcode = qrb(qthLon, qthLat, lon, lat, &dist, &az); + + if (retcode == QRA_OK) { + str.setNum(dist, 'f', 0); + str.append("km"); + dspLabel->setText(str); + + str.setNum(az, 'f', 0); + str.append("\xB0"); + dirLabel->setText(str); + } } } @@ -570,6 +582,13 @@ latlonVisible = settings.value("latlonVisible", FALSE).toBool(); qraVisible = settings.value("qraVisible", FALSE).toBool(); settings.endGroup(); + + /* Home location */ + settings.beginGroup("Home"); + qthName = settings.value("Name", "OZ9AEC").toString(); + qthLon = settings.value("Lon", 12.6500).toDouble(); + qthLat = settings.value("Lat", 55.6167).toDouble(); + settings.endGroup(); } //! Save user settings. @@ -590,5 +609,12 @@ settings.setValue("latlonVisible", latlonVisible); settings.setValue("qraVisible", qraVisible); settings.endGroup(); + + /* Home location */ + settings.beginGroup("Home"); + settings.setValue("Name", qthName); + settings.setValue("Lon", qthLon); + settings.setValue("Lat", qthLat); + settings.endGroup(); } Modified: trunk/hrsmap/MainWindow.h =================================================================== --- trunk/hrsmap/MainWindow.h 2007-12-25 16:45:25 UTC (rev 72) +++ trunk/hrsmap/MainWindow.h 2007-12-25 19:52:45 UTC (rev 73) @@ -67,7 +67,11 @@ bool latlonVisible; //!< Show Lat/Lon in statusbar. bool dirVisible; //!< Show bearing and distance in statusbar - + /* Home Location */ + QString qthName; //! Name of the home location + qreal qthLat; //! Latitude of the home station (dec. deg. North) + qreal qthLon; //! Longitude of the home station (dec. deg. East) + QSettings settings; //!< User settings for hrsmap MapView *view; //!< The graphics view rendering the scene This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-25 16:45:27
|
Revision: 72 http://hrs.svn.sourceforge.net/hrs/?rev=72&view=rev Author: csete Date: 2007-12-25 08:45:25 -0800 (Tue, 25 Dec 2007) Log Message: ----------- Implemented QRA field in the status bar. Modified Paths: -------------- trunk/hrsmap/ChangeLog trunk/hrsmap/MainWindow.cpp trunk/hrsmap/hrsmap.pro Modified: trunk/hrsmap/ChangeLog =================================================================== --- trunk/hrsmap/ChangeLog 2007-12-25 16:44:58 UTC (rev 71) +++ trunk/hrsmap/ChangeLog 2007-12-25 16:45:25 UTC (rev 72) @@ -1,3 +1,9 @@ +2007-12-25; Alexandru Csete <oz...@gm...> + + * MainWindow: + Implemented QRA field in the status bar. + + 2007-12-24; Alexandru Csete <oz...@gm...> * MainWindow: Modified: trunk/hrsmap/MainWindow.cpp =================================================================== --- trunk/hrsmap/MainWindow.cpp 2007-12-25 16:44:58 UTC (rev 71) +++ trunk/hrsmap/MainWindow.cpp 2007-12-25 16:45:25 UTC (rev 72) @@ -21,6 +21,7 @@ ***************************************************************************/ #include <QtGui> #include "../common/version.h" +#include "../common/qra.h" #include "MainWindow.h" #include "MapView.h" @@ -320,7 +321,7 @@ /* QRA locator label */ qraLabel = new QLabel("WW99WW"); qraLabel->setMinimumSize(qraLabel->sizeHint()); - qraLabel->setAlignment(Qt::AlignHCenter); + qraLabel->setAlignment(Qt::AlignLeft); /* Latitude label */ str = "99.99\xB0 N"; @@ -495,6 +496,9 @@ void MainWindow::updateCoord (qreal lat, qreal lon) { QString str; + char qra[7]; + qint32 retcode; + /* if Lat/Lon visible, set lat/lon label texts */ if (latlonVisible) { @@ -522,6 +526,10 @@ /* if QRA visible, convert lat/lon to QRA and set label text */ if (qraVisible) { + retcode = longlat2locator(lon, lat, qra, 3); + if (retcode == QRA_OK) { + qraLabel->setText(QString::fromAscii(qra, -1)); + } } /* if bearing is visible, calculate bearing and set label text */ Modified: trunk/hrsmap/hrsmap.pro =================================================================== --- trunk/hrsmap/hrsmap.pro 2007-12-25 16:44:58 UTC (rev 71) +++ trunk/hrsmap/hrsmap.pro 2007-12-25 16:45:25 UTC (rev 72) @@ -1,9 +1,11 @@ SOURCES += MainWindow.cpp \ + ../common/qra.cpp \ main.cpp \ MapView.cpp \ Lunar.cpp \ Solar.cpp HEADERS += ../common/version.h \ + ../common/qra.h \ MainWindow.h \ MapView.h \ Lunar.h \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-25 16:45:03
|
Revision: 71 http://hrs.svn.sourceforge.net/hrs/?rev=71&view=rev Author: csete Date: 2007-12-25 08:44:58 -0800 (Tue, 25 Dec 2007) Log Message: ----------- Added files. Added Paths: ----------- trunk/common/ChangeLog trunk/common/qra.cpp trunk/common/qra.h Added: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog (rev 0) +++ trunk/common/ChangeLog 2007-12-25 16:44:58 UTC (rev 71) @@ -0,0 +1,6 @@ +2007-12-25; Alexandru Csete <oz...@gm...> + + * qra.cpp, qra.h: + Added files containing utility functions for manipulating coordinates + and Maidenhead grid squares. + \ No newline at end of file Added: trunk/common/qra.cpp =================================================================== --- trunk/common/qra.cpp (rev 0) +++ trunk/common/qra.cpp 2007-12-25 16:44:58 UTC (rev 71) @@ -0,0 +1,582 @@ +/* + * Hamlib Interface - locator and bearing conversion calls + * Copyright (c) 2001-2006 by Stephane Fillod + * Copyright (c) 2003 by Nate Bargmann + * Copyright (c) 2003 by Dave Hines + * + * + * Code to determine bearing and range was taken from the Great Circle, + * by S. R. Sampson, N5OWK. + * Ref: "Air Navigation", Air Force Manual 51-40, 1 February 1987 + * Ref: "ARRL Satellite Experimenters Handbook", August 1990 + * + * Code to calculate distance and azimuth between two Maidenhead locators, + * taken from wwl, by IK0ZSN Mirko Caserta. + * + * New bearing code added by N0NB was found at: + * http://williams.best.vwh.net/avform.htm#Crs + * + * + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library 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 Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include <math.h> + +#include "qra.h" + +//#include <hamlib/rotator.h> + + +#define RADIAN (180.0 / M_PI) + +/* arc length for 1 degree, 60 Nautical Miles */ +#define ARC_IN_KM 111.2 + +/* The following is contributed by Dave Hines M1CXW + * + * begin dph + */ +/* + * These are the constants used when converting between Maidenhead grid + * locators and longitude/latitude values. MAX_LOCATOR_PAIRS is the maximum + * number of locator character pairs to convert. This number MUST NOT exceed + * the number of pairs of values in loc_char_range[]. + * Setting MAX_LOCATOR_PAIRS to 3 will convert the currently defined 6 + * character locators. A value of 4 will convert the extended 8 character + * locators described in section 3L of "The IARU region 1 VHF managers + * handbook". Values of 5 and 6 will extent the format even more, to the + * longest definition I have seen for locators, see + * http://www.btinternet.com/~g8yoa/geog/non-ra.html + * Beware that there seems to be no universally accepted standard for 10 & 12 + * character locators. + * + * The ranges of characters which will be accepted by locator2longlat, and + * generated by longlat2locator, are specified by the loc_char_range[] array. + * This array may be changed without requiring any other code changes. + * + * For the fifth pair to range from aa to xx use: + * const static qint32 loc_char_range[] = { 18, 10, 24, 10, 24, 10 }; + * + * For the fifth pair to range from aa to yy use: + * const static qint32 loc_char_range[] = { 18, 10, 24, 10, 25, 10 }; + * + * MAX_LOCATOR_PAIRS now sets the limit locator2longlat() will convert and + * sets the maximum length longlat2locator() will generate. Each function + * properly handles any value from 1 to 6 so MAX_LOCATOR_PAIRS should be + * left at 6. MIN_LOCATOR_PAIRS sets a floor on the shortest locator that + * should be handled. -N0NB + */ +const static qint32 loc_char_range[] = { 18, 10, 24, 10, 24, 10 }; + +#define MAX_LOCATOR_PAIRS 6 +#define MIN_LOCATOR_PAIRS 1 + +/* end dph */ + + +/** + * \brief Convert DMS to decimal degrees + * \param degrees Degrees, whole degrees + * \param minutes Minutes, whole minutes + * \param seconds Seconds, decimal seconds + * \param sw South or West + * + * Convert degree/minute/second angle to decimal degrees angle. + * \a degrees >360, \a minutes > 60, and \a seconds > 60.0 are allowed, + * but resulting angle won't be normalized. + * + * When the variable sw is passed a value of 1, the returned decimal + * degrees value will be negative (south or west). When passed a + * value of 0 the returned decimal degrees value will be positive + * (north or east). + * + * \return The angle in decimal degrees. + * + * \sa dec2dms() + */ + +qreal dms2dec(qint32 degrees, qint32 minutes, qreal seconds, qint32 sw) +{ + qreal st; + + if (degrees < 0) + degrees = abs(degrees); + if (minutes < 0) + minutes = abs(minutes); + if (seconds < 0) + seconds = fabs(seconds); + + st = (qreal)degrees + (qreal)minutes / 60. + seconds / 3600.; + + if (sw == 1) + return -st; + else + return st; +} + +/** + * \brief Convert D M.MMM notation to decimal degrees + * \param degrees Degrees, whole degrees + * \param minutes Minutes, decimal minutes + * \param sw South or West + * + * Convert a degrees, decimal minutes notation common on + * many GPS units to its decimal degrees value. + * + * \a degrees > 360, \a minutes > 60.0 are allowed, but + * resulting angle won't be normalized. + * + * When the variable sw is passed a value of 1, the returned decimal + * degrees value will be negative (south or west). When passed a + * value of 0 the returned decimal degrees value will be positive + * (north or east). + * + * \return The angle in decimal degrees. + * + * \sa dec2dmmm() + */ + +qreal dmmm2dec(qint32 degrees, qreal minutes, qint32 sw) +{ + qreal st; + + if (degrees < 0) + degrees = abs(degrees); + if (minutes < 0) + minutes = fabs(minutes); + + st = (qreal)degrees + minutes / 60.; + + if (sw == 1) + return -st; + else + return st; +} + +/** + * \brief Convert decimal degrees angle into DMS notation + * \param dec Decimal degrees + * \param degrees Pointer for the calculated whole Degrees + * \param minutes Pointer for the calculated whole Minutes + * \param seconds Pointer for the calculated decimal Seconds + * \param sw Pointer for the calculated SW flag + * + * Convert decimal degrees angle into its degree/minute/second + * notation. + * + * When \a dec < -180 or \a dec > 180, the angle will be normalized + * within these limits and the sign set appropriately. + * + * Upon return dec2dms guarantees 0 >= \a degrees <= 180, + * 0 >= \a minutes < 60, and 0.0 >= \a seconds < 60.0. + * + * When \a dec is < 0.0 \a sw will be set to 1. When \a dec is + * >= 0.0 \a sw will be set to 0. This flag allows the application + * to determine whether the DMS angle should be treated as negative + * (south or west). + * + * \retval QRA_ERR if any of the pointers are NULL. + * \retval QRA_OK if conversion went OK. + * + * \sa dms2dec() + */ + +qint32 dec2dms(qreal dec, qint32 *degrees, qint32 *minutes, qreal *seconds, qint32 *sw) +{ + qint32 deg, min; + qreal st; + + /* bail if NULL pointers passed */ + if (!degrees || !minutes || !seconds || !sw) + return QRA_ERR; + + /* reverse the sign if dec has a magnitude greater + * than 180 and factor out multiples of 360. + * e.g. when passed 270 st will be set to -90 + * and when passed -270 st will be set to 90. If + * passed 361 st will be set to 1, etc. If passed + * a value > -180 || < 180, value will be unchanged. + */ + if (dec >= 0.0) + st = fmod(dec + 180, 360) - 180; + else + st = fmod(dec - 180, 360) + 180; + + /* if after all of that st is negative, we want deg + * to be negative as well except for 180 which we want + * to be positive. + */ + if (st < 0.0 && st != -180) + *sw = 1; + else + *sw = 0; + + /* work on st as a positive value to remove a + * bug introduced by the effect of floor() when + * passed a negative value. e.g. when passed + * -96.8333 floor() returns -95! Also avoids + * a rounding error introduced on negative values. + */ + st = fabs(st); + + deg = (qint32)floor(st); + st = 60. * (st - (qreal)deg); + min = (qint32)floor(st); + st = 60. * (st - (qreal)min); + + *degrees = deg; + *minutes = min; + *seconds = st; + + return QRA_OK; +} + +/** + * \brief Convert a decimal angle into D M.MMM notation + * \param dec Decimal degrees + * \param degrees Pointer for the calculated whole Degrees + * \param minutes Pointer for the calculated decimal Minutes + * \param sw Pointer for the calculated SW flag + * + * Convert a decimal angle into its degree, decimal minute + * notation common on many GPS units. + * + * When passed a value < -180 or > 180, the value will be normalized + * within these limits and the sign set apropriately. + * + * Upon return dec2dmmm guarantees 0 >= \a degrees <= 180, + * 0.0 >= \a minutes < 60.0. + * + * When \a dec is < 0.0 \a sw will be set to 1. When \a dec is + * >= 0.0 \a sw will be set to 0. This flag allows the application + * to determine whether the D M.MMM angle should be treated as negative + * (south or west). + * + * \retval QRA_ERR if any of the pointers are NULL. + * \retval QRA_OK if conversion went OK. + * + * \sa dmmm2dec() + */ + +qint32 dec2dmmm(qreal dec, qint32 *degrees, qreal *minutes, qint32 *sw) +{ + qint32 r, min; + qreal sec; + + /* bail if NULL pointers passed */ + if (!degrees || !minutes || !sw) + return QRA_ERR; + + r = dec2dms(dec, degrees, &min, &sec, sw); + if (r != QRA_OK) + return r; + + *minutes = (qreal)min + sec / 60; + + return QRA_OK; +} + +/** + * \brief Convert Maidenhead grid locator to Longitude/Latitude + * \param longitude Pointer for the calculated Longitude + * \param latitude Pointer for the calculated Latitude + * \param locator The Maidenhead grid locator--2 through 12 char + nul string + * + * Convert Maidenhead grid locator to Longitude/Latitude (decimal degrees). + * The locator should be in 2 through 12 chars long format. + * \a locator2longlat is case insensitive, however it checks for + * locator validity. + * + * Decimal long/lat is computed to center of grid square, i.e. given + * EM19 will return coordinates equivalent to the southwest corner + * of EM19mm. + * + * \retval QRA_ERR if locator exceeds RR99xx99xx99 or exceeds length + * limit--currently 1 to 6 lon/lat pairs. + * \retval QRA_OK if conversion went OK. + * + * \bug The fifth pair ranges from aa to xx, there is another convention + * that ranges from aa to yy. At some point both conventions should be + * supported. + * + * \sa longlat2locator() + */ + +/* begin dph */ + +qint32 locator2longlat(qreal *longitude, qreal *latitude, const char *locator) +{ + qint32 x_or_y, paircount; + qint32 locvalue, pair; + qint32 divisions; + qreal xy[2], ordinate; + + /* bail if NULL pointers passed */ + if (!longitude || !latitude) + return QRA_ERR; + + paircount = strlen(locator) / 2; + + /* verify paircount is within limits */ + if (paircount > MAX_LOCATOR_PAIRS) + paircount = MAX_LOCATOR_PAIRS; + else if (paircount < MIN_LOCATOR_PAIRS) + return QRA_ERR; + + /* For x(=longitude) and y(=latitude) */ + for (x_or_y = 0; x_or_y < 2; ++x_or_y) { + ordinate = -90.0; + divisions = 1; + + for (pair = 0; pair < paircount; ++pair) { + locvalue = locator[pair*2 + x_or_y]; + + /* Value of digit or letter */ + locvalue -= (loc_char_range[pair] == 10) ? '0' : + (isupper(locvalue)) ? 'A' : 'a'; + + /* Check range for non-letter/digit or out of range */ + if ((locvalue < 0) || (locvalue >= loc_char_range[pair])) + return QRA_ERR; + + divisions *= loc_char_range[pair]; + ordinate += locvalue * 180.0 / divisions; + } + /* Center ordinate in the Maidenhead "square" or "subsquare" */ + ordinate += 90.0 / divisions; + + xy[x_or_y] = ordinate; + } + + *longitude = xy[0] * 2.0; + *latitude = xy[1]; + + return QRA_OK; +} +/* end dph */ + +/** + * \brief Convert longitude/latitude to Maidenhead grid locator + * \param longitude Longitude, decimal degrees + * \param latitude Latitude, decimal degrees + * \param locator Pointer for the Maidenhead Locator + * \param pair_count Precision expressed as lon/lat pairs in the locator + * + * Convert longitude/latitude (decimal degrees) to Maidenhead grid locator. + * \a locator must point to an array at least \a pair_count * 2 char + '\\0'. + * + * \retval QRA_ERR if \a locator is NULL or \a pair_count exceeds + * length limit. Currently 1 to 6 lon/lat pairs. + * \retval QRA_OK if conversion went OK. + * + * \bug \a locator is not tested for overflow. + * \bug The fifth pair ranges from aa to yy, there is another convention + * that ranges from aa to xx. At some point both conventions should be + * supported. + * + * \sa locator2longlat() + */ + +/* begin dph */ + +qint32 longlat2locator(qreal longitude, qreal latitude, char *locator, qint32 pair_count) +{ + qint32 x_or_y, pair, locvalue, divisions; + qreal square_size, ordinate; + + if (!locator) + return QRA_ERR; + + if (pair_count < MIN_LOCATOR_PAIRS || pair_count > MAX_LOCATOR_PAIRS) + return QRA_ERR; + + for (x_or_y = 0; x_or_y < 2; ++x_or_y) { + ordinate = (x_or_y == 0) ? longitude / 2.0 : latitude; + divisions = 1; + + /* The 1e-6 here guards against floating point rounding errors */ + ordinate = fmod(ordinate + 270.000001, 180.0); + for (pair = 0; pair < pair_count; ++pair) { + divisions *= loc_char_range[pair]; + square_size = 180.0 / divisions; + + locvalue = (qint32) (ordinate / square_size); + ordinate -= square_size * locvalue; + locvalue += (loc_char_range[pair] == 10) ? '0':'A'; + locator[pair * 2 + x_or_y] = locvalue; + } + } + locator[pair_count * 2] = '\0'; + + return QRA_OK; +} + +/* end dph */ + +/** + * \brief Calculate the distance and bearing between two points. + * \param lon1 The local Longitude, decimal degrees + * \param lat1 The local Latitude, decimal degrees + * \param lon2 The remote Longitude, decimal degrees + * \param lat2 The remote Latitude, decimal degrees + * \param distance Pointer for the distance, km + * \param azimuth Pointer for the bearing, decimal degrees + * + * Calculate the QRB between \a lon1, \a lat1 and \a lon2, \a lat2. + * + * This version will calculate the QRB to a precision sufficient + * for 12 character locators. Antipodal points, which are easily + * calculated, are considered equidistant and the bearing is + * simply resolved to be true north (0.0°). + * + * \retval QRA_ERR if NULL pointer passed or lat and lon values + * exceed -90 to 90 or -180 to 180. + * \retval QRA_OK if calculations are successful. + * + * \return The distance in kilometers and azimuth in decimal degrees + * for the short path are stored in \a distance and \a azimuth. + * + * \sa distance_long_path(), azimuth_long_path() + */ + +qint32 qrb(qreal lon1, qreal lat1, qreal lon2, qreal lat2, qreal *distance, qreal *azimuth) +{ + qreal delta_long, tmp, arc, az; + + /* bail if NULL pointers passed */ + if (!distance || !azimuth) + return -1; + + if ((lat1 > 90.0 || lat1 < -90.0) || (lat2 > 90.0 || lat2 < -90.0)) + return -1; + + if ((lon1 > 180.0 || lon1 < -180.0) || (lon2 > 180.0 || lon2 < -180.0)) + return -1; + + /* Prevent ACOS() Domain Error */ + if (lat1 == 90.0) + lat1 = 89.999999999; + else if (lat1 == -90.0) + lat1 = -89.999999999; + + if (lat2 == 90.0) + lat2 = 89.999999999; + else if (lat2 == -90.0) + lat2 = -89.999999999; + + /* Convert variables to Radians */ + lat1 /= RADIAN; + lon1 /= RADIAN; + lat2 /= RADIAN; + lon2 /= RADIAN; + + delta_long = lon2 - lon1; + + tmp = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(delta_long); + + if (tmp > .999999999999999) { + /* Station points coincide, use an Omni! */ + *distance = 0.0; + *azimuth = 0.0; + return QRA_OK; + } + + if (tmp < -.999999) { + /* + * points are antipodal, it's straight down. + * Station is equal distance in all Azimuths. + * So take 180 Degrees of arc times 60 nm, + * and you get 10800 nm, or whatever units... + */ + *distance = 180.0 * ARC_IN_KM; + *azimuth = 0.0; + return QRA_OK; + } + + arc = acos(tmp); + + /* + * One degree of arc is 60 Nautical miles + * at the surface of the earth, 111.2 km, or 69.1 sm + * This method is easier than the one in the handbook + */ + + /* Short Path */ + *distance = ARC_IN_KM * RADIAN * arc; + + /* This formula seems to work with very small distances + * + * I found it on the Web at: + * http://williams.best.vwh.net/avform.htm#Crs + * + * Strangely, all the computed values were negative thus the + * sign reversal below. + * - N0NB + */ + az = RADIAN * fmod(atan2(sin(lon1 - lon2) * cos(lat2), + cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon1 - lon2)), 2 * M_PI); + if (lon1 > lon2) { + az -= 360.; + *azimuth = -az; + } else { + if (az >= 0.0) + *azimuth = az; + else + *azimuth = -az; + } + + return QRA_OK; +} + +/** + * \brief Calculate the long path distance between two points. + * \param distance The shortpath distance + * + * Calculate the long path (respective of the short path) + * of a given distance. + * + * \return the distance in kilometers for the opposite path. + * + * \sa qrb() + */ + +qreal distance_long_path(qreal distance) +{ + return (ARC_IN_KM * 360.0) - distance; +} + +/** + * \brief Calculate the long path bearing between two points. + * \param azimuth The shortpath bearing + * + * Calculate the long path (respective of the short path) + * of a given bearing. + * + * \return the azimuth in decimal degrees for the opposite path. + * + * \sa qrb() + */ + +qreal azimuth_long_path(qreal azimuth) +{ + return 360.0 - azimuth; +} + Added: trunk/common/qra.h =================================================================== --- trunk/common/qra.h (rev 0) +++ trunk/common/qra.h 2007-12-25 16:44:58 UTC (rev 71) @@ -0,0 +1,42 @@ +/*************************************************************************** + * * + * HRS * + * Copyright (C) 2007 by Alexandru Csete OZ9AEC * + * * + * * + * 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 QRA_H +#define QRA_H + +#include <QtCore> + +#define QRA_OK 0 +#define QRA_ERR -1 + + +qreal dms2dec(int degrees, int minutes, qreal seconds, qint32 sw); +qreal dmmm2dec(int degrees, qreal minutes, qint32 sw); +qint32 dec2dms(qreal dec, qint32 *degrees, qint32 *minutes, qreal *seconds, qint32 *sw); +qint32 dec2dmmm(qreal dec, qint32 *degrees, qreal *minutes, qint32 *sw); +qint32 locator2longlat(qreal *longitude, qreal *latitude, const char *locator); +qint32 longlat2locator(qreal longitude, qreal latitude, char *locator, qint32 pair_count); +qint32 qrb(qreal lon1, qreal lat1, qreal lon2, qreal lat2, qreal *distance, qreal *azimuth); +qreal distance_long_path(qreal distance); +qreal azimuth_long_path(qreal azimuth); + + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-25 02:08:11
|
Revision: 70 http://hrs.svn.sourceforge.net/hrs/?rev=70&view=rev Author: csete Date: 2007-12-24 18:08:06 -0800 (Mon, 24 Dec 2007) Log Message: ----------- Minor doc update. Modified Paths: -------------- trunk/hrsmap/MainWindow.cpp Modified: trunk/hrsmap/MainWindow.cpp =================================================================== --- trunk/hrsmap/MainWindow.cpp 2007-12-25 01:59:55 UTC (rev 69) +++ trunk/hrsmap/MainWindow.cpp 2007-12-25 02:08:06 UTC (rev 70) @@ -376,7 +376,7 @@ } -//! Toggle qraVisible flag. +//! Toggle qraVisible flag and status bar label. /*! \param state The new status of the checkbox * * This slot is used to receive a signal when the qraVisible flag is toggled @@ -407,7 +407,7 @@ } -//! Toggle latlonVisible flag. +//! Toggle latlonVisible flag and status bar labels. /*! \param state The new status of the checkbox * * This slot is used to receive a signal when the latlonVisible flag is @@ -443,7 +443,7 @@ } -//! Toggle dirVisible flag. +//! Toggle dirVisible flag and status bas labels. /*! \param state The new status of the checkbox * * This slot is used to receive a signal when the dirVisible flag is @@ -482,8 +482,8 @@ //! Update target coordinates in the status bar. -/*! \param lat The Latitude in decimial degrees. - * \param lon The longitude in decimal degrees. +/*! \param lat The Latitude in decimial degrees North. + * \param lon The longitude in decimal degrees East. * * This function updates the coordinate display labels in the status bar. * The function is used as a slot and is called by the mouse movement event This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-25 01:59:57
|
Revision: 69 http://hrs.svn.sourceforge.net/hrs/?rev=69&view=rev Author: csete Date: 2007-12-24 17:59:55 -0800 (Mon, 24 Dec 2007) Log Message: ----------- Implemented View->Statusbar signals. Modified Paths: -------------- trunk/hrsmap/ChangeLog trunk/hrsmap/MainWindow.cpp trunk/hrsmap/MainWindow.h trunk/hrsmap/MapView.h Modified: trunk/hrsmap/ChangeLog =================================================================== --- trunk/hrsmap/ChangeLog 2007-12-24 18:50:23 UTC (rev 68) +++ trunk/hrsmap/ChangeLog 2007-12-25 01:59:55 UTC (rev 69) @@ -1,4 +1,11 @@ -2007-07-21; Alexandru Csete <oz...@go...> +2007-12-24; Alexandru Csete <oz...@gm...> + * MainWindow: + Automatically store and read settings. + Implemented View->Statusbar signals. + + +2007-07-21; Alexandru Csete <oz...@gm...> + * All: First functional version that can display a world map and day/night. Modified: trunk/hrsmap/MainWindow.cpp =================================================================== --- trunk/hrsmap/MainWindow.cpp 2007-12-24 18:50:23 UTC (rev 68) +++ trunk/hrsmap/MainWindow.cpp 2007-12-25 01:59:55 UTC (rev 69) @@ -32,39 +32,37 @@ MainWindow::MainWindow() { bool track; - + + /* set minimum size */ setMinimumSize (500, 350); - - /* initialise settings */ - qraVisible = TRUE; - latlonVisible = TRUE; - dirVisible = TRUE; - + + /* read settings */ + readSettings(); + /* create the graphics view and add it to the main window */ view = new MapView (); setCentralWidget(view); - + /* create menus and toolbars */ createActions(); createMenus(); //createContextMenu(); //createToolBars(); createStatusBar(); - readSettings(); - + setWindowTitle (tr("HRS Map %1.%2 %3") .arg(HRS_MAJOR_VERSION) .arg(HRS_MINOR_VERSION) .arg(HRS_BETA_STRING)); - + setWindowIcon(QIcon(":/icon/map.png")); - + /* mouse tracking */ track = qraVisible || latlonVisible || dirVisible; view->setTrackMouse (track); - + } @@ -189,16 +187,22 @@ sbQraAction = new QAction(tr("Maidenhead locator"), this); sbQraAction->setStatusTip(tr("Show the Maidenhead locator of the point under the mouse")); sbQraAction->setCheckable (true); + sbQraAction->setChecked (qraVisible); + connect(sbQraAction, SIGNAL(triggered(bool)), this, SLOT(qraToggled(bool))); /* View -> Statusbar -> Lat/Lon */ sbLatLonAction = new QAction(tr("Latitude and longitude"), this); sbLatLonAction->setStatusTip(tr("Show the latitude and longitude of the location under the mouse")); sbLatLonAction->setCheckable (true); + sbLatLonAction->setChecked (latlonVisible); + connect(sbLatLonAction, SIGNAL(triggered(bool)), this, SLOT(latlonToggled(bool))); /* View -> Statusbar -> Bearing and distance */ sbDirAction = new QAction(tr("Bearing and Distance"), this); sbDirAction->setStatusTip(tr("Show bearing and distance to the location under the mouse")); sbDirAction->setCheckable (true); + sbDirAction->setChecked (dirVisible); + connect(sbDirAction, SIGNAL(triggered(bool)), this, SLOT(dirToggled(bool))); /* View -> Home */ homeAction = new QAction(tr("Home location"), this); @@ -348,6 +352,19 @@ statusBar()->addPermanentWidget(dirLabel); statusBar()->addPermanentWidget(dspLabel); + /* hide labels that are not wanted by user */ + if (!qraVisible) { + statusBar()->removeWidget(qraLabel); + } + if (!latlonVisible) { + statusBar()->removeWidget(latLabel); + statusBar()->removeWidget(lonLabel); + } + if (!dirVisible) { + statusBar()->removeWidget(dirLabel); + statusBar()->removeWidget(dspLabel); + } + /* connect signals */ connect(view, SIGNAL(mouseMove(qreal,qreal)), this, SLOT(updateCoord(qreal,qreal))); @@ -358,13 +375,122 @@ //updateStatusBar(); } + +//! Toggle qraVisible flag. +/*! \param state The new status of the checkbox + * + * This slot is used to receive a signal when the qraVisible flag is toggled + * in the menu bar. + * + * If state is FALSE, the qraVisible flag is set to FALSE and the qraLabel + * widget is removed from the status bar. If state is TRUE, the qraVisible flag + * is set to TRUE and the qraLabel widget is inserted into the status bar. + */ +void MainWindow::qraToggled (bool state) +{ + bool track; + + + if (state) { + qraVisible = TRUE; + statusBar()->insertPermanentWidget(0,qraLabel,0); + qraLabel->show(); + } + else { + qraVisible = FALSE; + statusBar()->removeWidget(qraLabel); + } + + /* mouse tracking */ + track = qraVisible || latlonVisible || dirVisible; + view->setTrackMouse (track); +} + + +//! Toggle latlonVisible flag. +/*! \param state The new status of the checkbox + * + * This slot is used to receive a signal when the latlonVisible flag is + * toggled in the menu bar. + * + * If state is FALSE, the latlonVisible flag is set to FALSE and the latLabel + * and lonLabel widgets are removed from the status bar. If state is TRUE, the + * latlonVisible flag is set to TRUE and the latLabel and lonLabel widgets are + * inserted into the status bar. + */ +void MainWindow::latlonToggled (bool state) +{ + bool track; + int idx; + + if (state) { + latlonVisible = TRUE; + idx = qraVisible ? 1 : 0; + statusBar()->insertPermanentWidget(idx,latLabel,0); + statusBar()->insertPermanentWidget(idx+1,lonLabel,0); + latLabel->show(); + lonLabel->show(); + } + else { + latlonVisible = FALSE; + statusBar()->removeWidget(latLabel); + statusBar()->removeWidget(lonLabel); + } + + /* mouse tracking */ + track = qraVisible || latlonVisible || dirVisible; + view->setTrackMouse (track); +} + + +//! Toggle dirVisible flag. +/*! \param state The new status of the checkbox + * + * This slot is used to receive a signal when the dirVisible flag is + * toggled in the menu bar. + * + * If state is FALSE, the dirVisible flag is set to FALSE and the dirLabel + * and dspLabel widgets are removed from the status bar. If state is TRUE, the + * dirVisible flag is set to TRUE and the dirLabel and dspLabel widgets are + * inserted into the status bar. + */ +void MainWindow::dirToggled (bool state) +{ + bool track; + int idx=0; + + if (state) { + dirVisible = TRUE; + idx += qraVisible ? 1 : 0; + idx += latlonVisible ? 2 : 0; + statusBar()->insertPermanentWidget(idx,dirLabel,0); + statusBar()->insertPermanentWidget(idx+1,dspLabel,0); + dirLabel->show(); + dspLabel->show(); + } + else { + dirVisible = FALSE; + statusBar()->removeWidget(dirLabel); + statusBar()->removeWidget(dspLabel); + } + + /* mouse tracking */ + track = qraVisible || latlonVisible || dirVisible; + view->setTrackMouse (track); + +} + + //! Update target coordinates in the status bar. -/*! This function updates the coordinate display labels in the status bar. - The function is used as a slot and is called by the mouse movement - event trigger in the MapView object. - - Note that whether a status bar field is visible or not depends on the - current settings in the View menu. +/*! \param lat The Latitude in decimial degrees. + * \param lon The longitude in decimal degrees. + * + * This function updates the coordinate display labels in the status bar. + * The function is used as a slot and is called by the mouse movement event + * trigger in the MapView object. + * + * Note that whether a status bar field is visible or not depends on the + * current settings in the View menu. */ void MainWindow::updateCoord (qreal lat, qreal lon) { @@ -419,6 +545,9 @@ } //! Read user settings. +/*! This function is used to read the user settings and preferences when + the application is started. +*/ void MainWindow::readSettings() { /* window geometry */ @@ -426,9 +555,19 @@ resize(settings.value("size", QSize(500, 350)).toSize()); move(settings.value("pos", QPoint(200, 200)).toPoint()); settings.endGroup(); + + /* status bar */ + settings.beginGroup("StatusBar"); + dirVisible = settings.value("dirVisible", FALSE).toBool(); + latlonVisible = settings.value("latlonVisible", FALSE).toBool(); + qraVisible = settings.value("qraVisible", FALSE).toBool(); + settings.endGroup(); } //! Save user settings. +/*! This function is used to store the user settings when the application + is closed. +*/ void MainWindow::writeSettings() { /* window geometry */ @@ -436,5 +575,12 @@ settings.setValue("size", size()); settings.setValue("pos", pos()); settings.endGroup(); + + /* status bar */ + settings.beginGroup("StatusBar"); + settings.setValue("dirVisible", dirVisible); + settings.setValue("latlonVisible", latlonVisible); + settings.setValue("qraVisible", qraVisible); + settings.endGroup(); } Modified: trunk/hrsmap/MainWindow.h =================================================================== --- trunk/hrsmap/MainWindow.h 2007-12-24 18:50:23 UTC (rev 68) +++ trunk/hrsmap/MainWindow.h 2007-12-25 01:59:55 UTC (rev 69) @@ -44,6 +44,11 @@ private slots: bool saveAs(); void about(); + + /* status bar labels */ + void qraToggled (bool state); + void latlonToggled (bool state); + void dirToggled (bool state); void updateCoord (qreal lat, qreal lon); void clearLabels (); Modified: trunk/hrsmap/MapView.h =================================================================== --- trunk/hrsmap/MapView.h 2007-12-24 18:50:23 UTC (rev 68) +++ trunk/hrsmap/MapView.h 2007-12-25 01:59:55 UTC (rev 69) @@ -33,39 +33,39 @@ public: MapView(); ~MapView(); - + /* set and get config parameters */ double getDarkThreshold (); int getDarkOpacity (); void setDarkThreshold (double thld); void setDarkOpacity (int opc); - + void setTrackMouse (bool track); void paintEvent (QPaintEvent *event); void mouseMoveEvent (QMouseEvent * event); void enterEvent (QEvent * event); void leaveEvent (QEvent * event); /* maybe add show/hide events */ - - + + signals: void mouseEnter (void); void mouseLeave (void); void mouseMove (qreal lat, qreal lon); - + private slots: void updateShadow(); - + private: QPixmap *pixmap; QImage *shadow; int xmargin; int ymargin; - double threshold; //!< Complete darkness threshold - int opacity; //!< Opacity; higher value => darker - + double threshold; //!< Complete darkness threshold + int opacity; //!< Opacity; higher value => darker + QTimer *timer; //!< The periodic update timer - + inline void mapToLatLon (int x, int y, int w, int h, qreal *lat, qreal *lon); inline void mapToLatLon (int x, int y, qreal *lat, qreal *lon); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cs...@us...> - 2007-12-24 18:50:24
|
Revision: 68 http://hrs.svn.sourceforge.net/hrs/?rev=68&view=rev Author: csete Date: 2007-12-24 10:50:23 -0800 (Mon, 24 Dec 2007) Log Message: ----------- Added new menu items. Modified Paths: -------------- trunk/hrsmap/MainWindow.cpp trunk/hrsmap/MainWindow.h Modified: trunk/hrsmap/MainWindow.cpp =================================================================== --- trunk/hrsmap/MainWindow.cpp 2007-12-24 18:49:59 UTC (rev 67) +++ trunk/hrsmap/MainWindow.cpp 2007-12-24 18:50:23 UTC (rev 68) @@ -104,6 +104,8 @@ viewMenu->addAction(dxAction); viewMenu->addSeparator(); + viewMenu->addAction(borderAction); + viewMenu->addAction(prefixAction); viewMenu->addAction(gridAction); viewMenu->addAction(qraAction); @@ -213,11 +215,21 @@ dxAction->setStatusTip(tr("View DX spots on the map")); dxAction->setCheckable (true); + /* View -> Country borders */ + borderAction = new QAction(tr("Country borders"), this); + borderAction->setStatusTip(tr("Show the border lines between countries")); + borderAction->setCheckable(true); + + /* View -> Country prefix */ + prefixAction = new QAction(tr("Country prefix"), this); + prefixAction->setStatusTip(tr("Show country prefixes on the map")); + prefixAction->setCheckable(true); + /* View -> Grid lines */ - gridAction = new QAction(tr("Show grid"), this); + gridAction = new QAction(tr("Lat/Lon grid"), this); gridAction->setStatusTip(tr("Show Lat/Lon grid lines")); gridAction->setCheckable (true); - + /* View -> Maidenhead squares */ qraAction = new QAction(tr("Maidenhead locators"), this); qraAction->setStatusTip(tr("Show Maidenhead locator squares")); Modified: trunk/hrsmap/MainWindow.h =================================================================== --- trunk/hrsmap/MainWindow.h 2007-12-24 18:49:59 UTC (rev 67) +++ trunk/hrsmap/MainWindow.h 2007-12-24 18:50:23 UTC (rev 68) @@ -58,14 +58,14 @@ void writeSettings(); /* visibility flags */ - bool qraVisible; //!< Show Maidenhead square in statusbar. - bool latlonVisible; //!< Show Lat/Lon in statusbar. - bool dirVisible; //!< Show bearing and distance in statusbar + bool qraVisible; //!< Show Maidenhead square in statusbar. + bool latlonVisible; //!< Show Lat/Lon in statusbar. + bool dirVisible; //!< Show bearing and distance in statusbar QSettings settings; //!< User settings for hrsmap - MapView *view; //!< The graphics view rendering the scene + MapView *view; //!< The graphics view rendering the scene /* File Menu */ QMenu *fileMenu; //!< The 'File' menu @@ -92,6 +92,8 @@ QAction *homeAction; //!< The 'Home' menu item QAction *stnAction; //!< The 'Worked stations' menu item QAction *dxAction; //!< The 'DX Spots' menu item + QAction *borderAction; //!< The 'Country borders' menu item + QAction *prefixAction; //!< The 'Country prefix' menu item QAction *gridAction; //!< Lat/Lon grid lines QAction *qraAction; //!< Maidenhead labels QAction *fsAction; //!< The 'Fullscreen' menu item This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |