aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-11-23 17:34:25 +0500
committerAbyss777 <abyss@fox5.ru>2016-11-23 17:34:25 +0500
commite89bbb8ee9dd1dd1f19fb33f1f9291c6ae5f43db (patch)
tree51376f73260c9bbc89064ba2b5f2a428b6d46785 /src/org/traccar/protocol
parentdbbe99269140f057d3f72acca557730a6b10e902 (diff)
downloadtrackermap-server-e89bbb8ee9dd1dd1f19fb33f1f9291c6ae5f43db.tar.gz
trackermap-server-e89bbb8ee9dd1dd1f19fb33f1f9291c6ae5f43db.tar.bz2
trackermap-server-e89bbb8ee9dd1dd1f19fb33f1f9291c6ae5f43db.zip
Implement attributes helpers
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/CityeasyProtocolEncoder.java4
-rw-r--r--src/org/traccar/protocol/EelinkProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolEncoder.java8
-rw-r--r--src/org/traccar/protocol/NoranProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/RuptelaProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/T800xProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/WatchProtocolEncoder.java4
10 files changed, 14 insertions, 16 deletions
diff --git a/src/org/traccar/protocol/CityeasyProtocolEncoder.java b/src/org/traccar/protocol/CityeasyProtocolEncoder.java
index 0c149c1c9..c800131d6 100644
--- a/src/org/traccar/protocol/CityeasyProtocolEncoder.java
+++ b/src/org/traccar/protocol/CityeasyProtocolEncoder.java
@@ -50,13 +50,13 @@ public class CityeasyProtocolEncoder extends BaseProtocolEncoder {
case Command.TYPE_POSITION_SINGLE:
return encodeContent(CityeasyProtocolDecoder.MSG_LOCATION_REQUEST, content);
case Command.TYPE_POSITION_PERIODIC:
- content.writeShort(((Number) command.getAttributes().get(Command.KEY_FREQUENCY)).intValue());
+ content.writeShort(command.getInteger(Command.KEY_FREQUENCY));
return encodeContent(CityeasyProtocolDecoder.MSG_LOCATION_INTERVAL, content);
case Command.TYPE_POSITION_STOP:
content.writeShort(0);
return encodeContent(CityeasyProtocolDecoder.MSG_LOCATION_INTERVAL, content);
case Command.TYPE_SET_TIMEZONE:
- int timezone = ((Number) command.getAttributes().get(Command.KEY_TIMEZONE)).intValue();
+ int timezone = command.getInteger(Command.KEY_TIMEZONE);
if (timezone < 0) {
content.writeByte(1);
} else {
diff --git a/src/org/traccar/protocol/EelinkProtocolEncoder.java b/src/org/traccar/protocol/EelinkProtocolEncoder.java
index b9d6b6f97..5a28733f7 100644
--- a/src/org/traccar/protocol/EelinkProtocolEncoder.java
+++ b/src/org/traccar/protocol/EelinkProtocolEncoder.java
@@ -47,7 +47,7 @@ public class EelinkProtocolEncoder extends BaseProtocolEncoder {
switch (command.getType()) {
case Command.TYPE_CUSTOM:
- return encodeContent((String) command.getAttributes().get(Command.KEY_DATA));
+ return encodeContent(command.getString(Command.KEY_DATA));
case Command.TYPE_ENGINE_STOP:
return encodeContent("RELAY,1#");
case Command.TYPE_ENGINE_RESUME:
diff --git a/src/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/org/traccar/protocol/Gt06ProtocolEncoder.java
index b6ec5a0d1..8e00522a7 100644
--- a/src/org/traccar/protocol/Gt06ProtocolEncoder.java
+++ b/src/org/traccar/protocol/Gt06ProtocolEncoder.java
@@ -59,7 +59,7 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder {
boolean alternative;
Device device = Context.getIdentityManager().getDeviceById(command.getDeviceId());
if (device.getAttributes().containsKey("gt06.alternative")) {
- alternative = Boolean.parseBoolean((String) device.getAttributes().get("gt06.alternative"));
+ alternative = device.getBoolean("gt06.alternative");
} else {
alternative = Context.getConfig().getBoolean("gt06.alternative");
}
diff --git a/src/org/traccar/protocol/Jt600ProtocolEncoder.java b/src/org/traccar/protocol/Jt600ProtocolEncoder.java
index 3eb0566a4..0bf389460 100644
--- a/src/org/traccar/protocol/Jt600ProtocolEncoder.java
+++ b/src/org/traccar/protocol/Jt600ProtocolEncoder.java
@@ -29,7 +29,7 @@ public class Jt600ProtocolEncoder extends StringProtocolEncoder {
case Command.TYPE_ENGINE_RESUME:
return "(S07,1)";
case Command.TYPE_SET_TIMEZONE:
- int offset = ((Number) command.getAttributes().get(Command.KEY_TIMEZONE)).intValue() / 60;
+ int offset = command.getInteger(Command.KEY_TIMEZONE) / 60;
return "(S09,1," + offset + ")";
case Command.TYPE_REBOOT_DEVICE:
return "(S17)";
diff --git a/src/org/traccar/protocol/MeiligaoProtocolEncoder.java b/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
index a91b33a60..268bae392 100644
--- a/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
+++ b/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
@@ -24,7 +24,6 @@ import org.traccar.model.Command;
import javax.xml.bind.DatatypeConverter;
import java.nio.charset.StandardCharsets;
-import java.util.Map;
public class MeiligaoProtocolEncoder extends BaseProtocolEncoder {
@@ -62,13 +61,12 @@ public class MeiligaoProtocolEncoder extends BaseProtocolEncoder {
protected Object encodeCommand(Command command) {
ChannelBuffer content = ChannelBuffers.dynamicBuffer();
- Map<String, Object> attributes = command.getAttributes();
switch (command.getType()) {
case Command.TYPE_POSITION_SINGLE:
return encodeContent(command.getDeviceId(), MSG_TRACK_ON_DEMAND, content);
case Command.TYPE_POSITION_PERIODIC:
- content.writeShort(((Number) attributes.get(Command.KEY_FREQUENCY)).intValue() / 10);
+ content.writeShort(command.getInteger(Command.KEY_FREQUENCY) / 10);
return encodeContent(command.getDeviceId(), MSG_TRACK_BY_INTERVAL, content);
case Command.TYPE_ENGINE_STOP:
content.writeByte(0x01);
@@ -77,10 +75,10 @@ public class MeiligaoProtocolEncoder extends BaseProtocolEncoder {
content.writeByte(0x00);
return encodeContent(command.getDeviceId(), MSG_OUTPUT_CONTROL, content);
case Command.TYPE_ALARM_GEOFENCE:
- content.writeShort(((Number) attributes.get(Command.KEY_RADIUS)).intValue());
+ content.writeShort(command.getInteger(Command.KEY_RADIUS));
return encodeContent(command.getDeviceId(), MSG_MOVEMENT_ALARM, content);
case Command.TYPE_SET_TIMEZONE:
- int offset = ((Number) attributes.get(Command.KEY_TIMEZONE)).intValue() / 60;
+ int offset = command.getInteger(Command.KEY_TIMEZONE) / 60;
content.writeBytes(String.valueOf(offset).getBytes(StandardCharsets.US_ASCII));
return encodeContent(command.getDeviceId(), MSG_TIME_ZONE, content);
case Command.TYPE_REBOOT_DEVICE:
diff --git a/src/org/traccar/protocol/NoranProtocolEncoder.java b/src/org/traccar/protocol/NoranProtocolEncoder.java
index 5bd069218..25b510a73 100644
--- a/src/org/traccar/protocol/NoranProtocolEncoder.java
+++ b/src/org/traccar/protocol/NoranProtocolEncoder.java
@@ -52,7 +52,7 @@ public class NoranProtocolEncoder extends BaseProtocolEncoder {
case Command.TYPE_POSITION_SINGLE:
return encodeContent("*KW,000,000,000000#");
case Command.TYPE_POSITION_PERIODIC:
- int interval = ((Number) command.getAttributes().get(Command.KEY_FREQUENCY)).intValue();
+ int interval = command.getInteger(Command.KEY_FREQUENCY);
return encodeContent("*KW,000,002,000000," + interval + "#");
case Command.TYPE_POSITION_STOP:
return encodeContent("*KW,000,002,000000,0#");
diff --git a/src/org/traccar/protocol/RuptelaProtocolEncoder.java b/src/org/traccar/protocol/RuptelaProtocolEncoder.java
index c3b3a3619..0abfa18ce 100644
--- a/src/org/traccar/protocol/RuptelaProtocolEncoder.java
+++ b/src/org/traccar/protocol/RuptelaProtocolEncoder.java
@@ -43,7 +43,7 @@ public class RuptelaProtocolEncoder extends BaseProtocolEncoder {
switch (command.getType()) {
case Command.TYPE_CUSTOM:
- return encodeContent((String) command.getAttributes().get(Command.KEY_DATA));
+ return encodeContent(command.getString(Command.KEY_DATA));
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;
diff --git a/src/org/traccar/protocol/T800xProtocolEncoder.java b/src/org/traccar/protocol/T800xProtocolEncoder.java
index 7b02ed10b..6ed5dbccd 100644
--- a/src/org/traccar/protocol/T800xProtocolEncoder.java
+++ b/src/org/traccar/protocol/T800xProtocolEncoder.java
@@ -51,7 +51,7 @@ public class T800xProtocolEncoder extends BaseProtocolEncoder {
switch (command.getType()) {
case Command.TYPE_CUSTOM:
- return encodeContent(command, (String) command.getAttributes().get(Command.KEY_DATA));
+ return encodeContent(command, command.getString(Command.KEY_DATA));
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;
diff --git a/src/org/traccar/protocol/TeltonikaProtocolEncoder.java b/src/org/traccar/protocol/TeltonikaProtocolEncoder.java
index eb83477b8..fd6eae744 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolEncoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolEncoder.java
@@ -50,7 +50,7 @@ public class TeltonikaProtocolEncoder extends BaseProtocolEncoder {
switch (command.getType()) {
case Command.TYPE_CUSTOM:
- return encodeContent((String) command.getAttributes().get(Command.KEY_DATA));
+ return encodeContent(command.getString(Command.KEY_DATA));
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;
diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java
index f15c0f0c0..0b6a83ce9 100644
--- a/src/org/traccar/protocol/WatchProtocolEncoder.java
+++ b/src/org/traccar/protocol/WatchProtocolEncoder.java
@@ -33,7 +33,7 @@ public class WatchProtocolEncoder extends StringProtocolEncoder {
}
private int getEnableFlag(Command command) {
- if ((Boolean) command.getAttributes().get(Command.KEY_ENABLE)) {
+ if (command.getBoolean(Command.KEY_ENABLE)) {
return 1;
} else {
return 0;
@@ -51,7 +51,7 @@ public class WatchProtocolEncoder extends StringProtocolEncoder {
}
private String getBinaryData(Command command) {
- byte[] data = DatatypeConverter.parseHexBinary((String) command.getAttributes().get(Command.KEY_DATA));
+ byte[] data = DatatypeConverter.parseHexBinary(command.getString(Command.KEY_DATA));
int encodedLength = data.length;
for (byte b : data) {