aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/At2000FrameDecoder.java57
-rw-r--r--src/org/traccar/protocol/At2000Protocol.java42
-rw-r--r--src/org/traccar/protocol/At2000ProtocolDecoder.java134
-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/Tk103ProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/WatchProtocolEncoder.java4
14 files changed, 251 insertions, 18 deletions
diff --git a/src/org/traccar/protocol/At2000FrameDecoder.java b/src/org/traccar/protocol/At2000FrameDecoder.java
new file mode 100644
index 000000000..d0be3f5f4
--- /dev/null
+++ b/src/org/traccar/protocol/At2000FrameDecoder.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.protocol;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.handler.codec.frame.FrameDecoder;
+
+public class At2000FrameDecoder extends FrameDecoder {
+
+ private static final int BLOCK_LENGTH = 16;
+
+ private boolean firstPacket = true;
+
+ @Override
+ protected Object decode(
+ ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
+
+ if (buf.readableBytes() < 5) {
+ return null;
+ }
+
+ int length;
+ if (firstPacket) {
+ firstPacket = false;
+ length = buf.getUnsignedMedium(buf.readerIndex() + 2);
+ } else {
+ length = buf.getUnsignedMedium(buf.readerIndex() + 1);
+ }
+
+ length += BLOCK_LENGTH;
+ if (length % BLOCK_LENGTH != 0) {
+ length = (length / BLOCK_LENGTH + 1) * BLOCK_LENGTH;
+ }
+
+ if (buf.readableBytes() >= length) {
+ return buf.readBytes(length);
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/protocol/At2000Protocol.java b/src/org/traccar/protocol/At2000Protocol.java
new file mode 100644
index 000000000..418619cb4
--- /dev/null
+++ b/src/org/traccar/protocol/At2000Protocol.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.protocol;
+
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.traccar.BaseProtocol;
+import org.traccar.TrackerServer;
+
+import java.util.List;
+
+public class At2000Protocol extends BaseProtocol {
+
+ public At2000Protocol() {
+ super("at2000");
+ }
+
+ @Override
+ public void initTrackerServers(List<TrackerServer> serverList) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ @Override
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("frameDecoder", new At2000FrameDecoder());
+ pipeline.addLast("objectDecoder", new At2000ProtocolDecoder(At2000Protocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/At2000ProtocolDecoder.java b/src/org/traccar/protocol/At2000ProtocolDecoder.java
new file mode 100644
index 000000000..17da0eef7
--- /dev/null
+++ b/src/org/traccar/protocol/At2000ProtocolDecoder.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.protocol;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.jboss.netty.channel.Channel;
+import org.traccar.BaseProtocolDecoder;
+import org.traccar.DeviceSession;
+import org.traccar.helper.UnitsConverter;
+import org.traccar.model.Position;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import javax.xml.bind.DatatypeConverter;
+import java.net.SocketAddress;
+import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+import java.util.Date;
+
+public class At2000ProtocolDecoder extends BaseProtocolDecoder {
+
+ private static final int BLOCK_LENGTH = 16;
+
+ public At2000ProtocolDecoder(At2000Protocol protocol) {
+ super(protocol);
+ }
+
+ public static final int MSG_ACKNOWLEDGEMENT = 0x00;
+ public static final int MSG_DEVICE_ID = 0x01;
+ public static final int MSG_TRACK_REQUEST = 0x88;
+ public static final int MSG_TRACK_RESPONSE = 0x89;
+ public static final int MSG_SESSION_END = 0x0c;
+
+ private Cipher cipher;
+
+ private static void sendResponse(Channel channel) {
+ if (channel != null) {
+ ChannelBuffer response = ChannelBuffers.directBuffer(BLOCK_LENGTH);
+ response.writeByte(MSG_ACKNOWLEDGEMENT);
+ response.writeMedium(1);
+ response.writeByte(0x00); // success
+ response.writerIndex(BLOCK_LENGTH);
+ channel.write(response);
+ }
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ ChannelBuffer buf = (ChannelBuffer) msg;
+
+ if (buf.getUnsignedByte(buf.readerIndex()) == 0x01) {
+ buf.readUnsignedByte(); // codec id
+ }
+
+ int type = buf.readUnsignedByte();
+ buf.readUnsignedMedium(); // length
+ buf.skipBytes(BLOCK_LENGTH - 1 - 3);
+
+ if (type == MSG_DEVICE_ID) {
+
+ String imei = buf.readBytes(15).toString(StandardCharsets.US_ASCII);
+ if (getDeviceSession(channel, remoteAddress, imei) != null) {
+
+ byte[] iv = new byte[BLOCK_LENGTH];
+ buf.readBytes(iv);
+ IvParameterSpec ivSpec = new IvParameterSpec(iv);
+
+ SecretKeySpec keySpec = new SecretKeySpec(
+ DatatypeConverter.parseHexBinary("000102030405060708090a0b0c0d0e0f"), "AES");
+
+ cipher = Cipher.getInstance("AES/CBC/NoPadding");
+ cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
+
+ byte[] data = new byte[BLOCK_LENGTH];
+ buf.readBytes(data);
+ cipher.update(data);
+
+ }
+
+ } else if (type == MSG_TRACK_RESPONSE) {
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ byte[] data = new byte[buf.capacity() - BLOCK_LENGTH];
+ buf.readBytes(data);
+ buf = ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, cipher.update(data));
+
+ buf.readUnsignedShort(); // index
+ buf.readUnsignedShort(); // reserved
+
+ position.setValid(true);
+
+ position.setTime(new Date(buf.readLong() * 1000));
+
+ position.setLatitude(buf.readFloat());
+ position.setLongitude(buf.readFloat());
+ position.setAltitude(buf.readFloat());
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readFloat()));
+ position.setCourse(buf.readFloat());
+
+ return position;
+
+ }
+
+ sendResponse(channel);
+
+ return null;
+ }
+
+}
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/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
index 9d04483c1..d3bc0efdc 100644
--- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -113,9 +113,11 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
String type = sentence.substring(12, 16);
if (type.equals("BP00") || type.equals("BP05")) {
String content = sentence.substring(16);
- getDeviceSession(channel, remoteAddress, content.substring(0, 15));
+ if (content.length() >= 15) {
+ getDeviceSession(channel, remoteAddress, content.substring(0, 15));
+ }
if (type.equals("BP00")) {
- channel.write("(" + id + "AP01" + content.substring(15) + ")");
+ channel.write("(" + id + "AP01HSO)");
return null;
} else if (type.equals("BP05")) {
channel.write("(" + id + "AP05)");
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) {