aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-09-17 16:30:17 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-09-17 16:30:17 +1200
commit9587c1671abcb1d255bc9715c3b254006b761152 (patch)
tree3e131303e5edcdf8e6f207b95e496508b5b42d43
parent7e2ed343d2a6a03938c3f074417464c63d31fd59 (diff)
downloadtraccar-server-9587c1671abcb1d255bc9715c3b254006b761152.tar.gz
traccar-server-9587c1671abcb1d255bc9715c3b254006b761152.tar.bz2
traccar-server-9587c1671abcb1d255bc9715c3b254006b761152.zip
Support Atlanta OBD CAN data
-rw-r--r--src/org/traccar/protocol/L100ProtocolDecoder.java53
-rw-r--r--test/org/traccar/protocol/L100ProtocolDecoderTest.java3
2 files changed, 52 insertions, 4 deletions
diff --git a/src/org/traccar/protocol/L100ProtocolDecoder.java b/src/org/traccar/protocol/L100ProtocolDecoder.java
index d9f830ec5..9bc2e21c1 100644
--- a/src/org/traccar/protocol/L100ProtocolDecoder.java
+++ b/src/org/traccar/protocol/L100ProtocolDecoder.java
@@ -21,6 +21,7 @@ import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.helper.Checksum;
import org.traccar.helper.DateBuilder;
+import org.traccar.helper.ObdDecoder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.model.CellTower;
@@ -68,7 +69,7 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder {
.text("ATL")
.compile();
- private static final Pattern PATTERN_OBD = new PatternBuilder()
+ private static final Pattern PATTERN_OBD_LOCATION = new PatternBuilder()
.expression("[LH],") // archive
.text("ATL,")
.number("(d{15}),") // imei
@@ -95,6 +96,18 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder {
.groupEnd("?")
.compile();
+ private static final Pattern PATTERN_OBD_DATA = new PatternBuilder()
+ .expression("[LH],") // archive
+ .text("ATLOBD,")
+ .number("(d{15}),") // imei
+ .number("d+,") // type
+ .number("d+,") // index
+ .number("(dd)(dd)(dd),") // time (hhmmss)
+ .number("(dd)(dd)(dd),") // date (ddmmyy)
+ .expression("[^,]+,") // obd protocol
+ .expression("(.+)") // data
+ .compile();
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -102,7 +115,11 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder {
String sentence = (String) msg;
if (sentence.startsWith("L") || sentence.startsWith("H")) {
- return decodeObd(channel, remoteAddress, sentence);
+ if (sentence.substring(2, 8).equals("ATLOBD")) {
+ return decodeObdData(channel, remoteAddress, sentence);
+ } else {
+ return decodeObdLocation(channel, remoteAddress, sentence);
+ }
} else {
return decodeNormal(channel, remoteAddress, sentence);
}
@@ -150,9 +167,9 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private Object decodeObd(Channel channel, SocketAddress remoteAddress, String sentence) {
+ private Object decodeObdLocation(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN_OBD, sentence);
+ Parser parser = new Parser(PATTERN_OBD_LOCATION, sentence);
if (!parser.matches()) {
return null;
}
@@ -218,4 +235,32 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private Object decodeObdData(Channel channel, SocketAddress remoteAddress, String sentence) {
+
+ Parser parser = new Parser(PATTERN_OBD_DATA, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY));
+
+ for (String entry : parser.next().split(",")) {
+ String[] values = entry.split(":");
+ if (values.length == 2 && values[1].charAt(0) != 'X') {
+ position.add(ObdDecoder.decodeData(
+ Integer.parseInt(values[0].substring(2), 16), Integer.parseInt(values[1], 16), true));
+ }
+ }
+
+ return position;
+ }
+
}
diff --git a/test/org/traccar/protocol/L100ProtocolDecoderTest.java b/test/org/traccar/protocol/L100ProtocolDecoderTest.java
index 65a5a1afe..e03bc2c09 100644
--- a/test/org/traccar/protocol/L100ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/L100ProtocolDecoderTest.java
@@ -10,6 +10,9 @@ public class L100ProtocolDecoderTest extends ProtocolTest {
L100ProtocolDecoder decoder = new L100ProtocolDecoder(new L100Protocol());
+ verifyAttributes(decoder, text(
+ "L,ATLOBD,866795030475584,03,7429,143344,130918,CAN,0101:00076100,0103:0200,0104:3C,0105:84,010A:XX,010B:19,010C:0F98,010D:22,010E:68,010F:5A,0110:XXXX,0111:28,011C:20,011F:XXXX,0121:0000,0122:XXXX,012F:XX,0162:XX,0132:XXXX,0133:61,0143:00A8,0145:0F,0146:XX,0147:30,0148:XX,0149:31,014A:18,014B:XX,014C:92,0151:XX,0131:00BB,0144:8000,015E:XXXX,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0902:XXXXXXXXXXXXXXX"));
+
verifyPosition(decoder, text(
"H,ATL,866795030478513,02,0981,054448,230318,A,28.633486;N,77.222595;E,0,154,1.14,4.2,18,404,4,88,ad7b,#1031,0,ATL,"));