aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-12-21 16:54:46 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2018-12-21 16:54:46 -0800
commit0c0df0ff62a4b14aba8ef2ebd8642d1ee3dd4148 (patch)
tree8e13ed7eca0a1e3d5492a516d1f681b6c6200b09 /src
parente8e73376eac069134077a5be7978d9a3619913b3 (diff)
downloadtraccar-server-0c0df0ff62a4b14aba8ef2ebd8642d1ee3dd4148.tar.gz
traccar-server-0c0df0ff62a4b14aba8ef2ebd8642d1ee3dd4148.tar.bz2
traccar-server-0c0df0ff62a4b14aba8ef2ebd8642d1ee3dd4148.zip
Support PT100 protocol
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/protocol/L100FrameDecoder.java31
-rw-r--r--src/org/traccar/protocol/L100ProtocolDecoder.java69
2 files changed, 98 insertions, 2 deletions
diff --git a/src/org/traccar/protocol/L100FrameDecoder.java b/src/org/traccar/protocol/L100FrameDecoder.java
index b7caa14f4..9e08120dd 100644
--- a/src/org/traccar/protocol/L100FrameDecoder.java
+++ b/src/org/traccar/protocol/L100FrameDecoder.java
@@ -20,6 +20,8 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import org.traccar.BaseFrameDecoder;
+import java.nio.charset.StandardCharsets;
+
public class L100FrameDecoder extends BaseFrameDecoder {
@Override
@@ -30,6 +32,15 @@ public class L100FrameDecoder extends BaseFrameDecoder {
return null;
}
+ if (buf.getCharSequence(buf.readerIndex(), 4, StandardCharsets.US_ASCII).equals("ATL,")) {
+ return decodeNew(buf);
+ } else {
+ return decodeOld(buf);
+ }
+ }
+
+ private Object decodeOld(ByteBuf buf) {
+
int header = buf.getByte(buf.readerIndex());
boolean obd = header == 'L' || header == 'H';
@@ -38,9 +49,9 @@ public class L100FrameDecoder extends BaseFrameDecoder {
index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
} else {
index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x02);
- if (index == -1) {
+ if (index < 0) {
index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x04);
- if (index == -1) {
+ if (index < 0) {
return null;
}
}
@@ -60,4 +71,20 @@ public class L100FrameDecoder extends BaseFrameDecoder {
return null;
}
+ private Object decodeNew(ByteBuf buf) {
+
+ int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '@');
+ if (index < 0) {
+ return null;
+ }
+
+ if (buf.writerIndex() >= index + 1) {
+ ByteBuf frame = buf.readRetainedSlice(index - buf.readerIndex());
+ buf.skipBytes(1); // delimiter
+ return frame;
+ }
+
+ return null;
+ }
+
}
diff --git a/src/org/traccar/protocol/L100ProtocolDecoder.java b/src/org/traccar/protocol/L100ProtocolDecoder.java
index 07c5622cb..c4a4c0d58 100644
--- a/src/org/traccar/protocol/L100ProtocolDecoder.java
+++ b/src/org/traccar/protocol/L100ProtocolDecoder.java
@@ -109,6 +109,27 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder {
.expression("(.+)") // data
.compile();
+ private static final Pattern PATTERN_NEW = new PatternBuilder()
+ .groupBegin()
+ .text("ATL,")
+ .expression("[LH],") // archive
+ .number("(d{15}),") // imei
+ .groupEnd("?")
+ .expression("([NPT]),") // alarm
+ .number("(dd)(dd)(dd),") // date (ddmmyy)
+ .number("(dd)(dd)(dd),") // time (hhmmss)
+ .expression("([AV]),") // validity
+ .number("(d+.d+),([NS]),") // latitude
+ .number("(d+.d+),([EW]),") // longitude
+ .number("(d+.?d*),") // speed
+ .expression("(?:GPS|GSM|INV),")
+ .number("(d+),") // battery
+ .number("(d+),") // mcc
+ .number("(d+),") // mnc
+ .number("(d+),") // lac
+ .number("(d+)") // cid
+ .compile();
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -121,6 +142,8 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder {
} else {
return decodeObdLocation(channel, remoteAddress, sentence);
}
+ } else if (sentence.startsWith("ATL,") || sentence.substring(0, 1).matches("[NPT]")) {
+ return decodeNew(channel, remoteAddress, sentence);
} else {
return decodeNormal(channel, remoteAddress, sentence);
}
@@ -264,4 +287,50 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private Object decodeNew(Channel channel, SocketAddress remoteAddress, String sentence) {
+
+ Parser parser = new Parser(PATTERN_NEW, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ String imei = parser.next();
+ DeviceSession deviceSession;
+ if (imei != null) {
+ deviceSession = getDeviceSession(channel, remoteAddress, imei);
+ } else {
+ deviceSession = getDeviceSession(channel, remoteAddress);
+ }
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ switch (parser.next()) {
+ case "P":
+ position.set(Position.KEY_ALARM, Position.ALARM_SOS);
+ break;
+ case "T":
+ position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING);
+ break;
+ default:
+ break;
+ }
+
+ position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
+ position.setValid(parser.next().equals("A"));
+ position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ position.setSpeed(parser.nextDouble());
+
+ position.set(Position.KEY_BATTERY, parser.nextInt() * 0.001);
+
+ position.setNetwork(new Network(CellTower.from(
+ parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextHexInt())));
+
+ return position;
+ }
+
}