aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/protocol/AplicomProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/UlbotechProtocolDecoder.java62
-rw-r--r--src/org/traccar/protocol/Xt2400Protocol.java41
-rw-r--r--src/org/traccar/protocol/Xt2400ProtocolDecoder.java56
5 files changed, 154 insertions, 9 deletions
diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java
index c07a656b3..03d7dbd6b 100644
--- a/src/org/traccar/protocol/AplicomProtocolDecoder.java
+++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java
@@ -503,8 +503,6 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
getLastLocation(position, null);
- buf.readUnsignedShort(); // event
-
if ((selector & 0x0004) != 0) {
buf.skipBytes(4); // snapshot time
}
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index a717ddc4d..6ab997b86 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -73,6 +73,8 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_ALARM, Position.ALARM_SOS);
} else if (!BitUtil.check(status, 2)) {
position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
+ } else if (!BitUtil.check(status, 19)) {
+ position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
}
position.set(Position.KEY_IGNITION, BitUtil.check(status, 10));
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));
+ }
+ }
+
}
diff --git a/src/org/traccar/protocol/Xt2400Protocol.java b/src/org/traccar/protocol/Xt2400Protocol.java
new file mode 100644
index 000000000..0c5e9cd4c
--- /dev/null
+++ b/src/org/traccar/protocol/Xt2400Protocol.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2017 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.ConnectionlessBootstrap;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.traccar.BaseProtocol;
+import org.traccar.TrackerServer;
+
+import java.util.List;
+
+public class Xt2400Protocol extends BaseProtocol {
+
+ public Xt2400Protocol() {
+ super("xt2400");
+ }
+
+ @Override
+ public void initTrackerServers(List<TrackerServer> serverList) {
+ serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
+ @Override
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("objectDecoder", new Xt2400ProtocolDecoder(Xt2400Protocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/Xt2400ProtocolDecoder.java b/src/org/traccar/protocol/Xt2400ProtocolDecoder.java
new file mode 100644
index 000000000..623cc6f5b
--- /dev/null
+++ b/src/org/traccar/protocol/Xt2400ProtocolDecoder.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2017 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.traccar.BaseProtocolDecoder;
+
+import javax.xml.bind.DatatypeConverter;
+import java.net.SocketAddress;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class Xt2400ProtocolDecoder extends BaseProtocolDecoder {
+
+ public Xt2400ProtocolDecoder(Xt2400Protocol protocol) {
+ super(protocol);
+ }
+
+ private Map<Integer, byte[]> formats = new HashMap<>();
+
+ public void setConfig(String configString) {
+ Pattern pattern = Pattern.compile(":wycfg pcr\\[\\d+\\] ([0-9a-fA-F]{2})[0-9a-fA-F]{2}([0-9a-fA-F]+)");
+ Matcher matcher = pattern.matcher(configString);
+ while (matcher.find()) {
+ formats.put(Integer.parseInt(matcher.group(1)), DatatypeConverter.parseHexBinary(matcher.group(2)));
+ }
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ ChannelBuffer buf = (ChannelBuffer) msg;
+
+
+
+ return null;
+ }
+
+}