diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-09-08 07:30:17 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-09-08 07:30:17 +1200 |
commit | e84d1addacd76c05416c31b9e10b6a1618e41c9d (patch) | |
tree | c90ec20591ec15e317231aee4a9e290956f204c0 | |
parent | 179373c6b3d619922a5daf98220ffe831f56fba2 (diff) | |
download | traccar-server-e84d1addacd76c05416c31b9e10b6a1618e41c9d.tar.gz traccar-server-e84d1addacd76c05416c31b9e10b6a1618e41c9d.tar.bz2 traccar-server-e84d1addacd76c05416c31b9e10b6a1618e41c9d.zip |
Improve H02 protocol decoder
-rw-r--r-- | src/org/traccar/protocol/H02ProtocolDecoder.java | 43 | ||||
-rw-r--r-- | test/org/traccar/protocol/H02ProtocolDecoderTest.java | 13 |
2 files changed, 39 insertions, 17 deletions
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index 091d97cdd..69e53ec27 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -150,9 +150,20 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { .text("*") .expression("..,") // manufacturer .number("(d+),") // imei - .expression("[^,]+,") + .groupBegin() + .text("VP1,") + .expression("[ABV],") + .or() + .groupBegin() + .text("V1,") + .or() + .text("V4,") .any() + .or() + .text("V19,") + .groupEnd() .number("(?:(dd)(dd)(dd))?,") // time (hhmmss) + .groupEnd() .expression("([AV])?,") // validity .groupBegin() .number("-(d+)-(d+.d+),") // latitude @@ -169,25 +180,28 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { .number("(d+.?d*),") // speed .number("(d+.?d*)?,") // course .number("(?:(dd)(dd)(dd))?") // date (ddmmyy) - .any() - .number(",(x{8})") // status + .groupBegin() + .expression(",[^,]*,") + .expression("[^,]*,") + .expression("[^,]*") // sim info + .groupEnd("?") + .groupBegin() + .number(",(x{8})") .groupBegin() .number(",(d+),") // odometer .number("(-?d+),") // temperature .number("(d+.d+),") // fuel .number("(-?d+),") // altitude .number("(x+),") // lac - .number("(x+)#") // cid + .number("(x+)") // cid .or() - .number(",(d+),") - .number("(d+),") - .number("(d+),") - .number("(d+)#") + .text(",") + .expression("(.*)") // data .or() - .expression(",.*") + .groupEnd() .or() - .text("#") .groupEnd() + .text("#") .compile(); private static final Pattern PATTERN_NBR = new PatternBuilder() @@ -289,7 +303,9 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { position.setTime(new Date()); } - processStatus(position, parser.nextLong(16, 0)); + if (parser.hasNext()) { + processStatus(position, parser.nextLong(16, 0)); + } if (parser.hasNext(6)) { position.set(Position.KEY_ODOMETER, parser.nextInt(0)); @@ -302,8 +318,9 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { } if (parser.hasNext(4)) { - for (int i = 1; i <= 4; i++) { - position.set(Position.PREFIX_IO + i, parser.nextInt(0)); + String[] values = parser.next().split(","); + for (int i = 0; i < values.length; i++) { + position.set(Position.PREFIX_IO + (i + 1), values[i].trim()); } } diff --git a/test/org/traccar/protocol/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java index a14d57c3c..0b90a4767 100644 --- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java @@ -11,6 +11,15 @@ public class H02ProtocolDecoderTest extends ProtocolTest { H02ProtocolDecoder decoder = new H02ProtocolDecoder(new H02Protocol()); + verifyPosition(decoder, buffer( + "*HQ,4209951296,V19,214452,A,5201.0178,N,01830.5029,E,000.00,000,200417,,195.63.13.195,89480610500392633029,BFFFFBFF#")); + + verifyNull(decoder, buffer( + "*hq,356327080425330,VP1,A,2702.7215,S,15251.9309,E,0.62,0.0000,050917#")); + + verifyNull(decoder, buffer( + "*HQ,356327080425330,XT,1,100#")); + verifyAttributes(decoder, buffer( "*HQ,353111080001055,V3,044855,28403,01,001450,011473,158,-62,0292,0,X,030817,FFFFFBFF#")); @@ -215,10 +224,6 @@ public class H02ProtocolDecoderTest extends ProtocolTest { "*HQ,2705171109,V1,213324,A,5002.5849,N,01433.7822,E,0.00,000,140613,FFFFFFFF#"), Position.KEY_STATUS, 0xFFFFFFFFL); - verifyAttribute(decoder, buffer( - "*HQ,4109179024,V19,181519,V,3853.2587,S,06205.9175,W,000.00,000,090217,,5492932630888,8954315265044716555?,FFFFFBFF#"), - Position.KEY_STATUS, 0xFFFFFBFFL); - verifyAttribute(decoder, binary( "2441091144271222470112142233983006114026520E000000FFFFFBFFFF0014060000000001CC00262B0F170A"), Position.KEY_STATUS, 0xFFFFFBFFL); |