From 1afe1e818d77d2e6df520071aa7e6b0c9f335454 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 2 Nov 2020 22:03:03 -0800 Subject: Decode CalAmp user data --- .../traccar/protocol/CalAmpProtocolDecoder.java | 42 ++++++++++++++-------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/main/java/org/traccar/protocol/CalAmpProtocolDecoder.java index dad0ae774..59b1fdf21 100644 --- a/src/main/java/org/traccar/protocol/CalAmpProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/CalAmpProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2020 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. @@ -28,6 +28,7 @@ import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; +import java.nio.charset.StandardCharsets; import java.util.Date; public class CalAmpProtocolDecoder extends BaseProtocolDecoder { @@ -121,22 +122,34 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_EVENT, buf.readUnsignedByte()); } - int accType = BitUtil.from(buf.getUnsignedByte(buf.readerIndex()), 6); - int accCount = BitUtil.to(buf.readUnsignedByte(), 6); + if (type == MSG_EVENT_REPORT || type == MSG_LOCATE_REPORT || type == MSG_MINI_EVENT_REPORT) { - if (type != MSG_MINI_EVENT_REPORT) { - position.set("append", buf.readUnsignedByte()); - } + int accType = BitUtil.from(buf.getUnsignedByte(buf.readerIndex()), 6); + int accCount = BitUtil.to(buf.readUnsignedByte(), 6); - if (accType == 1) { - buf.readUnsignedInt(); // threshold - buf.readUnsignedInt(); // mask - } + if (type != MSG_MINI_EVENT_REPORT) { + position.set("append", buf.readUnsignedByte()); + } - for (int i = 0; i < accCount; i++) { - if (buf.readableBytes() >= 4) { - position.set("acc" + i, buf.readUnsignedInt()); + if (accType == 1) { + buf.readUnsignedInt(); // threshold + buf.readUnsignedInt(); // mask } + + for (int i = 0; i < accCount; i++) { + if (buf.readableBytes() >= 4) { + position.set("acc" + i, buf.readUnsignedInt()); + } + } + + } else if (type == MSG_USER_DATA) { + + buf.readUnsignedByte(); // message route + buf.readUnsignedByte(); // message id + position.set( + Position.KEY_RESULT, + buf.readCharSequence(buf.readUnsignedShort(), StandardCharsets.US_ASCII).toString().trim()); + } return position; @@ -192,7 +205,8 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel, remoteAddress, type, index, 0); } - if (type == MSG_EVENT_REPORT || type == MSG_LOCATE_REPORT || type == MSG_MINI_EVENT_REPORT) { + if (type == MSG_EVENT_REPORT || type == MSG_LOCATE_REPORT + || type == MSG_MINI_EVENT_REPORT || type == MSG_USER_DATA) { return decodePosition(deviceSession, type, buf); } -- cgit v1.2.3