aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-04-18 15:51:38 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-04-18 15:51:38 +1200
commit773768093c6c78906e54abe128cb1b4ca9430313 (patch)
tree07bb3e513ac19d53260fcfa283c05a4bd67de3b7 /src/org/traccar
parent053e03307f851f3d990caf8ba95dad4ea8836977 (diff)
downloadtrackermap-server-773768093c6c78906e54abe128cb1b4ca9430313.tar.gz
trackermap-server-773768093c6c78906e54abe128cb1b4ca9430313.tar.bz2
trackermap-server-773768093c6c78906e54abe128cb1b4ca9430313.zip
Support Atrack text message format
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/protocol/AtrackProtocolDecoder.java92
1 files changed, 81 insertions, 11 deletions
diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java
index 8138f0fcb..ac208c0f2 100644
--- a/src/org/traccar/protocol/AtrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java
@@ -219,7 +219,8 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
- private Position decodeString(Channel channel, SocketAddress remoteAddress, String sentence) {
+ private Position decodeInfo(Channel channel, SocketAddress remoteAddress, String sentence) {
+
Position position = new Position(getProtocolName());
getLastLocation(position, null);
@@ -258,21 +259,70 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
}
}
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+ private static final Pattern PATTERN = new PatternBuilder()
+ .text("@P,")
+ .number("x+,") // checksum
+ .number("d+,") // length
+ .number("d+,") // index
+ .number("(d+),") // imei
+ .number("(dddd)(dd)(dd)") // date (yymmdd)
+ .number("(dd)(dd)(dd),") // time (hhmmss)
+ .number("d+,") // rtc date and time
+ .number("d+,") // device date and time
+ .number("(-?d+),") // longitude
+ .number("(-?d+),") // latitude
+ .number("(d+),") // course
+ .number("(d+),") // report id
+ .number("(d+.d+),") // odometer
+ .number("(d+),") // hdop
+ .number("(d+),") // inputs
+ .number("(d+),") // speed
+ .number("(d+),") // outputs
+ .number("(d+),") // adc
+ .number("[^,]*,") // driver
+ .number("(d+),") // temp1
+ .number("(d+),") // temp2
+ .any()
+ .compile();
- ChannelBuffer buf = (ChannelBuffer) msg;
+ private Position decodeText(Channel channel, SocketAddress remoteAddress, String sentence) {
- if (buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) {
- if (channel != null) {
- channel.write(buf, remoteAddress); // keep-alive message
- }
+ Parser parser = new Parser(PATTERN, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
return null;
- } else if (buf.getByte(buf.readerIndex()) == '$') {
- return decodeString(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII).trim());
}
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.setValid(true);
+ position.setTime(parser.nextDateTime());
+ position.setLongitude(parser.nextInt() * 0.000001);
+ position.setLatitude(parser.nextInt() * 0.000001);
+ position.setCourse(parser.nextInt());
+
+ position.set(Position.KEY_EVENT, parser.nextInt());
+ position.set(Position.KEY_ODOMETER, parser.nextDouble() * 100);
+ position.set(Position.KEY_HDOP, parser.nextInt() * 0.1);
+ position.set(Position.KEY_INPUT, parser.nextInt());
+
+ position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt()));
+
+ position.set(Position.KEY_OUTPUT, parser.nextInt());
+ position.set(Position.PREFIX_ADC + 1, parser.nextInt());
+ position.set(Position.PREFIX_TEMP + 1, parser.nextInt());
+ position.set(Position.PREFIX_TEMP + 2, parser.nextInt());
+
+ return position;
+ }
+
+ private List<Position> decodeBinary(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
+
buf.skipBytes(2); // prefix
buf.readUnsignedShort(); // checksum
buf.readUnsignedShort(); // length
@@ -360,4 +410,24 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
return positions;
}
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ ChannelBuffer buf = (ChannelBuffer) msg;
+
+ if (buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) {
+ if (channel != null) {
+ channel.write(buf, remoteAddress); // keep-alive message
+ }
+ return null;
+ } else if (buf.getByte(buf.readerIndex()) == '$') {
+ return decodeInfo(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII).trim());
+ } else if (buf.getByte(buf.readerIndex() + 2) == ',') {
+ return decodeText(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII).trim());
+ } else {
+ return decodeBinary(channel, remoteAddress, buf);
+ }
+ }
+
}