From 2034139e1f64ceee146d376e3eb01915b0f86239 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 17 Jun 2014 21:17:33 +1200 Subject: Extend T55 protocol decoder --- src/org/traccar/protocol/T55ProtocolDecoder.java | 41 +++++++++++------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'src/org/traccar/protocol') 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 -- cgit v1.2.3