aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-02-18 21:54:29 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2013-02-18 21:54:29 +1300
commit62cba3756334997c9f0fe37409b37e771988691d (patch)
tree667b5cfdc791731c1275e6040f3beb0f8c338a9b
parent65fa2bc1268481e4a3b5beb59d6b72645dc77017 (diff)
downloadtraccar-server-62cba3756334997c9f0fe37409b37e771988691d.tar.gz
traccar-server-62cba3756334997c9f0fe37409b37e771988691d.tar.bz2
traccar-server-62cba3756334997c9f0fe37409b37e771988691d.zip
Fixed GpsGate decoder
-rw-r--r--src/org/traccar/protocol/GpsGateProtocolDecoder.java33
-rw-r--r--test/org/traccar/protocol/GpsGateProtocolDecoderTest.java2
2 files changed, 19 insertions, 16 deletions
diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
index 5f51feab9..f755a4ce5 100644
--- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java
+++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
@@ -65,30 +65,31 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
String sentence = (String) msg;
// Process login
- if (sentence.startsWith("$FRLIN")) {
- if (sentence.startsWith("$FRLIN,IMEI")) {
- String imei = sentence.substring(12, sentence.length() - 4);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- send(channel, "$FRSES," + channel.getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- send(channel, "$FRERR,AuthError,Unknown device");
+ if (sentence.startsWith("$FRLIN,")) {
+ int beginIndex = sentence.indexOf(',', 7);
+ if (beginIndex != -1) {
+ beginIndex += 1;
+ int endIndex = sentence.indexOf(',', beginIndex);
+ if (endIndex != -1) {
+ String imei = sentence.substring(beginIndex, endIndex);
+ try {
+ deviceId = getDataManager().getDeviceByImei(imei).getId();
+ send(channel, "$FRSES," + channel.getId());
+ } catch(Exception error) {
+ Log.warning("Unknown device - " + imei);
+ send(channel, "$FRERR,AuthError,Unknown device");
+ }
+ } else {
+ send(channel, "$FRERR,AuthError,Parse error");
}
} else {
- Log.warning("Unsupported login type");
- send(channel, "$FRERR,AuthError,Unsupported login type");
+ send(channel, "$FRERR,AuthError,Parse error");
}
}
// Process data
else if (sentence.contains("$GPRMC") && deviceId != null) {
- // Send response
- if (channel != null) {
- channel.write("OK1\r\n");
- }
-
// Parse message
Matcher parser = pattern.matcher(sentence);
if (!parser.matches()) {
diff --git a/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java b/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java
index 4f30d1224..9e6bb405f 100644
--- a/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java
@@ -13,6 +13,8 @@ public class GpsGateProtocolDecoderTest {
decoder.setDataManager(new TestDataManager());
assertNull(decoder.decode(null, null, "$FRLIN,,user1,8IVHF*7A"));
+
+ assertNull(decoder.decode(null, null, "$FRLIN,,354503026292842,VGZTHKT*0C"));
assertNull(decoder.decode(null, null, "$FRLIN,IMEI,1234123412341234,*7B"));