aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/BaseProtocolEncoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/BaseProtocolEncoder.java')
-rw-r--r--src/org/traccar/BaseProtocolEncoder.java15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/org/traccar/BaseProtocolEncoder.java b/src/org/traccar/BaseProtocolEncoder.java
index 050697801..2bf6cde66 100644
--- a/src/org/traccar/BaseProtocolEncoder.java
+++ b/src/org/traccar/BaseProtocolEncoder.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.
@@ -20,6 +20,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
import org.traccar.helper.Log;
import org.traccar.model.Command;
+import org.traccar.model.Device;
public abstract class BaseProtocolEncoder extends OneToOneEncoder {
@@ -27,6 +28,18 @@ public abstract class BaseProtocolEncoder extends OneToOneEncoder {
return Context.getIdentityManager().getDeviceById(deviceId).getUniqueId();
}
+ protected void initDevicePassword(Command command, String defaultPassword) {
+ if (!command.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) {
+ Device device = Context.getIdentityManager().getDeviceById(command.getDeviceId());
+ if (device.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) {
+ String password = (String) device.getAttributes().get(Command.KEY_DEVICE_PASSWORD);
+ command.set(Command.KEY_DEVICE_PASSWORD, password);
+ } else {
+ command.set(Command.KEY_DEVICE_PASSWORD, defaultPassword);
+ }
+ }
+ }
+
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {