diff options
-rw-r--r-- | src/org/traccar/protocol/Gl200ProtocolDecoder.java | 27 | ||||
-rw-r--r-- | test/org/traccar/protocol/Gl200ProtocolDecoderTest.java | 3 |
2 files changed, 21 insertions, 9 deletions
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index 60addcd04..ab6507122 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -32,6 +32,7 @@ import org.traccar.model.WifiAccessPoint; import java.net.SocketAddress; import java.util.LinkedList; import java.util.List; +import java.util.regex.Matcher; import java.util.regex.Pattern; public class Gl200ProtocolDecoder extends BaseProtocolDecoder { @@ -237,11 +238,13 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("(d{15}|x{14}),") // imei .expression("[^,]*,") // device name .number("(d+),") // count - .groupBegin() - .number("(x{12}),") // bssid - .number("(-?d+),,,,") // rssi - .groupEnd("+") - .any() + .number("((?:x{12},-?d+,,,,)+),,,,") // wifi + .number("(d{1,3}),") // battery + .number("(dddd)(dd)(dd)") // date + .number("(dd)(dd)(dd)").optional(2) // time + .text(",") + .number("(xxxx)") // count number + .text("$").optional() .compile(); private static final Pattern PATTERN = new PatternBuilder() @@ -620,12 +623,18 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { Network network = new Network(); - int count = parser.nextInt(); - for (int i = 0; i < count; i++) { - String mac = parser.next().replaceAll("(..)", "$1:"); - network.addWifiAccessPoint(WifiAccessPoint.from(mac.substring(0, mac.length() - 1), parser.nextInt())); + parser.nextInt(); // count + Matcher matcher = Pattern.compile("([0-9a-fA-F]{12}),(-?\\d+),,,,").matcher(parser.next()); + while (matcher.find()) { + String mac = matcher.group(1).replaceAll("(..)", "$1:"); + network.addWifiAccessPoint(WifiAccessPoint.from( + mac.substring(0, mac.length() - 1), Integer.parseInt(matcher.group(2)))); } + position.setNetwork(network); + + position.set(Position.KEY_BATTERY, parser.nextInt()); + return position; } diff --git a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java index e4625405b..51c4950f5 100644 --- a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class Gl200ProtocolDecoderTest extends ProtocolTest { Gl200ProtocolDecoder decoder = new Gl200ProtocolDecoder(new Gl200Protocol()); verifyNotNull(decoder, text( + "+RESP:GTWIF,210102,354524044608058,,4,c413e200ff14,-39,,,,c413e2010e55,-39,,,,c8d3ff04a837,-43,,,,42490f997c6d,-57,,,,,,,,100,20170201020055,0001$")); + + verifyNotNull(decoder, text( "+RESP:GTWIF,210102,354524044484948,,1,08626693fb98,-36,,,,,,,,97,20170119071300,05E3$")); verifyAttributes(decoder, text( |