aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-11-18 22:04:41 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-11-18 22:04:41 +1300
commita7f7df0ebdf56a6dbaa5a17600c05c5b6d3033a4 (patch)
tree23eb64d9a56b62db63b0154ee2e40a37b9727fa0
parenta0bc8e67dba450ab1ba3a61340f6c06bf0fa448b (diff)
downloadtrackermap-server-a7f7df0ebdf56a6dbaa5a17600c05c5b6d3033a4.tar.gz
trackermap-server-a7f7df0ebdf56a6dbaa5a17600c05c5b6d3033a4.tar.bz2
trackermap-server-a7f7df0ebdf56a6dbaa5a17600c05c5b6d3033a4.zip
Support GSM based locations (fix #346)
-rw-r--r--debug.xml2
-rw-r--r--src/org/traccar/location/BaseLocationProvider.java22
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java36
-rw-r--r--test/org/traccar/protocol/Gps103ProtocolDecoderTest.java5
4 files changed, 54 insertions, 11 deletions
diff --git a/debug.xml b/debug.xml
index 2e6e4e12a..426dadc4c 100644
--- a/debug.xml
+++ b/debug.xml
@@ -20,6 +20,8 @@
<entry key='location.enable'>false</entry>
<entry key='location.key'>fake</entry>
+ <entry key='location.mcc'>260</entry>
+ <entry key='location.mnc'>2</entry>
<entry key='distance.enable'>true</entry>
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<String, Object> 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(