check usb data for validity
@@ -363,6 +363,7 @@ public abstract class CameraActivity extends AppCompatActivity
// Data has the following form: voltage, lWheel, rWheel, obstacle
sendVehicleDataToSensorService(timestamp, data);
String[] itemList = data.split(",");
+ if (itemList.length == 4) {
vehicle.setBatteryVoltage(Float.parseFloat(itemList[0]));
vehicle.setLeftWheelTicks(Float.parseFloat(itemList[1]));
vehicle.setRightWheelTicks(Float.parseFloat(itemList[2]));
@@ -380,6 +381,10 @@ public abstract class CameraActivity extends AppCompatActivity
sonarTextView.setText(
String.format(Locale.US, "%3.0f cm", vehicle.getSonarReading()));
});
+ }
+ else {
+ Toast.makeText(context, "Skipping bad USB data, next update in 1s.", Toast.LENGTH_SHORT).show();
+ }
break;
}
}
