aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/AplicomProtocolDecoder.java298
-rw-r--r--src/org/traccar/protocol/CellocatorProtocol.java10
-rw-r--r--src/org/traccar/protocol/CguardProtocol.java47
-rw-r--r--src/org/traccar/protocol/CguardProtocolDecoder.java91
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolEncoder.java4
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolDecoder.java90
-rw-r--r--src/org/traccar/protocol/OigoProtocolDecoder.java4
7 files changed, 489 insertions, 55 deletions
diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java
index 23397b51c..d1f92ea0a 100644
--- a/src/org/traccar/protocol/AplicomProtocolDecoder.java
+++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2016 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.
@@ -27,6 +27,7 @@ import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import java.net.SocketAddress;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
@@ -75,11 +76,12 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
return unitId;
}
- private static final int DEFAULT_SELECTOR = 0x0002FC;
+ private static final int DEFAULT_SELECTOR_D = 0x0002fC;
+ private static final int DEFAULT_SELECTOR_E = 0x007ffc;
private static final int EVENT_DATA = 119;
- private void decodeEventData(int event, ChannelBuffer buf) {
+ private void decodeEventData(Position position, ChannelBuffer buf, int event) {
switch (event) {
case 2:
case 40:
@@ -106,6 +108,9 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
case 130:
buf.readUnsignedInt(); // incorrect
break;
+ case 188:
+ decodeEB(position, buf);
+ break;
default:
break;
}
@@ -191,44 +196,12 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
}
}
- @Override
- protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.readUnsignedByte(); // marker
- int version = buf.readUnsignedByte();
-
- String imei;
- if ((version & 0x80) != 0) {
- imei = String.valueOf((buf.readUnsignedInt() << (3 * 8)) | buf.readUnsignedMedium());
- } else {
- imei = String.valueOf(imeiFromUnitId(buf.readUnsignedMedium()));
- }
-
- buf.readUnsignedShort(); // length
-
- int selector = DEFAULT_SELECTOR;
- if ((version & 0x40) != 0) {
- selector = buf.readUnsignedMedium();
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- int event = buf.readUnsignedByte();
- position.set(Position.KEY_EVENT, event);
- position.set("eventInfo", buf.readUnsignedByte());
+ private void decodeD(Position position, ChannelBuffer buf, int selector, int event) {
if ((selector & 0x0008) != 0) {
position.setValid((buf.readUnsignedByte() & 0x40) != 0);
} else {
- return null; // no location data
+ getLastLocation(position, null);
}
if ((selector & 0x0004) != 0) {
@@ -313,14 +286,261 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
}
if ((selector & 0x1000) != 0) {
- decodeEventData(event, buf);
+ decodeEventData(position, buf, event);
}
if (Context.getConfig().getBoolean(getProtocolName() + ".can")
&& buf.readable() && (selector & 0x1000) != 0 && event == EVENT_DATA) {
-
decodeCanData(buf, position);
}
+ }
+
+ private void decodeE(Position position, ChannelBuffer buf, int selector) {
+
+ if ((selector & 0x0008) != 0) {
+ position.set("tachographEvent", buf.readUnsignedShort());
+ }
+
+ if ((selector & 0x0004) != 0) {
+ getLastLocation(position, new Date(buf.readUnsignedInt() * 1000));
+ } else {
+ getLastLocation(position, null);
+ }
+
+ if ((selector & 0x0010) != 0) {
+ String time = buf.readUnsignedByte() + "s " + buf.readUnsignedByte() + "m " + buf.readUnsignedByte() + "h "
+ + buf.readUnsignedByte() + "M " + buf.readUnsignedByte() + "D " + buf.readUnsignedByte() + "Y "
+ + buf.readByte() + "m " + buf.readByte() + "h";
+ position.set("tachographTime", time);
+ }
+
+ position.set("workState", buf.readUnsignedByte());
+ position.set("driver1State", buf.readUnsignedByte());
+ position.set("driver2State", buf.readUnsignedByte());
+
+ if ((selector & 0x0020) != 0) {
+ position.set("tachographStatus", buf.readUnsignedByte());
+ }
+
+ if ((selector & 0x0040) != 0) {
+ position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() / 256.0);
+ }
+
+ if ((selector & 0x0080) != 0) {
+ position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 5);
+ }
+
+ if ((selector & 0x0100) != 0) {
+ position.set(Position.KEY_TRIP_ODOMETER, buf.readUnsignedInt() * 5);
+ }
+
+ if ((selector & 0x8000) != 0) {
+ position.set("kFactor", buf.readUnsignedShort() * 0.001 + " pulses/m");
+ }
+
+ if ((selector & 0x0200) != 0) {
+ position.set(Position.KEY_RPM, buf.readUnsignedShort() * 0.125);
+ }
+
+ if ((selector & 0x0400) != 0) {
+ position.set("extraInfo", buf.readUnsignedShort());
+ }
+
+ if ((selector & 0x0800) != 0) {
+ position.set(Position.KEY_VIN, buf.readBytes(18).toString(StandardCharsets.US_ASCII).trim());
+ }
+ }
+
+ private void decodeH(Position position, ChannelBuffer buf, int selector) {
+
+ if ((selector & 0x0004) != 0) {
+ getLastLocation(position, new Date(buf.readUnsignedInt() * 1000));
+ } else {
+ getLastLocation(position, null);
+ }
+
+ if ((selector & 0x0040) != 0) {
+ buf.readUnsignedInt(); // reset time
+ }
+
+ if ((selector & 0x2000) != 0) {
+ buf.readUnsignedShort(); // snapshot counter
+ }
+
+ int index = 1;
+ while (buf.readableBytes() > 0) {
+
+ position.set("h" + index + "Index", buf.readUnsignedByte());
+
+ buf.readUnsignedShort(); // length
+
+ int n = buf.readUnsignedByte();
+ int m = buf.readUnsignedByte();
+
+ position.set("h" + index + "XLength", n);
+ position.set("h" + index + "YLength", m);
+
+ if ((selector & 0x0008) != 0) {
+ position.set("h" + index + "XType", buf.readUnsignedByte());
+ position.set("h" + index + "YType", buf.readUnsignedByte());
+ position.set("h" + index + "Parameters", buf.readUnsignedByte());
+ }
+
+ boolean percentageFormat = (selector & 0x0020) != 0;
+
+ StringBuilder data = new StringBuilder();
+ for (int i = 0; i < n * m; i++) {
+ if (percentageFormat) {
+ data.append(buf.readUnsignedByte() * 0.5).append("%").append(" ");
+ } else {
+ data.append(buf.readUnsignedShort()).append(" ");
+ }
+ }
+
+ position.set("h" + index + "Data", data.toString().trim());
+
+ position.set("h" + index + "Total", buf.readUnsignedInt());
+
+ if ((selector & 0x0010) != 0) {
+ int k = buf.readUnsignedByte();
+
+ data = new StringBuilder();
+ for (int i = 1; i < n; i++) {
+ if (k == 1) {
+ data.append(buf.readByte()).append(" ");
+ } else if (k == 2) {
+ data.append(buf.readShort()).append(" ");
+ }
+ }
+ position.set("h" + index + "XLimits", data.toString().trim());
+
+ data = new StringBuilder();
+ for (int i = 1; i < m; i++) {
+ if (k == 1) {
+ data.append(buf.readByte()).append(" ");
+ } else if (k == 2) {
+ data.append(buf.readShort()).append(" ");
+ }
+ }
+ position.set("h" + index + "YLimits", data.toString().trim());
+ }
+
+ index += 1;
+ }
+ }
+
+ private void decodeEB(Position position, ChannelBuffer buf) {
+
+ if (buf.readByte() != (byte) 'E' || buf.readByte() != (byte) 'B') {
+ return;
+ }
+
+ buf.readUnsignedByte(); // version
+ buf.readUnsignedShort(); // event
+ buf.readUnsignedByte(); // data validity
+ buf.readUnsignedByte(); // towed
+ buf.readUnsignedShort(); // length
+
+ while (buf.readableBytes() > 0) {
+ buf.readUnsignedByte(); // towed position
+ int type = buf.readUnsignedByte();
+ int length = buf.readUnsignedByte();
+
+ if (type == 0x01) {
+ position.set("brakeFlags", ChannelBuffers.hexDump(buf.readBytes(length)));
+ } else if (type == 0x02) {
+ position.set("wheelSpeed", buf.readUnsignedShort() / 256.0);
+ position.set("wheelSpeedDifference", buf.readUnsignedShort() / 256.0 - 125.0);
+ position.set("lateralAcceleration", buf.readUnsignedByte() / 10.0 - 12.5);
+ position.set("vehicleSpeed", buf.readUnsignedShort() / 256.0);
+ } else if (type == 0x03) {
+ position.set("axleLoadSum", buf.readUnsignedShort() * 2);
+ } else if (type == 0x04) {
+ position.set("tyrePressure", buf.readUnsignedByte() * 10);
+ position.set("pneumaticPressure", buf.readUnsignedByte() * 5);
+ } else if (type == 0x05) {
+ position.set("brakeLining", buf.readUnsignedByte() * 0.4);
+ position.set("brakeTemperature", buf.readUnsignedByte() * 10);
+ } else if (type == 0x06) {
+ position.set("totalDistance", buf.readUnsignedInt() * 5);
+ position.set("tripDistance", buf.readUnsignedInt() * 5);
+ position.set("serviceDistance", (buf.readUnsignedInt() - 2105540607) * 5);
+ } else if (type == 0x0A) {
+ position.set("brakeData", ChannelBuffers.hexDump(buf.readBytes(length)));
+ } else if (type == 0x0B) {
+ position.set("brakeMinMaxData", ChannelBuffers.hexDump(buf.readBytes(length)));
+ } else if (type == 0x0C) {
+ position.set("missingPgn", ChannelBuffers.hexDump(buf.readBytes(length)));
+ } else if (type == 0x0D) {
+ switch (buf.readUnsignedByte()) {
+ case 1:
+ position.set("brakeManufacturer", "Wabco");
+ break;
+ case 2:
+ position.set("brakeManufacturer", "Knorr");
+ break;
+ case 3:
+ position.set("brakeManufacturer", "Haldex");
+ break;
+ default:
+ position.set("brakeManufacturer", "Unknown");
+ break;
+ }
+ buf.readUnsignedByte();
+ buf.readBytes(17); // vin
+ position.set("towedDetectionStatus", buf.readUnsignedByte());
+ } else if (type == 0x0E) {
+ buf.skipBytes(length);
+ }
+ }
+ }
+
+ @Override
+ protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ ChannelBuffer buf = (ChannelBuffer) msg;
+
+ char protocol = (char) buf.readByte();
+ int version = buf.readUnsignedByte();
+
+ String imei;
+ if ((version & 0x80) != 0) {
+ imei = String.valueOf((buf.readUnsignedInt() << (3 * 8)) | buf.readUnsignedMedium());
+ } else {
+ imei = String.valueOf(imeiFromUnitId(buf.readUnsignedMedium()));
+ }
+
+ buf.readUnsignedShort(); // length
+
+ int selector = DEFAULT_SELECTOR_D;
+ if (protocol == 'E') {
+ selector = DEFAULT_SELECTOR_E;
+ }
+ if ((version & 0x40) != 0) {
+ selector = buf.readUnsignedMedium();
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
+ if (deviceSession == null) {
+ return null;
+ }
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ int event = buf.readUnsignedByte();
+ position.set(Position.KEY_EVENT, event);
+ position.set("eventInfo", buf.readUnsignedByte());
+
+ if (protocol == 'D') {
+ decodeD(position, buf, selector, event);
+ } else if (protocol == 'E') {
+ decodeE(position, buf, selector);
+ } else if (protocol == 'H') {
+ decodeH(position, buf, selector);
+ } else {
+ return null;
+ }
return position;
}
diff --git a/src/org/traccar/protocol/CellocatorProtocol.java b/src/org/traccar/protocol/CellocatorProtocol.java
index 6d8eea8f5..e5f6ac8f6 100644
--- a/src/org/traccar/protocol/CellocatorProtocol.java
+++ b/src/org/traccar/protocol/CellocatorProtocol.java
@@ -15,6 +15,7 @@
*/
package org.traccar.protocol;
+import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelPipeline;
import org.traccar.BaseProtocol;
@@ -40,6 +41,15 @@ public class CellocatorProtocol extends BaseProtocol {
};
server.setEndianness(ByteOrder.LITTLE_ENDIAN);
serverList.add(server);
+
+ server = new TrackerServer(new ConnectionlessBootstrap(), getName()) {
+ @Override
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(CellocatorProtocol.this));
+ }
+ };
+ server.setEndianness(ByteOrder.LITTLE_ENDIAN);
+ serverList.add(server);
}
}
diff --git a/src/org/traccar/protocol/CguardProtocol.java b/src/org/traccar/protocol/CguardProtocol.java
new file mode 100644
index 000000000..1e6d212c8
--- /dev/null
+++ b/src/org/traccar/protocol/CguardProtocol.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2016 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.jboss.netty.handler.codec.frame.LineBasedFrameDecoder;
+import org.jboss.netty.handler.codec.string.StringDecoder;
+import org.jboss.netty.handler.codec.string.StringEncoder;
+import org.traccar.BaseProtocol;
+import org.traccar.TrackerServer;
+
+import java.util.List;
+
+public class CguardProtocol extends BaseProtocol {
+
+ public CguardProtocol() {
+ super("cguard");
+ }
+
+ @Override
+ public void initTrackerServers(List<TrackerServer> serverList) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ @Override
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
+ pipeline.addLast("stringDecoder", new StringDecoder());
+ pipeline.addLast("stringEncoder", new StringEncoder());
+ pipeline.addLast("objectDecoder", new CguardProtocolDecoder(CguardProtocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/CguardProtocolDecoder.java b/src/org/traccar/protocol/CguardProtocolDecoder.java
new file mode 100644
index 000000000..1646363e5
--- /dev/null
+++ b/src/org/traccar/protocol/CguardProtocolDecoder.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2016 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.channel.Channel;
+import org.traccar.BaseProtocolDecoder;
+import org.traccar.DeviceSession;
+import org.traccar.helper.DateBuilder;
+import org.traccar.helper.Parser;
+import org.traccar.helper.PatternBuilder;
+import org.traccar.helper.UnitsConverter;
+import org.traccar.model.Position;
+
+import java.net.SocketAddress;
+import java.util.regex.Pattern;
+
+public class CguardProtocolDecoder extends BaseProtocolDecoder {
+
+ public CguardProtocolDecoder(CguardProtocol protocol) {
+ super(protocol);
+ }
+
+ private static final Pattern PATTERN = new PatternBuilder()
+ .text("NV:")
+ .number("(dd)(dd)(dd) ") // date
+ .number("(dd)(dd)(dd):") // time
+ .number("(-?d+.d+):") // longitude
+ .number("(-?d+.d+):") // latitude
+ .number("(d+.?d*):") // speed
+ .number("(?:NAN|(d+.?d*)):") // accuracy
+ .number("(?:NAN|(d+.?d*)):") // course
+ .number("(?:NAN|(d+.?d*))") // altitude
+ .compile();
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ String sentence = (String) msg;
+
+ if (sentence.startsWith("ID:") || sentence.startsWith("IDRO:")) {
+ getDeviceSession(channel, remoteAddress, sentence.substring(sentence.indexOf(':') + 1));
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Parser parser = new Parser(PATTERN, (String) msg);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
+
+ position.setValid(true);
+ position.setLatitude(parser.nextDouble());
+ position.setLongitude(parser.nextDouble());
+ position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
+
+ position.set(Position.KEY_ACCURACY, parser.nextDouble());
+
+ position.setCourse(parser.nextDouble());
+ position.setAltitude(parser.nextDouble());
+
+ return position;
+ }
+
+}
diff --git a/src/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/org/traccar/protocol/Gt06ProtocolEncoder.java
index e478424f9..e78a1b388 100644
--- a/src/org/traccar/protocol/Gt06ProtocolEncoder.java
+++ b/src/org/traccar/protocol/Gt06ProtocolEncoder.java
@@ -66,9 +66,9 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder {
switch (command.getType()) {
case Command.TYPE_ENGINE_STOP:
- return encodeContent(alternative ? "DYD,123456#\r\n" : "Relay,1#");
+ return encodeContent(alternative ? "DYD,123456#" : "Relay,1#");
case Command.TYPE_ENGINE_RESUME:
- return encodeContent(alternative ? "HFYD,123456#\r\n" : "Relay,0#");
+ return encodeContent(alternative ? "HFYD,123456#" : "Relay,0#");
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
index b7193d24b..b30bd7b85 100644
--- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
@@ -43,7 +43,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
return degrees + minutes / 60;
}
- private Position decodeNormalMessage(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
+ private Position decodeBinary(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
Position position = new Position();
position.setProtocol(getProtocolName());
@@ -120,7 +120,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private static final Pattern PATTERN = new PatternBuilder()
+ private static final Pattern PATTERN_W01 = new PatternBuilder()
.text("(")
.number("(d+),") // id
.text("W01,") // type
@@ -138,25 +138,22 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
.number("(d+),") // gsm signal
.number("(d+),") // alert type
.any()
- .text(")")
.compile();
- private Position decodeAlertMessage(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
+ private Position decodeW01(String sentence, Channel channel, SocketAddress remoteAddress) {
- Parser parser = new Parser(PATTERN, buf.toString(StandardCharsets.US_ASCII));
+ Parser parser = new Parser(PATTERN_W01, sentence);
if (!parser.matches()) {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
-
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setLongitude(parser.nextCoordinate());
@@ -176,6 +173,68 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private static final Pattern PATTERN_U01 = new PatternBuilder()
+ .text("(")
+ .number("(d+),") // id
+ .number("Udd,") // type
+ .number("d+,").optional() // alarm
+ .number("(dd)(dd)(dd),") // date (ddmmyy)
+ .number("(dd)(dd)(dd),") // time
+ .expression("([TF]),") // validity
+ .number("(d+.d+),([NS]),") // latitude
+ .number("(d+.d+),([EW]),") // longitude
+ .number("(d+.?d*),") // speed
+ .number("(d+),") // course
+ .number("(d+),") // satellites
+ .number("(d+%),") // battery
+ .expression("([01]+),") // status
+ .number("(d+),") // cid
+ .number("(d+),") // lac
+ .number("(d+),") // gsm signal
+ .number("(d+),") // odometer
+ .number("(d+)") // index
+ .any()
+ .compile();
+
+ private Position decodeU01(String sentence, Channel channel, SocketAddress remoteAddress) {
+
+ Parser parser = new Parser(PATTERN_U01, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ 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()
+ .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
+
+ position.setValid(parser.next().equals("T"));
+ position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+
+ position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble()));
+ position.setCourse(parser.nextDouble());
+
+ position.set(Position.KEY_SATELLITES, parser.nextInt());
+ position.set(Position.KEY_BATTERY, parser.next());
+ position.set(Position.KEY_STATUS, parser.nextInt(2));
+ position.set(Position.KEY_CID, parser.nextInt());
+ position.set(Position.KEY_LAC, parser.nextInt());
+ position.set(Position.KEY_GSM, parser.nextInt());
+ position.set(Position.KEY_ODOMETER, parser.nextLong() * 1000);
+ position.set(Position.KEY_INDEX, parser.nextInt());
+
+ return position;
+ }
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -184,9 +243,14 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
char first = (char) buf.getByte(0);
if (first == '$') {
- return decodeNormalMessage(buf, channel, remoteAddress);
+ return decodeBinary(buf, channel, remoteAddress);
} else if (first == '(') {
- return decodeAlertMessage(buf, channel, remoteAddress);
+ String sentence = buf.toString(StandardCharsets.US_ASCII);
+ if (sentence.contains("W01")) {
+ return decodeW01(sentence, channel, remoteAddress);
+ } else {
+ return decodeU01(sentence, channel, remoteAddress);
+ }
}
return null;
diff --git a/src/org/traccar/protocol/OigoProtocolDecoder.java b/src/org/traccar/protocol/OigoProtocolDecoder.java
index 799f47ea3..bbea38183 100644
--- a/src/org/traccar/protocol/OigoProtocolDecoder.java
+++ b/src/org/traccar/protocol/OigoProtocolDecoder.java
@@ -54,7 +54,7 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder {
DeviceSession deviceSession;
switch (BitUtil.to(tag, 3)) {
case 0:
- String imei = ChannelBuffers.hexDump(buf.readBytes(9)).substring(1, 1 + 15);
+ String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
deviceSession = getDeviceSession(channel, remoteAddress, imei);
break;
case 1:
@@ -75,6 +75,8 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder {
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
+ position.set(Position.KEY_EVENT, buf.readUnsignedByte());
+
int mask = buf.readInt();
if (BitUtil.check(mask, 0)) {