diff options
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r-- | src/org/traccar/protocol/ApelProtocolDecoder.java | 79 |
1 files changed, 37 insertions, 42 deletions
diff --git a/src/org/traccar/protocol/ApelProtocolDecoder.java b/src/org/traccar/protocol/ApelProtocolDecoder.java index 7b89d374e..3bfed1ebb 100644 --- a/src/org/traccar/protocol/ApelProtocolDecoder.java +++ b/src/org/traccar/protocol/ApelProtocolDecoder.java @@ -41,35 +41,30 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - /* - * Message types - */ - private static final short MSG_TYPE_NULL = 0; - private static final short MSG_TYPE_REQUEST_TRACKER_ID = 10; - private static final short MSG_TYPE_TRACKER_ID = 11; - private static final short MSG_TYPE_TRACKER_ID_EXT = 12; - private static final short MSG_TYPE_DISCONNECT = 20; - private static final short MSG_TYPE_REQUEST_PASSWORD = 30; - private static final short MSG_TYPE_PASSWORD = 31; - private static final short MSG_TYPE_REQUEST_STATE_FULL_INFO = 90; - private static final short MSG_TYPE_STATE_FULL_INFO_T104 = 92; - private static final short MSG_TYPE_REQUEST_CURRENT_GPS_DATA = 100; - private static final short MSG_TYPE_CURRENT_GPS_DATA = 101; - private static final short MSG_TYPE_REQUEST_SENSORS_STATE = 110; - private static final short MSG_TYPE_SENSORS_STATE = 111; - private static final short MSG_TYPE_SENSORS_STATE_T100 = 112; - private static final short MSG_TYPE_SENSORS_STATE_T100_4 = 113; - private static final short MSG_TYPE_REQUEST_LAST_LOG_INDEX = 120; - private static final short MSG_TYPE_LAST_LOG_INDEX = 121; - private static final short MSG_TYPE_REQUEST_LOG_RECORDS = 130; - private static final short MSG_TYPE_LOG_RECORDS = 131; - private static final short MSG_TYPE_EVENT = 141; - private static final short MSG_TYPE_TEXT = 150; - private static final short MSG_TYPE_ACK_ALARM = 160; - private static final short MSG_TYPE_SET_TRACKER_MODE = 170; - private static final short MSG_TYPE_GPRS_COMMAND = 180; - - private static final String HEX_CHARS = "0123456789ABCDEF"; + public static final short MSG_NULL = 0; + public static final short MSG_REQUEST_TRACKER_ID = 10; + public static final short MSG_TRACKER_ID = 11; + public static final short MSG_TRACKER_ID_EXT = 12; + public static final short MSG_DISCONNECT = 20; + public static final short MSG_REQUEST_PASSWORD = 30; + public static final short MSG_PASSWORD = 31; + public static final short MSG_REQUEST_STATE_FULL_INFO = 90; + public static final short MSG_STATE_FULL_INFO_T104 = 92; + public static final short MSG_REQUEST_CURRENT_GPS_DATA = 100; + public static final short MSG_CURRENT_GPS_DATA = 101; + public static final short MSG_REQUEST_SENSORS_STATE = 110; + public static final short MSG_SENSORS_STATE = 111; + public static final short MSG_SENSORS_STATE_T100 = 112; + public static final short MSG_SENSORS_STATE_T100_4 = 113; + public static final short MSG_REQUEST_LAST_LOG_INDEX = 120; + public static final short MSG_LAST_LOG_INDEX = 121; + public static final short MSG_REQUEST_LOG_RECORDS = 130; + public static final short MSG_LOG_RECORDS = 131; + public static final short MSG_EVENT = 141; + public static final short MSG_TEXT = 150; + public static final short MSG_ACK_ALARM = 160; + public static final short MSG_SET_TRACKER_MODE = 170; + public static final short MSG_GPRS_COMMAND = 180; private void sendSimpleMessage(Channel channel, short type) { ChannelBuffer request = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 8); @@ -84,7 +79,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { lastIndex = newIndex; } else if (newIndex > lastIndex) { ChannelBuffer request = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 14); - request.writeShort(MSG_TYPE_REQUEST_LOG_RECORDS); + request.writeShort(MSG_REQUEST_LOG_RECORDS); request.writeShort(6); request.writeInt((int) lastIndex); request.writeShort(512); @@ -105,15 +100,15 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedShort(); // length if (alarm) { - sendSimpleMessage(channel, MSG_TYPE_ACK_ALARM); + sendSimpleMessage(channel, MSG_ACK_ALARM); } - if (type == MSG_TYPE_TRACKER_ID) { + if (type == MSG_TRACKER_ID) { Log.warning("Unsupported authentication type"); return null; } - if (type == MSG_TYPE_TRACKER_ID_EXT) { + if (type == MSG_TRACKER_ID_EXT) { long id = buf.readUnsignedInt(); int length = buf.readUnsignedShort(); buf.skipBytes(length); @@ -121,7 +116,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { identify(buf.readBytes(length).toString(Charset.defaultCharset()), channel); } - else if (type == MSG_TYPE_LAST_LOG_INDEX) { + else if (type == MSG_LAST_LOG_INDEX) { long index = buf.readUnsignedInt(); if (index > 0) { newIndex = index; @@ -130,11 +125,11 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { } // Position - else if (hasDeviceId() && (type == MSG_TYPE_CURRENT_GPS_DATA || type == MSG_TYPE_STATE_FULL_INFO_T104 || type == MSG_TYPE_LOG_RECORDS)) { + else if (hasDeviceId() && (type == MSG_CURRENT_GPS_DATA || type == MSG_STATE_FULL_INFO_T104 || type == MSG_LOG_RECORDS)) { List<Position> positions = new LinkedList<>(); int recordCount = 1; - if (type == MSG_TYPE_LOG_RECORDS) { + if (type == MSG_LOG_RECORDS) { recordCount = buf.readUnsignedShort(); } @@ -145,13 +140,13 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { // Message index int subtype = type; - if (type == MSG_TYPE_LOG_RECORDS) { + if (type == MSG_LOG_RECORDS) { position.set(Event.KEY_ARCHIVE, true); lastIndex = buf.readUnsignedInt() + 1; position.set(Event.KEY_INDEX, lastIndex); subtype = buf.readUnsignedShort(); - if (subtype != MSG_TYPE_CURRENT_GPS_DATA && subtype != MSG_TYPE_STATE_FULL_INFO_T104) { + if (subtype != MSG_CURRENT_GPS_DATA && subtype != MSG_STATE_FULL_INFO_T104) { buf.skipBytes(buf.readUnsignedShort()); continue; } @@ -171,7 +166,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(buf.readInt() * 180.0 / 0x7FFFFFFF); // Speed and Validity - if (subtype == MSG_TYPE_STATE_FULL_INFO_T104) { + if (subtype == MSG_STATE_FULL_INFO_T104) { int speed = buf.readUnsignedByte(); position.setValid(speed != 255); position.setSpeed(UnitsConverter.knotsFromKph(speed)); @@ -188,7 +183,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { // Altitude position.setAltitude(buf.readShort()); - if (subtype == MSG_TYPE_STATE_FULL_INFO_T104) { + if (subtype == MSG_STATE_FULL_INFO_T104) { // Satellites position.set(Event.KEY_SATELLITES, buf.readUnsignedByte()); @@ -223,10 +218,10 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { // Skip CRC buf.readUnsignedInt(); - if (type == MSG_TYPE_LOG_RECORDS) { + if (type == MSG_LOG_RECORDS) { requestArchive(channel); } else { - sendSimpleMessage(channel, MSG_TYPE_REQUEST_LAST_LOG_INDEX); + sendSimpleMessage(channel, MSG_REQUEST_LAST_LOG_INDEX); } return positions; |