From 8eb7ced3563809046d0b569247db490201f7ac98 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 20 Nov 2018 20:26:21 +1300 Subject: Handle different event types --- src/org/traccar/protocol/FreematicsProtocolDecoder.java | 9 ++++++--- test/org/traccar/protocol/FreematicsProtocolDecoderTest.java | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/org/traccar/protocol/FreematicsProtocolDecoder.java b/src/org/traccar/protocol/FreematicsProtocolDecoder.java index b91690d71..866e0fd6e 100644 --- a/src/org/traccar/protocol/FreematicsProtocolDecoder.java +++ b/src/org/traccar/protocol/FreematicsProtocolDecoder.java @@ -37,9 +37,10 @@ public class FreematicsProtocolDecoder extends BaseProtocolDecoder { } private Object decodeEvent( - Channel channel, SocketAddress remoteAddress, String sentence) throws Exception { + Channel channel, SocketAddress remoteAddress, String sentence) { DeviceSession deviceSession = null; + String event = null; String time = null; for (String pair : sentence.split(",")) { @@ -53,6 +54,8 @@ public class FreematicsProtocolDecoder extends BaseProtocolDecoder { deviceSession = getDeviceSession(channel, remoteAddress, value); } break; + case "EV": + event = value; case "TS": time = value; break; @@ -61,8 +64,8 @@ public class FreematicsProtocolDecoder extends BaseProtocolDecoder { } } - if (channel != null && deviceSession != null && time != null) { - String message = "1#EV=1,RX=1,TS=" + time; + if (channel != null && deviceSession != null && event != null && time != null) { + String message = String.format("1#EV=%s,RX=1,TS=%s", event, time); message += '*' + Checksum.sum(message); channel.writeAndFlush(new NetworkMessage(message, remoteAddress)); } diff --git a/test/org/traccar/protocol/FreematicsProtocolDecoderTest.java b/test/org/traccar/protocol/FreematicsProtocolDecoderTest.java index 69a585076..a84c4e357 100644 --- a/test/org/traccar/protocol/FreematicsProtocolDecoderTest.java +++ b/test/org/traccar/protocol/FreematicsProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class FreematicsProtocolDecoderTest extends ProtocolTest { FreematicsProtocolDecoder decoder = new FreematicsProtocolDecoder(null); + verifyNull(decoder, text( + "1#EV=2,TS=1871902,ID=ESP32305C06C40A24*AC")); + verifyNull(decoder, text( "0#EV=1,TS=23930,ID=ID1C6606C40A24,SK=TEST_SERVER_KEY*49")); -- cgit v1.2.3