📄 sitesurveypage.cpp
字号:
/* SiteSurveyPage.cpp *//******************************************************************************************* Copyright 2002-2003 ATMEL Corporation. This file is part of ATMEL Wireless LAN Drivers. ATMEL Wireless LAN Drivers 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. ATMEL Wireless LAN Drivers 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 ATMEL Wireless LAN Drivers; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*******************************************************************************************/#include "SiteSurveyPage.h"#include "Decls.h"#include "MonitorPage.h"#include "EncryptionPage.h"#include "WinterFrame.h"#include "Accessor.h"#include "WinterTimer.h"#include "WinterData.h"#include "WinterModel.h"#include "HRStrings.h"#include "DevConfig.h"#include "WinterDebug.h"#include <wx/listctrl.h>#include <math.h>// CSurveyListCtrl class implementation//======================================CSurveyListCtrl::CSurveyListCtrl( wxWindow *parent, int id, const wxPoint &pos, const wxSize &size, long style ) : wxListCtrl( parent, id, pos, size, style ){ mInitialState = 0xFF; mInitialSSID = _( "" ); InsertColumn( 0, wxT( "BSSID" ) ); InsertColumn( 1, wxT( "SSID" ) ); InsertColumn( 2, _( "Signal" ) ); InsertColumn( 3, _( "Channel" ) ); InsertColumn( 4, _( "Encryption" ) ); InsertColumn( 5, _( "Type" ) );}CSurveyListCtrl::~CSurveyListCtrl( ){}void CSurveyListCtrl::SetInitialConditions( const wxString &SSID, int stationstate ){ mInitialSSID = SSID; mInitialState = stationstate; return;}void CSurveyListCtrl::Display( CBssInfoData data[ MAX_BSS_ENTRIES ], int count ){ Clear( ); int c, j; CWinterStringsProvider *sp = ( CWinterStringsProvider * ) CAccessor::Access( AID_STRINGSPROVIDER ); wxString bssid; wxString ssid; wxString signal; wxString channel; wxString encryption; wxString type; for( c = 0; c < count; c++ ) { bssid.Clear( ); ssid.Clear( ); signal.Clear( ); channel.Clear( ); encryption.Clear( ); type.Clear( ); for( j = 0; j < 5; j++ ) { bssid.Append( wxString::Format( wxT( "%02X : " ), data[ c ].GetBSSID( )[ j ] ) ); } bssid.Append( wxString::Format( wxT( "%02X" ), data[ c ].GetBSSID( )[ j ] ) ); for( j = 0; j < data[ c ].GetSSIDsize( ); j++ ) { ssid.Append( wxString::Format( wxT( "%c" ), data[ c ].GetSSID( )[ j ] ) ); } signal.Printf( wxT( "%02d %%" ), data[ c ].GetRSSI( ) ); channel.Printf( wxT( "%02d" ), data[ c ].GetChannel( ) ); encryption = sp->YesNoStrings[ data[ c ].GetUsingWep( ) ]; type = _( "Infrastructure" ); if( data[ c ].GetBSStype( ) == 1 ) { type = _( "Ad-Hoc" ); } InsertItem( c, bssid ); SetItem( c, 1, ssid ); SetItem( c, 2, signal ); SetItem( c, 3, channel ); SetItem( c, 4, encryption ); SetItem( c, 5, type ); if( ssid == mInitialSSID ) { wxListItem item; item.SetColumn( 0 ); item.SetId( c ); GetItem( item ); switch( mInitialState ) { case 0x05: // which means that the device is associated. // green item.SetBackgroundColour( wxColour( 0xA0, 0xFF, 0xA0 ) ); break; default: // else // red item.SetBackgroundColour( wxColour( 0xFF, 0xA0, 0xA0 ) ); break; } SetItem( item ); } } return;}void CSurveyListCtrl::Clear( ){ DeleteAllItems( ); return;}// CSiteSurveyPageTimer class imlementation//==========================================CSiteSurveyPageTimer::CSiteSurveyPageTimer( CSiteSurveyPage *owner ) : CWinterPageTimer( ( CWinterPage * ) owner ){}CSiteSurveyPageTimer::~CSiteSurveyPageTimer( ){}void CSiteSurveyPageTimer::Notify( ){ ( ( CSiteSurveyPage * ) mAssociatedPage )->OnTimerTick( ); return;}// CSiteSurveyPage class implementation//======================================BEGIN_EVENT_TABLE( CSiteSurveyPage, wxPanel ) EVT_SIZE( CSiteSurveyPage::OnSize ) EVT_IDLE( CSiteSurveyPage::OnIdle ) EVT_BUTTON( ID_BT_SURVEYPAGE_SCAN, CSiteSurveyPage::OnBtSurveyPageScan ) EVT_BUTTON( ID_BT_SURVEYPAGE_STOP, CSiteSurveyPage::OnBtSurveyPageStop ) EVT_LIST_ITEM_ACTIVATED( ID_LC_SURVEYPAGE , CSiteSurveyPage::OnSiteItemActivated ) END_EVENT_TABLE( )CSiteSurveyPage::CSiteSurveyPage( wxWindow *parent, int id, const wxPoint &pos, const wxSize &size, long style ) : CWinterPage( parent, id, pos ){ mLcSurvey = new CSurveyListCtrl( this, ID_LC_SURVEYPAGE ); mTmScan = new CSiteSurveyPageTimer( this ); mSiteSurveyState = SITE_SURVEY_IDLE; mBSSCount = 0; //sizer of buttons wxBoxSizer *sz_buttons = new wxBoxSizer( wxHORIZONTAL ); sz_buttons->Add( 1, 10, 1, 0 ); sz_buttons->Add( new wxButton( this, ID_BT_SURVEYPAGE_STOP, _( "S&top" ), wxDefaultPosition, wxDefaultSize ), 0, wxALIGN_RIGHT | wxRIGHT, 5 ); sz_buttons->Add( new wxButton( this, ID_BT_SURVEYPAGE_SCAN, _( "S&can" ), wxDefaultPosition, wxDefaultSize ), 0, wxALIGN_RIGHT | wxRIGHT, 5 ); //sizer of site survey page wxBoxSizer *sz_page_sitesurvey = new wxBoxSizer( wxVERTICAL ); sz_page_sitesurvey->Add( mLcSurvey, 1, wxEXPAND | wxALL, 5 ); sz_page_sitesurvey->Add( sz_buttons, 0, wxEXPAND, 0 ); sz_page_sitesurvey->Add( 1, 10, 0, 1 ); SetSizer( sz_page_sitesurvey ); SetAutoLayout( true ); return;}CSiteSurveyPage::~CSiteSurveyPage( ){ delete mTmScan;}bool CSiteSurveyPage::OnPageChanging( ){ mLcSurvey->Clear( ); return true;}bool CSiteSurveyPage::Scan( ){ CVnetDeviceBase *device = ( CVnetDeviceBase * ) CAccessor::Access( AID_CURRENTDEVICE ); if( device->StartSiteSurvey( ) == false ) { CWinterRuf ruf; ruf.Log( wxT( "Failed to initiate scan." ) ); return false; } mSiteSurveyState = SITE_SURVEY_IN_PROGRESS; mTmScan->Start( 1000 ); return true;}bool CSiteSurveyPage::StopScan( ){ CVnetDeviceBase *device = ( CVnetDeviceBase * ) CAccessor::Access( AID_CURRENTDEVICE ); if( device->StopSiteSurvey( ) == false ) { CWinterRuf ruf; ruf.Log( wxT( "Failed to terminate scan." ) ); return false; } mSiteSurveyState = SITE_SURVEY_COMPLETED; mTmScan->Stop( ); return true;}void CSiteSurveyPage::OnSize( wxSizeEvent &event ){ Layout(); wxListCtrl *list_ctrl = ( wxListCtrl * ) FindWindowById( ID_LC_SURVEYPAGE ); wxASSERT_MSG( list_ctrl != NULL, wxT( "Unable to retrieve pointer to wxListCtrl." ) ); wxSize list_ctrl_size = list_ctrl->GetClientSize(); double c_weight[ 6 ] = { 0.25, 0.20, 0.10, 0.10, 0.15, 0.20 }; int w = list_ctrl_size.GetWidth(); list_ctrl->Freeze( ); for( int c = 0; c < 6; c++ ) { list_ctrl->SetColumnWidth( c, ( int ) floor( c_weight[ c ] * w ) ); } list_ctrl->Thaw( ); event.Skip( ); return;}void CSiteSurveyPage::OnIdle( wxIdleEvent &event ){ wxButton *btscan = ( wxButton * ) FindWindowById( ID_BT_SURVEYPAGE_SCAN ); wxButton *btstop = ( wxButton * ) FindWindowById( ID_BT_SURVEYPAGE_STOP ); bool enable_btscan = false; if ( ( mSiteSurveyState == SITE_SURVEY_IDLE ) || ( mSiteSurveyState == SITE_SURVEY_COMPLETED ) ) { enable_btscan = true; } if( btscan->IsEnabled( ) != enable_btscan || btstop->IsEnabled( ) != !enable_btscan ) { btscan->Enable( enable_btscan ); btstop->Enable( !enable_btscan ); } event.Skip( ); return;}void CSiteSurveyPage::OnBtSurveyPageScan( wxCommandEvent &event ){ CWinterModel *model = ( CWinterModel * ) CAccessor::Access( AID_CURRENTMODEL ); CDeviceConfigurationData *data = ( CDeviceConfigurationData * ) model->GetChild( MC_DEVICECONFIGURATIONDATA ); char *ssid_str = new char[ MAX_SSID_LENGTH + 1 ]; memset( ssid_str, 0, MAX_SSID_LENGTH + 1 ); memcpy( ssid_str, data->GetSSID( ), data->GetSSIDLength( ) ); wxString ssid = ssid_str; int stationstate = data->GetStationState( ); delete ssid_str; mLcSurvey->Clear( ); mLcSurvey->SetInitialConditions( ssid, stationstate ); if( Scan( ) == false ) { ::wxMessageBox( _( "Failed to initialize scan." ), _( "Error!" ), wxICON_HAND ); return; } ( ( wxButton * ) FindWindowById( ID_BT_SURVEYPAGE_SCAN ) )->Enable( false ); ( ( wxButton * ) FindWindowById( ID_BT_SURVEYPAGE_STOP ) )->Enable( true ); return;}void CSiteSurveyPage::OnBtSurveyPageStop( wxCommandEvent &event ){ if( StopScan( ) == false ) { ::wxMessageBox( _( "Failed to terminate scan." ), _( "Error!" ), wxICON_HAND ); return; } ( ( wxButton * ) FindWindowById( ID_BT_SURVEYPAGE_SCAN ) )->Enable( true ); ( ( wxButton * ) FindWindowById( ID_BT_SURVEYPAGE_STOP ) )->Enable( false ); return;}void CSiteSurveyPage::OnSiteItemActivated( wxListEvent &event ){ CVnetDeviceBase *device = ( CVnetDeviceBase * ) CAccessor::Access( AID_CURRENTDEVICE ); wxNotebook *nbmain = ( wxNotebook * ) FindWindowById( ID_NB_MAINNOTEBOOK ); DEACTIVATE_TIMER( ); ::wxBeginBusyCursor( ); // XXX: The index is NOT zero based! if( device->SelectAPByIndex( event.GetIndex( ) + 1 ) == false ) { ::wxMessageBox( _( "Failed to select this AP." ), _( "Error" ), wxICON_HAND ); ACTIVATE_TIMER( ); ::wxEndBusyCursor( ); return; }#if ( DELAY_AFTER_SUBMIT == 1 ) ::wxSleep( 1 );#endif // DELAY_AFTER_SUBMIT == 1 ( ( CWinterPage * ) nbmain->GetPage( 0 ) )->UpdateWinterPage( ); nbmain->SetSelection( 0 ); mLcSurvey->Clear( ); ACTIVATE_TIMER( ); ::wxEndBusyCursor( ); return;}void CSiteSurveyPage::OnTimerTick( ){ CVnetDeviceBase *device = ( CVnetDeviceBase * ) CAccessor::Access( AID_CURRENTDEVICE ); mSiteSurveyState = device->GetSiteSurveyState( ); switch( mSiteSurveyState ) { case -1: mTmScan->Stop( ); mSiteSurveyState = SITE_SURVEY_IDLE; break; case SITE_SURVEY_IDLE: case SITE_SURVEY_COMPLETED: mBSSCount = device->GetAPInfo( mBSSInfo ); mLcSurvey->Display( mBSSInfo, mBSSCount ); mTmScan->Stop( ); break; case SITE_SURVEY_IN_PROGRESS: mBSSCount = device->GetAPInfo( mBSSInfo ); mLcSurvey->Display( mBSSInfo, mBSSCount ); break; } return;}// Higher update levelvoid CSiteSurveyPage::UpdateWinterPage( ){ mLcSurvey->Clear( ); return;}int CSiteSurveyPage::TestControlValues( CWinterModel *model ){ return 0;}int CSiteSurveyPage::TransferToControls( CWinterModel *model ){ return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -