CLI339 CLI339 Building Bluetooth Building Bluetooth Applications On The Applications On The Windows CE 5.0 And Windows CE 5.0 And Windows Mobile Windows Mobile Platforms Platforms Anil Dhawan Anil Dhawan Program Manager Program Manager Windows Mobile Windows Mobile
47
Embed
CLI339 Building Bluetooth Applications On The Windows CE 5.0 And Windows Mobile Platforms Anil Dhawan Program Manager Windows Mobile.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
CLI339CLI339Building Bluetooth Building Bluetooth Applications On The Applications On The Windows CE 5.0 And Windows CE 5.0 And Windows Mobile PlatformsWindows Mobile Platforms
Anil DhawanAnil DhawanProgram ManagerProgram ManagerWindows MobileWindows Mobile
Bluetooth Application ConceptsBluetooth Application Concepts
Windows CE DevelopmentWindows CE Development
Windows Mobile DevelopmentWindows Mobile Development
DemoDemo
Q&AQ&A
Bluetooth DevicesBluetooth Devices
Identified by unique addressIdentified by unique address
Advertise to others in discoverable Advertise to others in discoverable modemode
Class of device fieldClass of device field
Devices maintain list of supported Devices maintain list of supported servicesservices
Use Service Discovery for querying list on Use Service Discovery for querying list on other devicesother devices
Bluetooth ServicesBluetooth Services
Describe data exchange protocolsDescribe data exchange protocolsIdentified by a unique GUIDIdentified by a unique GUID
Standardized services called “profiles” Standardized services called “profiles” for common use casesfor common use cases
File Transfer (FTP)File Transfer (FTP)
Dial-Up networking (DUN)Dial-Up networking (DUN)
Stereo Audio (A2DP)Stereo Audio (A2DP)
General TipsGeneral Tips
Keep users informedKeep users informedUse OS UI for device discovery, pairingUse OS UI for device discovery, pairing
Application should handle latencyApplication should handle latency
Don’t block UI threadsDon’t block UI threads
Handle errors gracefullyHandle errors gracefully
Conserve the juiceConserve the juiceLimit time in discoverable modeLimit time in discoverable mode
Keep Bluetooth Off when not in useKeep Bluetooth Off when not in use
5 step process for application 5 step process for application developmentdevelopment
The 5 Step ProcessThe 5 Step Process
Find devices in rangeFind devices in range
Choose a device to connect withChoose a device to connect with
Establish a secure connection (pairing)Establish a secure connection (pairing)
Choose a serviceChoose a service
Transfer DataTransfer Data
Step 1: Find Devices In RangeStep 1: Find Devices In Range
Target devices must Target devices must be in discoverable modebe in discoverable mode
Client device listens to broadcasts Client device listens to broadcasts from discoverable devicesfrom discoverable devices
Step 2: Choose A Device Step 2: Choose A Device To Connect WithTo Connect With
OS usually provides GUI to connect OS usually provides GUI to connect with another devicewith another device
Each device identified by a unique Each device identified by a unique addressaddress
Step 3: Establish A Secure Step 3: Establish A Secure Connection Connection
Process called “pairing”Process called “pairing”
Requires both end points to use the Requires both end points to use the same pin keysame pin key
Usually part of connecting UIUsually part of connecting UI
Step 4: Choose A ServiceStep 4: Choose A Service
Each service identified by unique GUIDEach service identified by unique GUID
Set of “standard” services for well-Set of “standard” services for well-known profilesknown profiles
New applications can publish own New applications can publish own GUIDGUID
Services usually chosen through Services usually chosen through device UIdevice UI
Step 5: Transfer DataStep 5: Transfer Data
Point to point style 2-way Point to point style 2-way communicationcommunication
Applications use service/profile Applications use service/profile protocols to communicate effectivelyprotocols to communicate effectively
AgendaAgenda
Technology OverviewTechnology Overview
Bluetooth Application ConceptsBluetooth Application Concepts
Windows CE DevelopmentWindows CE Development
Windows Mobile DevelopmentWindows Mobile Development
DemoDemo
Q&AQ&A
Bluetooth Application Bluetooth Application ProgrammingProgramming
Winsock API is extended to support Winsock API is extended to support BluetoothBluetooth
New Protocol Family for Bluetooth New Protocol Family for Bluetooth
AF_BTHAF_BTH
New Protocol Option New Protocol Option
BTPROTO_RFCOMMBTPROTO_RFCOMM
New socket options for BluetoothNew socket options for BluetoothEnable/disable encryptionEnable/disable encryption
Control send/receive buffer sizeControl send/receive buffer size
Set power levelSet power level
Windows CE: Windows CE: Native ApproachNative Approach
Windows Sockets APIsWindows Sockets APIsDevice and Service Discovery: Device and Service Discovery: WSALookupServiceBegin(), WSALookupServiceBegin(), WSALookupServiceNext(), WSALookupServiceNext(), WSALookupServiceEnd()WSALookupServiceEnd()
Use standard socket connection APIsUse standard socket connection APIsbind(), listen(), accept(), connect()bind(), listen(), accept(), connect()
Data Transfer APIsData Transfer APIssend(), recv()send(), recv()
Bluetooth Enabling Legacy Bluetooth Enabling Legacy ApplicationsApplications
Useful for applications built around Useful for applications built around interfacing with serial devicesinterfacing with serial devices
GPS receivers, barcode scanners, etc.GPS receivers, barcode scanners, etc.
Virtual serial ports expose Bluetooth Virtual serial ports expose Bluetooth link as a COM portlink as a COM port
General Object Exchange Profile General Object Exchange Profile
Object Push ProfileObject Push Profile
File Transfer ProfileFile Transfer Profile
Headset ProfileHeadset Profile
Handsfree ProfileHandsfree Profile
Human Input Device ProfileHuman Input Device Profile
Personal Area Network ProfilePersonal Area Network Profile
Bluetooth Enabling Legacy Bluetooth Enabling Legacy Applications: Registering COM portsApplications: Registering COM portsPORTEMUPortParams pp;memset( &pp, 0, sizeof( pp ) );
// connect to serial port profile on device identified by// remoteDeviceAddrpp.device = remoteDeviceAddr;pp.uuidService = SerialPortServiceClass_UUID;pp.uiportflags =
RFCOMM_PORT_FLAGS_REMOTE_DCB;HANDLE h = RegisterDevice (L"COM", index, L"btd.dll",
(DWORD)&pp);
Bluetooth Enabling Legacy Bluetooth Enabling Legacy Applications: Serial Data TransferApplications: Serial Data TransferWCHAR szComPort[30];
// open previously registered COM port for reading and writingwsprintf( szComPort, L"COM%d:", index );
BluetoothBluetooth getsocknamegetsocknameUse getsockname to retrieve server channel Use getsockname to retrieve server channel
allocated to socket by a call to bind and allocated to socket by a call to bind and Bluetooth address of local device.Bluetooth address of local device.
Queries various parameters associated Queries various parameters associated with server channel or connection. The with server channel or connection. The parameters are as follows:parameters are as follows:
s must be Bluetooth sockets must be Bluetooth socket
level must be SOL_RFCOMMlevel must be SOL_RFCOMM
SO_BTH_GET_MTU_MAX,…SO_BTH_GET_MTU_MAX,…
BluetoothBluetooth setsockoptsetsockopt
Configures various parameters Configures various parameters associated with server channel or associated with server channel or connection. The parameters are as connection. The parameters are as follows:follows:
s must be Bluetooth sockets must be Bluetooth socket