aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-01-09 11:34:42 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-01-09 11:34:42 +1300
commit663231ec30ed41d60ef352e89ea61e9eb2b735c2 (patch)
treeea32f4b350bc7497bc738d2bb00b476423472efb /src
parentbc8a449d384506eac902b76870d7b565f96c05e6 (diff)
downloadtrackermap-server-663231ec30ed41d60ef352e89ea61e9eb2b735c2.tar.gz
trackermap-server-663231ec30ed41d60ef352e89ea61e9eb2b735c2.tar.bz2
trackermap-server-663231ec30ed41d60ef352e89ea61e9eb2b735c2.zip
Merge AutoFon and AutoFon45 protocols
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/protocol/AutoFon45FrameDecoder.java60
-rw-r--r--src/org/traccar/protocol/AutoFon45Protocol.java42
-rw-r--r--src/org/traccar/protocol/AutoFon45ProtocolDecoder.java130
-rw-r--r--src/org/traccar/protocol/AutoFonFrameDecoder.java19
-rw-r--r--src/org/traccar/protocol/AutoFonProtocolDecoder.java71
5 files changed, 81 insertions, 241 deletions
diff --git a/src/org/traccar/protocol/AutoFon45FrameDecoder.java b/src/org/traccar/protocol/AutoFon45FrameDecoder.java
deleted file mode 100644
index f382f4784..000000000
--- a/src/org/traccar/protocol/AutoFon45FrameDecoder.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2015 Vitaly Litvak (vitavaque@gmail.com)
- *
- * 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 AutoFon45FrameDecoder extends FrameDecoder {
-
- static final int MSG_LOGIN = 0x41;
- static final int MSG_LOCATION = 0x02;
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
-
- // Check minimum length
- if (buf.readableBytes() < 12) {
- return null;
- }
-
- int length;
- switch (buf.getUnsignedByte(buf.readerIndex())) {
- case MSG_LOGIN:
- length = 19;
- break;
- case MSG_LOCATION:
- length = 34;
- break;
- default:
- length = 0;
- break;
- }
-
- // Check length and return buffer
- if (length != 0 && buf.readableBytes() >= length) {
- return buf.readBytes(length);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/AutoFon45Protocol.java b/src/org/traccar/protocol/AutoFon45Protocol.java
deleted file mode 100644
index cceb3e476..000000000
--- a/src/org/traccar/protocol/AutoFon45Protocol.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2015 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.
- * 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 AutoFon45Protocol extends BaseProtocol {
-
- public AutoFon45Protocol() {
- super("autofon45");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new AutoFon45FrameDecoder());
- pipeline.addLast("objectDecoder", new AutoFon45ProtocolDecoder(AutoFon45Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java b/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java
deleted file mode 100644
index ad3097a68..000000000
--- a/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
- * Copyright 2015 Vitaly Litvak (vitavaque@gmail.com)
- *
- * 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 java.net.SocketAddress;
-import java.util.Arrays;
-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.helper.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-import static org.traccar.protocol.AutoFon45FrameDecoder.MSG_LOCATION;
-import static org.traccar.protocol.AutoFon45FrameDecoder.MSG_LOGIN;
-
-public class AutoFon45ProtocolDecoder extends BaseProtocolDecoder {
-
- public AutoFon45ProtocolDecoder(AutoFon45Protocol protocol) {
- super(protocol);
- }
-
- private static double convertCoordinate(short degrees, int minutes) {
- double value = degrees + BitUtil.from(minutes, 4) / 600000.0;
- if (BitUtil.check(minutes, 0)) {
- return value;
- } else {
- return -value;
- }
- }
-
- private static byte checksum(byte[] bytes, int offset, int len) {
- byte result = 0x3B;
- for (int i = offset; i < offset + len; i++) {
- result += 0x56 ^ bytes[i];
- result++;
- result ^= 0xC5 + bytes[i];
- result--;
- }
- return result;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- int type = buf.getUnsignedByte(buf.readerIndex());
-
- if (type == MSG_LOGIN) {
-
- byte[] bytes = new byte[19];
- buf.readBytes(bytes);
-
- String imei = ChannelBuffers.hexDump(ChannelBuffers.wrappedBuffer(bytes, 1, 8)).substring(1);
- if (!identify(imei, channel, remoteAddress)) {
- return null;
- }
-
- // Send response (checksum)
- if (channel != null) {
- byte[] response = "resp_crc=".getBytes("US-ASCII");
- response = Arrays.copyOf(response, response.length + 1);
- response[response.length - 1] = checksum(bytes, 0, 18);
- channel.write(ChannelBuffers.wrappedBuffer(response));
- }
-
- } else if (type == MSG_LOCATION) {
-
- buf.readUnsignedByte();
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(getDeviceId());
-
- short status = buf.readUnsignedByte();
- position.set(Event.KEY_ALARM, BitUtil.check(status, 7));
- position.set(Event.KEY_BATTERY, BitUtil.to(status, 7));
-
- buf.skipBytes(2); // remaining time
-
- position.set(Event.PREFIX_TEMP + 1, buf.readByte());
-
- buf.skipBytes(2); // timer (interval and units)
- buf.readByte(); // mode
- buf.readByte(); // gprs sending interval
-
- buf.skipBytes(6); // mcc, mnc, lac, cid
-
- int valid = buf.readUnsignedByte();
- position.setValid(BitUtil.from(valid, 6) != 0);
- position.set(Event.KEY_SATELLITES, BitUtil.from(valid, 6));
-
- int time = buf.readUnsignedMedium();
- int date = buf.readUnsignedMedium();
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(time / 10000, time / 100 % 100, time % 100)
- .setDateReverse(date / 10000, date / 100 % 100, date % 100);
- position.setTime(dateBuilder.getDate());
-
- position.setLatitude(convertCoordinate(buf.readUnsignedByte(), buf.readUnsignedMedium()));
- position.setLongitude(convertCoordinate(buf.readUnsignedByte(), buf.readUnsignedMedium()));
- position.setSpeed(buf.readUnsignedByte());
- position.setCourse(buf.readUnsignedShort());
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/AutoFonFrameDecoder.java b/src/org/traccar/protocol/AutoFonFrameDecoder.java
index 1ad9e6d3b..2c547d822 100644
--- a/src/org/traccar/protocol/AutoFonFrameDecoder.java
+++ b/src/org/traccar/protocol/AutoFonFrameDecoder.java
@@ -1,5 +1,6 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 Vitaly Litvak (vitavaque@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,10 +23,6 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder;
public class AutoFonFrameDecoder extends FrameDecoder {
- public static final int MSG_LOGIN = 0x10;
- public static final int MSG_LOCATION = 0x11;
- public static final int MSG_HISTORY = 0x12;
-
@Override
protected Object decode(
ChannelHandlerContext ctx,
@@ -39,15 +36,21 @@ public class AutoFonFrameDecoder extends FrameDecoder {
int length;
switch (buf.getUnsignedByte(buf.readerIndex())) {
- case MSG_LOGIN:
+ case AutoFonProtocolDecoder.MSG_LOGIN:
length = 12;
break;
- case MSG_LOCATION:
+ case AutoFonProtocolDecoder.MSG_LOCATION:
length = 78;
break;
- case MSG_HISTORY:
+ case AutoFonProtocolDecoder.MSG_HISTORY:
length = 257;
break;
+ case AutoFonProtocolDecoder.MSG_45_LOGIN:
+ length = 19;
+ break;
+ case AutoFonProtocolDecoder.MSG_45_LOCATION:
+ length = 34;
+ break;
default:
length = 0;
break;
diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java
index 84df09a29..07dd56ca5 100644
--- a/src/org/traccar/protocol/AutoFonProtocolDecoder.java
+++ b/src/org/traccar/protocol/AutoFonProtocolDecoder.java
@@ -1,5 +1,6 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 Vitaly Litvak (vitavaque@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +17,15 @@
package org.traccar.protocol;
import java.net.SocketAddress;
+import java.nio.charset.Charset;
+import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
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.helper.BitUtil;
import org.traccar.helper.DateBuilder;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -36,12 +40,24 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_LOCATION = 0x11;
public static final int MSG_HISTORY = 0x12;
+ public static final int MSG_45_LOGIN = 0x41;
+ public static final int MSG_45_LOCATION = 0x02;
+
private static double convertCoordinate(int raw) {
int degrees = raw / 1000000;
double minutes = (raw % 1000000) / 10000.0;
return degrees + minutes / 60;
}
+ private static double convertCoordinate(short degrees, int minutes) {
+ double value = degrees + BitUtil.from(minutes, 4) / 600000.0;
+ if (BitUtil.check(minutes, 0)) {
+ return value;
+ } else {
+ return -value;
+ }
+ }
+
private Position decodePosition(ChannelBuffer buf, boolean history) {
Position position = new Position();
@@ -134,6 +150,59 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder {
return positions;
+ } else if (type == MSG_45_LOGIN) {
+
+ String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
+ if (!identify(imei, channel, remoteAddress)) {
+ return null;
+ }
+
+ if (channel != null) {
+ ChannelBuffer response = ChannelBuffers.dynamicBuffer();
+ response.writeBytes("resp_crc=".getBytes(Charset.defaultCharset()));
+ response.writeByte(buf.getByte(buf.writerIndex() - 1));
+ channel.write(response);
+ }
+
+ } else if (type == MSG_45_LOCATION) {
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(getDeviceId());
+
+ short status = buf.readUnsignedByte();
+ position.set(Event.KEY_ALARM, BitUtil.check(status, 7));
+ position.set(Event.KEY_BATTERY, BitUtil.to(status, 7));
+
+ buf.skipBytes(2); // remaining time
+
+ position.set(Event.PREFIX_TEMP + 1, buf.readByte());
+
+ buf.skipBytes(2); // timer (interval and units)
+ buf.readByte(); // mode
+ buf.readByte(); // gprs sending interval
+
+ buf.skipBytes(6); // mcc, mnc, lac, cid
+
+ int valid = buf.readUnsignedByte();
+ position.setValid(BitUtil.from(valid, 6) != 0);
+ position.set(Event.KEY_SATELLITES, BitUtil.from(valid, 6));
+
+ int time = buf.readUnsignedMedium();
+ int date = buf.readUnsignedMedium();
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setTime(time / 10000, time / 100 % 100, time % 100)
+ .setDateReverse(date / 10000, date / 100 % 100, date % 100);
+ position.setTime(dateBuilder.getDate());
+
+ position.setLatitude(convertCoordinate(buf.readUnsignedByte(), buf.readUnsignedMedium()));
+ position.setLongitude(convertCoordinate(buf.readUnsignedByte(), buf.readUnsignedMedium()));
+ position.setSpeed(buf.readUnsignedByte());
+ position.setCourse(buf.readUnsignedShort());
+
+ return position;
+
}
return null;