@Override public String toString() { return toStringHelper(this) .add("timestamp", getTimestamp()) .add("command", getCommand()) .add("bus", getBus()) .add("enabled", isEnabled()) .add("bypass", isBypass()) .add("format", getFormat()) .add("unix_time",getUnixTime()) .add("action", getAction()) .add("diagnostic_request", getDiagnosticRequest()) .add("extras", getExtras()) .toString(); }
@Test public void keyNotNull() { assertThat(message.getKey(), notNullValue()); } }
@Override public MessageKey getKey() { if (super.getKey() == null) { HashMap<String, Object> key = new HashMap<>(); key.put(COMMAND_KEY, getCommand()); setKey(new MessageKey(key)); } return super.getKey(); }
@Test public void writeAndReadFromParcelWithDiagnostic() { message = new Command(request, action); Parcel parcel = Parcel.obtain(); message.writeToParcel(parcel, 0); // Reset parcel for reading parcel.setDataPosition(0); VehicleMessage createdFromParcel = VehicleMessage.CREATOR.createFromParcel(parcel); assertThat(createdFromParcel, instanceOf(Command.class)); assertEquals(message, createdFromParcel); }
private static BinaryMessages.DiagnosticControlCommand.Builder startSerializingDiagnosticRequest(Command message) { DiagnosticRequest diagnosticRequest = message.getDiagnosticRequest(); BinaryMessages.DiagnosticControlCommand.Builder messageBuilder = BinaryMessages.DiagnosticControlCommand.newBuilder(); if(message.hasAction()) { if(message.getAction().equals(DiagnosticRequest.ADD_ACTION_KEY)) { messageBuilder.setAction( BinaryMessages.DiagnosticControlCommand.Action.ADD); } else if(message.getAction().equals(DiagnosticRequest.CANCEL_ACTION_KEY)) { messageBuilder.setAction( BinaryMessages.DiagnosticControlCommand.Action.CANCEL);
@Test public void getCommandReturnsCommand() { assertEquals(command, message.getCommand()); }
} else if (DiagnosticResponse.containsRequiredFields(fields)) { message = sGson.fromJson(root, DiagnosticResponse.class); } else if (Command.containsRequiredFields(fields)) { message = sGson.fromJson(root, Command.class); } else if (CommandResponse.containsRequiredFields(fields)) {
CommandType commandType = message.getCommand(); if (commandType.equals(CommandType.VERSION)) { messageBuilder.setType(BinaryMessages.ControlCommand.Type.VERSION);
@Override public boolean equals(Object obj) { if (!super.equals(obj) || !(obj instanceof Command)) { return false; } final Command other = (Command) obj; return Objects.equal(getCommand(), other.getCommand()) && Objects.equal(getDiagnosticRequest(), other.getDiagnosticRequest()) && Objects.equal(getAction(), other.getAction()) && Objects.equal(getBus(), other.getBus()) && Objects.equal(isEnabled(), other.isEnabled()) && Objects.equal(isBypass(), other.isBypass()) && Objects.equal(getFormat(), other.getFormat()) && Objects.equal(getUnixTime(), other.getUnixTime()); }
@Before public void setup() { message = new Command(command); }
@Override public void writeToParcel(Parcel out, int flags) { super.writeToParcel(out, flags); out.writeSerializable(getCommand()); out.writeString(getAction()); out.writeParcelable(getDiagnosticRequest(), flags); out.writeInt(getBus()); out.writeByte((byte) (isEnabled() ? 1 : 0)); out.writeByte((byte) (isBypass() ? 1 : 0)); out.writeString(getFormat()); out.writeLong(getUnixTime()); }
switch (selectedItem) { case VERSION_POS: request = new Command(Command.CommandType.VERSION); break; request = new Command(Command.CommandType.DEVICE_ID); break; request = new Command(Command.CommandType.PLATFORM); break; enabled = Boolean.valueOf( mEnabledSpinner.getSelectedItem().toString()); request = new Command( Command.CommandType.PASSTHROUGH, selectedBus, enabled); break; bypass = Boolean.valueOf( mBypassSpinner.getSelectedItem().toString()); request = new Command(Command.CommandType.AF_BYPASS, bypass, selectedBus); break; request = new Command(format, Command.CommandType.PAYLOAD_FORMAT); break; request = new Command(Command.CommandType.RTC_CONFIGURATION, new Date().getTime()/1000L); break; request = new Command(Command.CommandType.SD_MOUNT_STATUS);
@Test public void serializeCommandUsesStringCommand() { String serialized = JsonFormatter.serialize(new Command( Command.CommandType.VERSION)); assertThat(serialized, containsString("version")); }
if(message instanceof DiagnosticRequest) { wrappedMessage = new Command(message.asDiagnosticRequest(), DiagnosticRequest.ADD_ACTION_KEY);
/** * 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; }
@Test public void sameCommandEquals() { Command anotherMessage = new Command(command); assertEquals(message, anotherMessage); }