From 90c2f67629064126834450aafcaffdc4187fe55a Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 13 Apr 2021 20:24:53 -0700 Subject: Support Mictrack command results --- .../traccar/protocol/MictrackProtocolDecoder.java | 44 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/traccar/protocol/MictrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MictrackProtocolDecoder.java index 5ea9f148c..029e7d99c 100644 --- a/src/main/java/org/traccar/protocol/MictrackProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MictrackProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2019 - 2021 Anton Tananaev (anton@traccar.org) * Copyright 2020 Roeland Boeters (roeland@geodelta.com) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -168,8 +168,48 @@ public class MictrackProtocolDecoder extends BaseProtocolDecoder { if (sentence.startsWith("MT")) { return decodeStandard(channel, remoteAddress, sentence); - } else { + } else if (sentence.contains("$")) { return decodeLowAltitude(channel, remoteAddress, sentence); + } else { + return decodeResult(channel, remoteAddress, sentence); + } + } + + private Object decodeResult( + Channel channel, SocketAddress remoteAddress, String sentence) throws Exception { + + if (sentence.matches("\\d{15} .+")) { + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, sentence.substring(0, 15)); + if (deviceSession == null) { + return null; + } + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + position.set(Position.KEY_RESULT, sentence.substring(16, sentence.length() - 1)); + + return position; + + } else { + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession == null) { + return null; + } + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + position.set(Position.KEY_RESULT, sentence.substring(0, sentence.length() - 1)); + + return position; + } } -- cgit v1.2.3