diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-03-08 23:02:40 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-03-08 23:02:40 +1300 |
commit | e2da4f276230e3687e42b11b4d94889fb3889436 (patch) | |
tree | 1d5de1a13727cca90277d54852aa6bb8b32cccd4 /src/org | |
parent | 18ec7e54839430503b5a73cbf2e63dfa2e234e7b (diff) | |
download | trackermap-server-e2da4f276230e3687e42b11b4d94889fb3889436.tar.gz trackermap-server-e2da4f276230e3687e42b11b4d94889fb3889436.tar.bz2 trackermap-server-e2da4f276230e3687e42b11b4d94889fb3889436.zip |
Extend GpsGate protocol support
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/protocol/GpsGateProtocolDecoder.java | 60 |
1 files changed, 55 insertions, 5 deletions
diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java index 421dc5304..b48fa6266 100644 --- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java +++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.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. @@ -17,6 +17,7 @@ package org.traccar.protocol; import java.net.SocketAddress; import java.util.regex.Pattern; + import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.helper.Checksum; @@ -31,7 +32,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - private static final Pattern PATTERN = new PatternBuilder() + private static final Pattern PATTERN_GPRMC = new PatternBuilder() .text("$GPRMC,") .number("(dd)(dd)(dd).?(d+)?,") // time .expression("([AV]),") // validity @@ -45,6 +46,24 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private static final Pattern PATTERN_FRCMD = new PatternBuilder() + .text("$FRCMD,") + .number("(d+),") // imei + .expression("[^,]*,") // command + .expression("[^,]*,") + .number("(dd)(dd.d+),") // latitude + .expression("([NS]),") + .number("(ddd)(dd.d+),") // longitude + .expression("([EW]),") + .number("(d+.?d*),") // altitude + .number("(d+.?d*),") // speed + .number("(d+.?d*),") // course + .number("(dd)(dd)(dd),") // date (ddmmyy) + .number("(dd)(dd)(dd).?(d+)?,") // time + .expression("([01]),") // validity + .any() + .compile(); + private void send(Channel channel, String message) { if (channel != null) { channel.write(message + Checksum.nmea(message) + "\r\n"); @@ -85,10 +104,10 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { // Version check send(channel, "$FRVER,1,0,GpsGate Server 1.0"); - } else if (sentence.startsWith("$GPRMC,") && hasDeviceId()) { + } else if (sentence.startsWith("$GPRMC,")) { - Parser parser = new Parser(PATTERN, sentence); - if (!parser.matches()) { + Parser parser = new Parser(PATTERN_GPRMC, sentence); + if (!parser.matches() || !hasDeviceId()) { return null; } @@ -109,6 +128,37 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { position.setTime(dateBuilder.getDate()); return position; + + } else if (sentence.startsWith("$FRCMD,")) { + + Parser parser = new Parser(PATTERN_FRCMD, sentence); + if (!parser.matches()) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + + if (!identify(parser.next(), channel, remoteAddress)) { + return null; + } + position.setDeviceId(getDeviceId()); + + position.setLatitude(parser.nextCoordinate()); + position.setLongitude(parser.nextCoordinate()); + position.setAltitude(parser.nextDouble()); + position.setSpeed(parser.nextDouble()); + position.setCourse(parser.nextDouble()); + + DateBuilder dateBuilder = new DateBuilder() + .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + position.setValid(parser.next().equals("1")); + + return position; + } return null; |