diff options
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/CharacterDelimiterFrameDecoder.java | 4 | ||||
-rw-r--r-- | src/org/traccar/protocol/Gps103Protocol.java | 2 | ||||
-rw-r--r-- | src/org/traccar/protocol/Gps103ProtocolDecoder.java | 56 |
3 files changed, 61 insertions, 1 deletions
diff --git a/src/org/traccar/CharacterDelimiterFrameDecoder.java b/src/org/traccar/CharacterDelimiterFrameDecoder.java index 5175f9b37..7ce83ff78 100644 --- a/src/org/traccar/CharacterDelimiterFrameDecoder.java +++ b/src/org/traccar/CharacterDelimiterFrameDecoder.java @@ -54,4 +54,8 @@ public class CharacterDelimiterFrameDecoder extends DelimiterBasedFrameDecoder { super(maxFrameLength, convertDelimiters(delimiters)); } + public CharacterDelimiterFrameDecoder(int maxFrameLength, boolean stripDelimiter, String... delimiters) { + super(maxFrameLength, stripDelimiter, convertDelimiters(delimiters)); + } + } diff --git a/src/org/traccar/protocol/Gps103Protocol.java b/src/org/traccar/protocol/Gps103Protocol.java index d112c1170..6272a3fd1 100644 --- a/src/org/traccar/protocol/Gps103Protocol.java +++ b/src/org/traccar/protocol/Gps103Protocol.java @@ -39,7 +39,7 @@ public class Gps103Protocol extends BaseProtocol { addServer(new TrackerServer(false, getName()) { @Override protected void addProtocolHandlers(PipelineBuilder pipeline) { - pipeline.addLast(new CharacterDelimiterFrameDecoder(2048, "\r\n", "\n", ";", "*")); + pipeline.addLast(new CharacterDelimiterFrameDecoder(2048, false, "\r\n", "\n", ";", "*")); pipeline.addLast(new StringEncoder()); pipeline.addLast(new StringDecoder()); pipeline.addLast(new Gps103ProtocolEncoder()); diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 4ef14b29b..b459f6340 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -100,6 +100,27 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private static final Pattern PATTERN_ALT = new PatternBuilder() + .text("imei:") + .number("(d+),") // imei + .expression("[^,]+,") + .expression("...,") // event + .expression(".{6},") // sensor id + .expression(".{4},") // sensor voltage + .number("(dd)(dd)(dd),") // time (hhmmss) + .number("(dd)(dd)(dd),") // date (ddmmyy) + .number("(d+),") // rssi + .number("(d),") // gps status + .number("(-?d+.d+),") // latitude + .number("(-?d+.d+),") // longitude + .number("(d+),") // speed + .number("(d+),") // course + .number("(-?d+),") // altitude + .number("(d+.d+),") // hdop + .number("(d+),") // satellites + .any() + .compile(); + private String decodeAlarm(String value) { if (value.startsWith("T:")) { return Position.ALARM_TEMPERATURE; @@ -270,6 +291,39 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { return position; } + + private Position decodeAlternative(Channel channel, SocketAddress remoteAddress, String sentence) { + + Parser parser = new Parser(PATTERN_ALT, 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()); + + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY)); + + position.set(Position.KEY_RSSI, parser.nextInt()); + + position.setValid(parser.nextInt() > 0); + position.setLatitude(parser.nextDouble()); + position.setLongitude(parser.nextDouble()); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt())); + position.setCourse(parser.nextInt()); + position.setAltitude(parser.nextInt()); + + position.set(Position.KEY_HDOP, parser.nextDouble()); + position.set(Position.KEY_SATELLITES, parser.nextInt()); + + return position; + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -301,6 +355,8 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { if (sentence.contains("OBD")) { return decodeObd(channel, remoteAddress, sentence); + } else if (sentence.endsWith("*")) { + return decodeAlternative(channel, remoteAddress, sentence); } else { return decodeRegular(channel, remoteAddress, sentence); } |