From f72eade8742022502e69b300296c8ac1fbf35b25 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 18 Dec 2012 22:31:16 +1300 Subject: Couple of small changes --- .../traccar/protocol/ProgressProtocolDecoder.java | 36 ++++++++++++++++------ 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'src/org/traccar/protocol/ProgressProtocolDecoder.java') diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java index 64aca8157..35db6e113 100644 --- a/src/org/traccar/protocol/ProgressProtocolDecoder.java +++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java @@ -47,15 +47,17 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder { /* * Message types */ - static final int MSG_NULL = 0; - static final int MSG_IDENT = 1; - static final int MSG_IDENT_FULL = 2; - static final int MSG_POINT = 10; - static final int MSG_LOG_SYNC = 100; - static final int MSG_LOGMSG = 101; - static final int MSG_TEXT = 102; - static final int MSG_ALARM = 200; - static final int MSG_ALARM_RECIEVED = 201; + private static final int MSG_NULL = 0; + private static final int MSG_IDENT = 1; + private static final int MSG_IDENT_FULL = 2; + private static final int MSG_POINT = 10; + private static final int MSG_LOG_SYNC = 100; + private static final int MSG_LOGMSG = 101; + private static final int MSG_TEXT = 102; + private static final int MSG_ALARM = 200; + private static final int MSG_ALARM_RECIEVED = 201; + + private static final String HEX_CHARS = "0123456789ABCDEF"; /** * Decode message @@ -150,12 +152,28 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder { // CAN adapter if ((extraFlags & 0x2) == 0x2) { int size = buf.readUnsignedShort(); + extendedInfo.append(""); + extendedInfo.append(buf.toString(buf.readerIndex(), size, Charset.defaultCharset())); + extendedInfo.append(""); buf.skipBytes(size); } // Passenger sensor if ((extraFlags & 0x4) == 0x4) { int size = buf.readUnsignedShort(); + + // Convert binary data to hex + StringBuilder hex = new StringBuilder(); + for (int i = buf.readerIndex(); i < buf.readerIndex() + size; i++) { + byte b = buf.getByte(i); + hex.append(HEX_CHARS.charAt((b & 0xf0) >> 4)); + hex.append(HEX_CHARS.charAt((b & 0x0F))); + } + + extendedInfo.append(""); + extendedInfo.append(hex); + extendedInfo.append(""); + buf.skipBytes(size); } -- cgit v1.2.3