|
The GPS accessory HGE-100 for Sony Ericsson mobile phones can easily be accessed from a Java MIDlet. This document describes the steps necessary to retrieve data sent from HGE-100 via JCOM. Data is encoded in NMEA messages and must be parsed accordingly. Included is an example implementation showing how to encapsulate communication and parse NMEA GPS messages.
Download example MIDlet>>
Establish connection When the GPS is connected (HGE-100 switch is set to GPS or GPS+PHF) a virtual serial channel is created, this channel is visible to the MIDlet as a com port named "AT5" and uses a 9600 baud rate.
To connect to the port: |
 |
CommConnection cc = (CommConnection)Connector.open("comm:AT5;baudrate=9600");
Get the streams:
InputStream in = cc.openInputStream();
OutputStream out = cc.openOutputStream();
Data flow control
There are two basic commands to control the data flow from HGE-100, $STA and $STO. To initiate the flow of data from HGE-100, the string $STA is sent. To stop the flow, send $STO.
String strSta = "$STA\r\n";
String strSta = "$STO\r\n";
out.write(strSta.getBytes()); // Tell HGE-100 to start transmitting NMEA data
out.write(strSto.getBytes()); // Tell HGE-100 to stop transmitting NMEA data
Receiving data from HGE-100
Once the connection is open, the streams are open and the data flow has been set up as above data can be read as below:
byte[] dataBuffer = new byte[BUFFER_SIZE];
int read = -1;
try {
while (active) {
//Read raw data
read = iStream.read(dataBuffer, 0, BUFFER_SIZE);
//Parse the raw data
parseData(dataBuffer, read);
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
}
}
} catch (IOException e) {
}
HGE-100 sends four NMEA messages as ASCII strings once every second. For details see the protocol specification for NMEA 0183.
The following messages are sent from HGE-100:
- RMC, Recommended Minimum message.
- GGA, Essential Fix data.
- GSA, GPS DOP and active satellites.
- GSV, Satellites in View.
A general NMEA message
The NMEA Data is encoded as an ASCII string containing comma separated words like the example below. The start of the string is always a dollar sign ($) and the end is an asterisk (*). Trailing is a checksum and carriage return and newline.
Example:
$GPGSA,A,2,29,19,28,,,,,,,,,,23.4,12.1,20.0*0F\r\n
Broken down in tokens:
(1) A dollar sign ($ = 0x24)
(2) Command word
(3) Delimiter (, = 0x2C)
(4) Data, delimiter, data, etc...
(5) An asterisk (* = 0x2A)
(6) A checksum
(7) Carriage return (\r = 0x0D)
(8) Newline (\n = 0x0A)
To simplify the implementation we just skip the checksum and parse data when successfully reaching the asterisk. A normal implementation would verify the checksum before accepting the data.
Parsing NMEA messages from HGE-100
The different messages are broken down as follows:
GPRMC Data are 10 words:
(1) Command word (GPRMC)
(2) Satellite-Derived Time ("HHMMSS.XXX", H=hour, M=minute, S=second, x=ms)
(3) Satellite Fix Status (A=active, V=invalid)
(4) Latitude Decimal Degrees ("HHMM.M", H=hour, M=minute)
(5) Latitude Hemisphere (N=north, S=south of equator)
(6) Longitude Decimal Degrees ("HHMM.M", H=hour, M=minute)
(7) Longitude Hemisphere (E=east, W=west of the Prime Meridian)
(8) Speed (knots)
(9) Bearing (direction of travel measured as an "azimuth")
(10) UTC Date ("DDMMYY", D=day, M=month, Y=year)
GPGGA Data are 15 words:
(1) Command word (GPGGA)
(2) Satellite-Derived Time ("HHMMSS.XXX", H=hour, M=minute, S=second, x=ms)
(3) Latitude Decimal Degrees ("HHMM.M", H=hour, M=minute)
(4) Latitude Hemisphere (N=north, S=south of equator)
(5) Longitude Decimal Degrees ("HHMM.M", H=hour, M=minute)
(6) Longitude Hemisphere (E=east, W=west of the Prime Meridian)
(7) GPS fix quality (0=invalid, 1=GPS fix, 2=DGPS fix)
(8) Number of satellites
(9) Horizontal Dilution of Precision (HDOP)
(10) Altitude in decimal value
(11) Altitude unit (M=meter)
(12) Height of geoid above WGS84 ellipsoid
(13) Height of geoid unit (M=meter)
(14) Age of Differential GPS data (seconds)
(15) Differential reference station ID
GPGSA Data are 17 words:
(1) Mode set (M=Manual forced to operate in 2D or 3D, A=Automatic 3D/2D)
(2) Mode running (1=Fix not available, 2=2D, 3=3D)
(3-14) IDs of satellites used in position fix
(15) PDOP
(16) HDOP
(17) VDOP
GPGSV Data are 19 words:
(1) Total number of messages of this type in this cycle
(2) Message number
(3) Total number of SVs in view
(4) SV PRN number
(5) Elevation in degrees, 90 maximum
(6) Azimuth, degrees from true north, 000 to 359
(7) SNR, 00-99 dB (null when not tracking)
(8-11) Information about second SV, same as field 4-7
(12-15) Information about third SV, same as field 4-7
(16-19) Information about fourth SV, same as field 4-7
The attached example shows how to open a communication channel to HGE-100. When connected the accessory is configured to send GPS data. The example shows how to parse this data easily. All communication and parsing is encapsulated in an easily extendable API. The example application also shows how this API might be used.
More information: