bluetooth/btexample/example/sdap/test/tbm.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // BT incoming SCO notification test code
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 #include <es_sock.h>
       
    20 #include <f32file.h>
       
    21 #include <bt_sock.h>
       
    22 #include <btextnotifiers.h>
       
    23 #include <c32comm.h>
       
    24 #include <btsdp.h>
       
    25 #include "exchange.h"
       
    26 
       
    27 #if defined (__WINS__)
       
    28 #define PDD_NAME _L("ECDRV")
       
    29 #define LDD_NAME _L("ECOMM")
       
    30 #else  // __GCC32__
       
    31 #define PDD_NAME _L("EUART4")	// port 0 on Assabet
       
    32 // don't use EUART2 - port 1 is IR
       
    33 #define ETNA_PDD_NAME _L("EUART3") // for port 2 on Assabet
       
    34 #define LDD_NAME _L("ECOMM")
       
    35 #endif
       
    36 
       
    37 GLDEF_D RTest test(_L("bluemeanie tests"));
       
    38 
       
    39 const TUint32 KServiceUID1 = 0x6D14AC98;
       
    40 const TUint32 KServiceUID2 = 0x7A8249bb;
       
    41 const TUint32 KServiceUID3 = 0xB885BE2E;
       
    42 const TUint32 KServiceUID4 = 0xF73C909E;
       
    43 
       
    44 //_LIT(KMenuText1, "A - Listen & Accept         F - Connect ACL");
       
    45 //_LIT(KMenuText2, "B - Await incoming SCO      G - Connect SCO");
       
    46 //_LIT(KMenuText3, "C - Await SCO disconnect    H - Disconnect SCO");
       
    47 //_LIT(KMenuText4, "D - Await ACL disconnect    I - Disconnect ACL");
       
    48 //_LIT(KMenuText5, "E - Receive Data            J - Send Data");
       
    49 //_LIT(KMenuText6, "K - Hard disconnect ACL");
       
    50 //_LIT(KMenuText7, "X - Exit");
       
    51 //_LIT(KNewLine, "\r\n");
       
    52 
       
    53 //const TBTDevAddr KDevAddr(MAKE_TINT64(0x0002, 0x5bff0a1e));
       
    54 
       
    55 class CTestBM : public CActive
       
    56 	{
       
    57 	public:
       
    58 		CTestBM();
       
    59 		void InitL();
       
    60 		void DoTestL();
       
    61 		void RunL();
       
    62 		void DoCancel();
       
    63 	private:
       
    64 	private:
       
    65 		CBluetoothExchanger* iExch;
       
    66 		CActiveScheduler* iSched;
       
    67 	};
       
    68 
       
    69 CTestBM::CTestBM() : CActive(CActive::EPriorityStandard)
       
    70 	{}
       
    71 
       
    72 void CTestBM::InitL()
       
    73 	{
       
    74 	TUUID uuid(KServiceUID1,KServiceUID2,KServiceUID3,KServiceUID4);
       
    75 	iSched = new(ELeave) CActiveScheduler;
       
    76 	CActiveScheduler::Install(iSched);
       
    77 	iExch = CBluetoothExchanger::NewL(uuid);
       
    78 	iSched->Add(this);
       
    79 	}
       
    80 
       
    81 void CTestBM::DoTestL()
       
    82 	{
       
    83 	test.Printf(_L("Press a key to start search\r\n"));
       
    84 	test.Getch();
       
    85 	iExch->LookForPeersL(iStatus);
       
    86 	SetActive();
       
    87 	iSched->Start();
       
    88 	test(iStatus == KErrNone);
       
    89 	test.Printf(_L("Completed with status %d\r\n"), iStatus.Int());
       
    90 	TInt count;
       
    91 	TBTSockAddr addr;
       
    92 	THostName name;
       
    93 	TNameEntry* entry;
       
    94 	iExch->First();
       
    95 	count = iExch->Count();
       
    96 	test.Printf(_L("%d compatible devices found\r\n"), count);
       
    97 	while(iExch->Next(entry) == KErrNone)
       
    98 		{
       
    99 		addr = (*entry)().iAddr;
       
   100 		name = (*entry)().iName;
       
   101 		test.Printf(_L("Device address 0x%02x%02x%02x%02x%02x%02x\r\n"),
       
   102 			addr.BTAddr()[0],
       
   103 			addr.BTAddr()[1],
       
   104 			addr.BTAddr()[2],
       
   105 			addr.BTAddr()[3],
       
   106 			addr.BTAddr()[4],
       
   107 			addr.BTAddr()[5]);
       
   108 		test.Printf(_L("Device name: %S\r\n"), &name);
       
   109 		}
       
   110 	test.Getch();
       
   111 	}
       
   112 
       
   113 void CTestBM::RunL()
       
   114 	{
       
   115 	iSched->Stop();
       
   116 	}
       
   117 
       
   118 void CTestBM::DoCancel()
       
   119 	{
       
   120 	//iExch->Cancel();
       
   121 	}
       
   122 
       
   123 void LoadLDD_PDD()
       
   124 	{
       
   125 	TInt r;
       
   126 #ifdef __EPOC32__
       
   127 	r=StartC32();
       
   128 	if (r!=KErrNone && r!=KErrAlreadyExists)
       
   129 		{
       
   130 		test.Printf(_L("Failed %d!\n\r"),r);
       
   131 		test(r==KErrNone);
       
   132 		}
       
   133 	else
       
   134 		test.Printf(_L("Started C32\n"));
       
   135 #endif
       
   136 	test.Printf(_L("Loading PDD\n"));
       
   137 	r=User::LoadPhysicalDevice(PDD_NAME);
       
   138 	if (r!=KErrNone && r!=KErrAlreadyExists)
       
   139 		{
       
   140 		test.Printf(_L("Failed %d!\n\r"),r);
       
   141 		test(r==KErrNone);
       
   142 		}
       
   143 	else 
       
   144 		test.Printf(_L("Loaded LDD\n"));
       
   145 	test.Printf(_L("Loading LDD\n"));
       
   146 	r=User::LoadLogicalDevice(LDD_NAME);
       
   147 	if (r!=KErrNone && r!=KErrAlreadyExists)
       
   148 		{
       
   149 		test.Printf(_L("Failed %d!\n\r"),r);
       
   150 		test(r==KErrNone);
       
   151 		}
       
   152 	else
       
   153 		test.Printf(_L("Loaded PDD\n"));
       
   154 	}
       
   155 
       
   156 
       
   157 void RunTestL()
       
   158 	{
       
   159 	CTestBM *st = new(ELeave) CTestBM;
       
   160 	CleanupStack::PushL(st);
       
   161 	LoadLDD_PDD();
       
   162 	st->InitL();
       
   163 	st->DoTestL();
       
   164 	CleanupStack::PopAndDestroy(st);
       
   165 	}
       
   166 
       
   167 TInt E32Main()
       
   168 	{
       
   169 	CTrapCleanup* cleanupStack=CTrapCleanup::New();
       
   170 
       
   171 	TRAPD(err,RunTestL());
       
   172 
       
   173 	delete cleanupStack;
       
   174    	
       
   175 	return err;
       
   176 	}
       
   177