Introduction To GPS, Part 3
Introduction To GPS, Part 3
Table of Contents
If you're viewing this document online, you can click any of the topics below to link directly to that section.
1. Introduction.............................................................. 2
2. Global positioning applications....................................... 6
3. The "Write once, run anywhere" promise .......................... 8
4. Java programming environments.................................... 11
5. Sample Application: MIDlet........................................... 15
6. Sample application: Java in the Palm OS.......................... 20
7. Summary ................................................................ 26
Section 1. Introduction
This is the third tutorial in a three-part series on developing GPS applications with Java
technology. It's recommended that you read through the first two tutorials, Introduction
to GPS, Part 1 and Introduction to GPS, Part 2, where fundamental GPS principles are
introduced and discussed. The prerequisite tutorials demonstrate basic Java
programming skills necessary for handling GPS data. The sample applications
presented in this tutorial focus on porting these GPS applications to a Java PDA
environment.
• The imports of a MIDlet, including the appropriate packages for network connectivity
required for the sample application's GPS lookup function, are examined.
• User interface elements of the MIDlet are explained.
• The commandAction method, which handles events initiated by the user of the
MIDlet, is presented and explained.
• An HTTP network connection is initiated and processed when the "Go" button is
pressed in the MIDlet.
• The configuration of Mobile Creator is important to the successful building of the
second sample application. A screenshot depicts the settings used to construct the
sample application.
• The Mobile Creator build process is presented, including all of the steps that Mobile
Creator hides from the SuperWaba developer, making the experience of getting
started that much more palatable.
• The user interface elements of the SuperWaba application are presented and
explained.
• The AddString method, which is the primary means of user feedback in the
ibmdwgpspalm application, is examined.
• The onEvent method, which reacts to user input and drives the core functionality of
the application, is presented.
• The ProcessPort method, which handles incoming data from the GPS unit, is
examined.
• Byte stream: Data sent from one device to another can be characterized as a stream
of individual bytes.
• DataInputStream: An implementation of the DataInput interface and an extension of
the InputStream class. The unique characteristic of the DataInputStream is its ability
to read Java native data types directly from a stream.
• Query: A very generic term used to represent a request or question originating from
a "client" application and responded to or answered by a server or service.
• HTTP: Hypertext Transport Protocol
• eCOS: The embedded Configurable Operating System, an open-source, real-time
operating system managed by RedHat, the distributor of a popular release of Linux.
• Eclipse: A comprehensive, open-source development environment.
• J2ME: Java 2 Micro Edition
Tools
This tutorial introduces a variety of software tools as viable alternatives for embedded
Java development in an effort to effectively paint the landscape of tool offerings.
Although there are many available Java development environments to choose from,
the tools chosen for use in this tutorial are the Websphere Studio Device Developer,
based on the Open Source Eclipse environment, and SuperWaba in conjunction with
Mobile Creator. Eclipse itself encompasses many technologies and is a project unto
itself. For the purposes of this tutorial, it is presented as a useful tool for managing
various build targets -- a unique aspect of wireless cross-platform development. Mobile
Creator and SuperWaba combine to be (arguably) the easiest Java development
environment for the Palm OS.
developerWorks.
• Tutorial Sample Code: The complete code to the tutorial's sample applications can
be found at: http://www.palm-communications.com/ibmdw .
The next panel examines the task of using GPS data after the technical task of
retrieving it is complete.
One viable application model combines the network connection available with modern
cell phones, the rich Java programatic environment available in the phone, and
relevant GPS data from either a built-in GPS receiver or a previously loaded store of
GPS position information. The phone may not have significant storage capabilities
when it comes to maps and images; however, it can certainly store waypoints, which
are no more resource-consuming than a telephone number. The Java environment
also provides network communication capabilities. The phone's ability to "punch-out" to
an Internet host and exchange information via HTTP presents a different, yet viable,
application model.
The next panel introduces the other focus of this tutorial -- PDA and embedded Java
programming tools and techniques for extracting GPS data in the Java environment.
• Communications
• Output technologies (video, sound, print)
• Input technologies (keyboard, pen/stylus, voice)
There are a multitude of PDA offerings in the marketplace today. Some have features
that rival low-end laptops, but the majority of PDAs and cell phones are still
resource-limited, and the expectation is that this trend will continue for some time. Until
power consumption and price-point challenges are overcome to allow high-resolution
graphics, memory capacity, and affordability (to name a few features), GPS developers
must hit the market where it currently exists.
The next section explores Java technology and the profiles that define functionality and
conformance levels
The promise
The promise of Java software development is, in short, "write once, run any (and
every) where." Originally thought to be the dragonslayer of client development woes,
Java technology has proven itself to be the most comfortable and productive on the
"back end," or "server side." For example, in the application server market (think Jboss,
WebLogic, WebSphere, iPlanet, Oracle 9i, SeeBeyond), a servlet or bean can be
developed on one platform, such as Solaris, and confidently deployed to another
platform, such as AIX. This is true because the activities of the server side application
consist of:
• Database interaction
• Fundamental "CompSci" actions such as searching and sorting
• Network communications (HTTP, Sockets, e-mail, FTP, etc.)
• Text generation (HTML, XML)
• CPU cycles
• Memory
• Network stack
These resources do not have the same device-specific limitations and constraints
found in client-side applications discussed in the previous section such as display,
sound, and data input mechanisms. It is precisely these resource challenges and the
quest to categorize what variety of application should be expected to run on a particular
device that lead to the topic of the next panel -- configurations and profiles.
Profile proliferation
JVMs can be found on everything from smart cards and chips up to the largest of
environments, such as the OS/390 from IBM. Can a smart card be expected to drive a
windowed terminal via the Abstract Windowing Toolkit? Of course not, as there is no
windowed terminal to drive. Nor can the JVM on a large supercomputer be outfitted
with the hooks and connectivity required for something such as I2C communication,
found at the board level of embedded designs. Obviously, each of the platforms
encompassed in this diverse spectrum has differing capabilities and priorities. This
diversity in JVM functionality requires a means to manage device design,
programming, and application expectations.
software vendors, and other parties with a vested interest in the shaping of a given
profile. There are many profiles available in the wireless marketplace including the
IrDA.org's specifications, Bluetooth's application profiles, and of course, the profiles of
primary interest to Java developers: the profiles governing the features and functions of
a particular Java environment.
The next panel introduces the Java 2 Micro Edition (J2ME) configurations and profiles
with relevance to mobile Java development and, as such, of importance to GPS
application development.
• Connected Device Configuration (CDC): The CDC is seen as the first step "down"
from the full J2SE specification. It is designed for devices with ample resources such
as memory and processor capabilities. It also defines networking functionality for
conforming devices and applications. This configuration is meant for applications
such as kiosks and similar dedicated-function applications.
• Connected Limited Device Configuration (CDLC). The CLDC is aimed at devices
with significant restrictions on memory, power, and connectivity. CLDC devices
include cell phones, pagers, and low-powered PDAs.
The next panel examines the bare minimum requirements for Java GPS applications
on a MIDP/CLDC-compliant device as well as a Palm OS device in particular, which
straddles the configurations in terms of capability and available offerings.
Minimum requirements
The minimum requirements for this tutorial's PDA/Gadget GPS applications fall into two
categories:
Cross-platform strategies
Nearly all embedded Java development occurs in a cross-platform manner, meaning
that the actual compilation and linking phases of the development cycle occur on a host
environment that differs from the target deployment platform. For example, when
developing the code for the sample applications, all development occurs on a Windows
or Linux machine, as opposed to a cell phone or Palm OS device. This strategy of
course is nothing new to developers with experience in the wireless or "handheld"
space; this practice has been the norm for decades now.
The next four panels explore a few of the available Palm/Java development
environments.
Commercial offerings
Despite its large open source following, there are indeed commercial Java products
available from organizations eager to capitalize on the demand for quality,
high-performance software based on Java technologies. With Nokia and other
manufacturers planning to push millions of Java-enabled devices onto the market over
the next few years, Java vendors are vying for pole position. Each offering attempts to
capitalize upon a distinct selling feature that sets their product apart from the
competition. Until hardware capabilities in small spaces make these optimizations
unnecessary, these companies will continue to argue that their brand of bread is sliced
better than the next. Following is a small sampling of the major players, along with their
unique selling propositions:
• The Jbed offering boasts a variety of features including on-device code compiler for
dynamic compilation, native code compilation target, and a Windows-based IDE for
application development. Jbed also makes a real-time version of its environment
available for various platforms. (See Tutorial resources on page 26 for a link.)
• Simplicity for Palm OS Platform from Data Representations (see Tutorial resources
on page 26 for a link) leverages IBM's J9 virtual machine for the underlying, run-time
Java environment. Simplicity is a Rapid Application Design (RAD) tool for Java
technology. The J9 virtual machine is available on numerous platforms and is a key
While each of these commercial offerings presents one or more unique selling features,
there are Java development options available at no cost from Sun and other
companies.
J2ME
Sun provides products for both the CDC and the CDLC configurations, including
environments for PDAs such as Palm OS and WinCE. From a GPS perspective, the
MID Profile does not support serial communications but does mandate HTTP
connectivity. As such, the J2ME offering is a viable alternative for the first sample
application, which relies solely on HTTP for retrieving relevant GPS data. John
Muchow's developerWorks tutorial provides an excellent introduction to MIDlets and
the use of the J2ME. See Tutorial resources on page 26 for more information.
The next panel examines a popular open source Java development environment and
toolset known as SuperWaba.
SuperWaba
Perhaps the most popular Java option for PDA platforms is SuperWaba. This toolset
provides a Java development environment that is outside the scope of traditional J2ME
Java classes. SuperWaba provides its own virtual machine and custom class libraries.
The code that is written is Java code; however, the core classes are part of the waba
package instead of the java package. A standard Java compiler is used for
compilation of projects into Java classes and packages. The core packages available
for Waba include:
• waba.util -- This package provides useful data structures along with a Date
object, which is undoubtedly important for virtually any application.
These classes provide all of the user interface and system level functions required for
building useful applications. Additional classes and packages can be added by anyone,
as the code is, in fact, pure Java code, compiled with the J2SE's JDK itself.
For the sake of completeness, the next panel introduces an industry buzzword that
sounds like Java technology but is explicitly not Java technology.
BREW goes beyond the simple technology of what can be done and where, by
addressing some of the economic aspects to wireless development. One of the largest
impediments to wireless application, network, and device adoption is the lack of
applications. Of course, this is a bit of a chicken-and-the-egg dilemma as it helps
application developers to have a platform before investing in developing new or ported
applications. In any event, BREW aims to assist in this adoption process by making it
easier to achieve financial gain in at least two distinct manners:
1. BREW has taken carefully considered actions to ensure the validity of any
downloaded application. This is achieved through the digital signature of applications
with a trusted certificate from Verisign. Only to the degree that downloadable
applications and content can be trusted, can mobile commerce take hold.
2. BREW reaches beyond technical specifications and delivers to carriers and other
operators the tools necessary for distributing BREW applications via its BREW
distribution system. This package includes download servers, transaction managers,
and hooks for integration with operator billing systems.
The next panel summarizes this brief survey of development environments and
describes the rationale behind the choices made for construction of this tutorial's two
sample applications.
The above sections just scratch the surface of the available Java development
environments for PDAs and other "micro" environments.
Two distinct tools were chosen for use in developing the two sample applications.
These tools were chosen based on their relevant strengths to accomplish the chosen
task and their broader relevance to the marketplace and Java development community.
Unfortunately, the tools used in the sample applications of the earlier tutorials are not
readily available for the Palm OS, as the Abstract Windowing Toolkit and javax.comm
are not part of J2ME. An alternative approach is required. The classes available from
WebSphere Studio Device Developer offer a wrapper class for the entire Palm OS
system. While this "OS" class is very comprehensive and virtually any task required on
the Palm can be achieved through the use of this class, it requires an intimate
knowledge of the underlying Palm OS "C" APIs. The use of such a class flies in the
face of the original goal of this tutorial -- to port the application from the prior tutorials
into a PDA environment with as much ease as possible. Due to the simplistic nature of
the application and the availability of an easy-to-use SerialPort class, the
SuperWaba environment, in conjunction with the Mobile Creator IDE, was selected for
use in the development of the second application.
Note that the Eclipse editor displays the contents of any Java class in an outline/tree
view. The currently selected Java class is shown by default. The next two panels
examine the actual source code of the MIDlet.
User interface
The MIDlet contains only two buttons. Remember, a MIDlet is designed to run on an
ultra-limited device, such as a cell phone. Here is the code to create the primary user
interface:
/**
* @see MIDlet#startApp()
*/
This code adds two buttons to the form and then sits idly by awaiting user input at one
of the buttons. Button presses are handled by the commandAction method. Note that
the commandAction method satisfies the requirement imposed by the
CommandListener interface.
}
...
}
The next panel discusses the actual HTTP connection and the use of an InputStream
for reading purposes.
query to the remote site. The query is reduced to a simple HTTP GET operation:
Note that the entire interaction with the remote host is accomplished within a try/catch
block. Upon any error, control of the application passes to the simplistic catch block
where it simply displays an error message to the standard error device.
Note that the buttons below the display control the action. The Start button is circled in
the first image. This concludes the first sample application. The next section examines
the use of SuperWaba for reading NMEA sentences from a Garmin GPS unit.
Motivation/purpose of sample
The second sample application is a port of an application from the first tutorial and is
named ibmdwgpspalm. This application demonstrates a few basic user interface
elements as well as the ever-important serial communications required for interacting
with a serial GPS device. As mentioned earlier, this application employs the
SuperWaba development toolset along with the Mobile Creator IDE. While the source
code presented here is not a direct port of the earlier code base, the functionality is
very similar. The earlier application utilized the Abstract Windowing Toolkit, a package
that is not readily available for the PDA environment. Basic elements of the waba.ui
package are responsible for the user interface elements of this application. Also, the
lack of a suitable javax.comm implementation for Palm OS leads to the use of the
SerialPort class from the waba.io package.
The next panel walks through the installation of the required toolsets.
Getting started
The three software components required for this application are the Mobile Creator, the
SuperWaba SDK, and the latest JDK from Sun Microsystems. Tools on page 4
contains links for obtaining each of these tools. Once they have been installed, the
Mobile Creator has a simple configuration setting dialog to fill out. This configuration
tells Mobile Creator where to find the SuperWaba installation and the JDK's Java
compiler, javac.exe. Here is a screenshot demonstrating a valid configuration:
The next panel details the steps involved in the creation of a Mobile
Creator/SuperWaba application.
The next panel highlights some of the application's user interface features and
structure.
public ibmdwgpspalm()
{
setDoubleBuffer(true);
setBorderStyle(TAB_ONLY_BORDER);
setTitle("ibmdwgpspalm");
add(btnStart = new Button("Start Reading Data"),10,20);
add(lb = new ListBox(),LEFT+5,AFTER-10);
lb.setRect(1,40,158,100);
btnStart.setRect(10,20,140,15);
Settings.setPalmOSStyle(true);
}
The next panel examines the onEvent method, reacting to user input.
Handling events
Once the button is tapped, the application moves into a mode for collecting data from
the GPS unit. The following code is responsible for reacting to the button tap and
initiating the communications session with the GPS, along with some other incidental
housekeeping:
{
sp.setReadTimeout(100);
sp.setFlowControl(false);
savetimer = addTimer(500);
running = true;
btnStart.setText("Stop Reading Data");
eatchecksum = false;
}
else
{
popupModal(new MessageBox("ibmdwgpspalm","Failed to Start!"));
}
}
else
{
sp.close();
running = false;
btnStart.setText("Start Reading Data");
removeTimer(savetimer);
sb.setLength(0);
}
}
break;
case ControlEvent.TIMER:
ProcessPort();
break;
}
}
Things to note about this code include the manner in which the SerialPort instance, sp,
is created and opened, as well as the addTimer method. addTimer causes the
application to raise an event periodically -- in this case, every 500 milliseconds or one
half second. The ControlEvent.TIMER event initiates the ProcessPort method
responsible for actually interacting with the serial port. The SuperWaba SerialPort is
polled at a frequency set by the parameter passed to addTimer. This functionality
differs from the event-driven model of javax.comm employed in the earlier tutorials.
The next panel examines the ProcessPort method, responsible for retrieving
information from the GPS unit and parsing it into NMEA sentences.
Note the use of the readCheck method. This method indicates the presence of data
available for reading. The data is accumulated into the StringBuffer variable, sb. When
the full sentence is available, the toString() method of the StringBuffer returns a
String representation of the NMEA sentence. This new string is passed to the
AddString method for inclusion in the ListBox user interface element.
Section 7. Summary
Tutorial summary
This tutorial examined some of the challenges facing embedded and portable Java
developers. The available toolset offerings cover a wide-spectrum of functionalities and
techniques to get the job done; however, it is clear that the embedded Java developer
does not share the same "write once" experience of the server side Java developer.
From a GPS perspective, the basic theme of data collection holds true: The core
requirement is a valid means to share data with a serial-based device. This
requirement is not easily met with the J2ME offering, nor is it met with uniformity.
Fortunately for the GPS enthusiast without a corporate budgetary backing, there is
SuperWaba. This open source environment not only fits the bill, but it does so with
traditional Java programming techniques, keeping things simple. One of the highlights
of the second sample application is the fact that no Palm OS-specific knowledge is
imparted in the code!
This tutorial also presented an alternative to the traditional data collection means of
GPS applications by introducing a network based, MIDP applet using the WebSphere
Studio Device Developer environment. Though simplistic in nature, it is a powerful
design pattern, suitable for numerous applications, GPS and otherwise.
Regardless of the path chosen, Java technology and GPS have tremendous promise,
particularly as GPS capabilities become built-in and more common in consumer
devices and as the Java crowd thins out to expose a consensus on how to interact on
these limited resource devices.
Tutorial resources
• The http://wireless.java.sun.com/ Web site is home to the J2ME release of the Java
language from Sun Microsystems.
• http://java.sun.com/j2me/docs contains the documentation relevant to the breadth of
capable device profiles.
• This site, http://www.palm-communications.com/ibmdw , contains all of the source
code presented in this tutorial.
• John Muchow's tutorial on MIDlets provides a nice introduction to the topic of
MIDP/CLDC and MIDlet development. The tutorial may be found at:
https://www6.software.ibm.com/developerworks/education/wi-midlet/
• The http://www.redhat.com/embedded/technologies/ecos Web site is the primary
source of information pertaining to the embedded configurable operating system
(eCos).
• The http://www.eclipse.org Web site is the home of the Eclipse IDE.
• http://www.oreillynet.com/wireless/ regularly presents wireless development content,
including GPS topics.
• The PalmOS emulator may be found at: http://www.palmos.com/dev/tools/emulator
Feedback
Please send us your feedback on this tutorial. We look forward to hearing from you!
Colophon
This tutorial was written entirely in XML, using the developerWorks Toot-O-Matic tutorial
generator. The open source Toot-O-Matic tool is an XSLT stylesheet and several XSLT
extension functions that convert an XML file into a number of HTML pages, a zip file, JPEG
heading graphics, and two PDF files. Our ability to generate multiple text and binary formats
from a single source file illustrates the power and flexibility of XML. (It also saves our
production team a great deal of time and effort.)