Commit b0b8a945 authored by James Goppert's avatar James Goppert

Added local qserial.

parent 79ceff26
......@@ -44,4 +44,3 @@ user_config.pri
*.cproject
*.sln
*.suo
*thirdParty*
[submodule "thirdParty/mavlink"]
path = thirdParty/mavlink
url = https://github.com/pixhawk/mavlink.git
[submodule "thirdParty/qserial"]
path = thirdParty/qserial
url = git://gitorious.org/inbiza-labs/qserialport.git
#!/bin/bash
PS3='Please enter your choice: '
LIST="all mavlink qserialport end"
echo
echo this script grabs upstream releases
function fetch_qserialport
{
rm -rf qserialport
git clone git://gitorious.org/inbiza-labs/qserialport.git
rm -rf qserialport/.git
}
function fetch_mavlink
{
echo you chose mavlink
echo fetching mavlink
rm -rf mavlink
git clone git@github.com:openmav/mavlink.git
rm -rf mavlink/.git
}
echo
select OPT in $LIST
do
case $OPT in
"qserialport")
fetch_qserialport
exit 0
;;
"mavlink")
fetch_mavlink
exit 0
;;
"all")
fetch_mavlink
fetch_qserialport
exit 0
;;
"exit")
exit 0
;;
*)
echo unknown option
exit 1
esac
done
qserial @ 004e3de5
Subproject commit 004e3de552fe25fee593dfcb03e2ffa82cb0b152
This diff is collapsed.
This diff is collapsed.
Installing QSerialPort
----------------------
QSerialPort requires Qt 4.6 or greater.
For Mac/Unix/Linux/Embedded Linux:
./configure
make
make install
/sbin/ldconfig, if necessary
For Windows:
configure
nmake (or make)
installwin
For Wince:
qmake -r qserialport.pro -spec <platform-name>
nmake
i.e "qmake -r qserialport.pro -spec wince50standard-x86-msvc2005" for wince 5.0 standard sdk
Notes
-----
- On unix, use --prefix=$PWD to build in-place
- if 'configure' doesn't work on Mac OSX (it doesn't work if QT is installed as SDK), use the following instead:
qmake -r qserialport.pro -spec macx-g++
make
make install
Optionally add lib_bundle config value to build it as framework:
qmake -r qserialport.pro -spec macx-g++ CONFIG+=lib_bundle
- To build QSerialPort as static library try CONFIG+=static with qmake or add it into conf.pri file.
- Visual Studio 2005 solution and project files are included into the package. Current solution is prepared for WIN32 builds.
If you want to build QSerialPort for WINCE using Visual Studio then do the following:
o replace qserialportnative_win32.cpp with qserialportnative_wince.cpp
o add wincommevtbreaker.cpp and wincommevtbreaker.h files into the project
Please report problems to:
labs@inbiza.com
This diff is collapsed.
/**
\mainpage Unofficial Qt Serial Port Library
%QSerialPort is a cross-platform serial port library, using Qt datatypes and
conventions. %QSerialPort inherits from <a href="http://doc.trolltech.com/4.7/qiodevice.html">QIODevice
</a> and works natively with any Qt class that uses QIODevice objects as input or output.
%QSerialPort should work everywhere %Qt does, including Windows/Unix/Linux/Embedded Linux/WinCE/MacOSX. This
version of %QSerialPort is for Qt4, and requires no Qt3 compatibility code.
\section Characteristics Device Characteristics
%QSerialPort has the following QIODevice characteristics:
- Supports event-driven and polling programming models
- It is a sequential device like <a href="http://doc.trolltech.com/4.7/qprocess.html">QProcess</a> and
<a href="http://doc.trolltech.com/4.7/qtcpsocket.html">QTcpSocket</a>
- It is an unbuffered device
\section using Using QSerialPort
The application simply includes &lt;QSerialPort> and links to
libqserialport. There are additional examples available in the "examples" directory.
You will notice that %QSerialPort is part of TNX namespace. TNX stands for Tonix
which is a Qt based cross-platform hardware control framework with built in JavaScript support. Since Tonix
is specially designed for embedded system development and robotics projects %QSerialPort is an essential part of it.
Example:
\code
#include <QSerialPort>
int main(int argc, char *argv[])
{
using namespace TNX;
QCoreApplication a(argc, argv);
QSerialPort serport("COM5", "9600,8,n,1");
if ( !serport.open() )
qFatal("Cannot open serial port %s. Exiting..", qPrintable(portName));
if ( !serport.setCommTimeouts(QSerialPort::CtScheme_NonBlockingRead) )
qWarning("Cannot set communications timeout values at port %s.", qPrintable(portName));
int byteCounter = 0;
forever {
if ( serport.waitForReadyRead(5000) ) { // 5sec
QByteArray data = serport.read(512);
byteCounter += data.size();
std::cout << "Received data @ " << qPrintable(QDateTime::currentDateTime().toString("hh:mm:ss.zzz")) <<
". Echo back." << std::endl;
serport.write(data);
if ( byteCounter >= 4096 )
break;
}
else {
std::cout << "Timeout while waiting for incoming data @ " <<
qPrintable(QDateTime::currentDateTime().toString("hh:mm:ss.zzz")) << std::endl;
}
}
std::cout << "Polling example is terminated successfully." << std::endl;
return 0;
}
\endcode
*/
Unofficial Qt Serial Port library version 1.0.0 alpha
-----------------------------------------------------
Date: October 15th, 2010
Website: http://www.inbiza.com/labs
Description
-----------
QSerialPort is a high performance cross platform serial library based on the QIODevice class from the Qt framework. Building this library on QIODevice allows for a much more integrated and native experience when developing Qt based applications.
The project stems from our work on high performance embedded systems where we need to squeeze out as much IO performance as possible from hardware with limited resources.
This library has been tested on:
Ð Linux on x86 and ARM ;
Ð Windows XP and CE 5 on x86;
Ð OS X 10.6 on x86 with a FTDI USB to Serial bridge.
API Documentation is located in the 'apidocs' subdirectory. Run 'make doc' to generate the documentation on a Linux system with Doxygen installed.
Special Thanks
--------------
We used Qt Cryptographic Architecture (QCA) project's layout
and qmake configuration as a model for our project. We thank to
Justin Karneges and QCA team for their great work.
Install
-------
For installation or compiling instructions, see the INSTALL file.
License
-------
This software is distributed under the terms of the GNU Lesser General Public License version 2.1.
Changes
-------
<none>
* 1.0.0 Alpha
o Symbian support
o mingw test/support
o Increase testing coverage - see TestPlan for details
o Make sure that QSerialPort works properly when created by a thread other than the main thread
o Add breakState() method
o Test line signal related methods
o Code cleanup
o Better documentation
##
## Unofficial Qt Serial Port Library
##
## Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
##
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU Lesser General Public License as published by the
## Free Software Foundation, either version 3 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 Lesser General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>
##
##
## @file app.pri
## www.inbiza.com
##
include(confapp.pri)
include(base.pri)
macx:QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6 #for universal
# qmake configuring apps with staticlib poses linking problems
windows|wince*:staticlib {
CONFIG-=shared
CONFIG-=staticlib
CONFIG+=static
}
exists(qserialport.prf) {
# our apps should build against the qserialport in this tree
include(qserialport.prf)
} else {
# attempt to use system-wide qserialport
CONFIG *= qserialport
}
##
## Unofficial Qt Serial Port Library
##
## Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
##
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU Lesser General Public License as published by the
## Free Software Foundation, either version 3 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 Lesser General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>
##
##
## @file base.pri
## www.inbiza.com
##
!isEmpty( QMAKESPEC ) {
MKSPEC = $$replace(QMAKESPEC,-," ")
MKSPEC = $$join(MKSPEC, " -L", )
PLATFORM_NAME = $$member(MKSPEC)
}
else{
unix:PLATFORM_NAME = $$system( uname -s )
windows: PLATFORM_NAME = Win32
}
QSERIALPORT_BASE = $$PWD
QSERIALPORT_SRCBASE = $$QSERIALPORT_BASE/src
QSERIALPORT_INCBASE = $$QSERIALPORT_BASE/include
QSERIALPORT_LIBDIR = $$QSERIALPORT_BASE/lib
QSERIALPORT_BUILDDIR = $$QSERIALPORT_BASE/build/$$PLATFORM_NAME
QSERIALPORT_BINDESTDIR = $$QSERIALPORT_BASE/bin
# qconf
PREFIX = /usr/local
BINDIR = /usr/local/bin
DATADIR = /usr/local/share
##
## Unofficial Qt Serial Port Library
##
## Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
##
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU Lesser General Public License as published by the
## Free Software Foundation, either version 3 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 Lesser General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>
##
##
## @file qserialport.prf
## www.inbiza.com
##
CONFIG += release
This diff is collapsed.
##
## Unofficial Qt Serial Port Library
##
## Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
##
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU Lesser General Public License as published by the
## Free Software Foundation, either version 3 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 Lesser General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>
##
##
## @file echo_eventmode.pro
## www.inbiza.com
##
include(../examples.pri)
DEPENDPATH += . $$QSERIALPORT_INCBASE/QtSerialPort
QT += network
!windows:TARGET = $$QSERIALPORT_BINDESTDIR/$$TARGET
# Input
SOURCES += main.cpp \
host.cpp
HEADERS += host.h
MOC_DIR = $$QSERIALPORT_BUILDDIR/GeneratedFiles/eventdriven
CONFIG(debug, debug|release) {
OBJECTS_DIR = $$QSERIALPORT_BUILDDIR/Debug/eventdriven
macx:TARGET = $$member(TARGET, 0)_debug
windows:TARGET = $$member(TARGET, 0)d
unix:!macx:TARGET = $$member(TARGET, 0).debug
}
else {
OBJECTS_DIR = $$QSERIALPORT_BUILDDIR/Release/eventdriven
}
/*
* Unofficial Qt Serial Port Library
*
* Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* author labs@inbiza.com
*/
#include <iostream>
#include <QtCore/QCoreApplication>
#include <QThread>
#include <QSerialPort>
#include <QTimerEvent>
#include <QDateTime>
#include "host.h"
Host::Host(TNX::QSerialPort &serPort, QObject *parent)
: QObject(parent), serialPort_(serPort), timerId_(0), byteCounter_(0)
{
using TNX::QSerialPort;
timerId_ = startTimer(5000);
connect(&serialPort_, SIGNAL(readyRead()), SLOT(onDataReceived()));
if ( !serialPort_.setCommTimeouts(QSerialPort::CtScheme_NonBlockingRead) )
qWarning("Cannot set communications timeout values at port %s.", qPrintable(serialPort_.portName()));
}
Host::~Host()
{
}
void Host::onDataReceived()
{
if ( timerId_ )
killTimer(timerId_);
QByteArray data = serialPort_.read(512);
byteCounter_ += data.size();
std::cout << "Thread id: " << QThread::currentThreadId() << " Received data @ " <<
qPrintable(QDateTime::currentDateTime().toString("hh:mm:ss.zzz")) << ". Echo back." << std::endl;
serialPort_.write(data);
if ( byteCounter_ >= 4096 ) {
std::cout << "Event-Driven example is terminated successfully." << std::endl;
qApp->exit(0);
}
// create a wait timer for the next packet
timerId_ = startTimer(5000); // 5sec
}
void Host::timerEvent(QTimerEvent *event)
{
Q_ASSERT(timerId_ == event->timerId());
killTimer(event->timerId());
timerId_ = 0;
std::cout << "Timeout occurred." << std::endl;
}
/*
* Unofficial Qt Serial Port Library
*
* Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* author labs@inbiza.com
*/
#ifndef HOST_H__
#define HOST_H__
#include <QObject>
class QTimerEvent;
namespace TNX { class QSerialPort; }
class Host : public QObject
{
Q_OBJECT
public:
Host(TNX::QSerialPort &serPort, QObject *parent = 0);
~Host();
protected:
virtual void timerEvent(QTimerEvent *event);
private slots:
void onDataReceived();
private:
TNX::QSerialPort &serialPort_;
int timerId_;
int byteCounter_;
};
#endif // HOST_H__
/*
* Unofficial Qt Serial Port Library
*
* Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* author labs@inbiza.com
*/
#include <iostream>
#include <QtCore/QCoreApplication>
#include <QThread>
#include <QString>
#include <QStringList>
#include <QDebug>
#include <QSerialPort>
#include "host.h"
void printHelp()
{
std::cout << "Usage: echo_eventmode [--help] [--port=<serial port>] [--set=<port settings>]" << std::endl;
std::cout << std::endl;
#if defined(Q_OS_WIN)
std::cout << "Example: echo_eventmode --port=COM3 --set=9600,8,N,1" << std::endl;
#else
std::cout << "Example: echo_eventmode --port=/dev/ttyS0 --set=9600,8,N,1" << std::endl;
#endif
}
bool processArgs(const QStringList &args, QString &serPort, QString &settings)
{
QHash<QString, QString> argPairs;
foreach( QString ar, args ) {
if ( ar.split('=').size() == 2 ) {
argPairs.insert(ar.split('=').at(0), ar.split('=').at(1));
}
else {
if ( ar == "--help" )
goto LPrintHelpAndExit;
}
}
settings = argPairs.value("--set", "9600,8,n,1");
#if defined(Q_OS_WIN)
serPort = argPairs.value("--port", "COM3");
#else
serPort = argPairs.value("--port", "/dev/ttyS0");
#endif
return true;
LPrintHelpAndExit:
printHelp();
return false;
}
int main(int argc, char *argv[])
{
using TNX::QSerialPort;
QCoreApplication a(argc, argv);
std::cout << "Serial port echo example with event-driven model, Copyright (c) 2010 Inbiza Systems Inc." << std::endl;
std::cout << "Created by Inbiza Labs <labs@inbiza.com>" << std::endl;
std::cout << std::endl;
std::cout << "Main thread id: " << QThread::currentThreadId() << std::endl;
QString portName;
QString settings;
if ( !processArgs(a.arguments(), portName, settings) )
return 0;
QSerialPort serport(portName, settings);
if ( !serport.open() )
qFatal("Cannot open serial port %s. Exiting..", qPrintable(portName));
Host host(serport);
return a.exec();
}
##
## Unofficial Qt Serial Port Library
##
## Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
##
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU Lesser General Public License as published by the
## Free Software Foundation, either version 3 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 Lesser General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>
##
##
## @file echo_pollingmode.pro
## www.inbiza.com
##
include(../examples.pri)
DEPENDPATH += . $$QSERIALPORT_INCBASE/QtSerialPort
QT += network
!windows:TARGET = $$QSERIALPORT_BINDESTDIR/$$TARGET
# Input
SOURCES += main.cpp
#HEADERS +=
MOC_DIR = $$QSERIALPORT_BUILDDIR/GeneratedFiles/polling
CONFIG(debug, debug|release) {
OBJECTS_DIR = $$QSERIALPORT_BUILDDIR/Debug/polling
macx:TARGET = $$member(TARGET, 0)_debug
windows:TARGET = $$member(TARGET, 0)d
unix:!macx:TARGET = $$member(TARGET, 0).debug
}
else {
OBJECTS_DIR = $$QSERIALPORT_BUILDDIR/Release/polling
}
/*
* Unofficial Qt Serial Port Library
*
* Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* author labs@inbiza.com
*/
#include <iostream>
#include <QtCore/QCoreApplication>
#include <QString>
#include <QStringList>
#include <QDateTime>
#include <QDebug>
#include <QSerialPort>
void printHelp()
{
std::cout << "Usage: echo_pollingmode [--help] [--port=<serial port>] [--set=<port settings>]" << std::endl;
std::cout << std::endl;
#if defined(Q_OS_WIN)
std::cout << "Example: echo_pollingmode --port=COM3 --set=9600,8,N,1" << std::endl;
#else
std::cout << "Example: echo_pollingmode --port=/dev/ttyS0 --set=9600,8,N,1" << std::endl;
#endif
}
bool processArgs(const QStringList &args, QString &serPort, QString &settings)
{
QHash<QString, QString> argPairs;
foreach( QString ar, args ) {
if ( ar.split('=').size() == 2 ) {
argPairs.insert(ar.split('=').at(0), ar.split('=').at(1));
}
else {
if ( ar == "--help" )
goto LPrintHelpAndExit;
}
}
settings = argPairs.value("--set", "9600,8,n,1");
#if defined(Q_OS_WIN)
serPort = argPairs.value("--port", "COM3");
#else
serPort = argPairs.value("--port", "/dev/ttyS0");
#endif
return true;
LPrintHelpAndExit:
printHelp();
return false;
}
int main(int argc, char *argv[])
{
using namespace TNX;
QCoreApplication a(argc, argv);
std::cout << "Serial port echo example with polling model, Copyright (c) 2010 Inbiza Systems Inc." << std::endl;
std::cout << "Created by Inbiza Labs <labs@inbiza.com>" << std::endl;
QString portName;
QString settings;
if ( !processArgs(a.arguments(), portName, settings) )
return 0;
QSerialPort serport(portName, settings);
if ( !serport.open() )
qFatal("Cannot open serial port %s. Exiting..", qPrintable(portName));
if ( !serport.setCommTimeouts(QSerialPort::CtScheme_NonBlockingRead) )
qWarning("Cannot set communications timeout values at port %s.", qPrintable(portName));
int byteCounter = 0;
forever {
if ( serport.waitForReadyRead(5000) ) { // 5sec
QByteArray data = serport.read(512);
byteCounter += data.size();
std::cout << "Received data @ " << qPrintable(QDateTime::currentDateTime().toString("hh:mm:ss.zzz")) <<
". Echo back." << std::endl;
serport.write(data);
if ( byteCounter >= 4096 )
break;
}
else {
std::cout << "Timeout while waiting for incoming data @ " <<
qPrintable(QDateTime::currentDateTime().toString("hh:mm:ss.zzz")) << std::endl;
}
}
std::cout << "Polling example is terminated successfully." << std::endl;
return 0;
}
##
## Unofficial Qt Serial Port Library
##
## Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
##
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU Lesser General Public License as published by the
## Free Software Foundation, either version 3 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 Lesser General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>
##
##
## @file examples.pri
## www.inbiza.com
##
include(../app.pri)
# default to console (individual programs can always override this if needed)
CONFIG += console
CONFIG -= app_bundle
QT -= gui
##
## Unofficial Qt Serial Port Library
##
## Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
##
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU Lesser General Public License as published by the
## Free Software Foundation, either version 3 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 Lesser General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>
##
##
## @file examples.pro
## www.inbiza.com
##
TEMPLATE = subdirs
SUBDIRS += \
tranceiver \
serial2tcpbridge \
echo_eventmode \
echo_pollingmode
/*
* Unofficial Qt Serial Port Library
*
* Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* author labs@inbiza.com
*/
#include <iostream>
#include <QTcpSocket>
#include <QTcpServer>
#include <QSerialPort>
#include "host.h"
Host::Host(const QString &serPort, int tcpPort, QObject *parent)
: QObject(parent), tcpPort_(tcpPort), tcpSocket_(NULL)
{
using TNX::QSerialPort;
serialPort_ = new QSerialPort(serPort, "9600,8,N,1", this);
tcpServer_ = new QTcpServer(this);
}
Host::~Host()
{
stop();
}
int Host::start()
{
// deal with serial port
if ( serialPort_->open() ) {
serialPort_->flushInBuffer();
serialPort_->flushOutBuffer();
}
else {
qFatal("Cannot open serial port: \"%s\". Giving up.", qPrintable(serialPort_->errorString()));
return -1;
}
connect(serialPort_, SIGNAL(readyRead()), SLOT(onDataReceivedSerial()));
// deal with tcp port
std::cout << "Waiting for connection on tcp port " << tcpPort_ << std::endl;
if ( tcpServer_->listen(QHostAddress::Any, tcpPort_) ) {
std::cout << "Listening on " << qPrintable(tcpServer_->serverAddress().toString()) << ":" << tcpServer_->serverPort() << std::endl;
connect(tcpServer_, SIGNAL(newConnection()), SLOT(onNewTcpConnection()));
}
else {
qFatal("Cannot listening tcp port: \"%s\". Giving up.", qPrintable(tcpServer_->errorString()));
return -1;
}
return 0;
}
int Host::stop()
{
serialPort_->close();
disconnect(serialPort_, SIGNAL(readyRead()), this, SLOT(onDataReceivedSerial()));
tcpServer_->close();
disconnect(tcpServer_, SIGNAL(newConnection()), this, SLOT(onNewTcpConnection()));
return 0;
}
void Host::onDataReceivedNetwork()
{
serialPort_->write(tcpSocket_->read(2048));
}
void Host::onDataReceivedSerial()
{
if ( tcpSocket_->state() == QAbstractSocket::ConnectedState ) {
tcpSocket_->write(serialPort_->read(2048));
}
}
void Host::onNewTcpConnection()
{
tcpSocket_ = tcpServer_->nextPendingConnection();
connect(tcpSocket_, SIGNAL(readyRead()), SLOT(onDataReceivedNetwork()));
std::cout << "Connection is established with " << qPrintable(tcpSocket_->peerAddress().toString()) << std::endl;
}
/*
* Unofficial Qt Serial Port Library
*
* Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* author labs@inbiza.com
*/
#ifndef HOST_H__
#define HOST_H__
#include <QObject>
class QTcpServer;
class QTcpSocket;
namespace TNX { class QSerialPort; }
class Host : public QObject
{
Q_OBJECT
public:
Host(const QString &serPort, int tcpPort, QObject *parent = 0);
~Host();
int start();
int stop();
private slots:
void onDataReceivedNetwork();
void onDataReceivedSerial();
void onNewTcpConnection();
private:
int tcpPort_;
TNX::QSerialPort *serialPort_;
QTcpServer *tcpServer_;
QTcpSocket *tcpSocket_;
};
#endif // HOST_H__
/*
* Unofficial Qt Serial Port Library
*
* Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* author labs@inbiza.com
*/
#include <QtCore/QCoreApplication>
#include <QStringList>
#include <QHash>
#include <QHostAddress>
#include <QDebug>
#include <iostream>
#include "host.h"
#include "proxy.h"
void printHelp()
{
std::cout << "Usage: ser2tcpbridge [--help] [--role= host|proxy] [--tcpport=<port>] " \
"[--serport=<serial port>] [--remotehost=<ip:port>]" << std::endl;
std::cout << std::endl;
std::cout << "Example: ser2tcpbridge --role=host --serport=/dev/ttySAC0 --tcpport=8765" << std::endl;
std::cout << "Example: ser2tcpbridge --role=proxy --remotehost=192.168.0.23:8765" << std::endl;
}
bool processArgs(const QStringList &args, QString &role, QString &serPort, QString &tcpPort,
QString &remoteHost)
{
QHash<QString, QString> argPairs;
if ( args.size() < 2 )
goto LPrintHelpAndExit;
foreach( QString ar, args ) {
if ( ar.split('=').size() == 2 )
argPairs.insert(ar.split('=').at(0), ar.split('=').at(1));
else {
if ( ar == "--help" )
goto LPrintHelpAndExit;
}
}
role = argPairs.value("--role", "host");
if ( role == "host" ) {
#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
serPort = argPairs.value("--serport", "com3");
#else
serPort = argPairs.value("--serport", "/dev/ttyS0");
#endif
tcpPort = argPairs.value("--tcpport", "8756");
}
else if ( role == "proxy" ) {
remoteHost = argPairs.value("--remotehost", "localhost");
tcpPort = argPairs.value("--tcpport", "8756");
}
else {
// invalid role
std::cout << "Invalid role specified." << std::endl;
goto LPrintHelpAndExit;
}
return true;
LPrintHelpAndExit:
printHelp();
return false;
}
int main(int argc, char *argv[])
{
QString role;
QString serPort;
QString tcpPort;
QString remoteHost;
QCoreApplication a(argc, argv);
std::cout << "Serial port to TCP Bridge example, Copyright (c) 2010 Inbiza Systems Inc." << std::endl;
std::cout << "Created by Inbiza Labs <labs@inbiza.com>" << std::endl;
if ( !processArgs(a.arguments(), role, serPort, tcpPort, remoteHost) )
return 0;
Host *host;
Proxy *proxy;
if ( role == "host" ) {
qDebug() << "role:" << role << "serport:" << serPort << "tcpport:" << tcpPort;
host = new Host(serPort, tcpPort.toInt(), &a);
host->start();
}
else {
qDebug() << "role:" << role << "remotehost:" << remoteHost << "tcpport:" << tcpPort;
QHostAddress addr = (remoteHost == "localhost" ? QHostAddress::LocalHost : QHostAddress(remoteHost));
proxy = new Proxy(addr, tcpPort.toInt(), &a);
proxy->start();
}
return a.exec();
}
This diff is collapsed.
/*
* Unofficial Qt Serial Port Library
*
* Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* author labs@inbiza.com
*/
#include <QTcpSocket>
#include <QHostAddress>
#include <QDebug>
#include <QTime>
#include "proxy.h"
Proxy::Proxy(const QHostAddress &remoteHost, int tcpPort, QObject *parent)
: QObject(parent), remoteHost_(remoteHost), tcpPort_(tcpPort), timer_(NULL)
{
socket_ = new QTcpSocket(this);
}
Proxy::~Proxy()
{
stop();
}
int Proxy::start()
{
connect(socket_, SIGNAL(connected()), SLOT(onConnected()));
connect(socket_, SIGNAL(disconnected()), SLOT(onDisconnected()));
connect(socket_, SIGNAL(readyRead()), SLOT(onDataReceivedNetwork()));
qDebug() << "Connecting to " << remoteHost_.toString() << ":" << tcpPort_;
socket_->connectToHost(remoteHost_, tcpPort_);
return 0;
}
int Proxy::stop()
{
disconnect(socket_, SIGNAL(connected()), this, SLOT(onConnected()));
disconnect(socket_, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
disconnect(socket_, SIGNAL(readyRead()), this, SLOT(onDataReceivedNetwork()));
return 0;
}
void Proxy::onDataReceivedNetwork()
{
QByteArray data = socket_->read(2048);
qDebug() << data.size() << " bytes received. Echo back.";
socket_->write(data);
}
void Proxy::onConnected()
{
qDebug() << "Socket is connected.";
}
void Proxy::onDisconnected()
{
qDebug() << "Socket is disconnected.";
}
/*
* Unofficial Qt Serial Port Library
*
* Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* author labs@inbiza.com
*/
#ifndef PROXY_H__
#define PROXY_H__
#include <QObject>
class QTcpSocket;
class QHostAddress;
class QTime;
class Proxy : public QObject
{
Q_OBJECT
public:
Proxy(const QHostAddress &remoteHost, int tcpPort, QObject *parent = 0);
~Proxy();
int start();
int stop();
private slots:
void onDataReceivedNetwork();
void onConnected();
void onDisconnected();
private:
QTcpSocket *socket_;
const QHostAddress &remoteHost_;
int tcpPort_;
QTime *timer_;
};
#endif // PROXY_H__
##
## Unofficial Qt Serial Port Library
##
## Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
##
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU Lesser General Public License as published by the
## Free Software Foundation, either version 3 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 Lesser General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>
##
##
## @file serial2udpbridge.pro
## www.inbiza.com
##
include(../examples.pri)
DEPENDPATH += . $$QSERIALPORT_INCBASE/QtSerialPort
QT += network
!windows:TARGET = $$QSERIALPORT_BINDESTDIR/$$TARGET
# Input
SOURCES += main.cpp \
host.cpp \
proxy.cpp
HEADERS += host.h \
proxy.h
MOC_DIR = $$QSERIALPORT_BUILDDIR/GeneratedFiles/serial2tcpbridge
CONFIG(debug, debug|release) {
OBJECTS_DIR = $$QSERIALPORT_BUILDDIR/Debug/serial2tcpbridge
macx:TARGET = $$member(TARGET, 0)_debug
windows:TARGET = $$member(TARGET, 0)d
unix:!macx:TARGET = $$member(TARGET, 0).debug
}
else {
OBJECTS_DIR = $$QSERIALPORT_BUILDDIR/Release/serial2tcpbridge
}
/*
* Unofficial Qt Serial Port Library
*
* Copyright (c) 2010 Inbiza Systems Inc. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 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 Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* author labs@inbiza.com
*/
#include <QtCore/QCoreApplication>
#include <QStringList>
#include <QDebug>
#include <QThread>
#include <QSerialPort>
#include <iostream>
#include "receiver.h"
#include "transmitter.h"
#include <QDateTime>
void printHelp()
{
std::cout << "Usage: tranceiver [--help] [--role= transmit|receive] [--serport=<serial port>] " \
"[--listen=<port>] [--remotehost=<ip:port>] [--buffersize=<number of bytes>|*]" << std::endl;
std::cout << "==========" << std::endl;
std::cout << "Example: tranceiver --role=transmit --serport=/dev/ttySAC0 --listen=8765 --remotehost=193.168.0.102:8765" << std::endl;
std::cout << "Example: tranceiver --role=receive --serport=/dev/ttyUSB0 --listen=8765 --remotehost=192.168.0.23:8765 --buffersize=*" << std::endl;
std::cout << "==========" << std::endl;
}
bool processArgs(const QStringList &args, QString &role, QString &serPort, QString &udpPort,
QString &remoteHost, QString &bufferSize)
{
QHash<QString, QString> argPairs;
if ( args.size() < 2 )
goto LPrintHelpAndExit;
foreach( QString ar, args ) {
if ( ar.split('=').size() == 2 )
argPairs.insert(ar.split('=').at(0), ar.split('=').at(1));
else {
if ( ar == "--help" )
goto LPrintHelpAndExit;
}
}
#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
serPort = argPairs.value("--serport", "com3");
#else
serPort = argPairs.value("--serport", "/dev/ttyS0");
#endif
role = argPairs.value("--role", "transmit");
if ( role == "transmit" ) {
remoteHost = argPairs.value("--remotehost", "localhost:8756");
udpPort = argPairs.value("--listen", "9766");
}
else if ( role == "receive" ) {
remoteHost = argPairs.value("--remotehost", "localhost:9766");
udpPort = argPairs.value("--listen", "8756");
bufferSize = argPairs.value("--buffersize", "*");
}
else {
// invalid role
std::cout << "Invalid role specified." << std::endl;
goto LPrintHelpAndExit;
}
return true;
LPrintHelpAndExit:
printHelp();
return false;
}
int main(int argc, char **argv)
{
QString role;
QString serPort;
QString udpPort;
QString remoteHost;
QString bufferSize;
QCoreApplication a(argc, argv);
std::cout << "Serial port transmitter/receiver example, Copyright (c) 2010 Inbiza Systems Inc." << std::endl;
std::cout << "Created by Inbiza Labs <labs@inbiza.com>" << std::endl;
std::cout << "==========" << std::endl;
std::cout << "Connect two networked computers with null-modem cable, run tranceiver with \"--role=transmit\" on one, and with \"--role=receive\" on ther other." << std::endl;
std::cout << "==========" << std::endl;
std::cout << std::endl;
if ( !processArgs(a.arguments(), role, serPort, udpPort, remoteHost, bufferSize) )
return 0;
qDebug() << "Mode:" << role << ", Serial Port:" << serPort << ", Port Settings:" << "9600,8,n,1" <<
", Listening at port: " << udpPort << ", Testing peer at: " << remoteHost << ", Buffer size: " << (bufferSize == "*" ? "equal to data set size" : bufferSize);
TNX::QSerialPort serialPort(serPort, "9600,8,n,1");
TNX::CommTimeouts commTimeouts;
commTimeouts.PosixVMIN = 1;
commTimeouts.PosixVTIME = 0;
commTimeouts.Win32ReadIntervalTimeout = 75;
commTimeouts.Win32ReadTotalTimeoutConstant = 250;
commTimeouts.Win32ReadTotalTimeoutMultiplier = 25;
commTimeouts.Win32WriteTotalTimeoutConstant = 250;
commTimeouts.Win32WriteTotalTimeoutMultiplier = 75;
if ( !serialPort.setCommTimeouts(commTimeouts) )
qWarning("Cannot set communications timeout values at port %s.", qPrintable(serPort));
Receiver *receiver = NULL;
Transmitter *transmitter = NULL;
if ( 0 == role.compare("transmit", Qt::CaseInsensitive) ) {
transmitter = new Transmitter(serialPort, remoteHost, udpPort.toInt(), &a);
if ( !transmitter->start() ) {
std::cout << "Cannot start transmitter. Quitting." << std::endl;
return 0;
}
}
else if ( 0 == role.compare("receive", Qt::CaseInsensitive) ) {
receiver = new Receiver(serialPort, remoteHost, udpPort.toInt(), QString((bufferSize == "*" ? "0" : bufferSize)).toInt(), &a);
if ( !receiver->start() ) {
std::cout << "Cannot start receiver. Quitting." << std::endl;
return 0;
}
}
else {
std::cout << "Wrong role defined. Quitting." << std::endl;
return 0;
}
return a.exec();
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include "qportsettings.h"
#include "qserialportnative.h"
#include "qserialport.h"
This diff is collapsed.
This diff is collapsed.
@echo off
REM install qmake feature file pointing to the current directory
if not defined QTDIR goto err
echo QSERIALPORT_INCDIR = "%CD%\include" > qserialport.prf
echo QSERIALPORT_LIBDIR = "%CD%\lib" >> qserialport.prf
type qserialport.prf.in >> qserialport.prf
copy qserialport.prf "%QTDIR%\mkspecs\features"
echo Installed qserialport.prf as a qmake feature.
goto end
:err
echo Error: QTDIR not set (example: set QTDIR=C:\Qt\4.5.2).
goto end
:end
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#!/bin/sh
export LD_LIBRARY_PATH="../../lib:$LD_LIBRARY_PATH"
cd qserialportunittest && make test && cd ..
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment