Great Events of the Twentieth Century11 The Impronto Simulator provides a simulated Bluetooth environment that allows developers to build Bluetooth-enabled Java applications without depl
Trang 2Contents
Trang 3Great Events of the Twentieth Centuryii
Trang 5Great Events of the Twentieth Century1
1
The Impronto Simulator provides a simulated Bluetooth environment that allows
developers to build Bluetooth-enabled Java applications without deploying them on Bluetooth devices The Impronto Simulator is 100% Java and supports the standard JABWT (Java APIs for Bluetooth Wireless Technologies) developed by the JSR-82 expert group
The following features are supported in the product:
• Provides full support for L2CAP, RFCOMM, OBEX, SDP, HCI, BCC
• Runs actual application code in simulated mode
• Provides a management console for tracking and controlling the run-time behaviour of devices and networks
• Allows users to create and configure virtual devices using the management console
• Has full logging capability for Bluetooth events, and can capture events for specific devices with event filtering
• Supports J2ME applications for Windows and Linux
This guide is intended for the following audience:
• Experienced Java developers who wish to build Java-based Bluetooth applications
• Software test engineers who require a simulated test environment for Bluetooth enabled applications
Overview
Audience
Trang 6• Developing with the Impronto Simulator
Getting Started - Chapter 2
This section provides system requirements and installation instructions It includes detailed instructions on how to run the Echo demo, a simple application that can be used to verify that the installation of the product was successful
Using the Simulator - Chapter 3
This chapter describes how to use the Impronto Simulator It introduces product features such as simulated device configuration and logging, and explains how to use them when running applications
JABWT Development - Chapters 4 - 9
This section of the guide provides an introduction to the major topics an application
developer should be familiar with when developing JABWT applications The topics
covered are:
• Device Discovery
• Service Discovery
• Service Registration
• Using the L2CAP protocol
• Using the RFCOMM protocol
• Using the OBEX protocol
Developing with the Impronto Simulator - Chapters 10 - 11
This section includes topics specific to developing with Impronto, including an overview of the useful Java libraries provided with Impronto, and a discussion of the differences between working with the simulator and using real Bluetooth devices
How This Guide is Organised
Trang 7Great Events of the Twentieth Century3
3
Java and Bluetooth Technology - Chapters 12 - 14
This section introduces important Java and Bluetooth concepts that relate to the Impronto Simulator It provides an overview of J2ME technologies, including CLDC and MIDP
This section also includes a chapter introducing the Bluetooth Control Center (BCC) and JABWT security
The following conventions have been adopted in this document:
All Java code in the text appears like this
All user input and menu selections referred to in the text appear like thislike thislike this
The Impronto Simulator can run on both the Linux and Windows platforms In this guide the character / / / has been used as a directory separator Please replace this character with \ \ \ \
if you are running the product on a Windows platform
The string {simulator_home} represents the directory into which the Simulator was installed
Document Conventions
Trang 8• Windows 2000 or Redhat Linux
For J2ME development:
Trang 9Great Events of the Twentieth Century5
Using J2ME applications with Impronto
J2ME applications may be tested with Impronto Simulator using me4se, a J2ME emulation environment for J2SE, available for download from http://www.me4se.org.This version of Impronto has been tested against me4se version 2.1.2, which is shipped with the
Simulator
The following section explains how to verify your installation using both J2ME and J2SE
Your Impronto installation includes a number of sample applications that you can use to verify that your installation has been successful and to practise using the simulator The sample applications are Chat, and Echo All examples run on J2SE and J2ME
This section steps through running the Echo demo, a very simple client-server application
in which the client connects to and sends a message to the server, and the server replies with the same message Both the client and server have a simple graphical interface, and the application has two preconfigured simulated devices that communicate using the L2CAP protocol
To verify your installation, you need to:
• set up your development environment
• build the demo applications
• start the Bluetooth Simulation Console tool
Installation Procedure
Verifying the Installation
Trang 10CHAPTER 2:Getting Started
• run the Echo demo and verify its output
Set-up Environment
To set up your environment to build the examples, do the following:
• On Windows, type set PATH=%PATH%;{set PATH=%PATH%;{simulator_home}\ant\bin
• On Linux, type export PATH=$PATH:{export PATH=$PATH:{simulator_home}/ant/bin
Build the sample applications
Now you need to build the sample applications:
• Change to the {simulator_home}/examples directory
• Type ant ant ant to build all applications
Start the Bluetooth Simulation Console
If you are using Windows and specified that you would like a desktop or Start menu
shortcut added when installing the simulator, you can start the Bluetooth Simulation Console using this shortcut Otherwise:
• Change to the {simulator_home}/bin directory
• On Windows, type managermanager
• On Linux, type /manager&./manager&
The Bluetooth Simulation Console should display, as in the next figure:
Trang 11Great Events of the Twentieth Century7
7
Trang 12CHAPTER 2:Getting Started
The following two sections guide you through running the Echo sample in J2SE and J2ME Run the Echo demo application - J2SE
This section tells you how to run the Echo sample application and verify its output in a J2SE environment
• Change to the {simulator_home}/examples/echo/bin directory
• On Windows, type start echo-serverstart echo-server
• On Linux, type echo-server&echo-server&
The server GUI will display:
A friendly name should be provided for the server - this name will be used to identify the server device in the simulator
• To set the friendly name, first select the Set Friendly NameSet Friendly NameSet Friendly Name option from the ServerServerServer menu
• Then enter the name - let’s call it foofoofoo - in the dialog as shown below, and click OKOK
Trang 13Great Events of the Twentieth Century9
9
You now need to start the server so that it is ready to accept connections from the Echo client
• Start the server by selecting Server - StartServer - Start
The server will display the following message if it started successfully
If you check the Simulation Console, this should also be updated as in the figure below - the device foo foo foo appears in the simulated network display and in the list of active devices
Trang 14CHAPTER 2:Getting Started
Once you have started the server, the next step is to run the Echo client You should open a new command prompt window
• On Windows, type start echo-clientstart echo-client
Trang 15Great Events of the Twentieth Century11
11
• On Linux, type echo-client&echo-client&
Like the Echo server device, the client device should also have a friendly name In addition, you must specify the server application that the client is to use
• To specify a friendly name for the client, select the Set Friendly NameSet Friendly NameSet Friendly Name option from the Client
Client menu
• Then enter the name in the dialog as shown and click OKOKOK
• Now select Select ServerSelect ServerSelect Server from the ClientClientClient menu
• Select the server application “Echo”, running on device “foo”, as shown in the dialog below, leaving the default setting of No Authentication/No EncryptionNo Authentication/No Encryption
Trang 16CHAPTER 2:Getting Started
Finally, you need to start the client
• Start the client by selecting Client - StartClient - StartClient - Start
Trang 17Great Events of the Twentieth Century13
Trang 18CHAPTER 2:Getting Started
And if you look at the Simulation Console, you can see both the client and server devices, and the connection between them
Trang 19Great Events of the Twentieth Century15
15
Run the Echo demo application - J2ME
Launch the server application:
• Run the MIDP Echo MIDP Echo MIDP Echo application
• Select ServerServerServer to start the server application
Trang 20CHAPTER 2:Getting Started
If you check the Simulation Console, this should also be updated as in the figure below - the device Device1 Device1 Device1 appears in the simulated network display and the list of active devices, and a new tab representing Device 1Device 1Device 1 has been added to the console
Once you have started the server, the next step is to run the Echo client:
• Run the MIDP EchoMIDP EchoMIDP Echo application
• Select ClientClientClient to start the client application
The client will search for, and then connect to, the server The Echo client and server will then exchange data
The client GUI is updated to show the transfer of information between the client and the server Notice that the server GUI is also updated
The client device appears in the Simulation Console as Device2Device2Device2 along with the server device, and the link between them is represented graphically as a line between the
devices, as shown in the second diagram below
Trang 21Great Events of the Twentieth Century17
17
Trang 22CHAPTER 2:Getting Started
Trang 23Great Events of the Twentieth Century19
• A simulation co-ordinator which manages active devices and routes communications between devices in the simulated network
• The Bluetooth Simulation Console, which monitors events and allows dynamic update
of device characteristics
When you run an application, you specify the device characteristics you would like the application to use The simulator creates the appropriate virtual device, and the Bluetooth Simulation Console is updated to show the currently active devices Each active device can
be selected and its characteristics viewed and updated dynamically
Java applications that conform to the JABWT standard will not require any code changes to use this simulated environment You simply need to set one or more system properties to allow an application to access its own simulated device
The Simulation Console also includes a logging mechanism that allows you to activate logging for specific devices and filter logged events
This chapter explains how to do the following:
Overview
Trang 24CHAPTER 3:Using the Simulator
• Create Bluetooth device descriptions using the Simulation Console
• Use the Simulation Console to monitor sessions and dynamically update device
characteristics
• Use the Simulation Console to activate security for a device and perform device
authentication
• Activate logging and event filtering
In order to run applications in the simulated environment, you must first define the
characteristics of the devices that will be used by your applications The Bluetooth
Simulation Console allows you to create new devices and edit existing devices The
characteristics of each device are stored in individual XML configuration files in the
Simulator configuration directory This directory is located by default in {simulator_home}/config
Device Maintenance Commands
You can find the device maintenance commands in the Simulation Console’s FileFileFile menu (Since we will not be using them, the Network and Service Views have been turned off in the screenshots which follow This is achieved by unchecking the ViewsViewsViews menu item under the ConfigureConfigureConfigure menu.)
Device Maintenance
Trang 25Great Events of the Twentieth Century21
Friendly Name to be used by this device This is a user-friendly name mapped to the Bluetooth address that can be used to identify your device
You check the box labelled ConnectableConnectableConnectable if the device is to be connectable If this box is unchecked then no device will be able to connect to this device This flag should always be set for servers
Trang 26CHAPTER 3:Using the Simulator
Device Classes
You can specify your device’s major device class - for example, whether it is a computer, a phone, or an audiovisual device - by right clicking the default option MiscellaneousMiscellaneousMiscellaneous and selecting from the drop-down list
Trang 27Great Events of the Twentieth Century23
Trang 28CHAPTER 3:Using the Simulator
Trang 29Great Events of the Twentieth Century25
25
Service Class
You can provide Service Class Service Class Service Class information for your device by selecting checkboxes in the Service Class panel A service class indicates the type of service that your device can provide - for instance, a device that offers a printing service would have the service class Rendering
Rendering A device that offers multiple types of service can have multiple service classes You can find out more about device and service classes in this guide’s Device Discovery and Creating Services chapters, and in the Bluetooth Assigned Numbers document (http://www.bluetooth.org/assigned-numbers/baseband.htm)
Discovery Mode
If you right-click on Not discoverableNot discoverableNot discoverable, the options for Discovery Mode are displayed in a drop-down menu The Device Discovery and Security and the Bluetooth Control Center chapters in this guide provide more details about these options Most applications will use the General DiscoverableGeneral DiscoverableGeneral Discoverable option
Trang 30CHAPTER 3:Using the Simulator
Trang 31Great Events of the Twentieth Century27
27
Security Mode
A device can be in one of three security modes:
• It will never initiate security procedures
• It will always initiate security procedures
• It will not initiate security procedures until a connection to a service is attempted.The last mode means that individual services on the device can specify their own security requirements for each opened connection It is the most common of the three in the real-world
The BCC is used to define overall security settings for a device, and deals with application security requests See the Bluetooth Control Centre chapter for more information
Trang 32CHAPTER 3:Using the Simulator
Trang 33Great Events of the Twentieth Century29
29
Saving the details
Before you save the details for your new device, you can specify other devices as known, such that your device can communicate with them without having to attempt discovery Pre-known devices are retrieved using JABWT APIs as given in the Bluetooth Control Center chapter
pre-To assign pre-known devices to your device, you click Pre-knownPre-knownPre-known
You are then prompted to provide the Bluetooth address and a label for any device you want to be pre-known by your device This label is normally the friendly name of the device
You save all the details for your new device by selecting Save Changes.Save Changes
The simulator saves the device details in an xml file in {simulator_home}/config using the friendly name you have supplied, for example the details of a device with the friendly name foo will be saved in foo.xml
Trang 34CHAPTER 3:Using the Simulator
A Bluetooth Java application that conforms to the JABWT standard should run within the simulator without any code changes However, you must set one or more system
properties to allow the application to interact with the simulator
You must specify an impronto.localdevice.friendlyname property for your
application - this property is used to link the application to a simulated device As indicated above, the value of this property should be the name of the XML file used to save the characteristics of your chosen device You can do this as a command line parameter when running the application, as in the following example:
java -Dimpronto.localdevice.friendlyname=foo MyClass
If you’re writing a J2SE application, you can do this in your code before calling any JABWT Running applications
Trang 35Great Events of the Twentieth Century31
Suppose that you have already set up your development environment and run the Echo server with the friendly name foofoofoo, as illustrated in the Getting Started chapter The
Simulation Console’s display indicates the presence of the server device in the simulated network, using its friendly name foofoofoo
Using The Simulation Console
Trang 36CHAPTER 3:Using the Simulator
To dynamically update the device foo foo foo using the Simulation Console, you first select the device using the foofoofoo tab at the top of the right pane of the Console
The characteristics of the device are displayed in the right hand pane of the device under the appropriate tab
Alternatively, you can click on the graphical representation of the device to select it, or select it from the list of devices displayed in the bottom left pane of the console
Trang 37Great Events of the Twentieth Century33
33
Now you can use the right-hand pane to update the device’s attributes - for instance, you can select another class in the device serviceClass serviceClass serviceClass list You then click Apply ChangesApply ChangesApply Changes This update to the device foofoofoo will be propagated to all other devices that perform a device inquiry in the simulated network Note that your changes will not be reflected in the
underlying configuration file for the device, unless you explicitly save the settings using File - Save Device
File - Save Device or by clicking Yes Yes Yes in the Save Modified DeviceSave Modified DeviceSave Modified Device dialog
Trang 38CHAPTER 3:Using the Simulator
Now let’s start the Echo client, using the friendly name barbarbar and selecting the server on foofoofoo,
as you did in the Getting Started chapter As you can see, the simulated network display is updated to show the device bar bar bar and its connection to the server device foofoofoo
You can display the status of a connection by double-clicking on the line connecting the client and server devices in the display A protocol-specific window appears that displays the current status of the connection The figure below shows the L2CAP protocol status window for the running Echo demo
Trang 39Great Events of the Twentieth Century35
Bonding is a process whereby two devices generate a shared link key This shared key can subsequently be used for authentication and encryption in a situation where security is called for
Link Security
Trang 40CHAPTER 3:Using the Simulator
To view any devices bonded with your device, you click the PeersPeersPeers button at the bottom of the Simulator Console This button only becomes active once you are running devices on the simulator
At present your device is not bonded with any devices, as shown in the figure below
You can add a new bonded device by clicking the AddAddAdd button
A dialog box displays that lists all discovered devices You can select any discovered device
as a peer