From 946ea72000eec3a1c38856e5649372d1ee7dd2b0 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 11 Jul 2016 16:15:02 +1200 Subject: Change command sending logic --- src/org/traccar/BaseProtocol.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/org/traccar/BaseProtocol.java') diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java index f968e81cc..352895629 100644 --- a/src/org/traccar/BaseProtocol.java +++ b/src/org/traccar/BaseProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,7 +52,9 @@ public abstract class BaseProtocol implements Protocol { @Override public void sendCommand(ActiveDevice activeDevice, Command command) { - if (command.getType().equals(Command.TYPE_CUSTOM)) { + if (supportedCommands.contains(command.getType())) { + activeDevice.write(command); + } else if (command.getType().equals(Command.TYPE_CUSTOM)) { String data = (String) command.getAttributes().get(Command.KEY_DATA); if (activeDevice.getChannel().getPipeline().get(StringEncoder.class) != null) { activeDevice.write(data); @@ -60,11 +62,7 @@ public abstract class BaseProtocol implements Protocol { activeDevice.write(ChannelBuffers.wrappedBuffer(DatatypeConverter.parseHexBinary(data))); } } else { - if (!supportedCommands.contains(command.getType())) { - throw new RuntimeException("Command " - + command.getType() + " is not supported in protocol " + getName()); - } - activeDevice.write(command); + throw new RuntimeException("Command " + command.getType() + " is not supported in protocol " + getName()); } } -- cgit v1.2.3