From 3471e62b0f3949621265c80dcaf2ba714aade697 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 17 Nov 2015 11:36:08 +1300 Subject: Finish Huabao protocol implementation --- test/org/traccar/protocol/HuabaoProtocolDecoderTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/org/traccar/protocol') diff --git a/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java b/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java index 0968d6d9c..1e2290851 100644 --- a/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java @@ -10,9 +10,18 @@ public class HuabaoProtocolDecoderTest extends ProtocolDecoderTest { HuabaoProtocolDecoder decoder = new HuabaoProtocolDecoder(new HuabaoProtocol()); + verifyNothing(decoder, binary( + "7E0100002D013511221122000500000000373031303748422D52303347424400000000000000000000003233363631303402CBD5424136383630387E")); + verifyNothing(decoder, binary( "7e0100002d007089994489002800000000000000000048422d523033474244000000000000000000000031393036373531024142433030303030d17e")); + verifyNothing(decoder, binary( + "7E0102000E013511221122000661757468656E7469636174696F6E3F7E")); + + verifyPosition(decoder, binary( + "7E02000032013511221122000700000000000C000301578CC006CA3A5C00470000000014072317201501040000000030011631010BD07E")); + } } -- cgit v1.2.3 From 7b46396a9e5b6546b89e927c715c65d59296cd83 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 18 Nov 2015 21:37:03 +1300 Subject: Add LBS example for GPS103 protocol --- test/org/traccar/protocol/Gps103ProtocolDecoderTest.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/org/traccar/protocol') diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java index 80d1424fc..03d7b5c72 100644 --- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class Gps103ProtocolDecoderTest extends ProtocolDecoderTest { Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(new Gps103Protocol()); + verifyNothing(decoder, text( + "imei:863070016871385,tracker,0000000119,,L,,,0FB6,,CB5D,,,")); + verifyPosition(decoder, text( "imei:359710045559474,tracker,151030080103,,F,000101.000,A,5443.3834,N,02512.9071,E,0.00,0;"), position("2015-10-30 00:01:01.000", true, 54.72306, 25.21512)); -- cgit v1.2.3 From a7f7df0ebdf56a6dbaa5a17600c05c5b6d3033a4 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 18 Nov 2015 22:04:41 +1300 Subject: Support GSM based locations (fix #346) --- debug.xml | 2 ++ src/org/traccar/location/BaseLocationProvider.java | 22 +++++++++---- .../traccar/protocol/Gps103ProtocolDecoder.java | 36 +++++++++++++++++++--- .../protocol/Gps103ProtocolDecoderTest.java | 5 ++- 4 files changed, 54 insertions(+), 11 deletions(-) (limited to 'test/org/traccar/protocol') diff --git a/debug.xml b/debug.xml index 2e6e4e12a..426dadc4c 100644 --- a/debug.xml +++ b/debug.xml @@ -20,6 +20,8 @@ false fake + 260 + 2 true diff --git a/src/org/traccar/location/BaseLocationProvider.java b/src/org/traccar/location/BaseLocationProvider.java index 80b10b33c..d6eddc1cd 100644 --- a/src/org/traccar/location/BaseLocationProvider.java +++ b/src/org/traccar/location/BaseLocationProvider.java @@ -15,6 +15,7 @@ */ package org.traccar.location; +import org.traccar.Context; import org.traccar.model.Event; import java.util.Map; @@ -23,13 +24,22 @@ public abstract class BaseLocationProvider implements LocationProvider { @Override public void getLocation(Map attributes, LocationProviderCallback callback) { - if (attributes.containsKey(Event.KEY_MCC) || attributes.containsKey(Event.KEY_MNC)) { - Number mcc = (Number) attributes.get(Event.KEY_MCC); - Number mnc = (Number) attributes.get(Event.KEY_MNC); - Number lac = (Number) attributes.get(Event.KEY_LAC); - Number cid = (Number) attributes.get(Event.KEY_CID); - getLocation(mcc.intValue(), mnc.intValue(), lac.longValue(), cid.longValue(), callback); + + Number mcc = (Number) attributes.get(Event.KEY_MCC); + if (mcc == null) { + mcc = Context.getConfig().getInteger("location.mcc"); + } + + Number mnc = (Number) attributes.get(Event.KEY_MNC); + if (mnc == null) { + mnc = Context.getConfig().getInteger("location.mnc"); } + + Number lac = (Number) attributes.get(Event.KEY_LAC); + Number cid = (Number) attributes.get(Event.KEY_CID); + + getLocation(mcc.intValue(), mnc.intValue(), lac.longValue(), cid.longValue(), callback); + } protected abstract void getLocation(int mcc, int mnc, long lac, long cid, LocationProviderCallback callback); diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index aa693f42e..a91848f5b 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -63,6 +63,17 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private static final Pattern PATTERN_NETWORK = new PatternBuilder() + .text("imei:") + .number("(d+),") // imei + .expression("[^,]+,") // alarm + .number("d+,,") + .text("L,,,") + .number("(x+),,") // lac + .number("(x+),,,") // cid + .any() + .compile(); + private static final Pattern PATTERN_HANDSHAKE = new PatternBuilder() .number("##,imei:(d+),A") .compile(); @@ -93,14 +104,31 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { return null; } - Parser parser = new Parser(PATTERN, sentence); + Position position = new Position(); + position.setProtocol(getProtocolName()); + + Parser parser = new Parser(PATTERN_NETWORK, sentence); + if (parser.matches()) { + + if (!identify(parser.next(), channel, remoteAddress)) { + return null; + } + position.setDeviceId(getDeviceId()); + + getLastLocation(position, null); + + position.set(Event.KEY_LAC, parser.nextInt(16)); + position.set(Event.KEY_CID, parser.nextInt(16)); + + return position; + + } + + parser = new Parser(PATTERN, sentence); if (!parser.matches()) { return null; } - Position position = new Position(); - position.setProtocol(getProtocolName()); - String imei = parser.next(); if (!identify(imei, channel, remoteAddress)) { return null; diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java index 03d7b5c72..371b137fd 100644 --- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java @@ -10,7 +10,10 @@ public class Gps103ProtocolDecoderTest extends ProtocolDecoderTest { Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(new Gps103Protocol()); - verifyNothing(decoder, text( + verifyAttributes(decoder, text( + "imei:359710041100000,tracker,000000000,,L,,,fa8,,c9af,,,,,0,0,0.00%,,")); + + verifyAttributes(decoder, text( "imei:863070016871385,tracker,0000000119,,L,,,0FB6,,CB5D,,,")); verifyPosition(decoder, text( -- cgit v1.2.3 From cc5d60ff499c39fb4db7e06b2e62fefe2a324f77 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 19 Nov 2015 09:51:28 +1300 Subject: Add more Huabao decoder unit tests --- test/org/traccar/protocol/HuabaoProtocolDecoderTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/org/traccar/protocol') diff --git a/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java b/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java index 1e2290851..b24b844d9 100644 --- a/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java @@ -22,6 +22,18 @@ public class HuabaoProtocolDecoderTest extends ProtocolDecoderTest { verifyPosition(decoder, binary( "7E02000032013511221122000700000000000C000301578CC006CA3A5C00470000000014072317201501040000000030011631010BD07E")); + verifyNothing(decoder, binary( + "7E010200100940278494700084323031313131303831313333323139369F7E")); + + verifyNothing(decoder, binary( + "7e010000190940278494700012000000000000000000000000000000000000094027849470000a7e")); + + verifyPosition(decoder, binary( + "7e0200002e094027587492000a000000010000000a03083db7001329f3000000140000130412164952010400000012360a0002341502cb0c20085c107e")); + + verifyPosition(decoder, binary( + "7e020000220014012499170007000000000000400e012af16f02cbd2ba000000000000150101194257010400000077a97e")); + } } -- cgit v1.2.3 From 5d919c8489ea3c88d3182fab77b6b24b9dd86bef Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 19 Nov 2015 10:35:57 +1300 Subject: Implement LBS support for TK103 --- src/org/traccar/protocol/Tk103ProtocolDecoder.java | 36 ++++++++++++++++++---- .../traccar/protocol/Tk103ProtocolDecoderTest.java | 3 ++ 2 files changed, 33 insertions(+), 6 deletions(-) (limited to 'test/org/traccar/protocol') diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 95728c447..6fa4edb06 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -64,6 +64,16 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { .number("d+") // installed .compile(); + private static final Pattern PATTERN_NETWORK = new PatternBuilder() + .number("(d{12})") // device id + .text("BZ00,") + .number("(d+),") // mcc + .number("(d+),") // mnc + .number("(x+),") // lac + .number("(x+),") // cid + .any() + .compile(); + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -88,11 +98,11 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { } } + Position position = new Position(); + position.setProtocol(getProtocolName()); + Parser parser = new Parser(PATTERN_BATTERY, sentence); if (parser.matches()) { - Position position = new Position(); - position.setProtocol(getProtocolName()); - if (!identify(parser.next(), channel)) { return null; } @@ -117,14 +127,28 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { return position; } + parser = new Parser(PATTERN_NETWORK, sentence); + if (parser.matches()) { + if (!identify(parser.next(), channel)) { + return null; + } + position.setDeviceId(getDeviceId()); + + getLastLocation(position, null); + + position.set(Event.KEY_MCC, parser.nextInt()); + position.set(Event.KEY_MNC, parser.nextInt()); + position.set(Event.KEY_LAC, parser.nextInt(16)); + position.set(Event.KEY_CID, parser.nextInt(16)); + + return position; + } + parser = new Parser(PATTERN, sentence); if (!parser.matches()) { return null; } - Position position = new Position(); - position.setProtocol(getProtocolName()); - if (!identify(parser.next(), channel)) { return null; } diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java index d9152ecf0..2bffbcd9a 100644 --- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class Tk103ProtocolDecoderTest extends ProtocolDecoderTest { Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(new Tk103Protocol()); + verifyAttributes(decoder, text( + "(088047194605BZ00,510,010,36e6,932c,43,36e6,766b,36,36e6,7668,32")); + verifyAttributes(decoder, text( "(013632651491,ZC20,040613,040137,6,42,112,0")); -- cgit v1.2.3 From 4c9466f694e48b69a14e9039bd9b8d717c3a3dc3 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 20 Nov 2015 09:46:39 +1300 Subject: Add support for TKQ messages --- src/org/traccar/protocol/WatchProtocolDecoder.java | 8 ++++++-- test/org/traccar/protocol/WatchProtocolDecoderTest.java | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'test/org/traccar/protocol') diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index a24d0a56b..92b7638fb 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -64,8 +64,8 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { private void sendResponse(Channel channel, String manufacturer, String id, String content) { if (channel != null) { - channel.write( - String.format("[%s*%s*%04x*%s]", manufacturer, id, content.length(), content)); + channel.write(String.format( + "[%s*%s*%04x*%s]", manufacturer, id, content.length(), content)); } } @@ -138,6 +138,10 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { return position; + } else if (type.equals("TKQ")) { + + sendResponse(channel, manufacturer, id, "TKQ"); + } return null; diff --git a/test/org/traccar/protocol/WatchProtocolDecoderTest.java b/test/org/traccar/protocol/WatchProtocolDecoderTest.java index 41af104dd..16074d36f 100644 --- a/test/org/traccar/protocol/WatchProtocolDecoderTest.java +++ b/test/org/traccar/protocol/WatchProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class WatchProtocolDecoderTest extends ProtocolDecoderTest { WatchProtocolDecoder decoder = new WatchProtocolDecoder(new WatchProtocol()); + verifyNothing(decoder, text( + "[3G*8800000015*0003*TKQ")); + verifyPosition(decoder, text( "[3G*4700186508*00B1*UD,301015,084840,V,45.853100,N,14.6224899,E,0.00,0.0,0.0,0,84,61,0,11,00000008,7,255,293,70,60,6453,139,60,6432,139,60,6431,132,60,6457,127,60,16353,126,60,6451,121,60,16352,118")); -- cgit v1.2.3 From 40674d8338c679a958ced0a94c4b61716775045d Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 21 Nov 2015 10:52:34 +1300 Subject: Add another Meiligao unit test case --- src/org/traccar/protocol/MeiligaoFrameDecoder.java | 4 +--- test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'test/org/traccar/protocol') diff --git a/src/org/traccar/protocol/MeiligaoFrameDecoder.java b/src/org/traccar/protocol/MeiligaoFrameDecoder.java index 6dcc6fd9c..9fb530f8a 100644 --- a/src/org/traccar/protocol/MeiligaoFrameDecoder.java +++ b/src/org/traccar/protocol/MeiligaoFrameDecoder.java @@ -26,9 +26,7 @@ public class MeiligaoFrameDecoder extends FrameDecoder { @Override protected Object decode( - ChannelHandlerContext ctx, - Channel channel, - ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { // Strip not '$' (0x24) bytes from the beginning while (buf.readable() && buf.getUnsignedByte(buf.readerIndex()) != 0x24) { diff --git a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java index 6d0ba50d5..0c3c570f5 100644 --- a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java @@ -12,8 +12,11 @@ public class MeiligaoProtocolDecoderTest extends ProtocolDecoderTest { MeiligaoProtocolDecoder decoder = new MeiligaoProtocolDecoder(new MeiligaoProtocol()); + verifyNothing(decoder, binary( + "24240011671440258855405000b24d0d0a")); + verifyPosition(decoder, binary( - "242400706796502079108999553131333131382e3030302c412c313033372e393637382c4e2c30363132312e353637392c572c302e35342c322e34322c3330303931352c2c2c412a37307c302e37377c392e397c303030307c303030302c303161327c3030313138373132374cae0d0a"), + "242400706796502079108999553131333131382e3030302c412c313033372e393637382c4e2c30363132312e353637392c572c302e35342c322e34322c3330303931352c2c2c412a37307c302e37377c392e397c303030307c303030302c303161327c3030313138373132374cae0d0a"), position("2015-09-30 11:31:18.000", true, 10.63280, -61.35947)); verifyPosition(decoder, binary( -- cgit v1.2.3