Don't want to display bluetooth device!
Login to reply to this topic.
jeu, 2004-12-16 10:30
Joined: 2004-10-09
Forum posts: 79
Hi!

I wold like not to display all possible bluetooth device, but to search for them and then choose automatically what is the right one to connect...

I'm analising the BTPointToPoint example, here it is the discovery part called in the connect function:

void CBTServiceSearcher::SelectDeviceByDiscoveryL(TRequestStatus& aObserverRequestStatus)
   {
   if (!iIsDeviceSelectorConnected)
       {
       User::LeaveIfError(iDeviceSelector.Connect());
       iIsDeviceSelectorConnected = ETrue;
       }

   //  Request a device selection
   TBTDeviceSelectionParamsPckg selectionFilter;
   selectionFilter().SetUUID(ServiceClass());

   iDeviceSelector.StartNotifierAndGetResponse(
       aObserverRequestStatus,
       KDeviceSelectionNotifierUid,
       selectionFilter,
       iResponse);
   }


I can't see where the results are displayed!
Thanks!
Corben

jeu, 2004-12-16 10:32
Joined: 2004-06-11
Forum posts: 404
Have you tried running the example?
Bye.
--Mayur.

jeu, 2004-12-16 10:39
Joined: 2004-10-09
Forum posts: 79
Yes... It runs correctly...
jeu, 2004-12-16 10:48
Joined: 2004-06-11
Forum posts: 404
So you want the discovery UI that pop ups ,right.
You want to implement the discovery part silently?
Bye.
--Mayur.

jeu, 2004-12-16 10:52
Joined: 2004-10-09
Forum posts: 79
Yes! Correct...

I know the name of the device, and I want that after a silent part of discovering, if that device is present my program connects to it...
jeu, 2004-12-16 11:05
Joined: 2004-06-11
Forum posts: 404
I think this is what you are looking for:
void CbuddyAppView::FindDevicesL()
{
   iInqSockAddrArray = new (ELeave) RArray<TInquirySockAddr>;
   
   CleanupStack::PushL(iInqSockAddrArray);
      //Keep it KGIAC so that all the devices can be detected
      //who are BT enabled
      StartDiscoveryL(iInqSockAddrArray,KGIAC);
   CleanupStack::Pop();
   
   TBuf<100> anote;
   _LIT(message,"%d devices found");
   anote.Format(message,iInqSockAddrArray->Count());
    CAknInformationNote* informationNote;
   informationNote = new (ELeave) CAknInformationNote;
    informationNote->ExecuteLD(anote);
}

//this function is for finding devices with BT ON
void   CbuddyAppView::StartDiscoveryL(RArray<TInquirySockAddr> *aInqSockAddrArray,
                              TUint aInquiryAddr,
                              TInt8 aMajorClass,
                              TInt8 aMinorClass,
                              TInt16 aServiceClass
                              )
{

   #define CAST_ISA(x) (TInquirySockAddr::Cast((x)().iAddr))
   
   RSocketServ   sockServ;
   RHostResolver hostResv;
   TProtocolDesc protInfo;
   TInquirySockAddr sockAddr;
   TRequestStatus ReqStatus;
   TNameEntry NameEntry;
   
   User::LeaveIfError(sockServ.Connect());
   
   CleanupClosePushL<RSocketServ>(sockServ);
   
   User::LeaveIfError(sockServ.FindProtocol(_L("BTLinkManager"),
                                  protInfo
                                 )
                  );
   
   User::LeaveIfError(hostResv.Open(sockServ,
                            protInfo.iAddrFamily,
                            protInfo.iProtocol
                           )
                 );
   
   
   CleanupClosePushL<RHostResolver>(hostResv);
   
   sockAddr.SetIAC(aInquiryAddr);
   
   sockAddr.SetAction(KHostResInquiry);
   
   hostResv.GetByAddress(sockAddr,NameEntry,ReqStatus);
   
   while(User::WaitForRequest(ReqStatus),(ReqStatus == KErrNone || ReqStatus == KRequestPending)){//while starts
      TInquirySockAddr &isa = CAST_ISA(NameEntry);
      //add if filter matches
      if((aMajorClass < 0 || aMajorClass == (TInt8)isa.MajorClassOfDevice()) &&
         (aMinorClass < 0 || aMinorClass == (TInt8)isa.MinorClassOfDevice()) &&
         (aServiceClass < 0 || aServiceClass == (TInt8)isa.MajorServiceClass())
        ){//if starts
           AddToListL(NameEntry,*aInqSockAddrArray);
        }//end of if
      hostResv.Next(NameEntry,ReqStatus);
   }//end of while
   
   CleanupStack::PopAndDestroy(2);
}


//this function is to build a list of disvoered lists
void   CbuddyAppView::AddToListL(TNameEntry& aNameEntry,
                         RArray<TInquirySockAddr>& aInqSockAddrEntry
                        )
{
   TInt i;
   TInquirySockAddr &isa = TInquirySockAddr::Cast(aNameEntry().iAddr);
   for(i=0;i<aInqSockAddrEntry.Count();i++){
      if(aInqSockAddrEntry[i].BTAddr() == isa.BTAddr()){
         return;
      }
   }
   TInquirySockAddr *isa_ptr = new (ELeave)TInquirySockAddr(isa);
   CleanupStack::PushL(isa_ptr);
      User::LeaveIfError(aInqSockAddrEntry.Append(*isa_ptr));
   CleanupStack::Pop();   
}

jeu, 2004-12-16 12:14
Joined: 2004-10-09
Forum posts: 79
I'm trying your code...

How do you define: iInqSockAddrArray?

It gives me: "undecleared identifier".

Thanks!
Corben
jeu, 2004-12-16 12:37
Joined: 2004-06-11
Forum posts: 404
RArray<TInquirySockAddr> *iInqSockAddrArray;

Sorry missed this out.
Wink Bye.
--Mayur.

jeu, 2004-12-16 13:49
Joined: 2004-10-09
Forum posts: 79
Quote from: mayur_24
void   CbuddyAppView::StartDiscoveryL(RArray<TInquirySockAddr> *aInqSockAddrArray,
                              TUint aInquiryAddr,
                              TInt8 aMajorClass,
                              TInt8 aMinorClass,
                              TInt16 aServiceClass
                              )

I was able to compile the code, but it finds that there are no devices in the area... I tought that it is due to the fact that StartDiscoverL requies 5 parameters, but when you call it you use 2 parameters! Is this a possible cause?

Thanks, Corben
jeu, 2004-12-16 13:57
Joined: 2004-06-11
Forum posts: 404
This code works for me.
And the default values are suffice.
Bye.
--Mayur.

jeu, 2004-12-16 13:59
Joined: 2004-10-09
Forum posts: 79
But when compiling it tells me:

error C2660: 'StartDiscoveryL' : function does not take 2 parameters

Did I forgot something?
jeu, 2004-12-16 14:08
Joined: 2004-06-11
Forum posts: 404
I should have passed the header file also.
I am so dumb... Embarassed
Here's the appview header , just take the relevant function declr's

Code:
class CbuddyAppView : public CCoeControl,
public MServiceDiscoObserver
   {
public:

/*!
 @function NewL
 
 @discussion Create a CbuddyAppView object, which will draw itself to aRect
 @param aRect the rectangle this view will be drawn to
 @result a pointer to the created instance of CbuddyAppView
 */
   static CbuddyAppView* NewL(const TRect& aRect);

/*!
 @function NewLC
 
 @discussion Create a CbuddyAppView object, which will draw itself to aRect
 @param aRect the rectangle this view will be drawn to
 @result a pointer to the created instance of CbuddyAppView
 */
   static CbuddyAppView* NewLC(const TRect& aRect);


/*!
 @function ~CbuddyAppView
 
 @discussion Destroy the object and release all memory
 */
    ~CbuddyAppView();

/*!
 @function UserDraw
 
 @discussion Draw this CHelloWorldAppView to the screen
 @param aRect the rectangle of this view that needs updating
 */
   void UserDraw() const;


public:  // from CCoeControl
/*!
 @function Draw
 
 @discussion Draw this CbuddyAppView to the screen
 @param aRect the rectangle of this view that needs updating
 */
   void Draw(const TRect& aRect) const;
 

/*!
 @function OfferKeyEventL
 
 @discussion Handle any user keypresses
 @param aKeyEvent holds the data for the event that occurred
 @param aType holds the type of key event that occured
 @result a TKeyResponse indicating if the key was consumed or not
 */
   TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);

/*!
 @function InputCapabilities
 
 @discussion Return the capabilities of the OfferKeyEventL
             method for this class
 @result a TCoeInputCapabilities indicating the capabilities
         for this class
 */
TCoeInputCapabilities InputCapabilities() const;


void FindServices();

void FindDevicesL();

void SwitchToMode(TDevMode1 aMode);

void StartMasterAndSlaveL();

void StartServices();

void HandleServiceDiscoveryCompleteL();

private:

/*!
 @function ConstructL
 
 @discussion  Perform the second phase construction of a CbuddyAppView object
 @param aRect the rectangle this view will be drawn to
 */
   void ConstructL(const TRect& aRect);

/*!
 @function CbuddyAppView
 
 @discussion Perform the first phase of two phase construction
 */
   CbuddyAppView();
   
   void  StartDiscoveryL(RArray<TInquirySockAddr> *aInqSockAddrArray,
 TUint aInquiryAddr,
 TInt8 aMajorClass = -1,
   TInt8 aMinorClass = -1,  
 TInt16 aServiceClass = -1
);

void   AddToListL(TNameEntry& aNameEntry,
RArray<TInquirySockAddr>& aInqSockAddrEntry
);

RArray<TInquirySockAddr> *iInqSockAddrArray;
CTwoServiceAdvertiser *iBTA;
CDiscoverService* ServiceDiscoverer;


   };

Hope this helps.
Bye.
--Mayur.

jeu, 2004-12-16 14:42
Joined: 2004-10-09
Forum posts: 79
Ok now I have a very stupid question...  Embarassed

It works, now how can I retrieve the name of the device to make a comparison? Tongue

Thanks for the help given so far!
Corben
ven, 2004-12-17 06:53
Joined: 2004-06-11
Forum posts: 404
I am not very clear about the question?
I think the device address should be enough for connection.
Bye.
--Mayur.

ven, 2004-12-17 09:57
Joined: 2004-10-09
Forum posts: 79
As i said, this was a stupid question...  Embarassed

I didn't tought to use the address to make a comparison, I wanted to use the name of the device! Tongue

Now I with the address...

I know this is stupid, but I'm not expert in this: I have that my address is 00:20:E0:79:56:61, how can I create a TInquirySockAddr object to make a comparison with the elemnts of the array iInqSockAddrArray?

Thaks!!!
Corben
ven, 2004-12-17 10:04
Joined: 2004-06-11
Forum posts: 404
As TInquirySockAddr class is derived from TDesC class and so you have
the Match fucntion at your disposal and so comparision must be easy.
Hope this helps.
--Mayur.


copyright 2003-2009 NewLC SARL