diff options
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/api/resource/AttributeAliasResource.java | 2 | ||||
-rw-r--r-- | src/org/traccar/protocol/AplicomProtocolDecoder.java | 153 |
2 files changed, 152 insertions, 3 deletions
diff --git a/src/org/traccar/api/resource/AttributeAliasResource.java b/src/org/traccar/api/resource/AttributeAliasResource.java index 6dbcf6ce8..2417fb0ec 100644 --- a/src/org/traccar/api/resource/AttributeAliasResource.java +++ b/src/org/traccar/api/resource/AttributeAliasResource.java @@ -35,7 +35,7 @@ import org.traccar.Context; import org.traccar.api.BaseResource; import org.traccar.model.AttributeAlias; -@Path("devices/aliases") +@Path("attributes/aliases") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public class AttributeAliasResource extends BaseResource { diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java index abd30ee45..d1f92ea0a 100644 --- a/src/org/traccar/protocol/AplicomProtocolDecoder.java +++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java @@ -81,7 +81,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { private static final int EVENT_DATA = 119; - private void decodeEventData(int event, ChannelBuffer buf) { + private void decodeEventData(Position position, ChannelBuffer buf, int event) { switch (event) { case 2: case 40: @@ -108,6 +108,9 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { case 130: buf.readUnsignedInt(); // incorrect break; + case 188: + decodeEB(position, buf); + break; default: break; } @@ -283,7 +286,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } if ((selector & 0x1000) != 0) { - decodeEventData(event, buf); + decodeEventData(position, buf, event); } if (Context.getConfig().getBoolean(getProtocolName() + ".can") @@ -348,6 +351,150 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } } + private void decodeH(Position position, ChannelBuffer buf, int selector) { + + if ((selector & 0x0004) != 0) { + getLastLocation(position, new Date(buf.readUnsignedInt() * 1000)); + } else { + getLastLocation(position, null); + } + + if ((selector & 0x0040) != 0) { + buf.readUnsignedInt(); // reset time + } + + if ((selector & 0x2000) != 0) { + buf.readUnsignedShort(); // snapshot counter + } + + int index = 1; + while (buf.readableBytes() > 0) { + + position.set("h" + index + "Index", buf.readUnsignedByte()); + + buf.readUnsignedShort(); // length + + int n = buf.readUnsignedByte(); + int m = buf.readUnsignedByte(); + + position.set("h" + index + "XLength", n); + position.set("h" + index + "YLength", m); + + if ((selector & 0x0008) != 0) { + position.set("h" + index + "XType", buf.readUnsignedByte()); + position.set("h" + index + "YType", buf.readUnsignedByte()); + position.set("h" + index + "Parameters", buf.readUnsignedByte()); + } + + boolean percentageFormat = (selector & 0x0020) != 0; + + StringBuilder data = new StringBuilder(); + for (int i = 0; i < n * m; i++) { + if (percentageFormat) { + data.append(buf.readUnsignedByte() * 0.5).append("%").append(" "); + } else { + data.append(buf.readUnsignedShort()).append(" "); + } + } + + position.set("h" + index + "Data", data.toString().trim()); + + position.set("h" + index + "Total", buf.readUnsignedInt()); + + if ((selector & 0x0010) != 0) { + int k = buf.readUnsignedByte(); + + data = new StringBuilder(); + for (int i = 1; i < n; i++) { + if (k == 1) { + data.append(buf.readByte()).append(" "); + } else if (k == 2) { + data.append(buf.readShort()).append(" "); + } + } + position.set("h" + index + "XLimits", data.toString().trim()); + + data = new StringBuilder(); + for (int i = 1; i < m; i++) { + if (k == 1) { + data.append(buf.readByte()).append(" "); + } else if (k == 2) { + data.append(buf.readShort()).append(" "); + } + } + position.set("h" + index + "YLimits", data.toString().trim()); + } + + index += 1; + } + } + + private void decodeEB(Position position, ChannelBuffer buf) { + + if (buf.readByte() != (byte) 'E' || buf.readByte() != (byte) 'B') { + return; + } + + buf.readUnsignedByte(); // version + buf.readUnsignedShort(); // event + buf.readUnsignedByte(); // data validity + buf.readUnsignedByte(); // towed + buf.readUnsignedShort(); // length + + while (buf.readableBytes() > 0) { + buf.readUnsignedByte(); // towed position + int type = buf.readUnsignedByte(); + int length = buf.readUnsignedByte(); + + if (type == 0x01) { + position.set("brakeFlags", ChannelBuffers.hexDump(buf.readBytes(length))); + } else if (type == 0x02) { + position.set("wheelSpeed", buf.readUnsignedShort() / 256.0); + position.set("wheelSpeedDifference", buf.readUnsignedShort() / 256.0 - 125.0); + position.set("lateralAcceleration", buf.readUnsignedByte() / 10.0 - 12.5); + position.set("vehicleSpeed", buf.readUnsignedShort() / 256.0); + } else if (type == 0x03) { + position.set("axleLoadSum", buf.readUnsignedShort() * 2); + } else if (type == 0x04) { + position.set("tyrePressure", buf.readUnsignedByte() * 10); + position.set("pneumaticPressure", buf.readUnsignedByte() * 5); + } else if (type == 0x05) { + position.set("brakeLining", buf.readUnsignedByte() * 0.4); + position.set("brakeTemperature", buf.readUnsignedByte() * 10); + } else if (type == 0x06) { + position.set("totalDistance", buf.readUnsignedInt() * 5); + position.set("tripDistance", buf.readUnsignedInt() * 5); + position.set("serviceDistance", (buf.readUnsignedInt() - 2105540607) * 5); + } else if (type == 0x0A) { + position.set("brakeData", ChannelBuffers.hexDump(buf.readBytes(length))); + } else if (type == 0x0B) { + position.set("brakeMinMaxData", ChannelBuffers.hexDump(buf.readBytes(length))); + } else if (type == 0x0C) { + position.set("missingPgn", ChannelBuffers.hexDump(buf.readBytes(length))); + } else if (type == 0x0D) { + switch (buf.readUnsignedByte()) { + case 1: + position.set("brakeManufacturer", "Wabco"); + break; + case 2: + position.set("brakeManufacturer", "Knorr"); + break; + case 3: + position.set("brakeManufacturer", "Haldex"); + break; + default: + position.set("brakeManufacturer", "Unknown"); + break; + } + buf.readUnsignedByte(); + buf.readBytes(17); // vin + position.set("towedDetectionStatus", buf.readUnsignedByte()); + } else if (type == 0x0E) { + buf.skipBytes(length); + } + } + } + @Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -389,6 +536,8 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { decodeD(position, buf, selector, event); } else if (protocol == 'E') { decodeE(position, buf, selector); + } else if (protocol == 'H') { + decodeH(position, buf, selector); } else { return null; } |