From f940d94548f45de9ece8195028abf4bafb979135 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 25 Mar 2017 16:50:08 +1300 Subject: Implement alarms for Meitrack --- src/org/traccar/protocol/Gt06ProtocolDecoder.java | 3 +-- .../traccar/protocol/MeitrackProtocolDecoder.java | 24 +++++++++++++++++++++- .../protocol/MeitrackProtocolDecoderTest.java | 3 +++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index bbba639c1..d94df7531 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -184,9 +184,8 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { case 0x11: return Position.ALARM_POWER_OFF; default: - break; + return null; } - return null; } @Override diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index bd6f3e8be..9189d2a66 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,6 +84,27 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { .text("\r\n").optional() .compile(); + private String decodeAlarm(int event) { + switch (event) { + case 1: + return Position.ALARM_SOS; + case 17: + return Position.ALARM_LOW_BATTERY; + case 18: + return Position.ALARM_POWER_CUT; + case 19: + return Position.ALARM_OVERSPEED; + case 20: + return Position.ALARM_GEOFENCE_ENTER; + case 21: + return Position.ALARM_GEOFENCE_EXIT; + case 36: + return Position.ALARM_TOW; + default: + return null; + } + } + private Position decodeRegularMessage(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { Parser parser = new Parser(PATTERN, buf.toString(StandardCharsets.US_ASCII)); @@ -102,6 +123,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { int event = parser.nextInt(); position.set(Position.KEY_EVENT, event); + position.set(Position.KEY_ALARM, decodeAlarm(event)); position.setLatitude(parser.nextDouble()); position.setLongitude(parser.nextDouble()); diff --git a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java index 9534df2e0..d387332d6 100644 --- a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class MeitrackProtocolDecoderTest extends ProtocolTest { MeitrackProtocolDecoder decoder = new MeitrackProtocolDecoder(new MeitrackProtocol()); + verifyPosition(decoder, buffer( + "$$T143,869013024733944,AAA,1,18.459575,-69.947161,170220142912,A,5,15,10,300,1.6,115,3989,187884,370|2|5337|2B2C,0100,0000|0000|0000|0964|0B04,,*C2")); + verifyPosition(decoder, buffer( "$$K157,866771027160687,AAA,3,37.040231,10.042391,160412151656,A,10,11,0,48,0.8,21,1035518,774980,605|2|0010|307B,0400,0000|0000|0000|0A47|03E3,,,1,0000,001206*2C")); -- cgit v1.2.3