From 8e4d44e045c6e0c800b3b353f6f55c64d731428c Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 20 Jul 2016 10:10:59 +1200 Subject: Adjust TK103 voltage values --- src/org/traccar/protocol/Tk103ProtocolDecoder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index a0998d50d..a76c208b5 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -118,12 +118,12 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { int battery = parser.nextInt(); if (battery != 65535) { - position.set(Position.KEY_BATTERY, battery); + position.set(Position.KEY_BATTERY, battery * 0.01); } int power = parser.nextInt(); if (power != 65535) { - position.set(Position.KEY_POWER, power); + position.set(Position.KEY_POWER, power * 0.1); } return position; -- cgit v1.2.3 From d6fba0cc479f32f57b3359c7b87344918339a650 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 20 Jul 2016 23:35:07 +1200 Subject: Revert temporary L100 removal This reverts commit 21a8fb81a0aa88a7bc1cb6804da034ecc9a79bcd. --- src/org/traccar/protocol/L100FrameDecoder.java | 50 +++++++++ src/org/traccar/protocol/L100Protocol.java | 44 ++++++++ src/org/traccar/protocol/L100ProtocolDecoder.java | 116 +++++++++++++++++++++ .../org/traccar/protocol/L100FrameDecoderTest.java | 24 +++++ .../traccar/protocol/L100ProtocolDecoderTest.java | 18 ++++ 5 files changed, 252 insertions(+) create mode 100644 src/org/traccar/protocol/L100FrameDecoder.java create mode 100644 src/org/traccar/protocol/L100Protocol.java create mode 100644 src/org/traccar/protocol/L100ProtocolDecoder.java create mode 100644 test/org/traccar/protocol/L100FrameDecoderTest.java create mode 100644 test/org/traccar/protocol/L100ProtocolDecoderTest.java (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/L100FrameDecoder.java b/src/org/traccar/protocol/L100FrameDecoder.java new file mode 100644 index 000000000..92af255dd --- /dev/null +++ b/src/org/traccar/protocol/L100FrameDecoder.java @@ -0,0 +1,50 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.handler.codec.frame.FrameDecoder; + +public class L100FrameDecoder extends FrameDecoder { + + @Override + protected Object decode( + ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { + + if (buf.readableBytes() < 80) { + return null; + } + + int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x02); + if (index == -1) { + index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x04); + if (index == -1) { + return null; + } + } + + index += 2; // checksum + + if (buf.readableBytes() >= index - buf.readerIndex()) { + return buf.readBytes(index - buf.readerIndex()); + } + + return null; + } + +} diff --git a/src/org/traccar/protocol/L100Protocol.java b/src/org/traccar/protocol/L100Protocol.java new file mode 100644 index 000000000..f866b5d69 --- /dev/null +++ b/src/org/traccar/protocol/L100Protocol.java @@ -0,0 +1,44 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.model.Command; + +import java.util.List; + +public class L100Protocol extends BaseProtocol { + + public L100Protocol() { + super("l100"); + } + + @Override + public void initTrackerServers(List serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new L100FrameDecoder()); + pipeline.addLast("objectDecoder", new L100ProtocolDecoder(L100Protocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/L100ProtocolDecoder.java b/src/org/traccar/protocol/L100ProtocolDecoder.java new file mode 100644 index 000000000..b7e2e91cc --- /dev/null +++ b/src/org/traccar/protocol/L100ProtocolDecoder.java @@ -0,0 +1,116 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.channel.Channel; +import org.traccar.BaseProtocolDecoder; +import org.traccar.helper.DateBuilder; +import org.traccar.helper.Parser; +import org.traccar.helper.PatternBuilder; +import org.traccar.model.Position; + +import java.net.SocketAddress; +import java.nio.charset.StandardCharsets; +import java.util.regex.Pattern; + +public class L100ProtocolDecoder extends BaseProtocolDecoder { + + public L100ProtocolDecoder(L100Protocol protocol) { + super(protocol); + } + + private static final Pattern PATTERN = new PatternBuilder() + .text("ATL") + .number("(d{15}),") // imei + .text("$GPRMC,") + .number("(dd)(dd)(dd).ddd,") // time + .expression("([AV]),") // validity + .number("(dd)(dd.d+),") // latitude + .expression("([NS]),") + .number("(ddd)(dd.d+),") // longitude + .expression("([EW]),") + .number("(d+.?d*)?,") // speed + .number("(d+.?d*)?,") // course + .number("(dd)(dd)(dd),") // date + .any() + .text("#") + .number("([01]+),") // io status + .number("(d+.d+|N.C),") // adc + .expression("[^,]*,") // reserved + .expression("[^,]*,") // reserved + .number("(d+.d+),") // odometer + .number("(d+.d+),") // temperature + .number("(d+.d+),") // battery + .number("(d+),") // gsm + .number("(d+),") // mcc + .number("(d+),") // mnc + .number("(d+),") // lac + .number("(d+)") // cid + .text("ATL") + .compile(); + + @Override + 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); + + Parser parser = new Parser(PATTERN, sentence); + if (!parser.matches()) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + + if (!identify(parser.next(), channel, remoteAddress)) { + return null; + } + position.setDeviceId(getDeviceId()); + + DateBuilder dateBuilder = new DateBuilder() + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + + position.setValid(parser.next().equals("A")); + position.setLatitude(parser.nextCoordinate()); + position.setLongitude(parser.nextCoordinate()); + position.setSpeed(parser.nextDouble()); + position.setCourse(parser.nextDouble()); + + 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()); + position.set(Position.PREFIX_TEMP + 1, parser.nextDouble()); + position.set(Position.KEY_BATTERY, parser.nextDouble()); + position.set(Position.KEY_GSM, parser.nextInt()); + position.set(Position.KEY_MCC, parser.nextInt()); + position.set(Position.KEY_MNC, parser.nextInt()); + position.set(Position.KEY_LAC, parser.nextInt()); + position.set(Position.KEY_CID, parser.nextInt()); + + return position; + } + +} diff --git a/test/org/traccar/protocol/L100FrameDecoderTest.java b/test/org/traccar/protocol/L100FrameDecoderTest.java new file mode 100644 index 000000000..f474fa678 --- /dev/null +++ b/test/org/traccar/protocol/L100FrameDecoderTest.java @@ -0,0 +1,24 @@ +package org.traccar.protocol; + +import org.junit.Assert; +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class L100FrameDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + L100FrameDecoder decoder = new L100FrameDecoder(); + + Assert.assertEquals( + binary("200141544c3335363839353033373533333734352c244750524d432c3131313731392e3030302c412c323833382e303034352c4e2c30373731332e333730372c452c302e30302c2c3132303831302c2c2c412a3735242c2330313130303131313030313031302c4e2e432c4e2e432c4e2e432c31323334352e36372c33312e342c342e322c32312c4d43432c4d4e432c4c41432c43656c6c494441544c027a"), + decoder.decode(null, null, binary("200141544c3335363839353033373533333734352c244750524d432c3131313731392e3030302c412c323833382e303034352c4e2c30373731332e333730372c452c302e30302c2c3132303831302c2c2c412a3735242c2330313130303131313030313031302c4e2e432c4e2e432c4e2e432c31323334352e36372c33312e342c342e322c32312c4d43432c4d4e432c4c41432c43656c6c494441544c027a"))); + + Assert.assertEquals( + binary("200341544c3335363839353033373533333734352c244750524d432c3131313731392e3030302c412c323833382e303034352c4e2c30373731332e333730372c452c302e30302c2c3132303831302c2c2c412a3735244c4f432c436f6e6e61756768742043697263757320c2a0436f6e6e617567687420506c61636520c2a04e65772044656c686920c2a044656c6869c2a0496e6469612c2330313130303130313130313031302c322e332c33352e36372c38302c31323334352e36372c33312e342c342e322c32312c4d43432c4d4e432c4c41432c43656c6c494441544c047a"), + decoder.decode(null, null, binary("200341544c3335363839353033373533333734352c244750524d432c3131313731392e3030302c412c323833382e303034352c4e2c30373731332e333730372c452c302e30302c2c3132303831302c2c2c412a3735244c4f432c436f6e6e61756768742043697263757320c2a0436f6e6e617567687420506c61636520c2a04e65772044656c686920c2a044656c6869c2a0496e6469612c2330313130303130313130313031302c322e332c33352e36372c38302c31323334352e36372c33312e342c342e322c32312c4d43432c4d4e432c4c41432c43656c6c494441544c047a"))); + + } + +} diff --git a/test/org/traccar/protocol/L100ProtocolDecoderTest.java b/test/org/traccar/protocol/L100ProtocolDecoderTest.java new file mode 100644 index 000000000..07e72140d --- /dev/null +++ b/test/org/traccar/protocol/L100ProtocolDecoderTest.java @@ -0,0 +1,18 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class L100ProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + L100ProtocolDecoder decoder = new L100ProtocolDecoder(new L100Protocol()); + + verifyPosition(decoder, binary( + "200141544c3335363839353033373533333734352c244750524d432c3131313731392e3030302c412c323833382e303034352c4e2c30373731332e333730372c452c302e30302c2c3132303831302c2c2c412a37352c2330313130303131313030313031302c4e2e432c4e2e432c4e2e432c31323334352e36372c33312e342c342e322c32312c3130302c3030302c3030303030312c303030303041544c027a")); + + } + +} -- cgit v1.2.3 From dfbadf146bc23231ffb7d3bc03d5933e43acf77f Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 20 Jul 2016 23:37:13 +1200 Subject: Update L100 protocol decoder --- src/org/traccar/protocol/L100ProtocolDecoder.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/L100ProtocolDecoder.java b/src/org/traccar/protocol/L100ProtocolDecoder.java index b7e2e91cc..ff0687751 100644 --- a/src/org/traccar/protocol/L100ProtocolDecoder.java +++ b/src/org/traccar/protocol/L100ProtocolDecoder.java @@ -18,6 +18,7 @@ package org.traccar.protocol; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; +import org.traccar.DeviceSession; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; @@ -82,10 +83,11 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(); position.setProtocol(getProtocolName()); - if (!identify(parser.next(), channel, remoteAddress)) { + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { return null; } - position.setDeviceId(getDeviceId()); + position.setDeviceId(deviceSession.getDeviceId()); DateBuilder dateBuilder = new DateBuilder() .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); -- cgit v1.2.3 From b762d087c09533cc66330d546b1832da2816a400 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 20 Jul 2016 23:41:34 +1200 Subject: Remove unused imports --- src/org/traccar/protocol/L100Protocol.java | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/L100Protocol.java b/src/org/traccar/protocol/L100Protocol.java index f866b5d69..95a4dce68 100644 --- a/src/org/traccar/protocol/L100Protocol.java +++ b/src/org/traccar/protocol/L100Protocol.java @@ -15,12 +15,10 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ConnectionlessBootstrap; import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.ChannelPipeline; import org.traccar.BaseProtocol; import org.traccar.TrackerServer; -import org.traccar.model.Command; import java.util.List; -- cgit v1.2.3 From 89806e14be5ff9637179c497b5ad2ac49a7a35c5 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 21 Jul 2016 00:13:33 +1200 Subject: Do not close HTTP connection --- src/org/traccar/protocol/OsmAndProtocolDecoder.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java index cfa8990dd..c5a37b47a 100644 --- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java +++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java @@ -123,9 +123,7 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder { } if (channel != null) { - HttpResponse response = new DefaultHttpResponse( - HttpVersion.HTTP_1_1, HttpResponseStatus.OK); - channel.write(response).addListener(ChannelFutureListener.CLOSE); + channel.write(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK)); } return position; -- cgit v1.2.3 From 82259ad4b16f28707ae15f917389774b51e3b0b3 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 21 Jul 2016 00:15:22 +1200 Subject: Remove unused imports --- src/org/traccar/protocol/OsmAndProtocolDecoder.java | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java index c5a37b47a..da502ca65 100644 --- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java +++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java @@ -16,10 +16,8 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelFutureListener; import org.jboss.netty.handler.codec.http.DefaultHttpResponse; import org.jboss.netty.handler.codec.http.HttpRequest; -import org.jboss.netty.handler.codec.http.HttpResponse; import org.jboss.netty.handler.codec.http.HttpResponseStatus; import org.jboss.netty.handler.codec.http.HttpVersion; import org.jboss.netty.handler.codec.http.QueryStringDecoder; -- cgit v1.2.3 From c92f37404893cce14a25379bcd84bb081e94f1b8 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 22 Jul 2016 13:26:45 +1200 Subject: Workaround for incorrect hemisphere (fix #2139) --- src/org/traccar/protocol/WatchProtocolDecoder.java | 6 +++--- test/org/traccar/protocol/WatchProtocolDecoderTest.java | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index ca63e701e..326552e7f 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,9 +47,9 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { .number("(dd)(dd)(dd),") // date (ddmmyy) .number("(dd)(dd)(dd),") // time .expression("([AV]),") // validity - .number(" *-?(d+.d+),") // latitude + .number(" *(-?d+.d+),") // latitude .expression("([NS]),") - .number(" *-?(d+.d+),") // longitude + .number(" *(-?d+.d+),") // longitude .expression("([EW])?,") .number("(d+.d+),") // speed .number("(d+.?d*),") // course diff --git a/test/org/traccar/protocol/WatchProtocolDecoderTest.java b/test/org/traccar/protocol/WatchProtocolDecoderTest.java index 89e9a7e77..a8f7b12bc 100644 --- a/test/org/traccar/protocol/WatchProtocolDecoderTest.java +++ b/test/org/traccar/protocol/WatchProtocolDecoderTest.java @@ -10,6 +10,10 @@ public class WatchProtocolDecoderTest extends ProtocolTest { WatchProtocolDecoder decoder = new WatchProtocolDecoder(new WatchProtocol()); + verifyPosition(decoder, text( + "[3G*6105117105*008D*UD2,210716,231601,V,-33.480366,N,-70.7630692,E,0.00,0.0,0.0,0,100,34,0,0,00000000,3,255,730,2,29731,54315,167,29731,54316,162,29731,54317,145"), + position("2016-07-21 23:16:01.000", false, -33.48037, -70.76307)); + verifyPosition(decoder, text( "[3G*4700222306*0077*UD,120316,140610,V,48.779045,N, 9.1574736,E,0.00,0.0,0.0,0,25,83,0,0,00000000,2,255,262,1,21041,9067,121,21041,5981,116")); -- cgit v1.2.3 From e218ed3cd4fa3c1630ba15faacc23774c40543d0 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 23 Jul 2016 00:58:59 +1200 Subject: Return http error if unknown --- src/org/traccar/protocol/OsmAndProtocolDecoder.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java index da502ca65..12192c457 100644 --- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java +++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java @@ -64,6 +64,9 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder { case "deviceid": DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, value); if (deviceSession == null) { + if (channel != null) { + channel.write(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST)); + } return null; } position.setDeviceId(deviceSession.getDeviceId()); -- cgit v1.2.3 From 5d9c7f4dde298d5b02a2aa688bb27949072e2a57 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 23 Jul 2016 01:01:15 +1200 Subject: Fix checkstyle issue --- src/org/traccar/protocol/OsmAndProtocolDecoder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java index 12192c457..f46511b27 100644 --- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java +++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java @@ -48,8 +48,7 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder { QueryStringDecoder decoder = new QueryStringDecoder(request.getUri()); Map> params = decoder.getParameters(); if (params.isEmpty()) { - decoder = new QueryStringDecoder( - request.getContent().toString(StandardCharsets.US_ASCII), false); + decoder = new QueryStringDecoder(request.getContent().toString(StandardCharsets.US_ASCII), false); params = decoder.getParameters(); } @@ -65,7 +64,8 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder { DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, value); if (deviceSession == null) { if (channel != null) { - channel.write(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST)); + channel.write( + new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST)); } return null; } -- cgit v1.2.3 From 83d2fdc694ca75eaef53adef76dad938e1bd6262 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 23 Jul 2016 01:26:41 +1200 Subject: Support GT02 command responses --- src/org/traccar/protocol/Gt02ProtocolDecoder.java | 13 +++++++++++-- test/org/traccar/protocol/Gt02ProtocolDecoderTest.java | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java index d93b93b83..dea1416ac 100644 --- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt02ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; +import java.nio.charset.StandardCharsets; public class Gt02ProtocolDecoder extends BaseProtocolDecoder { @@ -33,8 +34,9 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - public static final int MSG_HEARTBEAT = 0x1A; public static final int MSG_DATA = 0x10; + public static final int MSG_HEARTBEAT = 0x1A; + public static final int MSG_RESPONSE = 0x1C; @Override protected Object decode( @@ -102,6 +104,13 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(latitude); position.setLongitude(longitude); + } else if (type == MSG_RESPONSE) { + + getLastLocation(position, null); + + position.set(Position.KEY_RESULT, + buf.readBytes(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII)); + } else { return null; diff --git a/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java index 3cfa0ea4a..c957acd6c 100644 --- a/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java @@ -10,6 +10,12 @@ public class Gt02ProtocolDecoderTest extends ProtocolTest { Gt02ProtocolDecoder decoder = new Gt02ProtocolDecoder(new Gt02Protocol()); + verifyAttributes(decoder, binary( + "6868150000035889905895258400831c07415045584f4b210d0a")); + + verifyAttributes(decoder, binary( + "68682d0000035889905895258400951c1f415045584572726f723a20506172616d65746572203120284f4e2f4f4646290d0a")); + verifyAttributes(decoder, binary( "68680f0504035889905831401700df1a00000d0a")); -- cgit v1.2.3 From e176392ddbea44dc94c0904f21338a11b862ad4d Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 23 Jul 2016 11:49:28 +1200 Subject: Improve GpsGate protocol decoder --- src/org/traccar/protocol/GpsGateProtocolDecoder.java | 4 ++-- test/org/traccar/protocol/GpsGateProtocolDecoderTest.java | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java index 1cb0ddfde..afc17a9f7 100644 --- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java +++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java @@ -58,10 +58,10 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { .expression("([EW]),") .number("(d+.?d*),") // altitude .number("(d+.?d*),") // speed - .number("(d+.?d*),") // course + .number("(d+.?d*)?,") // course .number("(dd)(dd)(dd),") // date (ddmmyy) .number("(dd)(dd)(dd).?(d+)?,") // time - .expression("([01]),") // validity + .expression("([01])") // validity .any() .compile(); diff --git a/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java b/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java index 30861099f..11cfb66f5 100644 --- a/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class GpsGateProtocolDecoderTest extends ProtocolTest { GpsGateProtocolDecoder decoder = new GpsGateProtocolDecoder(new GpsGateProtocol()); + verifyPosition(decoder, text( + "$FRCMD,356406061385182,_SendMessage,,5223.88542,N,11440.45866,W,951.2,0.027,,220716,153507.00,1*5F")); + verifyPosition(decoder, text( "$FRCMD,353067011068246,_SendMessage,,1918.1942,N,09906.3696,W,2246.5,000.0,295.9,150416,213147.00,1,Odometer=*70")); -- cgit v1.2.3 From c7a0fa08fde55e8d14bfee9ed5f4f14ee42c0c30 Mon Sep 17 00:00:00 2001 From: Fabián Inostroza Date: Sun, 24 Jul 2016 02:44:04 -0400 Subject: Correctly process negative latitude and longitude. --- src/org/traccar/protocol/EasyTrackProtocolDecoder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java index fa792d7b5..41f395fd9 100644 --- a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java +++ b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java @@ -86,13 +86,13 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder { .setTime(parser.nextInt(16), parser.nextInt(16), parser.nextInt(16)); position.setTime(dateBuilder.getDate()); - if (BitUtil.check(parser.nextInt(16), 7)) { + if (BitUtil.check(parser.nextInt(16), 3)) { position.setLatitude(-parser.nextInt(16) / 600000.0); } else { position.setLatitude(parser.nextInt(16) / 600000.0); } - if (BitUtil.check(parser.nextInt(16), 7)) { + if (BitUtil.check(parser.nextInt(16), 3)) { position.setLongitude(-parser.nextInt(16) / 600000.0); } else { position.setLongitude(parser.nextInt(16) / 600000.0); -- cgit v1.2.3