From 210e2cd641bf89d9b86d247a237739d026208bcf Mon Sep 17 00:00:00 2001 From: anton2920 Date: Sun, 4 Sep 2022 14:21:12 +0100 Subject: Added files for G1rus protocol --- .../java/org/traccar/protocol/G1rusProtocol.java | 24 ++++++++++++++++++++++ .../org/traccar/protocol/G1rusProtocolDecoder.java | 18 ++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/main/java/org/traccar/protocol/G1rusProtocol.java create mode 100644 src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/protocol/G1rusProtocol.java b/src/main/java/org/traccar/protocol/G1rusProtocol.java new file mode 100644 index 000000000..0d77a8add --- /dev/null +++ b/src/main/java/org/traccar/protocol/G1rusProtocol.java @@ -0,0 +1,24 @@ +package org.traccar.protocol; + +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; +import org.traccar.TrackerServer; +import org.traccar.config.Config; + +import javax.inject.Inject; + +public class G1rusProtocol extends BaseProtocol { + + @Inject + public G1rusProtocol(Config config) { + addServer(new TrackerServer(config, getName(), false) { + @Override + protected void addProtocolHandlers(PipelineBuilder pipeline, Config config) { + pipeline.addLast(new StringEncoder()); + pipeline.addLast(new G1rusProtocolDecoder(G1rusProtocol.this)); + } + }); + } +} diff --git a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java new file mode 100644 index 000000000..f6251d6c2 --- /dev/null +++ b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java @@ -0,0 +1,18 @@ +package org.traccar.protocol; + +import io.netty.channel.Channel; +import org.traccar.BaseProtocolDecoder; +import org.traccar.Protocol; + +import java.net.SocketAddress; + +public class G1rusProtocolDecoder extends BaseProtocolDecoder { + public G1rusProtocolDecoder(Protocol protocol) { + super(protocol); + } + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + } +} -- cgit v1.2.3 From 3899a7627ca99ce10f9f26a8f19477639510e298 Mon Sep 17 00:00:00 2001 From: anton2920 Date: Mon, 5 Sep 2022 10:35:17 +0100 Subject: Implemented basic REGULAR -> SYS -> GPS parsing --- .../org/traccar/protocol/G1rusProtocolDecoder.java | 273 ++++++++++++++++++++- 1 file changed, 271 insertions(+), 2 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java index f6251d6c2..89303d1b1 100644 --- a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java @@ -1,18 +1,287 @@ package org.traccar.protocol; +import com.google.common.primitives.Doubles; +import com.google.common.primitives.Ints; +import com.google.common.primitives.Longs; +import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.BaseProtocolDecoder; import org.traccar.Protocol; +import org.traccar.model.Position; +import org.traccar.session.ConnectionManager; +import org.traccar.session.DeviceSession; import java.net.SocketAddress; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; public class G1rusProtocolDecoder extends BaseProtocolDecoder { public G1rusProtocolDecoder(Protocol protocol) { super(protocol); } + private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionManager.class); + + /* Constants */ + private static final int G1RUS_HEAD_TAIL = 0xF8; + + private static final int G1RUS_TYPE_HEARTBEAT = 0; + + private static final int G1RUS_TYPE_BCD_MASK = 0b00111111; + private static final int G1RUS_TYPE_REGULAR = 1; + private static final int G1RUS_TYPE_SMS_FORWARD = 2; + private static final int G1RUS_TYPE_SERIAL_PASS_THROUGH = 3; + private static final int G1RUS_TYPE_MIXED = 4; + + private static final int G1RUS_TYPE_EVENT_MASK = 0b01000000; + private static final int G1RUS_TYPE_NON_EVENT = 0; + private static final int G1RUS_TYPE_EVENT = 1; + + private static final int G1RUS_TYPE_IMEI_MASK = 0b10000000; + private static final int G1RUS_TYPE_IMEI_LONG = 0; + private static final int G1RUS_TYPE_IMEI_SHORT = 1; + + private static final int G1RUS_DATA_SYS_MASK = 0b00000001; + private static final int G1RUS_DATA_GPS_MASK = 0b00000010; + private static final int G1RUS_DATA_GSM_MASK = 0b00000100; + private static final int G1RUS_DATA_COT_MASK = 0b00001000; + private static final int G1RUS_DATA_ADC_MASK = 0b00010000; + private static final int G1RUS_DATA_DTT_MASK = 0b00100000; + /* Reserved */ + private static final int G1RUS_DATA_ETD_MASK = 0b10000000; + + private static final int G1RUS_GPS_SIGN_MASK = 0b00000001; + private static final int G1RUS_GPS_POS_MASK = 0b00000010; + private static final int G1RUS_GPS_SPD_MASK = 0b00000100; + private static final int G1RUS_GPS_AZTH_MASK = 0b00001000; + private static final int G1RUS_GPS_ALT_MASK = 0b00010000; + private static final int G1RUS_GPS_HDOP_MASK = 0b00100000; + private static final int G1RUS_GPS_VDOP_MASK = 0b01000000; + private static final int G1RUS_GPS_STAT_MASK = 0b10000000; + + + private void decodeSYSSub(ByteBuf buf) { + LOGGER.info(""); + + buf.skipBytes(1); /* Total length */ + + /* NOTE: assuming order: + * Device name -> Firmware version -> Hardware version. + * TODO: actually check it. + */ + + /* Device name */ + byte devNameLen = (byte) buf.readUnsignedByte(); + byte[] devName = new byte[devNameLen & 0xF]; + buf.readBytes(devName); + String devNameString = new String(devName); + LOGGER.info("Device name: " + devNameString); + + /* Firmware version */ + byte firmwareLen = (byte) buf.readUnsignedByte(); + byte[] firmware = new byte[firmwareLen & 0xF]; + buf.readBytes(firmware); + String firmwareString = new String(firmware); + LOGGER.info("Firmware version: " + firmwareString); + + /* Hardware version */ + byte hardwareLen = (byte) buf.readUnsignedByte(); + byte[] hardware = new byte[hardwareLen & 0xF]; + buf.readBytes(hardware); + String hardwareString = new String(hardware); + LOGGER.info("Hardware version: " + hardwareString); + + LOGGER.info(""); + } + + + private void decodeGPSSub(ByteBuf buf, Position position) { + LOGGER.info(""); + + buf.skipBytes(1); /* Total length */ + + short subMask = (short) buf.readUnsignedShort(); + if ((subMask & G1RUS_GPS_SIGN_MASK) == G1RUS_GPS_SIGN_MASK) { + buf.skipBytes(1); + } + if ((subMask & G1RUS_GPS_POS_MASK) == G1RUS_GPS_POS_MASK) { + byte[] pos_buf = new byte[4]; + buf.readBytes(pos_buf); + position.setLatitude((float) Ints.fromByteArray(pos_buf) / 1000000); + LOGGER.info("Latitude: " + position.getLatitude()); + + buf.readBytes(pos_buf); + position.setLongitude((float) Ints.fromByteArray(pos_buf) / 1000000); + LOGGER.info("Longitude: " + position.getLongitude()); + } + if ((subMask & G1RUS_GPS_SPD_MASK) == G1RUS_GPS_SPD_MASK) { + position.setSpeed(buf.readUnsignedShort()); + LOGGER.info("Speed: " + position.getSpeed()); + } + if ((subMask & G1RUS_GPS_AZTH_MASK) == G1RUS_GPS_AZTH_MASK) { + position.setCourse(buf.readUnsignedShort()); + LOGGER.info("Course: " + position.getCourse()); + } + if ((subMask & G1RUS_GPS_ALT_MASK) == G1RUS_GPS_ALT_MASK) { + position.setAltitude(buf.readUnsignedShort()); + LOGGER.info("Altitude: " + position.getAltitude()); + } + if ((subMask & G1RUS_GPS_HDOP_MASK) == G1RUS_GPS_HDOP_MASK) { + buf.skipBytes(2); + } + if ((subMask & G1RUS_GPS_VDOP_MASK) == G1RUS_GPS_VDOP_MASK) { + buf.skipBytes(2); + } + + LOGGER.info(""); + } + + + private void decodeADCSub(ByteBuf buf, Position position) { + + } + + + private Position decodeRegular(Channel channel, SocketAddress remoteAddress, ByteBuf buf, long imei, byte packetType) { + int timestamp_ = buf.readInt(); + long timestamp = (946684800 + timestamp_) * 1000L; /* Convert received time to proper UNIX timestamp */ + LOGGER.info("Date and time: " + new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(new Date(timestamp))); + + if ((packetType & G1RUS_TYPE_EVENT_MASK) != G1RUS_TYPE_NON_EVENT) { + buf.skipBytes(1); /* Event ID */ + } + + DeviceSession deviceSession = null; + Position position = null; + + short dataUploadingMask = (short) buf.readUnsignedShort(); + if ((dataUploadingMask & G1RUS_DATA_SYS_MASK) == G1RUS_DATA_SYS_MASK) { + decodeSYSSub(buf); + } + if ((dataUploadingMask & G1RUS_DATA_GPS_MASK) == G1RUS_DATA_GPS_MASK) { + deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(imei)); + if (deviceSession == null) { + return null; + } + position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + position.setTime(new Date(timestamp)); + + decodeGPSSub(buf, position); + } + if ((dataUploadingMask & G1RUS_DATA_GSM_MASK) == G1RUS_DATA_GSM_MASK) { + buf.skipBytes(buf.readUnsignedByte()); + } + if ((dataUploadingMask & G1RUS_DATA_COT_MASK) == G1RUS_DATA_COT_MASK) { + buf.skipBytes(buf.readUnsignedByte()); + } + if ((dataUploadingMask & G1RUS_DATA_ADC_MASK) == G1RUS_DATA_ADC_MASK) { + /*if (deviceSession == null) { + return null; + }*/ + + buf.skipBytes(buf.readUnsignedByte()); + // decodeADCSub(buf, position); + } + if ((dataUploadingMask & G1RUS_DATA_DTT_MASK) == G1RUS_DATA_DTT_MASK) { + buf.skipBytes(buf.readUnsignedByte()); + } + if ((dataUploadingMask & G1RUS_DATA_ETD_MASK) == G1RUS_DATA_ETD_MASK) { + buf.skipBytes(buf.readUnsignedByte()); + } + + return position; + } + + + private Object decodeSMSForward(ByteBuf buf) { + return null; + } + + + private Object decodeSerialPassThrough(ByteBuf buf) { + return null; + } + + + private void printPacketType(byte packetType) { + LOGGER.info("Packet type: " + (packetType == G1RUS_TYPE_HEARTBEAT ? "HEARTBEAT" : + "[" + ((packetType & G1RUS_TYPE_IMEI_MASK) == G1RUS_TYPE_IMEI_LONG ? "IMEI_LONG" : "IMEI_SHORT") + "]" + + "[" + ((packetType & G1RUS_TYPE_EVENT_MASK) == G1RUS_TYPE_NON_EVENT ? "NON-EVENT" : "EVENT") + "]" + + "[" + ((packetType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_REGULAR ? "REGULAR" : (packetType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_SMS_FORWARD ? "SMS FORWARD" : (packetType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_SERIAL_PASS_THROUGH ? "PASS THROUGH" : (packetType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_MIXED ? "MIXED PACKED" : "RESERVED/INVALID") + "]")); + } + + @Override - protected Object decode( - Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + ByteBuf buf = (ByteBuf) msg; + + buf.skipBytes(1); /* Head */ + + LOGGER.info("Protocol version: " + buf.readUnsignedByte()); + + byte packetType = (byte) buf.readUnsignedByte(); + printPacketType(packetType); + + byte[] imei = new byte[8]; + buf.readBytes(imei, 0, 7); + long imei_long = Longs.fromByteArray(imei); + LOGGER.info("IMEI: " + imei_long); + + List positions = null; + + if (packetType == G1RUS_TYPE_HEARTBEAT) { + return null; + } else if ((packetType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_REGULAR) { + positions = new LinkedList<>(); + Position position = decodeRegular(channel, remoteAddress, buf, imei_long, packetType); + if (position != null) { + positions.add(position); + } + } else if ((packetType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_SMS_FORWARD) { + return decodeSMSForward(buf); + } else if ((packetType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_SERIAL_PASS_THROUGH) { + return decodeSerialPassThrough(buf); + } else if ((packetType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_MIXED) { + positions = new LinkedList<>(); + + while (buf.readableBytes() > 3) { + short subPacketLength = (short) buf.readUnsignedShort(); + byte subPacketType = (byte) buf.readUnsignedByte(); + printPacketType(subPacketType); + + if ((subPacketType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_REGULAR) { + Position position = decodeRegular(channel, remoteAddress, buf, imei_long, packetType); + if (position != null) { + positions.add(position); + } + } else { + try { + buf.skipBytes(subPacketLength - 1); + } catch (Exception e) { + return positions; + } + } + /* else if ((subPacketType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_SMS_FORWARD) { + buf.skipBytes(subPacketLength - 1); + *//*decodeSMSForward(buf);*//* + } else if ((subPacketType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_SERIAL_PASS_THROUGH) { + buf.skipBytes(subPacketLength - 1); + *//*decodeSerialPassThrough(buf);*//* + }*/ + } + } else { + LOGGER.error("Unknown packet type!"); + } + + buf.skipBytes(2); /* CRC */ /* TODO: actually check it */ + // buf.skipBytes(1); /* Tail */ + byte tail = (byte) buf.readUnsignedByte(); + + return positions; } } -- cgit v1.2.3 From 546f565023575c0975b7cc8fa3b9dea2f420918b Mon Sep 17 00:00:00 2001 From: anton2920 Date: Mon, 5 Sep 2022 11:21:45 +0100 Subject: Added support for escaping byte sequences --- .../org/traccar/protocol/G1rusProtocolDecoder.java | 107 +++++++++++++++------ 1 file changed, 75 insertions(+), 32 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java index 89303d1b1..d962e601e 100644 --- a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java @@ -3,6 +3,7 @@ package org.traccar.protocol; import com.google.common.primitives.Doubles; import com.google.common.primitives.Ints; import com.google.common.primitives.Longs; +import com.google.common.primitives.Shorts; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; import org.slf4j.Logger; @@ -63,6 +64,50 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { private static final int G1RUS_GPS_VDOP_MASK = 0b01000000; private static final int G1RUS_GPS_STAT_MASK = 0b10000000; + private static final int G1RUS_ESCAPE_CHAR = 0x1B; + + + private byte readUnsignedByteUnescaped(ByteBuf buf) { + byte first = (byte) buf.readUnsignedByte(); + if (first != G1RUS_ESCAPE_CHAR) { + return first; + } else { /* first == 0x1B */ + byte second = (byte) buf.readUnsignedByte(); + if (second == 0x00) { + return first; + } else { /* second == 0xE3 */ + return (byte) 0xF8; + } + } + } + + + private void readBytesUnescaped(ByteBuf buf, byte[] to) { + for (int i = 0; i < to.length; ++i) { + to[i] = readUnsignedByteUnescaped(buf); + } + } + + private void readBytesUnescaped(ByteBuf buf, byte[] to, int dstIndex, int length) { + for (int i = dstIndex; i < length; ++i) { + to[i] = readUnsignedByteUnescaped(buf); + } + } + + + private short readUnsignedShortUnescaped(ByteBuf buf) { + byte[] shortBuf = new byte[2]; + readBytesUnescaped(buf, shortBuf); + return Shorts.fromByteArray(shortBuf); + } + + + private int readIntUnescaped(ByteBuf buf) { + byte[] intBuf = new byte[4]; + readBytesUnescaped(buf, intBuf); + return Ints.fromByteArray(intBuf); + } + private void decodeSYSSub(ByteBuf buf) { LOGGER.info(""); @@ -75,23 +120,23 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { */ /* Device name */ - byte devNameLen = (byte) buf.readUnsignedByte(); + byte devNameLen = readUnsignedByteUnescaped(buf); byte[] devName = new byte[devNameLen & 0xF]; - buf.readBytes(devName); + readBytesUnescaped(buf, devName); String devNameString = new String(devName); LOGGER.info("Device name: " + devNameString); /* Firmware version */ - byte firmwareLen = (byte) buf.readUnsignedByte(); + byte firmwareLen = readUnsignedByteUnescaped(buf); byte[] firmware = new byte[firmwareLen & 0xF]; - buf.readBytes(firmware); + readBytesUnescaped(buf, firmware); String firmwareString = new String(firmware); LOGGER.info("Firmware version: " + firmwareString); /* Hardware version */ - byte hardwareLen = (byte) buf.readUnsignedByte(); + byte hardwareLen = readUnsignedByteUnescaped(buf); byte[] hardware = new byte[hardwareLen & 0xF]; - buf.readBytes(hardware); + readBytesUnescaped(buf, hardware); String hardwareString = new String(hardware); LOGGER.info("Hardware version: " + hardwareString); @@ -104,30 +149,30 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(1); /* Total length */ - short subMask = (short) buf.readUnsignedShort(); + short subMask = readUnsignedShortUnescaped(buf); if ((subMask & G1RUS_GPS_SIGN_MASK) == G1RUS_GPS_SIGN_MASK) { buf.skipBytes(1); } if ((subMask & G1RUS_GPS_POS_MASK) == G1RUS_GPS_POS_MASK) { byte[] pos_buf = new byte[4]; - buf.readBytes(pos_buf); + readBytesUnescaped(buf, pos_buf); position.setLatitude((float) Ints.fromByteArray(pos_buf) / 1000000); LOGGER.info("Latitude: " + position.getLatitude()); - buf.readBytes(pos_buf); + readBytesUnescaped(buf, pos_buf); position.setLongitude((float) Ints.fromByteArray(pos_buf) / 1000000); LOGGER.info("Longitude: " + position.getLongitude()); } if ((subMask & G1RUS_GPS_SPD_MASK) == G1RUS_GPS_SPD_MASK) { - position.setSpeed(buf.readUnsignedShort()); + position.setSpeed(readUnsignedShortUnescaped(buf)); LOGGER.info("Speed: " + position.getSpeed()); } if ((subMask & G1RUS_GPS_AZTH_MASK) == G1RUS_GPS_AZTH_MASK) { - position.setCourse(buf.readUnsignedShort()); + position.setCourse(readUnsignedShortUnescaped(buf)); LOGGER.info("Course: " + position.getCourse()); } if ((subMask & G1RUS_GPS_ALT_MASK) == G1RUS_GPS_ALT_MASK) { - position.setAltitude(buf.readUnsignedShort()); + position.setAltitude(readUnsignedShortUnescaped(buf)); LOGGER.info("Altitude: " + position.getAltitude()); } if ((subMask & G1RUS_GPS_HDOP_MASK) == G1RUS_GPS_HDOP_MASK) { @@ -147,7 +192,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { private Position decodeRegular(Channel channel, SocketAddress remoteAddress, ByteBuf buf, long imei, byte packetType) { - int timestamp_ = buf.readInt(); + int timestamp_ = readIntUnescaped(buf); long timestamp = (946684800 + timestamp_) * 1000L; /* Convert received time to proper UNIX timestamp */ LOGGER.info("Date and time: " + new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(new Date(timestamp))); @@ -158,7 +203,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { DeviceSession deviceSession = null; Position position = null; - short dataUploadingMask = (short) buf.readUnsignedShort(); + short dataUploadingMask = readUnsignedShortUnescaped(buf); if ((dataUploadingMask & G1RUS_DATA_SYS_MASK) == G1RUS_DATA_SYS_MASK) { decodeSYSSub(buf); } @@ -174,24 +219,24 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { decodeGPSSub(buf, position); } if ((dataUploadingMask & G1RUS_DATA_GSM_MASK) == G1RUS_DATA_GSM_MASK) { - buf.skipBytes(buf.readUnsignedByte()); + buf.skipBytes(readUnsignedByteUnescaped(buf)); } if ((dataUploadingMask & G1RUS_DATA_COT_MASK) == G1RUS_DATA_COT_MASK) { - buf.skipBytes(buf.readUnsignedByte()); + buf.skipBytes(readUnsignedByteUnescaped(buf)); } if ((dataUploadingMask & G1RUS_DATA_ADC_MASK) == G1RUS_DATA_ADC_MASK) { /*if (deviceSession == null) { return null; }*/ - buf.skipBytes(buf.readUnsignedByte()); + buf.skipBytes(readUnsignedByteUnescaped(buf)); // decodeADCSub(buf, position); } if ((dataUploadingMask & G1RUS_DATA_DTT_MASK) == G1RUS_DATA_DTT_MASK) { - buf.skipBytes(buf.readUnsignedByte()); + buf.skipBytes(readUnsignedByteUnescaped(buf)); } if ((dataUploadingMask & G1RUS_DATA_ETD_MASK) == G1RUS_DATA_ETD_MASK) { - buf.skipBytes(buf.readUnsignedByte()); + buf.skipBytes(readUnsignedByteUnescaped(buf)); } return position; @@ -220,15 +265,17 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; - buf.skipBytes(1); /* Head */ + if (buf.readUnsignedByte() != G1RUS_HEAD_TAIL) { + return null; + } - LOGGER.info("Protocol version: " + buf.readUnsignedByte()); + LOGGER.info("Protocol version: " + readUnsignedByteUnescaped(buf)); - byte packetType = (byte) buf.readUnsignedByte(); + byte packetType = readUnsignedByteUnescaped(buf); printPacketType(packetType); byte[] imei = new byte[8]; - buf.readBytes(imei, 0, 7); + readBytesUnescaped(buf, imei, 0, 7); long imei_long = Longs.fromByteArray(imei); LOGGER.info("IMEI: " + imei_long); @@ -249,22 +296,18 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { } else if ((packetType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_MIXED) { positions = new LinkedList<>(); - while (buf.readableBytes() > 3) { - short subPacketLength = (short) buf.readUnsignedShort(); - byte subPacketType = (byte) buf.readUnsignedByte(); + while (buf.readableBytes() > 5) { + short subPacketLength = readUnsignedShortUnescaped(buf); + byte subPacketType = readUnsignedByteUnescaped(buf); printPacketType(subPacketType); if ((subPacketType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_REGULAR) { - Position position = decodeRegular(channel, remoteAddress, buf, imei_long, packetType); + Position position = decodeRegular(channel, remoteAddress, buf, imei_long, subPacketType); if (position != null) { positions.add(position); } } else { - try { - buf.skipBytes(subPacketLength - 1); - } catch (Exception e) { - return positions; - } + buf.skipBytes(subPacketLength - 1); } /* else if ((subPacketType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_SMS_FORWARD) { buf.skipBytes(subPacketLength - 1); -- cgit v1.2.3 From 37976d783941a0ccf3a5a6bf9a24316515217629 Mon Sep 17 00:00:00 2001 From: anton2920 Date: Mon, 5 Sep 2022 11:50:52 +0100 Subject: Fixed skipping escaped bytes --- .../org/traccar/protocol/G1rusProtocolDecoder.java | 70 +++++++++++++--------- 1 file changed, 41 insertions(+), 29 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java index d962e601e..6d4ae9d1f 100644 --- a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java @@ -67,8 +67,8 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { private static final int G1RUS_ESCAPE_CHAR = 0x1B; - private byte readUnsignedByteUnescaped(ByteBuf buf) { - byte first = (byte) buf.readUnsignedByte(); + private short readUnsignedByteUnescaped(ByteBuf buf) { + short first = buf.readUnsignedByte(); if (first != G1RUS_ESCAPE_CHAR) { return first; } else { /* first == 0x1B */ @@ -76,21 +76,28 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { if (second == 0x00) { return first; } else { /* second == 0xE3 */ - return (byte) 0xF8; + return (short) 0xF8; } } } + private void skipBytesUnescaped(ByteBuf buf, int howMany) { + for (int i = 0; i < howMany; ++i) { + readUnsignedByteUnescaped(buf); + } + } + + private void readBytesUnescaped(ByteBuf buf, byte[] to) { for (int i = 0; i < to.length; ++i) { - to[i] = readUnsignedByteUnescaped(buf); + to[i] = (byte) readUnsignedByteUnescaped(buf); } } private void readBytesUnescaped(ByteBuf buf, byte[] to, int dstIndex, int length) { for (int i = dstIndex; i < length; ++i) { - to[i] = readUnsignedByteUnescaped(buf); + to[i] = (byte) readUnsignedByteUnescaped(buf); } } @@ -112,7 +119,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { private void decodeSYSSub(ByteBuf buf) { LOGGER.info(""); - buf.skipBytes(1); /* Total length */ + skipBytesUnescaped(buf, 1); /* Total length */ /* NOTE: assuming order: * Device name -> Firmware version -> Hardware version. @@ -120,21 +127,21 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { */ /* Device name */ - byte devNameLen = readUnsignedByteUnescaped(buf); + short devNameLen = readUnsignedByteUnescaped(buf); byte[] devName = new byte[devNameLen & 0xF]; readBytesUnescaped(buf, devName); String devNameString = new String(devName); LOGGER.info("Device name: " + devNameString); /* Firmware version */ - byte firmwareLen = readUnsignedByteUnescaped(buf); + short firmwareLen = readUnsignedByteUnescaped(buf); byte[] firmware = new byte[firmwareLen & 0xF]; readBytesUnescaped(buf, firmware); String firmwareString = new String(firmware); LOGGER.info("Firmware version: " + firmwareString); /* Hardware version */ - byte hardwareLen = readUnsignedByteUnescaped(buf); + short hardwareLen = readUnsignedByteUnescaped(buf); byte[] hardware = new byte[hardwareLen & 0xF]; readBytesUnescaped(buf, hardware); String hardwareString = new String(hardware); @@ -147,11 +154,11 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { private void decodeGPSSub(ByteBuf buf, Position position) { LOGGER.info(""); - buf.skipBytes(1); /* Total length */ + skipBytesUnescaped(buf, 1); /* Total length */ short subMask = readUnsignedShortUnescaped(buf); if ((subMask & G1RUS_GPS_SIGN_MASK) == G1RUS_GPS_SIGN_MASK) { - buf.skipBytes(1); + skipBytesUnescaped(buf, 1); } if ((subMask & G1RUS_GPS_POS_MASK) == G1RUS_GPS_POS_MASK) { byte[] pos_buf = new byte[4]; @@ -176,10 +183,10 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { LOGGER.info("Altitude: " + position.getAltitude()); } if ((subMask & G1RUS_GPS_HDOP_MASK) == G1RUS_GPS_HDOP_MASK) { - buf.skipBytes(2); + skipBytesUnescaped(buf, 2); } if ((subMask & G1RUS_GPS_VDOP_MASK) == G1RUS_GPS_VDOP_MASK) { - buf.skipBytes(2); + skipBytesUnescaped(buf, 2); } LOGGER.info(""); @@ -191,13 +198,13 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { } - private Position decodeRegular(Channel channel, SocketAddress remoteAddress, ByteBuf buf, long imei, byte packetType) { + private Position decodeRegular(Channel channel, SocketAddress remoteAddress, ByteBuf buf, long imei, short packetType) { int timestamp_ = readIntUnescaped(buf); long timestamp = (946684800 + timestamp_) * 1000L; /* Convert received time to proper UNIX timestamp */ LOGGER.info("Date and time: " + new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(new Date(timestamp))); if ((packetType & G1RUS_TYPE_EVENT_MASK) != G1RUS_TYPE_NON_EVENT) { - buf.skipBytes(1); /* Event ID */ + skipBytesUnescaped(buf, 1); /* Event ID */ } DeviceSession deviceSession = null; @@ -219,24 +226,24 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { decodeGPSSub(buf, position); } if ((dataUploadingMask & G1RUS_DATA_GSM_MASK) == G1RUS_DATA_GSM_MASK) { - buf.skipBytes(readUnsignedByteUnescaped(buf)); + skipBytesUnescaped(buf, readUnsignedByteUnescaped(buf)); } if ((dataUploadingMask & G1RUS_DATA_COT_MASK) == G1RUS_DATA_COT_MASK) { - buf.skipBytes(readUnsignedByteUnescaped(buf)); + skipBytesUnescaped(buf, readUnsignedByteUnescaped(buf)); } if ((dataUploadingMask & G1RUS_DATA_ADC_MASK) == G1RUS_DATA_ADC_MASK) { /*if (deviceSession == null) { return null; }*/ - buf.skipBytes(readUnsignedByteUnescaped(buf)); + skipBytesUnescaped(buf, readUnsignedByteUnescaped(buf)); // decodeADCSub(buf, position); } if ((dataUploadingMask & G1RUS_DATA_DTT_MASK) == G1RUS_DATA_DTT_MASK) { - buf.skipBytes(readUnsignedByteUnescaped(buf)); + skipBytesUnescaped(buf, readUnsignedByteUnescaped(buf)); } if ((dataUploadingMask & G1RUS_DATA_ETD_MASK) == G1RUS_DATA_ETD_MASK) { - buf.skipBytes(readUnsignedByteUnescaped(buf)); + skipBytesUnescaped(buf, readUnsignedByteUnescaped(buf)); } return position; @@ -253,7 +260,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { } - private void printPacketType(byte packetType) { + private void printPacketType(short packetType) { LOGGER.info("Packet type: " + (packetType == G1RUS_TYPE_HEARTBEAT ? "HEARTBEAT" : "[" + ((packetType & G1RUS_TYPE_IMEI_MASK) == G1RUS_TYPE_IMEI_LONG ? "IMEI_LONG" : "IMEI_SHORT") + "]" + "[" + ((packetType & G1RUS_TYPE_EVENT_MASK) == G1RUS_TYPE_NON_EVENT ? "NON-EVENT" : "EVENT") + "]" + @@ -271,7 +278,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { LOGGER.info("Protocol version: " + readUnsignedByteUnescaped(buf)); - byte packetType = readUnsignedByteUnescaped(buf); + short packetType = readUnsignedByteUnescaped(buf); printPacketType(packetType); byte[] imei = new byte[8]; @@ -298,7 +305,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { while (buf.readableBytes() > 5) { short subPacketLength = readUnsignedShortUnescaped(buf); - byte subPacketType = readUnsignedByteUnescaped(buf); + short subPacketType = readUnsignedByteUnescaped(buf); printPacketType(subPacketType); if ((subPacketType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_REGULAR) { @@ -307,13 +314,13 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { positions.add(position); } } else { - buf.skipBytes(subPacketLength - 1); + skipBytesUnescaped(buf, subPacketLength - 1); } /* else if ((subPacketType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_SMS_FORWARD) { - buf.skipBytes(subPacketLength - 1); + skipBytesUnescaped(buf, subPacketLength - 1); *//*decodeSMSForward(buf);*//* } else if ((subPacketType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_SERIAL_PASS_THROUGH) { - buf.skipBytes(subPacketLength - 1); + skipBytesUnescaped(buf, subPacketLength - 1); *//*decodeSerialPassThrough(buf);*//* }*/ } @@ -321,9 +328,14 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { LOGGER.error("Unknown packet type!"); } - buf.skipBytes(2); /* CRC */ /* TODO: actually check it */ - // buf.skipBytes(1); /* Tail */ - byte tail = (byte) buf.readUnsignedByte(); + skipBytesUnescaped(buf, 2); /* CRC */ /* TODO: actually check it */ + // skipBytesUnescaped(buf, 1); /* Tail */ + short tail = buf.readUnsignedByte(); + if (tail == G1RUS_HEAD_TAIL) { + LOGGER.info("Tail: OK"); + } else { + LOGGER.error("Tail: FAIL!"); + } return positions; } -- cgit v1.2.3 From 24cb3a2faaa1fba33983e4e942af8d0c35df5802 Mon Sep 17 00:00:00 2001 From: anton2920 Date: Mon, 5 Sep 2022 12:19:23 +0100 Subject: Removed extra lines --- src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java index 6d4ae9d1f..056fc2d4d 100644 --- a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java @@ -1,6 +1,5 @@ package org.traccar.protocol; -import com.google.common.primitives.Doubles; import com.google.common.primitives.Ints; import com.google.common.primitives.Longs; import com.google.common.primitives.Shorts; @@ -329,7 +328,6 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { } skipBytesUnescaped(buf, 2); /* CRC */ /* TODO: actually check it */ - // skipBytesUnescaped(buf, 1); /* Tail */ short tail = buf.readUnsignedByte(); if (tail == G1RUS_HEAD_TAIL) { LOGGER.info("Tail: OK"); -- cgit v1.2.3 From 6196ea366cfc5c668ef35940bcac50672badd82d Mon Sep 17 00:00:00 2001 From: anton2920 Date: Mon, 5 Sep 2022 12:56:16 +0100 Subject: Added decoding of ADC sub-packet --- .../org/traccar/protocol/G1rusProtocolDecoder.java | 49 +++++++++++++++++----- 1 file changed, 39 insertions(+), 10 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java index 056fc2d4d..24bd69d45 100644 --- a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java @@ -63,6 +63,8 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { private static final int G1RUS_GPS_VDOP_MASK = 0b01000000; private static final int G1RUS_GPS_STAT_MASK = 0b10000000; + private static final int G1RUS_ADC_DATA_MASK = 0b0000111111111111; + private static final int G1RUS_ESCAPE_CHAR = 0x1B; @@ -101,7 +103,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { } - private short readUnsignedShortUnescaped(ByteBuf buf) { + private int readUnsignedShortUnescaped(ByteBuf buf) { byte[] shortBuf = new byte[2]; readBytesUnescaped(buf, shortBuf); return Shorts.fromByteArray(shortBuf); @@ -155,7 +157,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { skipBytesUnescaped(buf, 1); /* Total length */ - short subMask = readUnsignedShortUnescaped(buf); + int subMask = readUnsignedShortUnescaped(buf); if ((subMask & G1RUS_GPS_SIGN_MASK) == G1RUS_GPS_SIGN_MASK) { skipBytesUnescaped(buf, 1); } @@ -192,8 +194,36 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { } + private int getADValue(int rawValue) { + final int AD_MIN = -10; + final int AD_MAX = 100; + + return rawValue * (AD_MAX - AD_MIN) / 4096 + AD_MIN; + } + + private void decodeADCSub(ByteBuf buf, Position position) { + LOGGER.info(""); + + skipBytesUnescaped(buf, 1); + + /* NOTE: assuming order: + * External battery voltage -> Backup battery voltage -> Device temperature voltage. + * TODO: actually check this. + */ + int externalVoltage = readUnsignedShortUnescaped(buf) & G1RUS_ADC_DATA_MASK; + LOGGER.info("External voltage: " + getADValue(externalVoltage) + "V [" + externalVoltage + "]"); + + int backupVoltage = readUnsignedShortUnescaped(buf) & G1RUS_ADC_DATA_MASK; + LOGGER.info("Backup voltage: " + getADValue(backupVoltage) + "V [" + backupVoltage + "]"); + position.set(Position.KEY_BATTERY, getADValue(backupVoltage)); + + int temperature = readUnsignedShortUnescaped(buf) & G1RUS_ADC_DATA_MASK; + LOGGER.info("Device temperature: " + getADValue(temperature) + "°C [" + temperature + "]"); + position.set(Position.KEY_DEVICE_TEMP, getADValue(temperature)); + + LOGGER.info(""); } @@ -209,7 +239,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { DeviceSession deviceSession = null; Position position = null; - short dataUploadingMask = readUnsignedShortUnescaped(buf); + int dataUploadingMask = readUnsignedShortUnescaped(buf); if ((dataUploadingMask & G1RUS_DATA_SYS_MASK) == G1RUS_DATA_SYS_MASK) { decodeSYSSub(buf); } @@ -231,12 +261,11 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { skipBytesUnescaped(buf, readUnsignedByteUnescaped(buf)); } if ((dataUploadingMask & G1RUS_DATA_ADC_MASK) == G1RUS_DATA_ADC_MASK) { - /*if (deviceSession == null) { - return null; - }*/ - - skipBytesUnescaped(buf, readUnsignedByteUnescaped(buf)); - // decodeADCSub(buf, position); + if (deviceSession == null) { + skipBytesUnescaped(buf, readUnsignedByteUnescaped(buf)); + } else { + decodeADCSub(buf, position); + } } if ((dataUploadingMask & G1RUS_DATA_DTT_MASK) == G1RUS_DATA_DTT_MASK) { skipBytesUnescaped(buf, readUnsignedByteUnescaped(buf)); @@ -303,7 +332,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { positions = new LinkedList<>(); while (buf.readableBytes() > 5) { - short subPacketLength = readUnsignedShortUnescaped(buf); + int subPacketLength = readUnsignedShortUnescaped(buf); short subPacketType = readUnsignedByteUnescaped(buf); printPacketType(subPacketType); -- cgit v1.2.3 From 5dd61da7a9927bb28c880a5fe50997170aaf536c Mon Sep 17 00:00:00 2001 From: anton2920 Date: Mon, 5 Sep 2022 13:06:49 +0100 Subject: Added support for decoding more data from GPS sub-packet --- .../org/traccar/protocol/G1rusProtocolDecoder.java | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java index 24bd69d45..fd30b170e 100644 --- a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java @@ -159,16 +159,20 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { int subMask = readUnsignedShortUnescaped(buf); if ((subMask & G1RUS_GPS_SIGN_MASK) == G1RUS_GPS_SIGN_MASK) { - skipBytesUnescaped(buf, 1); + short signValid = readUnsignedByteUnescaped(buf); + LOGGER.info("Fix sign: " + ((signValid & 0b1100000) >> 5)); + LOGGER.info("Satellite number: " + (signValid & 0b0011111)); + position.setValid(((signValid & 0b1100000) >> 5) == 2); + position.set(Position.KEY_SATELLITES, signValid & 0b0011111); } if ((subMask & G1RUS_GPS_POS_MASK) == G1RUS_GPS_POS_MASK) { - byte[] pos_buf = new byte[4]; - readBytesUnescaped(buf, pos_buf); - position.setLatitude((float) Ints.fromByteArray(pos_buf) / 1000000); + byte[] posBuf = new byte[4]; + readBytesUnescaped(buf, posBuf); + position.setLatitude((float) Ints.fromByteArray(posBuf) / 1000000); LOGGER.info("Latitude: " + position.getLatitude()); - readBytesUnescaped(buf, pos_buf); - position.setLongitude((float) Ints.fromByteArray(pos_buf) / 1000000); + readBytesUnescaped(buf, posBuf); + position.setLongitude((float) Ints.fromByteArray(posBuf) / 1000000); LOGGER.info("Longitude: " + position.getLongitude()); } if ((subMask & G1RUS_GPS_SPD_MASK) == G1RUS_GPS_SPD_MASK) { @@ -184,10 +188,12 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { LOGGER.info("Altitude: " + position.getAltitude()); } if ((subMask & G1RUS_GPS_HDOP_MASK) == G1RUS_GPS_HDOP_MASK) { - skipBytesUnescaped(buf, 2); + position.set(Position.KEY_HDOP, readUnsignedShortUnescaped(buf)); + LOGGER.info("HDOP: " + position.getAttributes().get(Position.KEY_HDOP)); } if ((subMask & G1RUS_GPS_VDOP_MASK) == G1RUS_GPS_VDOP_MASK) { - skipBytesUnescaped(buf, 2); + position.set(Position.KEY_VDOP, readUnsignedShortUnescaped(buf)); + LOGGER.info("VDOP: " + position.getAttributes().get(Position.KEY_VDOP)); } LOGGER.info(""); @@ -311,8 +317,8 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { byte[] imei = new byte[8]; readBytesUnescaped(buf, imei, 0, 7); - long imei_long = Longs.fromByteArray(imei); - LOGGER.info("IMEI: " + imei_long); + long imeiLong = Longs.fromByteArray(imei); + LOGGER.info("IMEI: " + imeiLong); List positions = null; @@ -320,7 +326,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { return null; } else if ((packetType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_REGULAR) { positions = new LinkedList<>(); - Position position = decodeRegular(channel, remoteAddress, buf, imei_long, packetType); + Position position = decodeRegular(channel, remoteAddress, buf, imeiLong, packetType); if (position != null) { positions.add(position); } @@ -337,7 +343,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { printPacketType(subPacketType); if ((subPacketType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_REGULAR) { - Position position = decodeRegular(channel, remoteAddress, buf, imei_long, subPacketType); + Position position = decodeRegular(channel, remoteAddress, buf, imeiLong, subPacketType); if (position != null) { positions.add(position); } -- cgit v1.2.3 From d55ae464806430ee57bbd56737f024ead95748a2 Mon Sep 17 00:00:00 2001 From: anton2920 Date: Wed, 7 Sep 2022 09:48:29 +0100 Subject: Moved logger messages to debug logs --- .../org/traccar/protocol/G1rusProtocolDecoder.java | 52 +++++++++++----------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java index fd30b170e..b1b7230e1 100644 --- a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java @@ -118,7 +118,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { private void decodeSYSSub(ByteBuf buf) { - LOGGER.info(""); + LOGGER.debug(""); skipBytesUnescaped(buf, 1); /* Total length */ @@ -132,36 +132,36 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { byte[] devName = new byte[devNameLen & 0xF]; readBytesUnescaped(buf, devName); String devNameString = new String(devName); - LOGGER.info("Device name: " + devNameString); + LOGGER.debug("Device name: " + devNameString); /* Firmware version */ short firmwareLen = readUnsignedByteUnescaped(buf); byte[] firmware = new byte[firmwareLen & 0xF]; readBytesUnescaped(buf, firmware); String firmwareString = new String(firmware); - LOGGER.info("Firmware version: " + firmwareString); + LOGGER.debug("Firmware version: " + firmwareString); /* Hardware version */ short hardwareLen = readUnsignedByteUnescaped(buf); byte[] hardware = new byte[hardwareLen & 0xF]; readBytesUnescaped(buf, hardware); String hardwareString = new String(hardware); - LOGGER.info("Hardware version: " + hardwareString); + LOGGER.debug("Hardware version: " + hardwareString); - LOGGER.info(""); + LOGGER.debug(""); } private void decodeGPSSub(ByteBuf buf, Position position) { - LOGGER.info(""); + LOGGER.debug(""); skipBytesUnescaped(buf, 1); /* Total length */ int subMask = readUnsignedShortUnescaped(buf); if ((subMask & G1RUS_GPS_SIGN_MASK) == G1RUS_GPS_SIGN_MASK) { short signValid = readUnsignedByteUnescaped(buf); - LOGGER.info("Fix sign: " + ((signValid & 0b1100000) >> 5)); - LOGGER.info("Satellite number: " + (signValid & 0b0011111)); + LOGGER.debug("Fix sign: " + ((signValid & 0b1100000) >> 5)); + LOGGER.debug("Satellite number: " + (signValid & 0b0011111)); position.setValid(((signValid & 0b1100000) >> 5) == 2); position.set(Position.KEY_SATELLITES, signValid & 0b0011111); } @@ -169,34 +169,34 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { byte[] posBuf = new byte[4]; readBytesUnescaped(buf, posBuf); position.setLatitude((float) Ints.fromByteArray(posBuf) / 1000000); - LOGGER.info("Latitude: " + position.getLatitude()); + LOGGER.debug("Latitude: " + position.getLatitude()); readBytesUnescaped(buf, posBuf); position.setLongitude((float) Ints.fromByteArray(posBuf) / 1000000); - LOGGER.info("Longitude: " + position.getLongitude()); + LOGGER.debug("Longitude: " + position.getLongitude()); } if ((subMask & G1RUS_GPS_SPD_MASK) == G1RUS_GPS_SPD_MASK) { position.setSpeed(readUnsignedShortUnescaped(buf)); - LOGGER.info("Speed: " + position.getSpeed()); + LOGGER.debug("Speed: " + position.getSpeed()); } if ((subMask & G1RUS_GPS_AZTH_MASK) == G1RUS_GPS_AZTH_MASK) { position.setCourse(readUnsignedShortUnescaped(buf)); - LOGGER.info("Course: " + position.getCourse()); + LOGGER.debug("Course: " + position.getCourse()); } if ((subMask & G1RUS_GPS_ALT_MASK) == G1RUS_GPS_ALT_MASK) { position.setAltitude(readUnsignedShortUnescaped(buf)); - LOGGER.info("Altitude: " + position.getAltitude()); + LOGGER.debug("Altitude: " + position.getAltitude()); } if ((subMask & G1RUS_GPS_HDOP_MASK) == G1RUS_GPS_HDOP_MASK) { position.set(Position.KEY_HDOP, readUnsignedShortUnescaped(buf)); - LOGGER.info("HDOP: " + position.getAttributes().get(Position.KEY_HDOP)); + LOGGER.debug("HDOP: " + position.getAttributes().get(Position.KEY_HDOP)); } if ((subMask & G1RUS_GPS_VDOP_MASK) == G1RUS_GPS_VDOP_MASK) { position.set(Position.KEY_VDOP, readUnsignedShortUnescaped(buf)); - LOGGER.info("VDOP: " + position.getAttributes().get(Position.KEY_VDOP)); + LOGGER.debug("VDOP: " + position.getAttributes().get(Position.KEY_VDOP)); } - LOGGER.info(""); + LOGGER.debug(""); } @@ -209,7 +209,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { private void decodeADCSub(ByteBuf buf, Position position) { - LOGGER.info(""); + LOGGER.debug(""); skipBytesUnescaped(buf, 1); @@ -219,24 +219,24 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { */ int externalVoltage = readUnsignedShortUnescaped(buf) & G1RUS_ADC_DATA_MASK; - LOGGER.info("External voltage: " + getADValue(externalVoltage) + "V [" + externalVoltage + "]"); + LOGGER.debug("External voltage: " + getADValue(externalVoltage) + "V [" + externalVoltage + "]"); int backupVoltage = readUnsignedShortUnescaped(buf) & G1RUS_ADC_DATA_MASK; - LOGGER.info("Backup voltage: " + getADValue(backupVoltage) + "V [" + backupVoltage + "]"); + LOGGER.debug("Backup voltage: " + getADValue(backupVoltage) + "V [" + backupVoltage + "]"); position.set(Position.KEY_BATTERY, getADValue(backupVoltage)); int temperature = readUnsignedShortUnescaped(buf) & G1RUS_ADC_DATA_MASK; - LOGGER.info("Device temperature: " + getADValue(temperature) + "°C [" + temperature + "]"); + LOGGER.debug("Device temperature: " + getADValue(temperature) + "°C [" + temperature + "]"); position.set(Position.KEY_DEVICE_TEMP, getADValue(temperature)); - LOGGER.info(""); + LOGGER.debug(""); } private Position decodeRegular(Channel channel, SocketAddress remoteAddress, ByteBuf buf, long imei, short packetType) { int timestamp_ = readIntUnescaped(buf); long timestamp = (946684800 + timestamp_) * 1000L; /* Convert received time to proper UNIX timestamp */ - LOGGER.info("Date and time: " + new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(new Date(timestamp))); + LOGGER.debug("Date and time: " + new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(new Date(timestamp))); if ((packetType & G1RUS_TYPE_EVENT_MASK) != G1RUS_TYPE_NON_EVENT) { skipBytesUnescaped(buf, 1); /* Event ID */ @@ -295,7 +295,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { private void printPacketType(short packetType) { - LOGGER.info("Packet type: " + (packetType == G1RUS_TYPE_HEARTBEAT ? "HEARTBEAT" : + LOGGER.debug("Packet type: " + (packetType == G1RUS_TYPE_HEARTBEAT ? "HEARTBEAT" : "[" + ((packetType & G1RUS_TYPE_IMEI_MASK) == G1RUS_TYPE_IMEI_LONG ? "IMEI_LONG" : "IMEI_SHORT") + "]" + "[" + ((packetType & G1RUS_TYPE_EVENT_MASK) == G1RUS_TYPE_NON_EVENT ? "NON-EVENT" : "EVENT") + "]" + "[" + ((packetType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_REGULAR ? "REGULAR" : (packetType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_SMS_FORWARD ? "SMS FORWARD" : (packetType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_SERIAL_PASS_THROUGH ? "PASS THROUGH" : (packetType & G1RUS_TYPE_BCD_MASK) == G1RUS_TYPE_MIXED ? "MIXED PACKED" : "RESERVED/INVALID") + "]")); @@ -310,7 +310,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { return null; } - LOGGER.info("Protocol version: " + readUnsignedByteUnescaped(buf)); + LOGGER.debug("Protocol version: " + readUnsignedByteUnescaped(buf)); short packetType = readUnsignedByteUnescaped(buf); printPacketType(packetType); @@ -318,7 +318,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { byte[] imei = new byte[8]; readBytesUnescaped(buf, imei, 0, 7); long imeiLong = Longs.fromByteArray(imei); - LOGGER.info("IMEI: " + imeiLong); + LOGGER.debug("IMEI: " + imeiLong); List positions = null; @@ -365,7 +365,7 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { skipBytesUnescaped(buf, 2); /* CRC */ /* TODO: actually check it */ short tail = buf.readUnsignedByte(); if (tail == G1RUS_HEAD_TAIL) { - LOGGER.info("Tail: OK"); + LOGGER.debug("Tail: OK"); } else { LOGGER.error("Tail: FAIL!"); } -- cgit v1.2.3