|
Compression
|
|
|
Note that the following is done at object creation to ensure proper formatting:
private final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
TNCparser()
{
dfs.setDecimalSeparator('.');
dfs.setZeroDigit('0');
}
This code converts compressed format to standard format.
protected String convertCompressed(String theString, Report theReport)
{
// theString is the compressed part of the packet
if (!theReport.toField.startsWith("AP"))
return "NOTVALIDPACKET"; // Will cause lat parse to bomb
// Parse Icon for later adjustment
char symID = theString.charAt(0);
// Adjust the icon for plain text
if ((symID >= 'a') && (symID <= 'j')) symID = (char)(symID - 49);
char symCode = theString.charAt(9);
// Compute lat/long
Double lat = new Double(90.0-((((((((theString.charAt(1)-33)*91.0)+(theString.charAt(2)-33))*91.0)+(theString.charAt(3)-33))*91.0)+(theString.charAt(4)-33))/380926.0));
Double longitude = new Double(-180.0+((((((((theString.charAt(5)-33)*91.0)+(theString.charAt(6)-33))*91.0)+(theString.charAt(7)-33))*91.0)+(theString.charAt(8)-33))/190463.0));
// Compute course/speed bytes
String cs = "";
if (theString.charAt(10) == ' ')
{
if (symCode == '_' || symCode == 'W')
cs = "000/000"; // Compressed Weather Report
}
else
{
// c/s represents something
if (((theString.charAt(12) - 33) & 0x18) == 0x10)
{
theReport.reportType = "GGA";
theReport.altitude = (int)Math.round(Math.pow(1.002,(theString.charAt(10)-33)*91+(theString.charAt(11)-33)));
}
else if (theString.charAt(10) == '{')
{
// Radio Range
DecimalFormat df = new DecimalFormat("0000", dfs);
cs = "RNG" + df.format(2.0*Math.pow(1.08,theString.charAt(11)-33));
}
else
{
// Course/Speed
DecimalFormat df = new DecimalFormat("000", dfs);
// Compressed speed is in Knots
cs = df.format((theString.charAt(10)-33)*4);
if (cs.equals("000")) cs = "360";
cs += "/" + df.format(Math.pow(1.08,theString.charAt(11)-33)-1.0);
}
if (((theString.charAt(12)-33) & 0x18) == 0x18)
theReport.reportType = "RMC";
else if (((theString.charAt(12)-33) & 0x18) == 0x08)
theReport.reportType = "GLL";
}
// Create the strings for replacing the compressed info
DecimalFormat latf = new DecimalFormat("00", dfs);
DecimalFormat longf = new DecimalFormat("000", dfs);
DecimalFormat minf = new DecimalFormat("00.00", dfs);
String lats = latf.format(Math.abs(lat.intValue())) + minf.format(Math.abs((lat.doubleValue() - lat.intValue())*60.0));
if (lat.doubleValue() >= 0.0) lats = lats + "N";
else lats = lats + "S";
String longs = longf.format(Math.abs(longitude.intValue())) + minf.format( Math.abs((longitude.doubleValue() - longitude.intValue())*60.0));
if (longitude.doubleValue() < 0.0) longs = longs + "W";
else longs = longs + "E";
// Replaced the compressed data with plain text
if (theString.length() > 13)
cs += theString.substring(13);
return lats + symID + longs + symCode + cs;
}
|
|
APRS is a registered trademark of APRS Software and Bob Bruninga, WB4APR. Copyright ©
2005 - Peter Loveall AE5PL pete@ae5pl.net
|