diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-11-02 22:03:03 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-11-02 22:03:03 -0800 |
commit | 1afe1e818d77d2e6df520071aa7e6b0c9f335454 (patch) | |
tree | cb37f680d1f6f2f2f384c9ea96ae2e71ea5565ae /src/main/java/org/traccar/protocol | |
parent | c2f3554886b62690b2dc705e037517b34da99340 (diff) | |
download | traccar-server-1afe1e818d77d2e6df520071aa7e6b0c9f335454.tar.gz traccar-server-1afe1e818d77d2e6df520071aa7e6b0c9f335454.tar.bz2 traccar-server-1afe1e818d77d2e6df520071aa7e6b0c9f335454.zip |
Decode CalAmp user data
Diffstat (limited to 'src/main/java/org/traccar/protocol')
-rw-r--r-- | src/main/java/org/traccar/protocol/CalAmpProtocolDecoder.java | 42 |
1 files changed, 28 insertions, 14 deletions
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); } |