/** * Convert a Measurement to a SimpleVehicleMessage and send it through the * active VehicleInterface. * * @param message The desired message to send to the vehicle. * @return true if the message was sent successfully on an interface. */ public boolean send(Measurement message) { return send(message.toVehicleMessage()); }
mVehicleManager.removeListener(Latitude.class, this); mVehicleManager.removeListener(Longitude.class, this); mVehicleManager.removeListener(VehicleSpeed.class, this); } else { Log.d(TAG, "Enabled overwriting native GPS with OpenXC GPS"); mVehicleManager.addListener(Latitude.class, this); mVehicleManager.addListener(Longitude.class, this); mVehicleManager.addListener(VehicleSpeed.class, this);
/** * Change the active vehicle interface to a new type using its default * resource identifier. * * To disable all vehicle interfaces, pass null to this function. * * @param vehicleInterfaceType the VI type to activate or null to disable * all VIs. */ public void setVehicleInterface( Class<? extends VehicleInterface> vehicleInterfaceType) throws VehicleServiceException { setVehicleInterface(vehicleInterfaceType, null); }
public void stop() { if(mVehicleManager != null) { mVehicleManager.removeListener(Latitude.class, this); mVehicleManager.removeListener(Longitude.class, this); mVehicleManager.removeListener(VehicleSpeed.class, this); } if(mLocationManager != null && mLocationManager.getProvider( VEHICLE_LOCATION_PROVIDER) != null) { mLocationManager.removeTestProvider(VEHICLE_LOCATION_PROVIDER); } }
public void onServiceConnected(ComponentName className, IBinder service) { Log.i(TAG, "Bound to VehicleManager"); mVehicleManager = ((VehicleManager.VehicleBinder)service ).getService(); mVehicleManager.addListener(SimpleVehicleMessage.class, mListener); mVehicleManager.addListener(EventedSimpleVehicleMessage.class, mListener); }
if(enabled) { try { getVehicleManager().setVehicleInterface(null); } catch(VehicleServiceException e) { Log.e(TAG, "Unable to remove existing vehicle interface"); return; getVehicleManager().addSource(mTraceSource); } else { Log.d(TAG, "Trace file + " + traceFile + " already playing");
/** * Send a message to the VehicleInterface and wait up to 2 seconds to * receive a response. * * This is a blocking version of the other request(...) method. * * @return The response if one is received before the timeout, otherwise * null. */ public VehicleMessage request(KeyedMessage message) { BlockingMessageListener callback = new BlockingMessageListener(); request(message, callback); return callback.waitForResponse(); }
mVehicleManager.addOnVehicleInterfaceConnectedListener( mConnectionListener); } catch (VehicleServiceException e) { if (mVehicleManager.isViConnected()) { updateViInfo();
private void setFileRecordingStatus(boolean enabled) { Log.i(TAG, "Setting recording to " + enabled); if(enabled) { String directory = getPreferenceString(R.string.recording_directory_key); if(directory != null) { if(mFileRecorder == null || !mCurrentDirectory.equals(directory)) { mCurrentDirectory = directory; stopRecording(); mFileRecorder = new FileRecorderSink( new AndroidFileOpener(directory)); getVehicleManager().addSink(mFileRecorder); } } else { Log.d(TAG, "No recording base directory set (" + directory + "), not starting recorder"); } } else { stopRecording(); } }
mVehicleManager.addOnVehicleInterfaceConnectedListener( mConnectionListener); } catch (VehicleServiceException e) {
@Before public void setup() { manager = new VehicleManager(); }
private synchronized void setPhoneSensorSourceStatus(boolean enabled) { Log.i(TAG, "Setting phone source setting to " + enabled); if(enabled) { if(mPhoneSensorSource == null) { stopSensorCapture(); try { mPhoneSensorSource = new PhoneSensorSource( getContext()); } catch(Exception e) { Log.w(TAG, "Unable to start Phone Sensor Source", e); return; } getVehicleManager().addSource(mPhoneSensorSource); } else { Log.d(TAG, "Phone Sensor already activated"); } } else { stopSensorCapture(); } }
/** * Unregister a previously registered keyed message listener. * * @param message The message with the key this listener was previously * registered to receive. * @param listener The listener to remove. */ public void removeListener(KeyedMessage message, VehicleMessage.Listener listener) { removeListener(message.getKey(), listener); }
/** * Register to receive a callback when a message with the given key is * received. * * @param key The key you want to receive updates. * @param listener An listener instance to receive the callback. */ public void addListener(MessageKey key, VehicleMessage.Listener listener) { addListener(ExactKeyMatcher.buildExactMatcher(key), listener); }
/** * Send a command request to the vehicle that does not require any metadata. * * @param type The command request type to send to the VI. * @return The message returned by the VI in response to this command or * null if none was received. */ public String requestCommandMessage(CommandType type) { VehicleMessage message = request(new Command(type)); String value = null; if(message != null) { // Because we use the same key and value for commands and command // responses, if for some reason a Command is echoed back to the // device instead of a CommandResponse, you could get a casting // exception when trying to cast this message here. If we got a // Command, just ignore it and assume no response - I wasn't able to // reproduce it but we did have a few Bugsnag reports about it. try { CommandResponse response = message.asCommandResponse(); if(response.getStatus()) { value = response.getMessage(); } } catch(ClassCastException e) { Log.w(TAG, "Expected a command response but got " + message + " -- ignoring, assuming no response"); } } return value; }
private void setUploadingStatus(boolean enabled) { Log.i(TAG, "Setting uploading to " + enabled); if(enabled) { String path = getPreferenceString(R.string.uploading_path_key); if(!UploaderSink.validatePath(path)) { String error = "Target URL in preferences not valid " + "-- not starting uploading a trace"; Log.w(TAG, error); SharedPreferences.Editor editor = getPreferences().edit(); editor.putBoolean(getString(R.string.uploading_checkbox_key), false); editor.commit(); } else { if(mUploader != null) { stopUploading(); } try { mUploader = new UploaderSink(getContext(), path); } catch(DataSinkException e) { Log.w(TAG, "Unable to add uploader sink", e); return; } getVehicleManager().addSink(mUploader); } } else { stopUploading(); } }
private void onSendDiagnosticRequest(Spinner busSpinner, EditText idView, EditText modeView, EditText pidView) { boolean validInput = true; if(idView.getText().toString().isEmpty()) { idView.setError("ID is required"); validInput = false; } if(modeView.getText().toString().isEmpty()) { modeView.setError("Mode is required"); validInput = false; } if(validInput) { DiagnosticRequest request = new DiagnosticRequest( Integer.valueOf(busSpinner.getSelectedItem().toString()), Integer.valueOf(idView.getText().toString(), 16), Integer.valueOf(modeView.getText().toString(), 16)); // Make sure to update after sending so the timestamp is set by the // VehicleManager String pidString = pidView.getText().toString(); if(!pidString.isEmpty()) { request.setPid(Integer.valueOf(pidString, 16)); } mVehicleManager.send(request); // Make sure to update after sending so the timestamp is set by the // VehicleManager updateLastRequestView(request); } else { Log.i(TAG, "Form is invalid, not sending diagnostic request"); } }
private synchronized void setUsbStatus(boolean enabled) { if(enabled) { Log.i(TAG, "Enabling the USB vehicle interface"); try { getVehicleManager().setVehicleInterface( UsbVehicleInterface.class); } catch(VehicleServiceException e) { Log.e(TAG, "Unable to add USB interface"); } } } }
/** * Unregister a previously registered key listener. * * @param key The key this listener was previously registered to * receive updates on. * @param listener The listener to remove. */ public void removeListener(MessageKey key, VehicleMessage.Listener listener) { removeListener(ExactKeyMatcher.buildExactMatcher(key), listener); }
public void onServiceConnected(ComponentName className, IBinder service) { Log.i(TAG, "Bound to VehicleManager"); mVehicleManager = ((VehicleManager.VehicleBinder)service ).getService(); mVehicleManager.addListener(DiagnosticResponse.class, mListener); }