Remove extended client protocol

Этот коммит содержится в:
Anton Tananaev
2015-08-12 20:06:18 +12:00
родитель c008c5f65e
Коммит d49bc6ad28
15 изменённых файлов: 11 добавлений и 60 удалений
-2
Просмотреть файл
@@ -37,7 +37,6 @@ public class MainActivity extends PreferenceActivity implements OnSharedPreferen
public static final String KEY_PORT = "port";
public static final String KEY_INTERVAL = "interval";
public static final String KEY_PROVIDER = "provider";
public static final String KEY_EXTENDED = "extended";
public static final String KEY_STATUS = "status";
@Override
@@ -70,7 +69,6 @@ public class MainActivity extends PreferenceActivity implements OnSharedPreferen
preferenceScreen.findPreference(KEY_PORT).setEnabled(enabled);
preferenceScreen.findPreference(KEY_INTERVAL).setEnabled(enabled);
preferenceScreen.findPreference(KEY_PROVIDER).setEnabled(enabled);
preferenceScreen.findPreference(KEY_EXTENDED).setEnabled(enabled);
}
@Override
+10 -23
Просмотреть файл
@@ -63,35 +63,22 @@ public class ProtocolFormatter {
/**
* Format location message
*/
public static String createLocationMessage(boolean extended, Location l, double battery) {
StringBuilder s = new StringBuilder(extended ? "$TRCCR," : "$GPRMC,");
public static String createLocationMessage(Location l, double battery) {
StringBuilder s = new StringBuilder("$GPRMC,");
Formatter f = new Formatter(s, Locale.ENGLISH);
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ENGLISH);
calendar.setTimeInMillis(l.getTime());
if (extended) {
f.format("%1$tH%1$tM%1$tS.%1$tL,A,", calendar);
f.format("%1$tY%1$tm%1$td%1$tH%1$tM%1$tS.%1$tL,A,", calendar);
double lat = l.getLatitude();
double lon = l.getLongitude();
f.format("%02d%07.4f,%c,", (int) Math.abs(lat), Math.abs(lat) % 1 * 60, lat < 0 ? 'S' : 'N');
f.format("%03d%07.4f,%c,", (int) Math.abs(lon), Math.abs(lon) % 1 * 60, lon < 0 ? 'W' : 'E');
f.format("%.6f,%.6f,", l.getLatitude(), l.getLongitude());
f.format("%.2f,%.2f,", l.getSpeed() * 1.943844, l.getBearing());
f.format("%.2f,", l.getAltitude());
f.format("%.0f,", battery);
} else {
f.format("%1$tH%1$tM%1$tS.%1$tL,A,", calendar);
double lat = l.getLatitude();
double lon = l.getLongitude();
f.format("%02d%07.4f,%c,", (int) Math.abs(lat), Math.abs(lat) % 1 * 60, lat < 0 ? 'S' : 'N');
f.format("%03d%07.4f,%c,", (int) Math.abs(lon), Math.abs(lon) % 1 * 60, lon < 0 ? 'W' : 'E');
double speed = l.getSpeed() * 1.943844; // speed in knots
f.format("%.2f,%.2f,", speed, l.getBearing());
f.format("%1$td%1$tm%1$ty,,", calendar);
}
double speed = l.getSpeed() * 1.943844; // speed in knots
f.format("%.2f,%.2f,", speed, l.getBearing());
f.format("%1$td%1$tm%1$ty,,", calendar);
byte checksum = 0;
for (byte b : s.substring(1).getBytes()) {
+1 -3
Просмотреть файл
@@ -40,7 +40,6 @@ public class TrackingService extends Service implements PositionProvider.Positio
private int port;
private int interval;
private String provider;
private boolean extended;
private ClientController clientController;
private PositionProvider positionProvider;
@@ -63,7 +62,6 @@ public class TrackingService extends Service implements PositionProvider.Positio
provider = sharedPreferences.getString(MainActivity.KEY_PROVIDER, null);
port = Integer.valueOf(sharedPreferences.getString(MainActivity.KEY_PORT, null));
interval = Integer.valueOf(sharedPreferences.getString(MainActivity.KEY_INTERVAL, null));
extended = sharedPreferences.getBoolean(MainActivity.KEY_EXTENDED, false);
} catch (Exception error) {
Log.w(LOG_TAG, error);
}
@@ -99,7 +97,7 @@ public class TrackingService extends Service implements PositionProvider.Positio
public void onPositionUpdate(Position position) {
if (position != null) {
StatusActivity.addMessage(getString(R.string.status_location_update));
clientController.setNewLocation(ProtocolFormatter.createLocationMessage(extended, position.location, 0));
clientController.setNewLocation(ProtocolFormatter.createLocationMessage(position.location, 0));
}
}