aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
authorRafael Guterres <guterresrafael@gmail.com>2015-11-21 02:13:24 -0200
committerRafael Guterres <guterresrafael@gmail.com>2015-11-21 02:13:24 -0200
commit77cd23da84ebebcf99a97a8aef88aa9a4884ca40 (patch)
treef95fa042b4755e925be8d0c8416fcb648ea23aa3 /src/org/traccar/protocol
parentf5a266953e53a7f1785bcb584759582621ec9de3 (diff)
parent7623704e12a3e60420c86add5cfdc18b14061752 (diff)
downloadtraccar-server-77cd23da84ebebcf99a97a8aef88aa9a4884ca40.tar.gz
traccar-server-77cd23da84ebebcf99a97a8aef88aa9a4884ca40.tar.bz2
traccar-server-77cd23da84ebebcf99a97a8aef88aa9a4884ca40.zip
Merge tananaev/master
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/EelinkProtocolDecoder.java5
-rw-r--r--src/org/traccar/protocol/FlextrackProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/Gl200ProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java36
-rw-r--r--src/org/traccar/protocol/Gt02ProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/HuabaoProtocolDecoder.java113
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolDecoder.java9
-rw-r--r--src/org/traccar/protocol/MegastekProtocolDecoder.java28
-rw-r--r--src/org/traccar/protocol/MeiligaoFrameDecoder.java4
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolDecoder.java10
-rw-r--r--src/org/traccar/protocol/SuntechProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/T800xProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java36
-rw-r--r--src/org/traccar/protocol/Tlt2hProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/TotemProtocolDecoder.java21
-rw-r--r--src/org/traccar/protocol/WatchProtocolDecoder.java8
17 files changed, 254 insertions, 56 deletions
diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java
index b3a062db3..b75587743 100644
--- a/src/org/traccar/protocol/EelinkProtocolDecoder.java
+++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java
@@ -86,7 +86,10 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
position.setCourse(buf.readUnsignedShort());
- position.set(Event.KEY_CID, ChannelBuffers.hexDump(buf.readBytes(9)));
+ position.set(Event.KEY_MCC, buf.readUnsignedShort());
+ position.set(Event.KEY_MNC, buf.readUnsignedShort());
+ position.set(Event.KEY_LAC, buf.readUnsignedShort());
+ position.set(Event.KEY_CID, buf.readUnsignedShort());
position.setValid((buf.readUnsignedByte() & 0x01) != 0);
diff --git a/src/org/traccar/protocol/FlextrackProtocolDecoder.java b/src/org/traccar/protocol/FlextrackProtocolDecoder.java
index 363d5502c..bc9825b49 100644
--- a/src/org/traccar/protocol/FlextrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/FlextrackProtocolDecoder.java
@@ -125,8 +125,8 @@ public class FlextrackProtocolDecoder extends BaseProtocolDecoder {
position.setAltitude(parser.nextInt());
position.set(Event.KEY_HDOP, parser.nextInt() * 0.1);
- position.set(Event.KEY_CID, parser.next());
- position.set(Event.KEY_LAC, parser.next());
+ position.set(Event.KEY_CID, parser.nextInt(16));
+ position.set(Event.KEY_LAC, parser.nextInt(16));
position.set(Event.KEY_ODOMETER, parser.nextInt());
return position;
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
index 29884bb00..42786d4fe 100644
--- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
@@ -116,7 +116,9 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
.text(",")
.number("(0ddd)?,") // mcc
.number("(0ddd)?,") // mnc
- .number("(xxxx|x{8})?,") // loc
+ .number("(?:xxxx)?")
+ .number("(xxxx)").optional(2) // lac
+ .text(",")
.number("(xxxx)?,") // cell
.groupBegin()
.number("(d+.d)?,") // odometer
@@ -215,10 +217,12 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
getLastLocation(position, null);
}
- position.set(Event.KEY_MCC, parser.next());
- position.set(Event.KEY_MNC, parser.next());
- position.set(Event.KEY_LAC, parser.next());
- position.set(Event.KEY_CID, parser.next());
+ if (parser.hasNext(4)) {
+ position.set(Event.KEY_MCC, parser.nextInt());
+ position.set(Event.KEY_MNC, parser.nextInt());
+ position.set(Event.KEY_LAC, parser.nextInt(16));
+ position.set(Event.KEY_CID, parser.nextInt(16));
+ }
position.set(Event.KEY_ODOMETER, parser.next());
position.set(Event.KEY_BATTERY, parser.next());
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
index aa693f42e..a91848f5b 100644
--- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
@@ -63,6 +63,17 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
+ private static final Pattern PATTERN_NETWORK = new PatternBuilder()
+ .text("imei:")
+ .number("(d+),") // imei
+ .expression("[^,]+,") // alarm
+ .number("d+,,")
+ .text("L,,,")
+ .number("(x+),,") // lac
+ .number("(x+),,,") // cid
+ .any()
+ .compile();
+
private static final Pattern PATTERN_HANDSHAKE = new PatternBuilder()
.number("##,imei:(d+),A")
.compile();
@@ -93,14 +104,31 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Parser parser = new Parser(PATTERN, sentence);
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+
+ Parser parser = new Parser(PATTERN_NETWORK, sentence);
+ if (parser.matches()) {
+
+ if (!identify(parser.next(), channel, remoteAddress)) {
+ return null;
+ }
+ position.setDeviceId(getDeviceId());
+
+ getLastLocation(position, null);
+
+ position.set(Event.KEY_LAC, parser.nextInt(16));
+ position.set(Event.KEY_CID, parser.nextInt(16));
+
+ return position;
+
+ }
+
+ parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
String imei = parser.next();
if (!identify(imei, channel, remoteAddress)) {
return null;
diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
index d15d999cf..53739ee1c 100644
--- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
@@ -100,6 +100,10 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
position.setLatitude(latitude);
position.setLongitude(longitude);
+ } else {
+
+ return null;
+
}
return position;
diff --git a/src/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/org/traccar/protocol/HuabaoProtocolDecoder.java
index 931f985a5..792c89c8b 100644
--- a/src/org/traccar/protocol/HuabaoProtocolDecoder.java
+++ b/src/org/traccar/protocol/HuabaoProtocolDecoder.java
@@ -16,10 +16,20 @@
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.helper.BitUtil;
+import org.traccar.helper.ChannelBufferTools;
+import org.traccar.helper.Checksum;
+import org.traccar.helper.DateBuilder;
+import org.traccar.helper.UnitsConverter;
+import org.traccar.model.Event;
+import org.traccar.model.Position;
import java.net.SocketAddress;
+import java.nio.charset.Charset;
+import java.util.TimeZone;
public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
@@ -27,7 +37,38 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
+ public static final int MSG_GENERAL_RESPONSE = 0x8001;
public static final int MSG_TERMINAL_REGISTER = 0x0100;
+ public static final int MSG_TERMINAL_REGISTER_RESPONSE = 0x8100;
+ public static final int MSG_TERMINAL_AUTH = 0x0102;
+ public static final int MSG_LOCATION_REPORT = 0x0200;
+
+ public static final int RESULT_SUCCESS = 0;
+
+ private void sendResponse(
+ Channel channel, SocketAddress remoteAddress, int type, ChannelBuffer id, ChannelBuffer data) {
+ ChannelBuffer response = ChannelBuffers.dynamicBuffer();
+ response.writeByte(0x7e);
+ response.writeShort(type);
+ response.writeShort(data.readableBytes());
+ response.writeBytes(id);
+ response.writeShort(1); // index
+ response.writeBytes(data);
+ response.writeByte(Checksum.xor(response.toByteBuffer(1, response.readableBytes() - 1)));
+ response.writeByte(0x7e);
+ if (channel != null) {
+ channel.write(response, remoteAddress);
+ }
+ }
+
+ private void sendGeneralResponse(
+ Channel channel, SocketAddress remoteAddress, ChannelBuffer id, int type, int index) {
+ ChannelBuffer response = ChannelBuffers.dynamicBuffer();
+ response.writeShort(index);
+ response.writeShort(type);
+ response.writeByte(RESULT_SUCCESS);
+ sendResponse(channel, remoteAddress, MSG_GENERAL_RESPONSE, id, response);
+ }
@Override
protected Object decode(
@@ -36,10 +77,74 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
ChannelBuffer buf = (ChannelBuffer) msg;
buf.readUnsignedByte(); // start marker
- //int type = buf.readUnsignedShort();
- //int flags = buf.readUnsignedShort();
- buf.skipBytes(6); // phone number
- buf.readUnsignedShort(); // index
+ int type = buf.readUnsignedShort();
+ buf.readUnsignedShort(); // body length
+ ChannelBuffer id = buf.readBytes(6); // phone number
+ int index = buf.readUnsignedShort();
+
+ if (!identify(id.toString(Charset.defaultCharset()), channel, remoteAddress)) {
+ return null;
+ }
+
+ if (type == MSG_TERMINAL_REGISTER) {
+
+ ChannelBuffer response = ChannelBuffers.dynamicBuffer();
+ response.writeShort(index);
+ response.writeByte(RESULT_SUCCESS);
+ response.writeBytes("authentication".getBytes(Charset.defaultCharset()));
+ sendResponse(channel, remoteAddress, MSG_TERMINAL_REGISTER_RESPONSE, id, response);
+
+ } else if (type == MSG_TERMINAL_AUTH) {
+
+ sendGeneralResponse(channel, remoteAddress, id, type, index);
+
+ } else if (type == MSG_LOCATION_REPORT) {
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(getDeviceId());
+
+ position.set(Event.KEY_ALARM, buf.readUnsignedInt());
+
+ int flags = buf.readInt();
+
+ position.set(Event.KEY_IGNITION, BitUtil.check(flags, 0));
+
+ position.setValid(BitUtil.check(flags, 1));
+
+ double lat = buf.readUnsignedInt() * 0.000001;
+ double lon = buf.readUnsignedInt() * 0.000001;
+
+ if (BitUtil.check(flags, 2)) {
+ position.setLatitude(-lat);
+ } else {
+ position.setLatitude(lat);
+ }
+
+ if (BitUtil.check(flags, 3)) {
+ position.setLongitude(-lon);
+ } else {
+ position.setLongitude(lon);
+ }
+
+ position.setAltitude(buf.readShort());
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort() * 0.1));
+ position.setCourse(buf.readUnsignedShort());
+
+ DateBuilder dateBuilder = new DateBuilder(TimeZone.getTimeZone("GMT+8"))
+ .setYear(ChannelBufferTools.readHexInteger(buf, 2))
+ .setMonth(ChannelBufferTools.readHexInteger(buf, 2))
+ .setDay(ChannelBufferTools.readHexInteger(buf, 2))
+ .setHour(ChannelBufferTools.readHexInteger(buf, 2))
+ .setMinute(ChannelBufferTools.readHexInteger(buf, 2))
+ .setSecond(ChannelBufferTools.readHexInteger(buf, 2));
+ position.setTime(dateBuilder.getDate());
+
+ // additional information
+
+ return position;
+
+ }
return null;
}
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
index d9e31fe48..b576b063d 100644
--- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
@@ -94,8 +94,13 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
position.setAltitude(buf.readUnsignedShort());
- position.set(Event.KEY_CID, buf.readUnsignedShort());
- position.set(Event.KEY_LAC, buf.readUnsignedShort());
+ int cid = buf.readUnsignedShort();
+ int lac = buf.readUnsignedShort();
+ if (cid != 0 && lac != 0) {
+ position.set(Event.KEY_CID, cid);
+ position.set(Event.KEY_LAC, lac);
+ }
+
position.set(Event.KEY_GSM, buf.readUnsignedByte());
} else if (version == 2) {
diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java
index a58e57703..dc9e6056e 100644
--- a/src/org/traccar/protocol/MegastekProtocolDecoder.java
+++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java
@@ -53,14 +53,16 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
.number("(d)?,") // charger
.number("(d+)?,") // mcc
.number("(d+)?,") // mnc
- .number("(xxxx,xxxx);") // location code
+ .number("(xxxx),") // lac
+ .number("(xxxx);") // cid
.any() // checksum
.compile();
private static final Pattern PATTERN_ALTERNATIVE = new PatternBuilder()
.number("(d+),") // mcc
.number("(d+),") // mnc
- .number("(xxxx,xxxx),") // location code
+ .number("(xxxx),") // lac
+ .number("(xxxx),") // cid
.number("(d+),") // gsm signal
.number("(d+),") // battery
.number("(d+),") // flags
@@ -171,9 +173,12 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
position.set(Event.KEY_CHARGE, Integer.parseInt(charger) == 1);
}
- position.set(Event.KEY_MCC, parser.next());
- position.set(Event.KEY_MNC, parser.next());
- position.set(Event.KEY_LAC, parser.next());
+ if (parser.hasNext(3)) {
+ position.set(Event.KEY_MCC, parser.nextInt());
+ position.set(Event.KEY_MNC, parser.nextInt());
+ position.set(Event.KEY_LAC, parser.nextInt(16));
+ position.set(Event.KEY_CID, parser.nextInt(16));
+ }
} else {
@@ -194,9 +199,10 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
}
position.setDeviceId(getDeviceId());
- position.set(Event.KEY_MCC, parser.next());
- position.set(Event.KEY_MNC, parser.next());
- position.set(Event.KEY_LAC, parser.next());
+ position.set(Event.KEY_MCC, parser.nextInt());
+ position.set(Event.KEY_MNC, parser.nextInt());
+ position.set(Event.KEY_LAC, parser.nextInt(16));
+ position.set(Event.KEY_CID, parser.nextInt(16));
position.set(Event.KEY_GSM, parser.next());
position.set(Event.KEY_BATTERY, Double.parseDouble(parser.next()));
@@ -236,7 +242,8 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
.number("(d+.d+),") // odometer
.number("(d+),") // mcc
.number("(d+),") // mnc
- .number("(xxxx,xxxx),") // cell
+ .number("(xxxx),") // lac
+ .number("(xxxx),") // cid
.number("(d+)?,") // gsm
.expression("([01]+),") // input
.expression("([01]+),") // output
@@ -295,7 +302,8 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
position.set(Event.KEY_ODOMETER, parser.nextDouble());
position.set(Event.KEY_MCC, parser.nextInt());
position.set(Event.KEY_MNC, parser.nextInt());
- position.set(Event.KEY_CID, parser.next());
+ position.set(Event.KEY_LAC, parser.nextInt(16));
+ position.set(Event.KEY_CID, parser.nextInt(16));
String gsm = parser.next();
if (gsm != null) {
diff --git a/src/org/traccar/protocol/MeiligaoFrameDecoder.java b/src/org/traccar/protocol/MeiligaoFrameDecoder.java
index 6dcc6fd9c..9fb530f8a 100644
--- a/src/org/traccar/protocol/MeiligaoFrameDecoder.java
+++ b/src/org/traccar/protocol/MeiligaoFrameDecoder.java
@@ -26,9 +26,7 @@ public class MeiligaoFrameDecoder extends FrameDecoder {
@Override
protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
+ ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
// Strip not '$' (0x24) bytes from the beginning
while (buf.readable() && buf.getUnsignedByte(buf.readerIndex()) != 0x24) {
diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
index 2b8460fc7..4bde5cf75 100644
--- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
@@ -119,10 +119,10 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
position.set(Event.KEY_ODOMETER, parser.next());
position.set("runtime", parser.next());
- position.set(Event.KEY_MCC, parser.next());
- position.set(Event.KEY_MCC, parser.next());
- position.set(Event.KEY_LAC, parser.next());
- position.set(Event.KEY_CID, parser.next());
+ position.set(Event.KEY_MCC, parser.nextInt());
+ position.set(Event.KEY_MNC, parser.nextInt());
+ position.set(Event.KEY_LAC, parser.nextInt(16));
+ position.set(Event.KEY_CID, parser.nextInt(16));
position.set(Event.KEY_STATUS, parser.next());
for (int i = 1; i <= 3; i++) {
@@ -196,7 +196,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
position.set(Event.KEY_ODOMETER, buf.readUnsignedInt());
position.set("runtime", buf.readUnsignedInt());
position.set(Event.KEY_MCC, buf.readUnsignedShort());
- position.set(Event.KEY_MCC, buf.readUnsignedShort());
+ position.set(Event.KEY_MNC, buf.readUnsignedShort());
position.set(Event.KEY_LAC, buf.readUnsignedShort());
position.set(Event.KEY_CID, buf.readUnsignedShort());
position.set(Event.KEY_STATUS, buf.readUnsignedShort());
diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java
index b0d85b101..38f771eec 100644
--- a/src/org/traccar/protocol/SuntechProtocolDecoder.java
+++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java
@@ -83,7 +83,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
.setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
position.setTime(dateBuilder.getDate());
- position.set(Event.KEY_CID, parser.next());
+ parser.next(); // location code + bsic
position.setValid(true);
position.setLatitude(parser.nextDouble());
diff --git a/src/org/traccar/protocol/T800xProtocolDecoder.java b/src/org/traccar/protocol/T800xProtocolDecoder.java
index 2127be331..83d815e0f 100644
--- a/src/org/traccar/protocol/T800xProtocolDecoder.java
+++ b/src/org/traccar/protocol/T800xProtocolDecoder.java
@@ -143,10 +143,14 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
getLastLocation(position, dateBuilder.getDate());
- position.set(Event.KEY_MCC, buf.readUnsignedShort());
- position.set(Event.KEY_MNC, buf.readUnsignedShort());
- position.set(Event.KEY_LAC, buf.readUnsignedShort());
- position.set(Event.KEY_CID, buf.readUnsignedShort());
+ byte[] array = new byte[16];
+ buf.readBytes(array);
+ ChannelBuffer swapped = ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, array);
+
+ position.set(Event.KEY_MCC, swapped.readUnsignedShort());
+ position.set(Event.KEY_MNC, swapped.readUnsignedShort());
+ position.set(Event.KEY_LAC, swapped.readUnsignedShort());
+ position.set(Event.KEY_CID, swapped.readUnsignedShort());
// two more cell towers
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
index 3592cae79..2217b5ce4 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -114,7 +114,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
}
if (BitUtil.check(locationMask, 5)) {
- position.set("area", buf.readUnsignedShort());
+ position.set(Event.KEY_LAC, buf.readUnsignedShort());
position.set(Event.KEY_CID, buf.readUnsignedShort());
}
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
index 95728c447..6fa4edb06 100644
--- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -64,6 +64,16 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
.number("d+") // installed
.compile();
+ private static final Pattern PATTERN_NETWORK = new PatternBuilder()
+ .number("(d{12})") // device id
+ .text("BZ00,")
+ .number("(d+),") // mcc
+ .number("(d+),") // mnc
+ .number("(x+),") // lac
+ .number("(x+),") // cid
+ .any()
+ .compile();
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -88,11 +98,11 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
}
}
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+
Parser parser = new Parser(PATTERN_BATTERY, sentence);
if (parser.matches()) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
if (!identify(parser.next(), channel)) {
return null;
}
@@ -117,14 +127,28 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ parser = new Parser(PATTERN_NETWORK, sentence);
+ if (parser.matches()) {
+ if (!identify(parser.next(), channel)) {
+ return null;
+ }
+ position.setDeviceId(getDeviceId());
+
+ getLastLocation(position, null);
+
+ position.set(Event.KEY_MCC, parser.nextInt());
+ position.set(Event.KEY_MNC, parser.nextInt());
+ position.set(Event.KEY_LAC, parser.nextInt(16));
+ position.set(Event.KEY_CID, parser.nextInt(16));
+
+ return position;
+ }
+
parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
if (!identify(parser.next(), channel)) {
return null;
}
diff --git a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
index d9d50947e..24e9893bb 100644
--- a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
@@ -86,7 +86,7 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder {
position.setProtocol(getProtocolName());
position.setDeviceId(getDeviceId());
- position.set(Event.KEY_CID, parser.next());
+ parser.next(); // base station info
DateBuilder dateBuilder = new DateBuilder()
.setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java
index 321b78b7c..88eecab70 100644
--- a/src/org/traccar/protocol/TotemProtocolDecoder.java
+++ b/src/org/traccar/protocol/TotemProtocolDecoder.java
@@ -55,7 +55,8 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
.number("(ddd)") // battery
.number("(dddd)|") // power
.number("(d+)|").optional() // adc
- .number("(x+)|") // location code
+ .number("x*(xxxx)") // lac
+ .number("(xxxx)|") // cid
.number("(d+)|") // temperature
.number("(d+.d+)|") // odometer
.number("d+|") // serial number
@@ -84,7 +85,8 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
.number("(dd)") // battery
.number("(dd)|") // external power
.number("(d+)|") // adc
- .number("(x{8})|") // location code
+ .number("(xxxx)") // lac
+ .number("(xxxx)|") // cid
.number("(d+)|") // temperature
.number("(d+.d+)|") // odometer
.number("d+|") // serial number
@@ -107,7 +109,8 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
.number("(dddd)") // adc 2
.number("(ddd)") // temperature 1
.number("(ddd)") // temperature 2
- .number("(x{8})") // location code
+ .number("(xxxx)") // lac
+ .number("(xxxx)") // cid
.expression("([AV])") // validity
.number("(dd)") // satellites
.number("(ddd)") // course
@@ -185,7 +188,14 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
position.set(Event.KEY_BATTERY, parser.next());
position.set(Event.KEY_POWER, parser.nextDouble());
position.set(Event.PREFIX_ADC + 1, parser.next());
- position.set(Event.KEY_LAC, parser.next());
+
+ int lac = parser.nextInt(16);
+ int cid = parser.nextInt(16);
+ if (lac != 0 && cid != 0) {
+ position.set(Event.KEY_LAC, lac);
+ position.set(Event.KEY_CID, cid);
+ }
+
position.set(Event.PREFIX_TEMP + 1, parser.next());
position.set(Event.KEY_ODOMETER, parser.next());
@@ -203,7 +213,8 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
position.set(Event.PREFIX_ADC + 2, parser.next());
position.set(Event.PREFIX_TEMP + 1, parser.next());
position.set(Event.PREFIX_TEMP + 2, parser.next());
- position.set(Event.KEY_LAC, parser.next());
+ position.set(Event.KEY_LAC, parser.nextInt(16));
+ position.set(Event.KEY_CID, parser.nextInt(16));
position.setValid(parser.next().equals("A"));
position.set(Event.KEY_SATELLITES, parser.next());
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java
index a24d0a56b..92b7638fb 100644
--- a/src/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/org/traccar/protocol/WatchProtocolDecoder.java
@@ -64,8 +64,8 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
private void sendResponse(Channel channel, String manufacturer, String id, String content) {
if (channel != null) {
- channel.write(
- String.format("[%s*%s*%04x*%s]", manufacturer, id, content.length(), content));
+ channel.write(String.format(
+ "[%s*%s*%04x*%s]", manufacturer, id, content.length(), content));
}
}
@@ -138,6 +138,10 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
return position;
+ } else if (type.equals("TKQ")) {
+
+ sendResponse(channel, manufacturer, id, "TKQ");
+
}
return null;