author | mickeyl <mickeyl> | 2004-01-03 18:27:07 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-01-03 18:27:07 (UTC) |
commit | 3889c8f853aa2d128f54389b17f08fc7b9150788 (patch) (side-by-side diff) | |
tree | 692bf0541e19d19f9ac93059463e4c4eb2e43e5f | |
parent | c69a2abd7718d8acddb4ce96a1909b33056e2dcd (diff) | |
download | opie-3889c8f853aa2d128f54389b17f08fc7b9150788.zip opie-3889c8f853aa2d128f54389b17f08fc7b9150788.tar.gz opie-3889c8f853aa2d128f54389b17f08fc7b9150788.tar.bz2 |
show GPS coordinates in the more common DMS format
-rw-r--r-- | noncore/net/wellenreiter/gui/gps.cpp | 66 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/gps.h | 13 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/mainwindow.cpp | 8 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/scanlist.cpp | 9 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/scanlist.h | 2 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/wellenreiter.cpp | 2 |
6 files changed, 82 insertions, 18 deletions
diff --git a/noncore/net/wellenreiter/gui/gps.cpp b/noncore/net/wellenreiter/gui/gps.cpp index 288afee..31f95ce 100644 --- a/noncore/net/wellenreiter/gui/gps.cpp +++ b/noncore/net/wellenreiter/gui/gps.cpp @@ -1,69 +1,131 @@ /********************************************************************** ** 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" -#include <unistd.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]; 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.111; stream >> lat; stream.skipWhiteSpace(); float lon = -111.111; stream >> lon; stream.readRawBytes( &buf[0], 200 ); // read and discard the stuff until EOF return GpsLocation( lat, lon ); } } - return GpsLocation( -1.0, -1.0 ); + return GpsLocation( -111.111, -111.111 ); } + +QString GpsLocation::dmsPosition() const +{ + if ( _latitude == -111.111 || _longitude == -111.11 ) + 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/gps.h b/noncore/net/wellenreiter/gui/gps.h index 8143fe4..cfe1cdb 100644 --- a/noncore/net/wellenreiter/gui/gps.h +++ b/noncore/net/wellenreiter/gui/gps.h @@ -1,46 +1,51 @@ /********************************************************************** ** 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. ** **********************************************************************/ #ifndef GPS_H #define GPS_H #include <qobject.h> #include <qsocket.h> -struct GpsLocation +class GpsLocation { - GpsLocation( const float& lat, const float& lon ) : latitude(lat), longitude(lon) {}; + public: + GpsLocation( const float& lat, const float& lon ) : _latitude(lat), _longitude(lon) {}; ~GpsLocation() {}; - float latitude; - float longitude; + float latitude() const { return _latitude; }; + float longitude() const { return _longitude; }; + QString dmsPosition() const; + private: + float _latitude; + float _longitude; }; class GPS : public QObject { Q_OBJECT public: GPS( QObject* parent = 0, const char * name = "GPS" ); ~GPS(); bool open( const QString& host = "localhost", int port = 2947 ); GpsLocation position() const; private: QSocket* _socket; }; #endif // GPS_H diff --git a/noncore/net/wellenreiter/gui/mainwindow.cpp b/noncore/net/wellenreiter/gui/mainwindow.cpp index ca9851c..d4e3279 100644 --- a/noncore/net/wellenreiter/gui/mainwindow.cpp +++ b/noncore/net/wellenreiter/gui/mainwindow.cpp @@ -203,53 +203,53 @@ 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->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:00:20:EF:A6:43"), true, 6, 80, GpsLocation( 10.10, 20.20 ) ); + 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:A0:F8:E7:16:22"), false, 3, 10, GpsLocation( 5.5, 2.3 ) ); - mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:AA:01:E7:56:62"), false, 3, 15, GpsLocation( 2.3, 5.5 ) ); - mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:B0:8E:E7:56:E2"), false, 3, 20, GpsLocation( -10.0, -20.5 ) ); + 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 ) ); } 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 ""; } diff --git a/noncore/net/wellenreiter/gui/scanlist.cpp b/noncore/net/wellenreiter/gui/scanlist.cpp index 1cca507..d89c71f 100644 --- a/noncore/net/wellenreiter/gui/scanlist.cpp +++ b/noncore/net/wellenreiter/gui/scanlist.cpp @@ -168,49 +168,49 @@ void MScanListView::addNewItem( const QString& type, #ifdef DEBUG qDebug( "%s is a dupe - ignoring...", (const char*) macaddr ); #endif item->receivedBeacon(); return; } } else { s.sprintf( "(i) New network: ESSID '%s'", (const char*) essid ); MLogWindow::logwindow()->log( s ); network = new MScanListItem( this, "network", essid, QString::null, 0, 0, 0 ); } // insert new station as child from network // no essid to reduce clutter, maybe later we have a nick or stationname to display!? #ifdef DEBUG qDebug( "inserting new station %s", (const char*) macaddr ); #endif MScanListItem* station = new MScanListItem( network, type, "", macaddr, wep, channel, signal ); station->setManufacturer( mac.manufacturer() ); - station->setLocation( loc.latitude, loc.longitude ); + station->setLocation( loc.dmsPosition() ); if ( type == "managed" ) { s.sprintf( "(i) New Access Point in '%s' [%d]", (const char*) essid, channel ); } else { s.sprintf( "(i) New AdHoc station in '%s' [%d]", (const char*) essid, channel ); } MLogWindow::logwindow()->log( s ); } void MScanListView::addIfNotExisting( MScanListItem* network, const OMacAddress& addr, const QString& type ) { MScanListItem* subitem = static_cast<MScanListItem*>( network->firstChild() ); while ( subitem && ( subitem->text( col_ap ) != addr.toString(true) ) ) { #ifdef DEBUG qDebug( "subitemtext: %s", (const char*) subitem->text( col_ap ) ); #endif subitem = static_cast<MScanListItem*> ( subitem->nextSibling() ); @@ -512,54 +512,51 @@ void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, listView()->triggerUpdate(); this->type = type; _type = type; _essid = essid; _macaddr = macaddr; _channel = channel; _beacons = 1; _signal = 0; if ( WellenreiterConfigWindow::instance()->openTree->isChecked() ) { listView()->ensureItemVisible( this ); } } void MScanListItem::setManufacturer( const QString& manufacturer ) { setText( col_manuf, manufacturer ); } -void MScanListItem::setLocation( const float& latitude, const float& longitude ) +void MScanListItem::setLocation( const QString& location ) { - if ( latitude == 0.0 || longitude == 0.0 ) - setText( col_location, "N/A" ); - else - setText( col_location, QString().sprintf( "%.2f / %.2f", latitude, longitude ) ); + setText( col_location, location ); } void MScanListItem::playSound( const QString& sound ) const { #ifdef QWS if ( sound == "Ignore" ) return; else if ( sound == "Touch" ) ODevice::inst()->touchSound(); else if ( sound == "Key" ) ODevice::inst()->keySound(); else if ( sound == "Alarm" ) ODevice::inst()->alarmSound(); #endif } void MScanListItem::receivedBeacon() { _beacons++; #ifdef DEBUG qDebug( "MScanListItem %s: received beacon #%d", (const char*) _macaddr, _beacons ); #endif setText( col_sig, QString::number( _beacons ) ); setText( col_lastseen, QTime::currentTime().toString() ); MScanListItem* p = (MScanListItem*) parent(); diff --git a/noncore/net/wellenreiter/gui/scanlist.h b/noncore/net/wellenreiter/gui/scanlist.h index a9b74f1..6cd8fc0 100644 --- a/noncore/net/wellenreiter/gui/scanlist.h +++ b/noncore/net/wellenreiter/gui/scanlist.h @@ -82,49 +82,49 @@ class MScanListItem: public OListViewItem bool wep = false, int channel = 0, int signal = 0 ); protected: virtual void decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ); public: QString type; public: //const QString& type() { return _type; }; const QString& essid() const; const QString& macaddr() { return _macaddr; }; bool wep() { return _wep; }; int channel() { return _channel; }; int signal() { return _signal; }; int beacons() { return _beacons; }; void setSignal( int signal ) { /* TODO */ }; void receivedBeacon(); void setManufacturer( const QString& manufacturer ); - void setLocation( const float& latitude, const float& longitude ); + void setLocation( const QString& location ); virtual OListViewItem* childFactory(); virtual void serializeTo( QDataStream& s ) const; virtual void serializeFrom( QDataStream& s ); protected: void playSound( const QString& ) const; private: QString _type; QString _essid; QString _macaddr; bool _wep; int _channel; int _signal; int _beacons; }; //****************************** MScanListViewFactory **************************************************************** /* class MScanListViewFactory : public OListViewFactory diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp index 9255a6d..5575d6e 100644 --- a/noncore/net/wellenreiter/gui/wellenreiter.cpp +++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp @@ -168,49 +168,49 @@ void Wellenreiter::handleBeacon( OPacket* p, OWaveLanManagementPacket* beacon ) } else if ( beacon->canESS() ) { type = "managed"; } else { qWarning( "Wellenreiter::invalid frame [possibly noise] detected!" ); return; } OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); QString essid = ssid ? ssid->ID() : QString("<unknown>"); OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); int channel = ds ? ds->channel() : -1; OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); GpsLocation loc( 0, 0 ); if ( configwindow->enableGPS->isChecked() ) { // TODO: add check if GPS is working!? qDebug( "Wellenreiter::gathering GPS data..." ); loc = gps->position(); - qDebug( "Wellenreiter::GPS data received is ( %f , %f )", loc.latitude, loc.longitude ); + qDebug( "Wellenreiter::GPS data received is ( %f , %f ) - dms string = '%s'", loc.latitude(), loc.longitude(), loc.dmsPosition().latin1() ); } netView()->addNewItem( type, essid, header->macAddress2(), beacon->canPrivacy(), channel, 0, loc ); // update graph window if ( ds ) { OPrismHeaderPacket* prism = static_cast<OPrismHeaderPacket*>( p->child( "Prism" ) ); if ( prism ) graphwindow->traffic( ds->channel(), prism->signalStrength() ); else graphwindow->traffic( ds->channel(), 95 ); } } void Wellenreiter::handleWlanData( OPacket* p, OWaveLanDataPacket* data, OMacAddress& from, OMacAddress& to ) { OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" ); if ( wlan->fromDS() && !wlan->toDS() ) { netView()->fromDStraffic( wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() ); from = wlan->macAddress3(); to = wlan->macAddress2(); |