diff options
Diffstat (limited to 'src/org/traccar/protocol/Jt600ProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/Jt600ProtocolDecoder.java | 66 |
1 files changed, 55 insertions, 11 deletions
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index f5d8a79a4..109f8a68a 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 2018 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. @@ -15,11 +15,12 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; +import org.traccar.NetworkMessage; import org.traccar.helper.BcdUtil; import org.traccar.helper.BitBuffer; import org.traccar.helper.BitUtil; @@ -49,7 +50,42 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { return degrees + minutes / 60; } - private List<Position> decodeBinary(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) { + private void decodeStatus(Position position, ByteBuf buf) { + + int value = buf.readUnsignedByte(); + + position.set(Position.KEY_IGNITION, BitUtil.check(value, 0)); + position.set(Position.KEY_DOOR, BitUtil.check(value, 6)); + + value = buf.readUnsignedByte(); + + position.set(Position.KEY_CHARGE, BitUtil.check(value, 0)); + position.set(Position.KEY_BLOCKED, BitUtil.check(value, 1)); + + if (BitUtil.check(value, 2)) { + position.set(Position.KEY_ALARM, Position.ALARM_SOS); + } + if (BitUtil.check(value, 3) || BitUtil.check(value, 4)) { + position.set(Position.KEY_ALARM, Position.ALARM_GPS_ANTENNA_CUT); + } + if (BitUtil.check(value, 4)) { + position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); + } + + value = buf.readUnsignedByte(); + + if (BitUtil.check(value, 2)) { + position.set(Position.KEY_ALARM, Position.ALARM_FATIGUE_DRIVING); + } + if (BitUtil.check(value, 3)) { + position.set(Position.KEY_ALARM, Position.ALARM_TOW); + } + + buf.readUnsignedByte(); // reserved + + } + + private List<Position> decodeBinary(ByteBuf buf, Channel channel, SocketAddress remoteAddress) { List<Position> positions = new LinkedList<>(); @@ -57,7 +93,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { boolean longFormat = buf.getUnsignedByte(buf.readerIndex()) == 0x75; - String id = String.valueOf(Long.parseLong(ChannelBuffers.hexDump(buf.readBytes(5)))); + String id = String.valueOf(Long.parseLong(ByteBufUtil.hexDump(buf.readSlice(5)))); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); if (deviceSession == null) { return null; @@ -109,7 +145,15 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedInt(); // vehicle id combined - position.set(Position.KEY_STATUS, buf.readUnsignedShort()); + int status = buf.readUnsignedShort(); + position.set(Position.KEY_ALARM, BitUtil.check(status, 1) ? Position.ALARM_GEOFENCE_ENTER : null); + position.set(Position.KEY_ALARM, BitUtil.check(status, 2) ? Position.ALARM_GEOFENCE_EXIT : null); + position.set(Position.KEY_ALARM, BitUtil.check(status, 3) ? Position.ALARM_POWER_CUT : null); + position.set(Position.KEY_ALARM, BitUtil.check(status, 4) ? Position.ALARM_VIBRATION : null); + position.set(Position.KEY_BLOCKED, BitUtil.check(status, 7)); + position.set(Position.KEY_ALARM, BitUtil.check(status, 8 + 3) ? Position.ALARM_LOW_BATTERY : null); + position.set(Position.KEY_ALARM, BitUtil.check(status, 8 + 6) ? Position.ALARM_FAULT : null); + position.set(Position.KEY_STATUS, status); int battery = buf.readUnsignedByte(); if (battery == 0xff) { @@ -152,7 +196,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { int fuel = buf.readUnsignedByte() << 8; - position.set(Position.KEY_STATUS, buf.readUnsignedInt()); + decodeStatus(position, buf); position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000); fuel += buf.readUnsignedByte(); @@ -297,9 +341,9 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { if (channel != null) { if (type.equals("U01") || type.equals("U02") || type.equals("U03")) { - channel.write("(S39)"); + channel.writeAndFlush(new NetworkMessage("(S39)", remoteAddress)); } else if (type.equals("U06")) { - channel.write("(S20)"); + channel.writeAndFlush(new NetworkMessage("(S20)", remoteAddress)); } } @@ -310,7 +354,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; char first = (char) buf.getByte(0); if (first == '$') { |