aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2014-06-17 21:17:33 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2014-06-17 21:17:33 +1200
commit2034139e1f64ceee146d376e3eb01915b0f86239 (patch)
tree44bd5352d25e219be36ae3385cd2a01c704555e4 /src/org
parent32ef234d143057b7f1e785c38073c23e8ca1e108 (diff)
downloadtrackermap-server-2034139e1f64ceee146d376e3eb01915b0f86239.tar.gz
trackermap-server-2034139e1f64ceee146d376e3eb01915b0f86239.tar.bz2
trackermap-server-2034139e1f64ceee146d376e3eb01915b0f86239.zip
Extend T55 protocol decoder
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/protocol/T55ProtocolDecoder.java41
1 files changed, 18 insertions, 23 deletions
diff --git a/src/org/traccar/protocol/T55ProtocolDecoder.java b/src/org/traccar/protocol/T55ProtocolDecoder.java
index 37f4369ee..e7a012f8d 100644
--- a/src/org/traccar/protocol/T55ProtocolDecoder.java
+++ b/src/org/traccar/protocol/T55ProtocolDecoder.java
@@ -81,50 +81,45 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
"(\\d+\\.?\\d*)," + // Battery
".+");
+ private void identify(String id) {
+ try {
+ deviceId = getDataManager().getDeviceByImei(id).getId();
+ } catch(Exception error) {
+ Log.warning("Unknown device - " + id);
+ }
+ }
+
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, Object msg)
throws Exception {
String sentence = (String) msg;
+
+ if (!sentence.startsWith("$") && sentence.contains("$")) {
+ int index = sentence.indexOf("$");
+ identify(sentence.substring(0, index));
+ sentence = sentence.substring(index);
+ }
// Identification
if (sentence.startsWith("$PGID")) {
- String imei = sentence.substring(6, sentence.length() - 3);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
+ identify(sentence.substring(6, sentence.length() - 3));
}
// Identification
else if (sentence.startsWith("$PCPTI")) {
- String id = sentence.substring(7, sentence.indexOf(",", 7));
- try {
- deviceId = getDataManager().getDeviceByImei(id).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
- }
+ identify(sentence.substring(7, sentence.indexOf(",", 7)));
}
// Identification
else if (sentence.startsWith("IMEI")) {
- String id = sentence.substring(5, sentence.length());
- try {
- deviceId = getDataManager().getDeviceByImei(id).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
- }
+ identify(sentence.substring(5, sentence.length()));
}
// Identification
else if (Character.isDigit(sentence.charAt(0)) & sentence.length() == 15) {
- try {
- deviceId = getDataManager().getDeviceByImei(sentence).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + sentence);
- }
+ identify(sentence);
}
// Location