diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-04-28 16:08:40 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-04-28 16:08:40 +1200 |
commit | c763c6c688a2148e46c951c9fc33c09e640bcd9d (patch) | |
tree | b259117ab656c5c473ef3b0d4d6bf4598b226723 /src/org/traccar/protocol/L100ProtocolDecoder.java | |
parent | 7e121784cc9fc79d058f2bdc5bd631a027e7c455 (diff) | |
download | trackermap-server-c763c6c688a2148e46c951c9fc33c09e640bcd9d.tar.gz trackermap-server-c763c6c688a2148e46c951c9fc33c09e640bcd9d.tar.bz2 trackermap-server-c763c6c688a2148e46c951c9fc33c09e640bcd9d.zip |
Refactor L100 protocol for Atlanta devices
Diffstat (limited to 'src/org/traccar/protocol/L100ProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/L100ProtocolDecoder.java | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/src/org/traccar/protocol/L100ProtocolDecoder.java b/src/org/traccar/protocol/L100ProtocolDecoder.java index de966d7af..1fe18ff5e 100644 --- a/src/org/traccar/protocol/L100ProtocolDecoder.java +++ b/src/org/traccar/protocol/L100ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; @@ -27,7 +26,6 @@ import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; -import java.nio.charset.StandardCharsets; import java.util.regex.Pattern; public class L100ProtocolDecoder extends BaseProtocolDecoder { @@ -43,9 +41,9 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder { .number("(dd)(dd)(dd)") // time (hhmmss.sss) .number(".(ddd)").optional() .expression(",([AV]),") // validity - .number("(dd)(dd.d+),") // latitude + .number("(d+)(dd.d+),") // latitude .expression("([NS]),") - .number("(ddd)(dd.d+),") // longitude + .number("(d+)(dd.d+),") // longitude .expression("([EW]),") .number("(d+.?d*)?,") // speed .number("(d+.?d*)?,") // course @@ -59,7 +57,7 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder { .number("(d+.d+),") // odometer .number("(d+.d+),") // temperature .number("(d+.d+),") // battery - .number("(d+),") // gsm + .number("(d+),") // rssi .number("(d+),") // mcc .number("(d+),") // mnc .number("(x+),") // lac @@ -71,12 +69,7 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; - - buf.readUnsignedByte(); // start marker - buf.readUnsignedByte(); // type - - String sentence = buf.readBytes(buf.readableBytes() - 2).toString(StandardCharsets.US_ASCII); + String sentence = (String) msg; Parser parser = new Parser(PATTERN, sentence); if (!parser.matches()) { @@ -92,7 +85,7 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt(0)); position.setValid(parser.next().equals("A")); position.setLatitude(parser.nextCoordinate()); @@ -100,18 +93,20 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(parser.nextDouble(0)); position.setCourse(parser.nextDouble(0)); - dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); + dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); position.setTime(dateBuilder.getDate()); position.set(Position.KEY_STATUS, parser.next()); position.set(Position.PREFIX_ADC + 1, parser.next()); - position.set(Position.KEY_ODOMETER, parser.nextDouble(0)); - position.set(Position.PREFIX_TEMP + 1, parser.nextDouble(0)); - position.set(Position.KEY_BATTERY, parser.nextDouble(0)); - - int rssi = parser.nextInt(0); - position.setNetwork(new Network(CellTower.from( - parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0), rssi))); + position.set(Position.KEY_ODOMETER, parser.nextDouble()); + position.set(Position.PREFIX_TEMP + 1, parser.nextDouble()); + position.set(Position.KEY_BATTERY, parser.nextDouble()); + + int rssi = parser.nextInt(); + if (rssi > 0) { + position.setNetwork(new Network(CellTower.from( + parser.nextInt(), parser.nextInt(), parser.nextHexInt(), parser.nextHexInt(), rssi))); + } return position; } |