/** * 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()); }
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 void onSendCanMessage(Spinner busSpinner, EditText idView, EditText payloadView) { boolean validInput = true; if(idView.getText().toString().isEmpty()) { idView.setError("ID is required"); validInput = false; } if(payloadView.getText().toString().isEmpty()) { payloadView.setError("Payload is required"); validInput = false; } if(payloadView.getText().toString().length() % 2 == 1) { payloadView.setError("Payload must be specified as full bytes"); validInput = false; } if(validInput) { System.out.println(payloadView.getText().toString()); CanMessage message = new CanMessage( Integer.valueOf(busSpinner.getSelectedItem().toString()), Integer.valueOf(idView.getText().toString(), 16), ByteAdapter.hexStringToByteArray(payloadView.getText().toString())); mVehicleManager.send(message); // Make sure to update after sending so the timestamp is set by the // VehicleManager mAdapter.add(message.asCanMessage()); } else { Log.i(TAG, "Form is invalid, not sending message"); } }
/** * Send a message to the VehicleInterface and register the given listener to * receive the first response matching the message's key. * * This function is non-blocking. * * The listener is unregistered after the first response is received. If you * need to accept multiple responses for the same request, you must manually * register your own listener to control its lifecycle. * * @param message The desired message to send to the vehicle. * @param listener The message listener that should receive a callback when * a response matching the outgoing message's key is received from the * VI. */ public void request(KeyedMessage message, VehicleMessage.Listener listener) { // Register the listener as non-persistent, so it is deleted after // receiving the first response mNotifier.register(ExactKeyMatcher.buildExactMatcher(message.getKey()), listener, false); send(message); }
@Test public void doesntDereferenceNullIfNotConectedToRemote() { manager.send(new VehicleMessage()); } }