courselog.gpsutils
Class Converters

java.lang.Object
  extended by courselog.gpsutils.Converters

public class Converters
extends java.lang.Object

Utility routines to convert values, either from NMEA, either from numeric to strings. Try to reduce memory allocation as much as possible. Try to be fast.


Field Summary
static int classCurrentFormat
          Flag indicating the format for converting speeds and distances.
static int DDMMSS_LAT
          Convert angle to a latitude string (N/S).
static int DDMMSS_LON
          Convert angle to a longitude string (E/W).
static int FORMAT_KM_M
          Option specifying units in (km/h, m).
static int FORMAT_KT_NM
          Option specifying units in (Kt, Nm).
static double KILOMETERSPERNAUTICMILES
          Number of kilometers per nautic miles
 
Constructor Summary
Converters()
           
 
Method Summary
static java.lang.String ddmmss(double ang, int flgLatLon)
          Convert an angle into a new String.
static java.lang.String formatAltitude(double alt)
          Convert an altitude in meters into a new String.
static java.lang.String formatDistance(double len)
          Format a distance value in meters into a string.
static java.lang.String formatDuration(double dur)
          Provides a new String indicating a duration in seconds.
static java.lang.String formatHeading(double hdg)
          Formats a heading into a new String.
static java.lang.String formatSpeed(double spd)
          Format a speed in km/h.
static java.lang.String formatUTC(double utc)
          Generate a new String from a double values expressed with hhmmss.ssss value into a string HH:MM:SS
static void intToHexBytes(int val, byte[] charChk, int idxChk, int len)
          Convert an int into an hexadecimal serie of char into a buffer.
static double nMEA2Deg(double nMEAVal)
          Change a double value of latitude or longitude parsed from NMEA sentence into a decimal degree value.
static void parseCSVSentence(java.lang.String code, byte[] b, int idxS, int iEnd, double[] tVal, int[] tInt, char[] tChar)
          General parser of a CSV sentence.
static int readIntFromBuffer(byte[] b, int start, int stop)
          Reads an int value from buffer b.
static int valByteHex(byte[] charChk, int idxChk, int len)
          Convert hexadecimal value of length len, starting at idxChk in buffer charChk.
static int writeDblInBuffer(byte[] b, int start, int len, int dec, double val)
          Write a double value val into buffer b.
static int writeIntInBuffer(byte[] b, int start, int len, int val)
          Write an int value val into buffer b.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KILOMETERSPERNAUTICMILES

public static final double KILOMETERSPERNAUTICMILES
Number of kilometers per nautic miles

See Also:
Constant Field Values

DDMMSS_LAT

public static final int DDMMSS_LAT
Convert angle to a latitude string (N/S). Switch value for ddmmss() method.

See Also:
ddmmss(double,int), Constant Field Values

DDMMSS_LON

public static final int DDMMSS_LON
Convert angle to a longitude string (E/W). Switch value for ddmmss() method.

See Also:
ddmmss(double,int), Constant Field Values

FORMAT_KM_M

public static final int FORMAT_KM_M
Option specifying units in (km/h, m).

See Also:
Constant Field Values

FORMAT_KT_NM

public static final int FORMAT_KT_NM
Option specifying units in (Kt, Nm).

See Also:
Constant Field Values

classCurrentFormat

public static int classCurrentFormat
Flag indicating the format for converting speeds and distances. One of FORMAT_KM_M or FORMAT_KT_NM.

Constructor Detail

Converters

public Converters()
Method Detail

valByteHex

public static int valByteHex(byte[] charChk,
                             int idxChk,
                             int len)
Convert hexadecimal value of length len, starting at idxChk in buffer charChk.

Parameters:
charChk - Buffer containing the hexadecimal value.
idxChk - Index of first character in the buffer.
len - Length of the value to convert.
Returns:
Hexadecimal value.

intToHexBytes

public static void intToHexBytes(int val,
                                 byte[] charChk,
                                 int idxChk,
                                 int len)
Convert an int into an hexadecimal serie of char into a buffer.

Parameters:
val - Value to convert.
charChk - Buffer to put the hex characters in.
idxChk - Starting index where to put the Hex characters.
len - Length of the hex string to produce.

nMEA2Deg

public static double nMEA2Deg(double nMEAVal)
Change a double value of latitude or longitude parsed from NMEA sentence into a decimal degree value. NMEA values are formatted as DDMM.MMMM.

Parameters:
nMEAVal - Degrees value from NMEA format.
Returns:
Degree values with decimal degrees.

ddmmss

public static java.lang.String ddmmss(double ang,
                                      int flgLatLon)
Convert an angle into a new String. The string is formatted into DD°MM'SS"X where X depends on the value of flag flgLatLon (latitude, longitude).

Parameters:
ang - Angle values in decimal degrees.
flgLatLon - Flag indicating wether its a latitude or a longitude.
Returns:
Formatted string.
See Also:
DDMMSS_LAT

formatUTC

public static java.lang.String formatUTC(double utc)
Generate a new String from a double values expressed with hhmmss.ssss value into a string HH:MM:SS

Parameters:
utc - Time value obtained from NMEA.
Returns:
new String HH:MM:SS (decimal of seconds are not used, not accurate.

formatDuration

public static java.lang.String formatDuration(double dur)
Provides a new String indicating a duration in seconds. Format is HHHhMM'SSS"

Parameters:
dur - Duration value in seconds.
Returns:
new String formatted.

formatAltitude

public static java.lang.String formatAltitude(double alt)
Convert an altitude in meters into a new String. Format AAAA.A m

Parameters:
alt - Altitude value in degrees.
Returns:
new String with the altitude.

formatHeading

public static java.lang.String formatHeading(double hdg)
Formats a heading into a new String. Format is HHH.H°

Parameters:
hdg - Heading value in degrees.
Returns:
New String formatted.

formatDistance

public static java.lang.String formatDistance(double len)
Format a distance value in meters into a string. Format is DDD.DDD km.

Parameters:
len - Distance to format in meters.
Returns:
New formatted string.

formatSpeed

public static java.lang.String formatSpeed(double spd)
Format a speed in km/h. New String format is VVV.V km/h .

Parameters:
spd - Speed value in km/h.
Returns:
New formatted String.

writeIntInBuffer

public static int writeIntInBuffer(byte[] b,
                                   int start,
                                   int len,
                                   int val)
Write an int value val into buffer b. Characters start at start with the sign character or a blank. Length of the int is len with initial '0' if needed.

Parameters:
b - Buffer to put value in.
start - Start index in buffer (sign or blank).
len - Length (number of digits excluding sign).
val - Value to put in the buffer.
Returns:
index right after the last formatted character.

readIntFromBuffer

public static int readIntFromBuffer(byte[] b,
                                    int start,
                                    int stop)
Reads an int value from buffer b. Characters start at start with the sign character or leading blanks. The int should stop at stop index. Returns 0 if no valid value was read (be careful, also returns 0 if this was 0!)

Parameters:
b - Buffer to put value in.
start - Start index in buffer (sign or blank).
stop - Index of the position where conversion stops.
Returns:
integer value that was read.

writeDblInBuffer

public static int writeDblInBuffer(byte[] b,
                                   int start,
                                   int len,
                                   int dec,
                                   double val)
Write a double value val into buffer b. Characters start at start with the sign character or a blank. Length of the integer part is len-dec-1 with initial '0' if needed. A decimal point is put then the deciaml values with dec digits.

Parameters:
b - Buffer to put value in.
start - Start index in buffer (sign or blank).
len - Total length excluding the leading sign or blank.
dec - Number of decimals.
val - Double value to format.
Returns:
index right after the last formatted character.

parseCSVSentence

public static void parseCSVSentence(java.lang.String code,
                                    byte[] b,
                                    int idxS,
                                    int iEnd,
                                    double[] tVal,
                                    int[] tInt,
                                    char[] tChar)
General parser of a CSV sentence. Uses a serie of characters indicating how to interpret CSV data and puts values into associated vector.
'V' means a double.
 'C' means a single char.
 'I' means an integer.
Example : code of NMEA GGA sentence is "VVCVCIIVVCVCVI".
 2 first values are double (UTC and lat), then comes 'N' or 'S' indicator,
 then longitude with 'W' or 'E' then status as int, then number of satellites.
 tVal[0]=UTC, tVal[1]=Lat, tVal[2]=lon, ...
 tInt[0]=status, tInt[1]=nb sats,
 tChar[0]='N' or 'S', tChar[1]='W' or 'E', ...

Parameters:
code - Sequence if identifier to decode the sentence
b - Buffer containing data
idxS - Start of relevant data.
iEnd - End of relevant data.