aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-03-16 06:20:43 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2017-03-16 06:20:43 +1300
commit32cf37a4784418bc9be8d66add1b51af3aa91a4d (patch)
tree807e841af51541d6b7b6710f52c561deff7ff586 /src/org
parent7446d4984a81b7298b390803cdf141f0d4e7cb8a (diff)
downloadtrackermap-server-32cf37a4784418bc9be8d66add1b51af3aa91a4d.tar.gz
trackermap-server-32cf37a4784418bc9be8d66add1b51af3aa91a4d.tar.bz2
trackermap-server-32cf37a4784418bc9be8d66add1b51af3aa91a4d.zip
Implement Ulbotech response handling
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/protocol/UlbotechProtocolDecoder.java62
1 files changed, 55 insertions, 7 deletions
diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java
index 19e9cd5e9..97912e128 100644
--- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java
+++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java
@@ -22,7 +22,10 @@ import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.helper.BitUtil;
+import org.traccar.helper.DateBuilder;
import org.traccar.helper.ObdDecoder;
+import org.traccar.helper.Parser;
+import org.traccar.helper.PatternBuilder;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.CellTower;
import org.traccar.model.Network;
@@ -31,6 +34,7 @@ import org.traccar.model.Position;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Date;
+import java.util.regex.Pattern;
public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
@@ -161,27 +165,58 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
}
}
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+ private static final Pattern PATTERN = new PatternBuilder()
+ .text("*TS")
+ .number("dd,") // protocol version
+ .number("(d{15}),") // device id
+ .number("(dd)(dd)(dd)") // time
+ .number("(dd)(dd)(dd),") // date
+ .expression("([^#]+)") // command
+ .text("#")
+ .compile();
- ChannelBuffer buf = (ChannelBuffer) msg;
+ private Object decodeText(Channel channel, SocketAddress remoteAddress, String sentence) {
- if (buf.readUnsignedByte() != 0xF8) {
+ Parser parser = new Parser(PATTERN, sentence);
+ if (!parser.matches()) {
return null;
}
- buf.readUnsignedByte(); // version
- buf.readUnsignedByte(); // type
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
Position position = new Position();
position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
+
+ getLastLocation(position, dateBuilder.getDate());
+
+ position.set(Position.KEY_RESULT, parser.next());
+
+ return position;
+ }
+
+ private Object decodeBinary(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
+
+ buf.readUnsignedByte(); // header
+ buf.readUnsignedByte(); // version
+ buf.readUnsignedByte(); // type
String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
+
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
long seconds = buf.readUnsignedInt() & 0x7fffffffL;
@@ -298,4 +333,17 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ ChannelBuffer buf = (ChannelBuffer) msg;
+
+ if (buf.getUnsignedByte(buf.readerIndex()) == 0xF8) {
+ return decodeBinary(channel, remoteAddress, buf);
+ } else {
+ return decodeText(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII));
+ }
+ }
+
}