-rw-r--r-- | noncore/net/wellenreiter/TODO | 2 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/gps.cpp | 28 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/mainwindow.cpp | 15 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/mainwindow.h | 1 |
4 files changed, 29 insertions, 17 deletions
diff --git a/noncore/net/wellenreiter/TODO b/noncore/net/wellenreiter/TODO index fd70fc7..b6ec617 100644 --- a/noncore/net/wellenreiter/TODO +++ b/noncore/net/wellenreiter/TODO @@ -1,58 +1,60 @@ /************************************************************************ /* W e l l e n r e i t e r I I /* =============================== /* /* Version: 1.0.2 /************************************************************************ ---------------------------------------------------- Ideas as of Wellenreiter II / December 2003 ---------------------------------------------------- -------- ENGINE -------- - enable multiple packet sources - infrared - bluetooth - usb? - define packet structure in a metalanguage and generate the actual parsing code (hmmm) - pester the ethereal folks to settle for an application independant packet dissection framework... (unlikely) - adaptive hopping scheme ! - gather interface capabilities - enable sniffing in wired networks +- fix autodetection (interface name) + --------- UI --------- - display interface capabilities (or rewrite networksettings?) - distinguish wireless bridges (WDS traffic) - expand/collapse all - add configuration for scrollback buffer in hex window and log window - revamp hex window, make it more sophisticated than just a QMultiLineEdit - tree view - beep over headphone / customizable --------- FILES --------- - write kismet-like .network format and format to be importable into AutoRoute - implement beacon stripping (the first beacon is enough to detect a new network - further beacons just blow up the capture file) diff --git a/noncore/net/wellenreiter/gui/gps.cpp b/noncore/net/wellenreiter/gui/gps.cpp index b814427..5b1b4a4 100644 --- a/noncore/net/wellenreiter/gui/gps.cpp +++ b/noncore/net/wellenreiter/gui/gps.cpp @@ -1,131 +1,127 @@ /********************************************************************** ** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. ** ** This file is part of Opie Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #include "gps.h" /* QT */ #include <qtextstream.h> /* STD */ #include <stdlib.h> #include <unistd.h> GPS::GPS( QObject* parent, const char * name ) :QObject( parent, name ) { qDebug( "GPS::GPS()" ); _socket = new QSocket( this, "gpsd commsock" ); } GPS::~GPS() { qDebug( "GPS::~GPS()" ); } bool GPS::open( const QString& host, int port ) { _socket->connectToHost( host, port ); } GpsLocation GPS::position() const { char buf[256]; + double lat = -111.0; + double lon = -111.0; int result = _socket->writeBlock( "p\r\n", 3 ); _socket->flush(); if ( result ) { int numAvail = _socket->bytesAvailable(); qDebug( "GPS write succeeded, %d bytes available for reading...", numAvail ); if ( numAvail ) { - QTextStream stream( _socket ); - - QString str; - stream.readRawBytes( &buf[0], 7 ); - float lat = -111; - stream >> lat; - stream.skipWhiteSpace(); - float lon = -111; - stream >> lon; - stream.readRawBytes( &buf[0], 200 ); // read and discard the stuff until EOF + int numRead = _socket->readBlock( &buf[0], sizeof buf ); + int numScan = sscanf( &buf[0], "GPSD,P=%lg %lg", &lat, &lon); + if ( numRead < 7 || numScan != 2 ) + { + qDebug( "GPS read %d bytes succeeded, invalid response: '%s'", numRead, &buf[0] ); + return GpsLocation( -111, -111 ); + } + else + { return GpsLocation( lat, lon ); } } + } return GpsLocation( -111, -111 ); } QString GpsLocation::dmsPosition() const { if ( _latitude == -111 || _longitude == -111 ) return "N/A"; if ( _latitude == 0.0 && _longitude == 0.0 ) return "NULL"; /* compute latitude */ QString dms = "N"; if ( _latitude >= 0 ) dms.append( "+" ); int trunc = int( _latitude ); float rest = _latitude - trunc; float minf = rest * 60; int minutes = int( minf ); rest = minf - minutes; int seconds = int( rest * 60 ); dms.append( QString::number( trunc ) ); dms.append( "° " ); dms.append( QString::number( ::abs( minutes ) ) ); dms.append( "' " ); dms.append( QString::number( ::abs( seconds ) ) ); dms.append( "'' " ); /* compute longitude */ dms.append( " | W" ); if ( _longitude > 0 ) dms.append( "+" ); trunc = int( _longitude ); rest = _longitude - trunc; minf = rest * 60; minutes = int( minf ); rest = minf - minutes; seconds = int( rest * 60 ); dms.append( QString::number( trunc ) ); dms.append( "° " ); dms.append( QString::number( ::abs( minutes ) ) ); dms.append( "' " ); dms.append( QString::number( ::abs( seconds ) ) ); dms.append( "'' " ); return dms; } - - - - - - diff --git a/noncore/net/wellenreiter/gui/mainwindow.cpp b/noncore/net/wellenreiter/gui/mainwindow.cpp index 05a8913..b462afd 100644 --- a/noncore/net/wellenreiter/gui/mainwindow.cpp +++ b/noncore/net/wellenreiter/gui/mainwindow.cpp @@ -1,84 +1,85 @@ /********************************************************************** ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. ** ** This file is part of Opie Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #include "configwindow.h" #include "gps.h" #include "logwindow.h" #include "hexwindow.h" #include "mainwindow.h" #include "wellenreiter.h" #include "scanlist.h" #include <qcombobox.h> #include <qdatastream.h> #include <qfile.h> #include <qfileinfo.h> #include <qlabel.h> #include <qlayout.h> #include <qlineedit.h> #include <qiconset.h> #include <qmenubar.h> #include <qmessagebox.h> #include <qpopupmenu.h> #include <qpushbutton.h> #include <qstatusbar.h> +#include <qspinbox.h> #include <qtextstream.h> #include <qtoolbutton.h> #ifdef QWS #include <qpe/resource.h> #include <opie2/ofiledialog.h> using namespace Opie; #else #include "resource.h" #include <qapplication.h> #include <qfiledialog.h> #endif WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f ) :QMainWindow( parent, name, f ) { cw = new WellenreiterConfigWindow( this ); mw = new Wellenreiter( this ); mw->setConfigWindow( cw ); setCentralWidget( mw ); // setup application icon #ifndef QWS setIcon( Resource::loadPixmap( "wellenreiter/appicon-trans" ) ); setIconText( "Wellenreiter/X11" ); #endif // setup tool buttons startButton = new QToolButton( 0 ); #ifdef QWS startButton->setAutoRaise( true ); #endif startButton->setIconSet( Resource::loadIconSet( "wellenreiter/SearchIcon" ) ); startButton->setEnabled( false ); connect( startButton, SIGNAL( clicked() ), mw, SLOT( startClicked() ) ); stopButton = new QToolButton( 0 ); #ifdef QWS stopButton->setAutoRaise( true ); #endif stopButton->setIconSet( Resource::loadIconSet( "wellenreiter/CancelIcon" ) ); stopButton->setEnabled( false ); connect( stopButton, SIGNAL( clicked() ), mw, SLOT( stopClicked() ) ); QToolButton* d = new QToolButton( 0 ); #ifdef QWS @@ -88,196 +89,208 @@ WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * n connect( d, SIGNAL( clicked() ), this, SLOT( showConfigure() ) ); uploadButton = new QToolButton( 0 ); #ifdef QWS uploadButton->setAutoRaise( true ); #endif uploadButton->setIconSet( Resource::loadIconSet( "up" ) ); uploadButton->setEnabled( false ); //uploadButton->setEnabled( true ); // DEBUGGING connect( uploadButton, SIGNAL( clicked() ), this, SLOT( uploadSession() ) ); // setup menu bar int id; QMenuBar* mb = menuBar(); QPopupMenu* fileSave = new QPopupMenu( mb ); fileSave->insertItem( tr( "&Session..." ), this, SLOT( fileSaveSession() ) ); fileSave->insertItem( tr( "&Text Log..." ), this, SLOT( fileSaveLog() ) ); fileSave->insertItem( tr( "&Hex Log..." ), this, SLOT( fileSaveHex() ) ); QPopupMenu* fileLoad = new QPopupMenu( mb ); fileLoad->insertItem( tr( "&Session..." ), this, SLOT( fileLoadSession() ) ); //fileLoad->insertItem( "&Log", this, SLOT( fileLoadLog() ) ); QPopupMenu* file = new QPopupMenu( mb ); file->insertItem( tr( "&New" ), this, SLOT( fileNew() ) ); id = file->insertItem( tr( "&Load" ), fileLoad ); file->insertItem( tr( "&Save" ), fileSave ); file->insertSeparator(); uploadID = file->insertItem( tr( "&Upload Session" ), this, SLOT( uploadSession() ) ); file->insertSeparator(); file->insertItem( tr( "&Exit" ), qApp, SLOT( quit() ) ); QPopupMenu* view = new QPopupMenu( mb ); view->insertItem( tr( "&Configure..." ) ); QPopupMenu* sniffer = new QPopupMenu( mb ); sniffer->insertItem( tr( "&Configure..." ), this, SLOT( showConfigure() ) ); sniffer->insertSeparator(); startID = sniffer->insertItem( tr( "&Start" ), mw, SLOT( startClicked() ) ); sniffer->setItemEnabled( startID, false ); stopID = sniffer->insertItem( tr( "Sto&p" ), mw, SLOT( stopClicked() ) ); sniffer->setItemEnabled( stopID, false ); QPopupMenu* demo = new QPopupMenu( mb ); demo->insertItem( tr( "&Add something" ), this, SLOT( demoAddStations() ) ); + demo->insertItem( tr( "&Read from GPSd" ), this, SLOT( demoReadFromGps() ) ); id = mb->insertItem( tr( "&File" ), file ); //id = mb->insertItem( tr( "&View" ), view ); //mb->setItemEnabled( id, false ); id = mb->insertItem( tr( "&Sniffer" ), sniffer ); id = mb->insertItem( tr( "&Demo" ), demo ); mb->setItemEnabled( id, true ); mb->setItemEnabled( uploadID, false ); #ifdef QWS mb->insertItem( startButton ); mb->insertItem( stopButton ); mb->insertItem( uploadButton ); mb->insertItem( d ); #else // Qt3 changed the insertion order. It's now totally random :( mb->insertItem( d ); mb->insertItem( uploadButton ); mb->insertItem( stopButton ); mb->insertItem( startButton ); #endif updateToolButtonState(); // setup status bar (for now only on X11) #ifndef QWS statusBar()->message( tr( "Ready." ) ); #endif connect( mw, SIGNAL( startedSniffing() ), this, SLOT( changedSniffingState() ) ); connect( mw, SIGNAL( stoppedSniffing() ), this, SLOT( changedSniffingState() ) ); }; void WellenreiterMainWindow::showConfigure() { qDebug( "show configure..." ); cw->setCaption( tr( "Configure" ) ); #ifdef QWS cw->showMaximized(); #endif int result = cw->exec(); if ( result ) updateToolButtonState(); } void WellenreiterMainWindow::updateToolButtonState() { const QString& interface = cw->interfaceName->currentText(); const int cardtype = cw->driverType(); if ( ( interface != "<select>" ) && ( cardtype != 0 ) ) { startButton->setEnabled( true ); menuBar()->setItemEnabled( startID, true ); } else { startButton->setEnabled( false ); menuBar()->setItemEnabled( startID, false ); } } void WellenreiterMainWindow::changedSniffingState() { startButton->setEnabled( !mw->sniffing ); menuBar()->setItemEnabled( startID, !mw->sniffing ); stopButton->setEnabled( mw->sniffing ); menuBar()->setItemEnabled( stopID, mw->sniffing ); if ( !mw->sniffing ) { menuBar()->setItemEnabled( uploadID, true ); uploadButton->setEnabled( true ); } } WellenreiterMainWindow::~WellenreiterMainWindow() { qDebug( "Wellenreiter:: bye." ); }; void WellenreiterMainWindow::demoAddStations() { - //mw = 0; // test SIGSGV handling + //mw = 0; // test SIGSEGV handling mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:00:20:EF:A6:43"), true, 6, 80, GpsLocation( 39.8794, -94.0936) ); mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:30:6D:EF:A6:23"), true, 11, 10, GpsLocation( 0.0, 0.0 ) ); mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:03:F8:E7:16:22"), false, 3, 10, GpsLocation( 5.5, 2.3 ) ); mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:04:01:E7:56:62"), false, 3, 15, GpsLocation( 2.3, 5.5 ) ); mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:05:8E:E7:56:E2"), false, 3, 20, GpsLocation( -10.0, -20.5 ) ); } +void WellenreiterMainWindow::demoReadFromGps() +{ + WellenreiterConfigWindow* configwindow = WellenreiterConfigWindow::instance(); + GPS* gps = new GPS( this ); + gps->open( configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() ); + GpsLocation loc = gps->position(); + + QMessageBox::information( this, "Wellenreiter/Opie", tr( "GPS said:\n$1" ).arg( loc.dmsPosition() ) ); +} + + QString WellenreiterMainWindow::getFileName( bool save ) { QMap<QString, QStringList> map; map.insert( tr("All"), QStringList() ); QStringList text; text << "text/*"; map.insert( tr("Text"), text ); text << "*"; map.insert( tr("All"), text ); QString str; if ( save ) { #ifdef QWS str = OFileDialog::getSaveFileName( 2, "/", QString::null, map ); #else str = QFileDialog::getSaveFileName(); #endif if ( str.isEmpty() /*|| QFileInfo(str).isDir()*/ ) return ""; } else { #ifdef QWS str = OFileDialog::getOpenFileName( 2, "/", QString::null, map ); #else str = QFileDialog::getOpenFileName(); #endif if ( str.isEmpty() || !QFile(str).exists() || QFileInfo(str).isDir() ) return ""; } return str; } void WellenreiterMainWindow::fileSaveLog() { QString fname = getFileName( true ); if ( !fname.isEmpty() ) { QFile f( fname ); if ( f.open(IO_WriteOnly) ) { QTextStream t( &f ); t << mw->logWindow()->getLog(); f.close(); qDebug( "Saved log to file '%s'", (const char*) fname ); } diff --git a/noncore/net/wellenreiter/gui/mainwindow.h b/noncore/net/wellenreiter/gui/mainwindow.h index 8d4e768..a5cb7a5 100644 --- a/noncore/net/wellenreiter/gui/mainwindow.h +++ b/noncore/net/wellenreiter/gui/mainwindow.h @@ -5,58 +5,59 @@ ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <qmainwindow.h> class Wellenreiter; class WellenreiterConfigWindow; class QIconSet; class QToolButton; class WellenreiterMainWindow: public QMainWindow { Q_OBJECT public: WellenreiterMainWindow( QWidget * parent = 0, const char * name = "mainwindow", WFlags f = 0 ); ~WellenreiterMainWindow(); QString getFileName( bool save ); protected: Wellenreiter* mw; WellenreiterConfigWindow* cw; QToolButton* startButton; QToolButton* stopButton; QToolButton* uploadButton; int startID; int stopID; int uploadID; protected: virtual void closeEvent( QCloseEvent* ); void updateToolButtonState(); public slots: void showConfigure(); void demoAddStations(); + void demoReadFromGps(); void fileSaveLog(); void fileSaveHex(); void fileSaveSession(); void fileLoadSession(); void fileNew(); void uploadSession(); void changedSniffingState(); }; #endif |