ebook img

Bluetooth Application Programming with the Java APIs (The Morgan Kaufmann Series in Networking) PDF

286 Pages·2003·2.81 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Bluetooth Application Programming with the Java APIs (The Morgan Kaufmann Series in Networking)

To my wife, Karmen, and son, Zane —Tim To my daughter, Rose, and her family, Terry, Morgan, and Andrew —Paul To my wife, Sundari, and sons, Sailesh and Shiva —Bala Preface Bluetooth(cid:2) wireless technology is a short-range radio standard that provides new opportunities for wireless devices. Originally, Bluetooth wireless technology was designed as a way of eliminating the cables attached to nearly all consumer electronic devices. However, the goals forBluetoothwirelesstechnologygrewasitsdesignersrecognizedthatit enables anew kind ofwireless network between electronic devices. Since 2001, Java developers have had the opportunity to develop applicationsforavarietyofwirelessdevicesandcellphones.In2000,the Java community recognized the importance of creating a standard extension to the Java programming language for use with Bluetooth devices. A standard application programming interface (API) for Blue- toothwasneededbecauseeachBluetoothsoftwareprotocolstackhadits own API for application programmers. These proprietary APIs meant that a Bluetooth application had to be ported to different Bluetooth stacks to run on different devices. Apart from the work involved in writing the code, interoperability testing on the various devices costs timeandmoneyfortheinvolvedcompanies.AstandardAPIwouldhelp alleviate alltheseproblems. A team of experts from across the industry was assembled for this effort under Java Specification Request 82 (JSR-82). The result was a specification for Java APIs for Bluetooth wireless technology (JABWT). Since the release of JSR-82 in the spring of 2002, Bluetooth wireless technology has become a standard feature in cell phones with many of these phones also havingsupport forJSR-82. ThisbookisbasedontheBluetoothApplicationProgrammingwiththe Java APIs [2] written by the same authors. For this Essentials Edition, the authorshaveupdatedthebackgroundinformationtoreflectthechanges that have occurred in the area of Bluetooth wireless technology and xiii xiv Preface JSR-82, including support for MIDP Push, since Bluetooth Application Programming with the Java APIs was published in 2004. While reading theJSR-82specificationdocumentprovidesyouwithadescriptionofthe API, this book provides you with the rationale and best practices in utilizing the API. The objectivesof this book are to Give an overview of JavaTM Platform, Micro Edition (Java ME) and Bluetooth wireless technology Outline the JABWT architecture Explain the API indetail Intended Audience The book is intended for software developers, academics, and other professionals who want to develop Java software for Bluetooth devices. To gain the most out of this book, you will find it helpful to have a working knowledge of Java ME and familiarity with Bluetooth wireless technology. The book cites several references that provide additional information on these subjects. We believe that a Java ME programmer will need no additional reading beyond this book to write JABWT applications. Ifyou wouldlikemoreexamplesor moreinformation ondevelop- ing and porting JSR-82 to a handset, the authors recommend the pre- decessor to this book: Bluetooth Application Programming with the Java APIs. How This Book Is Organized Different readers of this book will be seeking different information. We have identified three sets of people: 1. Those lookingfor an overview tomake decisions onprojects 2. Thosewhowillbeleadingprojectsormanagingprojectsinthisarea 3. Programmers who need detailed information on how to program using JABWT Preface xv Apart from the introductory chapters, the chapters are organized into three main sections to accommodate the three sets of people identified above. The three divisions are 1. Overview: The executive introduction 2. API capabilities: The explanationfor the project manager 3. Programming with the API: The programmer’s guide Readers can choose the sections that suit their needs in each chapter. Chapters1through3areoverviewchapters.Chapters4through9detail the various sections of the API. Chapter 9 describes the MIDP Push capabilities added since the last book. Throughout the book many code examplesaregiventoexplaintheAPI.ThecompleteJSR-82APIisavail- able at www.jcp.org/en/jsr/detail?id=82. There is a website for this book where you can access the complete codeexamplesfoundinthebook.Inaddition,youcanfindthelatestnews aboutJABWT,bookerrata,andotherusefullinks.Toaccessthewebsite,go towww.mkp.comandusethesearchoptionwiththetitleofthisbook. The topics inthis book areorganized as follows: Chapter 1, Introduction, presents an overview of Bluetooth wireless technology and Java ME. It also provides a context for the JABWT specification. Chapter2,AnOverviewofJABWT,definesthegoals,characteristics,and scopeof JABWT. Chapter 3, High-Level Architecture, presents the high-level architecture of JABWT. Chapter 4, RFCOMM, discusses the APIs for Bluetooth serial port com- munications using RFCOMM. Chapter 5, OBEX, introduces the architecture and the APIs for making OBEX connections. Chapter 6, Device Discovery, discusses the APIs for Bluetooth device discovery. Chapter7,ServiceDiscovery,describestheAPIsforservicediscoveryand service registration. Chapter8,L2CAP,presentstheAPIforBluetoothcommunicationsusing the logicallink control and adaptationprotocol. Chapter 9, Push Registry, describes the support available in JABWT for the Push Registry as described inMIDP2.0. About the Authors Timothy J. Thompson is a Principal Software Engineer on the Advanced Technology and Architecture team in Motorola’s Mobile Device Business. He is currently the JSR-82 Maintenance Lead. He was the OBEX architect on the JABWT specification team at Motorola. He received his Master’s degree in Computer Science from Texas A&M University. Paul J. Kline manages a team that develops Linux Board Support PackagesfortheMultimediaApplicationsDivisionatFreescaleSemicon- ductor.Previously,heworkedatMotorolawherehewasamemberofthe JSR-82ExpertGroupandthefirstJSR-82MaintenanceLead.Hereceived hisPh.D.inMathematicalPsychologyfromtheUniversityofMichigan. C Bala Kumar manages platform development for the Multimedia ApplicationsDivisionatFreescaleSemiconductor.Previously,heworked atMotorolawherehechairedtheindustryexpertgroupthatdefinedthe Java APIs for Bluetooth wireless technology. He received his Master’s degree inElectricalEngineering from the University ofTexas atAustin. xvi Acknowledgments A large number of people were involved with the original development oftheJavaAPIsforBluetoothwirelesstechnology.Asthethreeofusset outtowriteabookexplainingthoseBluetoothAPIs,wewerepleasedto discoverthatwewouldagainreceivecontributionsandassistancefroma large number of dedicated and talented individuals. The authors thank Glade Diviney, Peter Kembro, and Ashwin KamalWhitchurchforreviewingthebookBluetoothApplicationProgram- ming with the Java APIs, which is the basis of this book, and making valuable comments and suggestions. Thanks also to R. Thiagarajan, N. Murugan, Franck Thibaut, Ramesh Errabolu, Ranjani Vaidyanathan, and Ravi Viswanathan, who commented on various chapters of the original book. Of course, the authors are totally responsible for any errors that remain. When the original book was in the proposal stage, we received excellentadviceandsuggestionsfromAlokGoyal,TeckYangLee,Girish Managoli, Brent Miller, Venugopal Mruthyunjaya, N. Ramachandran, Rajeev Shorey, and Mark Vandenbrink. Ashwin Whitchurch, Brent Miller, Glade Diviney, and Girish Managoli provided additional feed- back on the proposal forthis book. TheJavaAPIsforBluetoothwirelesstechnologyweredevelopedby a team of industry experts, the JSR-82 expert group, and the team at Motorola that drafted the specification, wrote the reference implemen- tation, and developed the conformance tests. The authors believe that the efforts and contributions of all these individuals produced an API that will have important benefits to the Java community. The authors wouldliketothankthemembersoftheJSR-82expertgroupforalltheir work on the API: Jouni Ahokas, Patrick Connolly, Glade Diviney, MasahiroKuroda,TeckYangLee,PaulMackay,BrentMiller,JimPanian, xvii xviii Acknowledgments FarooqAnjum,CharatpongChotigavanich,PeterDawson,PeterDuche- min, Jean-Philippe Galvan, Daryl Hlasny, Knud Steven Knudsen, AndrewLeszczynski, Martin Mellody,AnthonyScian,and BradThreatt. Wegreatlyappreciateallofthecontributionsoftheothermembers oftheJSR-82teamatMotorola:LawrenceChan,JudyHo,WillHolcomb, Judy Lin, Mitra Mechanic, Ramesh Errabolu, Ranjani Vaidyanathan, Ravi Viswanathan, and Allen Peloquin. Jim Erwin, Jim Lynch, Aler Krishnan, Ed Wiencek, and Mark Patrick provided a great deal of assistance tothe JSR-82 team. WewouldalsoliketothankKhurramQureshiandMarkVandenbrink fortheirhelpandsupportinmakingthisbookareality. The authors are very grateful to Rick Adams, Gregory Chalson, LianneHong,KarynJohnson,andMamataReddyofMorganKaufmann forall their hard work Timthankshiswife,Karmen,forherencouragement,patience,and support. Paul thanks hiswife, Dianne, for her supportand encouragement. BalathanksSundari,Sailesh,andShivafortheirunderstandingand supportthroughlongnightsandweekendsworkingonthisproject.Bala also thanks his mother, Suseela, and sister, Surya, for all their patient nurturing and Mr. B. Kanakasabai for being his lifelong friend and mentor. TimThompson Paul Kline C Bala Kumar 1 I n t r o d u c t i o n CHAPTER This chapter begins with an introduction to wireless connectivity and Bluetooth(cid:2)wirelesstechnology.Itthen gives (cid:129) An overview of theBluetooth protocol stack (cid:129) An overview of theJava Platform, Micro Edition (cid:129) Adescription ofthe needforJavatechnology inBluetooth devices 1.1 Wireless Connectivity Weareintheinformationage.Theterm‘‘informationage’’cameabout becauseoftheexchangeofmassiveamountsofdatabetweencomputing devices using wired and wireless forms of communication. We are rapidlymovingtowardaworld inwhich communicationsand comput- ing areubiquitous. Today, high-speed networks connect servers, personal computers, and other personal computing devices. High-end routers manage the networks.Thedistinctionbetweenvoiceanddatanetworkshasblurred, andthesamenetworktendstocarrybothtypesoftraffic.Thedesireand need to communicate with distant computers led to the creation of the Internet. The days of consumers buying a personal computer for stand- alone applicationshavedisappeared.Thesedaystheprimarymotivefor buyingapersonalcomputeristouseitasacommunicationtoolsothat one can have Internet access to e-mail and the World Wide Web. The same is true of today’s embedded computing devices. Instead of simply being an organizer or phone, embedded computing devices have becomeanotherway toaccess theInternet. 2 ChapterOne:Introduction Increased dependence on the Internet and the need to stay con- nected from anywhere at all times have led to advances in mobile computing and communications. We have been communicating with- outwiresforsometimewithsatellites,cordlessphones,cellularphones, and remote-control devices. However, in recent years the wireless com- munications industry has seen explosive growth. Long-range wireless communication invariably uses radio frequency (RF). Typically, long- range communications use the licensed parts of the RF spectrum, and user fees apply. Short-range communications can use either RF or infra- red and typically use unlicensed (i.e., free) parts of the frequency spectrum. There are many short-range wireless standards, but the three main ones are Infrared from the Infrared Data Association(cid:2) (IrDA(cid:2)), Blue- tooth wireless technology, and wireless local area network (WLAN). WLAN is also known as IEEE 802.11, and it comes in several variants (802.11b, 802.11g, 802.11a, 802.11n, etc.), which operate at 2.4 giga- hertz (GHz) or 5 GHz. The IrDA created a wireless communications system that makes use of infrared light. Whereas RF communication can penetrate many objects, IrDA is limited to line of sight. Both 802.11b and Bluetooth wireless technologies communicate in the 2.4- GHz RF band but are aimed at different market segments. The 802.11 technology has a longer range but consumes substantially more power than Bluetooth wireless technology. The 802.11 variant is primarily for data. The only protocol for supporting voice is Voice over Internet Protocol (VoIP). Table 1.1 provides a comparison of these three technologies. Wireless communications allow computing and communication devices to be used almost anywhere and to be used in new, progressive ways. The increase in wireless mobile Internet devices is proof that wireless connectivity is pervasive. Powerful software programming environments will help fuel this mobile computing explosion by enablingthedevelopmentofcompellingapplications.TheJavaplatform provides a powerful programming environment that has great promise for wireless devices. Many mobile devices now come with support for Java Platform, Micro Edition (Java ME) programs. This book explains how to program Bluetooth applications with the Java programming language. WhatIsBluetoothWirelessTechnology? 3 Table1.1 ComparisonofWirelessCommunicationTechnologies Featureand IrDA WirelessLAN Bluetooth function communication Connectiontype Infrared,narrowbeam,line Spreadspectrum,spherical Spreadspectrum, ofsight spherical Spectrum Optical850–900nm RF2.4GHz(5GHzfor802.11a/n) RF2.4GHz Transmission 40–500mW/Sr 100mW 10–100mW power Maximumdata 9600bps–16Mbps(very 11Mbps(54Mbpsfor802.11a, 3Mbps rate rare) 802.11g) Range 1m 100m 10–100m Supported 2 Connectsthroughanaccesspoint 8(active),200 devices (passive) Voicechannels No No Yes Addressing 32-bitphysicalID 48-bitMAC 48-bitMAC 1.2 What Is Bluetooth Wireless Technology? Bluetoothwirelesstechnologyisanopenspecificationforalow-cost,low- power,short-rangeradiotechnologyforadhocwirelesscommunicationof voice and data anywhere in the world. Let us examine each of these attributes. (cid:129) Anopenspecificationmeansthatthespecificationispubliclyavail- able androyalty free. (cid:129) Short-range radio technology means devices can communicate over theairusingradiowavesatadistanceof10meters(m).Withhigher transmissionpowertherangeincreasestoapproximately100m. (cid:129) Becausecommunicationiswithinashortrange,theradios arelow power andare suited forportable, battery-operated devices. (cid:129) Bluetoothwirelesstechnologysupportsbothvoiceanddata,allow- ingdevicesto communicate either type of content. (cid:129) Bluetooth wireless technology works anywhere in the world because it operates at 2.4 GHz in the globally available, license- free, industrial, scientific, andmedical (ISM) band.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.