diff options
-rw-r--r-- | src/org/traccar/protocol/T55ProtocolDecoder.java | 41 | ||||
-rw-r--r-- | test/org/traccar/protocol/T55ProtocolDecoderTest.java | 6 |
2 files changed, 24 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 diff --git a/test/org/traccar/protocol/T55ProtocolDecoderTest.java b/test/org/traccar/protocol/T55ProtocolDecoderTest.java index 283a9c88e..4a8de708c 100644 --- a/test/org/traccar/protocol/T55ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/T55ProtocolDecoderTest.java @@ -48,6 +48,12 @@ public class T55ProtocolDecoderTest { verify(decoder.decode(null, null, "$GPGGA,000000.000,6010.34349,N,02445.72838,E,1,05,1.7,0.9,M,35.1,M,,*59")); + + verify(decoder.decode(null, null, + "123456789$GPGGA,000000.000,4610.1676,N,00606.4586,E,0,00,4.3,0.0,M,50.7,M,,0000*59")); + + verify(decoder.decode(null, null, + "123456789$GPRMC,155708.252,V,4610.1676,N,00606.4586,E,000.0,000.0,060214,,,N*76")); } |