diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-09-08 03:13:09 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-09-08 12:13:53 +1200 |
commit | 5e481bfc1596de062093c5bc01cf168ed906aafc (patch) | |
tree | 10dcccbe4aadcd5fc8ab1d8a35213095ca0bac64 | |
parent | 7294d12706466840562b073a5a58a3696c0e54da (diff) | |
download | trackermap-server-5e481bfc1596de062093c5bc01cf168ed906aafc.tar.gz trackermap-server-5e481bfc1596de062093c5bc01cf168ed906aafc.tar.bz2 trackermap-server-5e481bfc1596de062093c5bc01cf168ed906aafc.zip |
Support H02 V3 message type
-rw-r--r-- | src/org/traccar/protocol/H02ProtocolDecoder.java | 62 | ||||
-rw-r--r-- | test/org/traccar/protocol/H02ProtocolDecoderTest.java | 11 |
2 files changed, 69 insertions, 4 deletions
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index aa3d47650..091d97cdd 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -222,6 +222,24 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private static final Pattern PATTERN_V3 = new PatternBuilder() + .text("*") + .expression("..,") // manufacturer + .number("(d+),") // imei + .text("V3,") + .number("(dd)(dd)(dd),") // time (hhmmss) + .number("(ddd)") // mcc + .number("(d+),") // mnc + .number("(d+),") // count + .expression("(.*),") // cell info + .number("(x{4}),") // battery + .number("d+,") // reboot info + .text("X,") + .number("(dd)(dd)(dd),") // date (ddmmyy) + .number("(x{8})") // status + .text("#").optional() + .compile(); + private Position decodeText(String sentence, Channel channel, SocketAddress remoteAddress) { Parser parser = new Parser(PATTERN, sentence); @@ -366,6 +384,48 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { return position; } + private Position decodeV3(String sentence, Channel channel, SocketAddress remoteAddress) { + + Parser parser = new Parser(PATTERN_V3, sentence); + if (!parser.matches()) { + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + DateBuilder dateBuilder = new DateBuilder() + .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); + + int mcc = parser.nextInt(); + int mnc = parser.nextInt(); + + int count = parser.nextInt(); + Network network = new Network(); + String[] values = parser.next().split(","); + for (int i = 0; i < count; i++) { + network.addCellTower(CellTower.from( + mcc, mnc, Integer.parseInt(values[i * 4]), Integer.parseInt(values[i * 4 + 1]))); + } + position.setNetwork(network); + + position.set(Position.KEY_BATTERY, parser.nextHexInt()); + + dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); + + getLastLocation(position, dateBuilder.getDate()); + + processStatus(position, parser.nextLong(16, 0)); + + return position; + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -385,6 +445,8 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { return decodeLbs(sentence, channel, remoteAddress); case "LINK": return decodeLink(sentence, channel, remoteAddress); + case "V3": + return decodeV3(sentence, channel, remoteAddress); default: return decodeText(sentence, channel, remoteAddress); } diff --git a/test/org/traccar/protocol/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java index 48f4d987e..a14d57c3c 100644 --- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class H02ProtocolDecoderTest extends ProtocolTest { H02ProtocolDecoder decoder = new H02ProtocolDecoder(new H02Protocol()); + verifyAttributes(decoder, buffer( + "*HQ,353111080001055,V3,044855,28403,01,001450,011473,158,-62,0292,0,X,030817,FFFFFBFF#")); + verifyPosition(decoder, binary( "2442091341332059572807175137358006000183640e000000fffffbfdff001f080000000000ea1e0000000021")); @@ -20,10 +23,10 @@ public class H02ProtocolDecoderTest extends ProtocolTest { verifyAttributes(decoder, buffer( "*HQ,1700086468,LINK,180902,15,0,84,0,0,240517,FFFFFBFF#")); - verifyNull(decoder, buffer( + verifyAttributes(decoder, buffer( "*HQ,355488020882405,V3,095426,74001,01,010278,045142,128,-92,02DE,0,X,090517,FFFFFBFF#")); - verifyNull(decoder, buffer( + verifyAttributes(decoder, buffer( "*HQ,355488020882405,V3,095426,74001,04,010278,045142,128,-92,010278,026311,125,,010278,026582,125,,010278,028322,119,,02DD,0,X,090517,FFFFFBFF#")); verifyPosition(decoder, buffer( @@ -50,7 +53,7 @@ public class H02ProtocolDecoderTest extends ProtocolTest { verifyAttributes(decoder, buffer( "*HQ,4109179024,NBR,103732,722,310,0,6,8106,32010,23,8101,22007,25,8106,12010,23,8106,22105,22,8101,22012,16,8106,42010,5,100217,FFFFFBFF,5#")); - verifyNull(decoder, buffer( + verifyAttributes(decoder, buffer( "*HQ,355488020930796,V3,002339,62160,06,024852,035421,148,0,024852,035425,143,,022251,036482,137,,024852,000335,133,,024852,031751,133,,024852,035423,133,,02A1,0,X,010104,EFE7FBFF#")); verifyPosition(decoder, buffer( @@ -80,7 +83,7 @@ public class H02ProtocolDecoderTest extends ProtocolTest { verifyAttributes(decoder, buffer( "*HQ,1600068860,LINK,112137,20,8,67,0,0,081116,FFFFFBFF#")); - verifyNull(decoder, buffer( + verifyAttributes(decoder, buffer( "*HQ,355488020533263,V3,121536,65501,04,000152,014001,156,-64,000161,010642,138,,000152,014003,129,,000152,013973,126,,02E4,0,X,071116,FFFFFBFF#")); verifyPosition(decoder, buffer( |