From 69b21e59dda3677a641adf8edeb78e31f76d8267 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 18 Jul 2016 17:45:40 +0500 Subject: Use password for command from device attributes --- src/org/traccar/protocol/WondexProtocolEncoder.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/protocol/WondexProtocolEncoder.java') diff --git a/src/org/traccar/protocol/WondexProtocolEncoder.java b/src/org/traccar/protocol/WondexProtocolEncoder.java index 9d000d9ea..20341ae8d 100644 --- a/src/org/traccar/protocol/WondexProtocolEncoder.java +++ b/src/org/traccar/protocol/WondexProtocolEncoder.java @@ -1,15 +1,24 @@ package org.traccar.protocol; +import org.traccar.Context; import org.traccar.StringProtocolEncoder; import org.traccar.helper.Log; -import org.traccar.model.Command;; +import org.traccar.model.Command; +import org.traccar.model.Device; public class WondexProtocolEncoder extends StringProtocolEncoder { @Override protected Object encodeCommand(Command command) { - // Temporary put default password command.set(Command.KEY_DEVICE_PASSWORD, "0000"); + if (Context.getDeviceManager() != null) { + Device device = Context.getDeviceManager().getDeviceById(command.getDeviceId()); + if (device != null) { + if (device.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) { + command.set(Command.KEY_DEVICE_PASSWORD, device.getAttributes().get(Command.KEY_DEVICE_PASSWORD).toString()); + } + } + } switch (command.getType()) { case Command.TYPE_REBOOT_DEVICE: -- cgit v1.2.3 From 919329b4a96247ca52e94b028589b8556615d456 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 18 Jul 2016 20:47:03 +0500 Subject: Fix nested if --- src/org/traccar/protocol/TotemProtocolEncoder.java | 7 +++---- src/org/traccar/protocol/WondexProtocolEncoder.java | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'src/org/traccar/protocol/WondexProtocolEncoder.java') diff --git a/src/org/traccar/protocol/TotemProtocolEncoder.java b/src/org/traccar/protocol/TotemProtocolEncoder.java index 50e15075e..fb8e762c5 100644 --- a/src/org/traccar/protocol/TotemProtocolEncoder.java +++ b/src/org/traccar/protocol/TotemProtocolEncoder.java @@ -30,11 +30,10 @@ public class TotemProtocolEncoder extends StringProtocolEncoder { command.set(Command.KEY_DEVICE_PASSWORD, "000000"); if (Context.getDeviceManager() != null) { Device device = Context.getDeviceManager().getDeviceById(command.getDeviceId()); - if (device != null) { - if (device.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) { - command.set(Command.KEY_DEVICE_PASSWORD, device.getAttributes().get(Command.KEY_DEVICE_PASSWORD).toString()); + if (device != null && device.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) { + command.set(Command.KEY_DEVICE_PASSWORD, device.getAttributes() + .get(Command.KEY_DEVICE_PASSWORD).toString()); } - } } switch (command.getType()) { diff --git a/src/org/traccar/protocol/WondexProtocolEncoder.java b/src/org/traccar/protocol/WondexProtocolEncoder.java index 20341ae8d..7a323e4a8 100644 --- a/src/org/traccar/protocol/WondexProtocolEncoder.java +++ b/src/org/traccar/protocol/WondexProtocolEncoder.java @@ -13,11 +13,10 @@ public class WondexProtocolEncoder extends StringProtocolEncoder { command.set(Command.KEY_DEVICE_PASSWORD, "0000"); if (Context.getDeviceManager() != null) { Device device = Context.getDeviceManager().getDeviceById(command.getDeviceId()); - if (device != null) { - if (device.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) { - command.set(Command.KEY_DEVICE_PASSWORD, device.getAttributes().get(Command.KEY_DEVICE_PASSWORD).toString()); + if (device != null && device.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) { + command.set(Command.KEY_DEVICE_PASSWORD, device.getAttributes() + .get(Command.KEY_DEVICE_PASSWORD).toString()); } - } } switch (command.getType()) { -- cgit v1.2.3 From 53b5d27767ff03da241c21e83b2cb2e12fcda60c Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 19 Jul 2016 06:52:57 +0500 Subject: Remove unnecessary checks and use cast instead toString() --- src/org/traccar/protocol/TotemProtocolEncoder.java | 10 ++++------ src/org/traccar/protocol/WondexProtocolEncoder.java | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) (limited to 'src/org/traccar/protocol/WondexProtocolEncoder.java') diff --git a/src/org/traccar/protocol/TotemProtocolEncoder.java b/src/org/traccar/protocol/TotemProtocolEncoder.java index fb8e762c5..1c870f63c 100644 --- a/src/org/traccar/protocol/TotemProtocolEncoder.java +++ b/src/org/traccar/protocol/TotemProtocolEncoder.java @@ -28,12 +28,10 @@ public class TotemProtocolEncoder extends StringProtocolEncoder { protected Object encodeCommand(Command command) { command.set(Command.KEY_DEVICE_PASSWORD, "000000"); - if (Context.getDeviceManager() != null) { - Device device = Context.getDeviceManager().getDeviceById(command.getDeviceId()); - if (device != null && device.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) { - command.set(Command.KEY_DEVICE_PASSWORD, device.getAttributes() - .get(Command.KEY_DEVICE_PASSWORD).toString()); - } + Device device = Context.getIdentityManager().getDeviceById(command.getDeviceId()); + if (device.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) { + command.set(Command.KEY_DEVICE_PASSWORD, (String) device.getAttributes() + .get(Command.KEY_DEVICE_PASSWORD)); } switch (command.getType()) { diff --git a/src/org/traccar/protocol/WondexProtocolEncoder.java b/src/org/traccar/protocol/WondexProtocolEncoder.java index 7a323e4a8..568ca6aa0 100644 --- a/src/org/traccar/protocol/WondexProtocolEncoder.java +++ b/src/org/traccar/protocol/WondexProtocolEncoder.java @@ -11,12 +11,10 @@ public class WondexProtocolEncoder extends StringProtocolEncoder { protected Object encodeCommand(Command command) { command.set(Command.KEY_DEVICE_PASSWORD, "0000"); - if (Context.getDeviceManager() != null) { - Device device = Context.getDeviceManager().getDeviceById(command.getDeviceId()); - if (device != null && device.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) { - command.set(Command.KEY_DEVICE_PASSWORD, device.getAttributes() - .get(Command.KEY_DEVICE_PASSWORD).toString()); - } + Device device = Context.getIdentityManager().getDeviceById(command.getDeviceId()); + if (device.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) { + command.set(Command.KEY_DEVICE_PASSWORD, (String) device.getAttributes() + .get(Command.KEY_DEVICE_PASSWORD)); } switch (command.getType()) { -- cgit v1.2.3