diff options
Diffstat (limited to 'src/org/traccar/protocol')
150 files changed, 1861 insertions, 527 deletions
diff --git a/src/org/traccar/protocol/AdmProtocol.java b/src/org/traccar/protocol/AdmProtocol.java index 40dd340cf..067ccf053 100644 --- a/src/org/traccar/protocol/AdmProtocol.java +++ b/src/org/traccar/protocol/AdmProtocol.java @@ -32,7 +32,7 @@ public class AdmProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 1, -3, 0)); diff --git a/src/org/traccar/protocol/ApelProtocol.java b/src/org/traccar/protocol/ApelProtocol.java index ae1af1243..47bce37a0 100644 --- a/src/org/traccar/protocol/ApelProtocol.java +++ b/src/org/traccar/protocol/ApelProtocol.java @@ -32,7 +32,7 @@ public class ApelProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, 4, 0)); diff --git a/src/org/traccar/protocol/AplicomProtocol.java b/src/org/traccar/protocol/AplicomProtocol.java index 8aae9554a..5155133c9 100644 --- a/src/org/traccar/protocol/AplicomProtocol.java +++ b/src/org/traccar/protocol/AplicomProtocol.java @@ -30,7 +30,7 @@ public class AplicomProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new AplicomFrameDecoder()); diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java index 23397b51c..d1f92ea0a 100644 --- a/src/org/traccar/protocol/AplicomProtocolDecoder.java +++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2013 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Date; @@ -75,11 +76,12 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { return unitId; } - private static final int DEFAULT_SELECTOR = 0x0002FC; + private static final int DEFAULT_SELECTOR_D = 0x0002fC; + private static final int DEFAULT_SELECTOR_E = 0x007ffc; 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: @@ -106,6 +108,9 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { case 130: buf.readUnsignedInt(); // incorrect break; + case 188: + decodeEB(position, buf); + break; default: break; } @@ -191,44 +196,12 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } } - @Override - protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - - ChannelBuffer buf = (ChannelBuffer) msg; - - buf.readUnsignedByte(); // marker - int version = buf.readUnsignedByte(); - - String imei; - if ((version & 0x80) != 0) { - imei = String.valueOf((buf.readUnsignedInt() << (3 * 8)) | buf.readUnsignedMedium()); - } else { - imei = String.valueOf(imeiFromUnitId(buf.readUnsignedMedium())); - } - - buf.readUnsignedShort(); // length - - int selector = DEFAULT_SELECTOR; - if ((version & 0x40) != 0) { - selector = buf.readUnsignedMedium(); - } - - Position position = new Position(); - position.setProtocol(getProtocolName()); - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); - if (deviceSession == null) { - return null; - } - position.setDeviceId(deviceSession.getDeviceId()); - - int event = buf.readUnsignedByte(); - position.set(Position.KEY_EVENT, event); - position.set("eventInfo", buf.readUnsignedByte()); + private void decodeD(Position position, ChannelBuffer buf, int selector, int event) { if ((selector & 0x0008) != 0) { position.setValid((buf.readUnsignedByte() & 0x40) != 0); } else { - return null; // no location data + getLastLocation(position, null); } if ((selector & 0x0004) != 0) { @@ -313,14 +286,261 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } if ((selector & 0x1000) != 0) { - decodeEventData(event, buf); + decodeEventData(position, buf, event); } if (Context.getConfig().getBoolean(getProtocolName() + ".can") && buf.readable() && (selector & 0x1000) != 0 && event == EVENT_DATA) { - decodeCanData(buf, position); } + } + + private void decodeE(Position position, ChannelBuffer buf, int selector) { + + if ((selector & 0x0008) != 0) { + position.set("tachographEvent", buf.readUnsignedShort()); + } + + if ((selector & 0x0004) != 0) { + getLastLocation(position, new Date(buf.readUnsignedInt() * 1000)); + } else { + getLastLocation(position, null); + } + + if ((selector & 0x0010) != 0) { + String time = buf.readUnsignedByte() + "s " + buf.readUnsignedByte() + "m " + buf.readUnsignedByte() + "h " + + buf.readUnsignedByte() + "M " + buf.readUnsignedByte() + "D " + buf.readUnsignedByte() + "Y " + + buf.readByte() + "m " + buf.readByte() + "h"; + position.set("tachographTime", time); + } + + position.set("workState", buf.readUnsignedByte()); + position.set("driver1State", buf.readUnsignedByte()); + position.set("driver2State", buf.readUnsignedByte()); + + if ((selector & 0x0020) != 0) { + position.set("tachographStatus", buf.readUnsignedByte()); + } + + if ((selector & 0x0040) != 0) { + position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() / 256.0); + } + + if ((selector & 0x0080) != 0) { + position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 5); + } + + if ((selector & 0x0100) != 0) { + position.set(Position.KEY_TRIP_ODOMETER, buf.readUnsignedInt() * 5); + } + + if ((selector & 0x8000) != 0) { + position.set("kFactor", buf.readUnsignedShort() * 0.001 + " pulses/m"); + } + + if ((selector & 0x0200) != 0) { + position.set(Position.KEY_RPM, buf.readUnsignedShort() * 0.125); + } + + if ((selector & 0x0400) != 0) { + position.set("extraInfo", buf.readUnsignedShort()); + } + + if ((selector & 0x0800) != 0) { + position.set(Position.KEY_VIN, buf.readBytes(18).toString(StandardCharsets.US_ASCII).trim()); + } + } + + 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 { + + ChannelBuffer buf = (ChannelBuffer) msg; + + char protocol = (char) buf.readByte(); + int version = buf.readUnsignedByte(); + + String imei; + if ((version & 0x80) != 0) { + imei = String.valueOf((buf.readUnsignedInt() << (3 * 8)) | buf.readUnsignedMedium()); + } else { + imei = String.valueOf(imeiFromUnitId(buf.readUnsignedMedium())); + } + + buf.readUnsignedShort(); // length + + int selector = DEFAULT_SELECTOR_D; + if (protocol == 'E') { + selector = DEFAULT_SELECTOR_E; + } + if ((version & 0x40) != 0) { + selector = buf.readUnsignedMedium(); + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); + if (deviceSession == null) { + return null; + } + position.setDeviceId(deviceSession.getDeviceId()); + + int event = buf.readUnsignedByte(); + position.set(Position.KEY_EVENT, event); + position.set("eventInfo", buf.readUnsignedByte()); + + if (protocol == 'D') { + decodeD(position, buf, selector, event); + } else if (protocol == 'E') { + decodeE(position, buf, selector); + } else if (protocol == 'H') { + decodeH(position, buf, selector); + } else { + return null; + } return position; } diff --git a/src/org/traccar/protocol/AppelloProtocol.java b/src/org/traccar/protocol/AppelloProtocol.java index f7826caab..b129a7520 100755 --- a/src/org/traccar/protocol/AppelloProtocol.java +++ b/src/org/traccar/protocol/AppelloProtocol.java @@ -33,7 +33,7 @@ public class AppelloProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); diff --git a/src/org/traccar/protocol/AquilaProtocol.java b/src/org/traccar/protocol/AquilaProtocol.java index 1bf5f4ee7..9607edd55 100644 --- a/src/org/traccar/protocol/AquilaProtocol.java +++ b/src/org/traccar/protocol/AquilaProtocol.java @@ -33,7 +33,7 @@ public class AquilaProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); diff --git a/src/org/traccar/protocol/Ardi01Protocol.java b/src/org/traccar/protocol/Ardi01Protocol.java index 595692cc5..5b7770647 100644 --- a/src/org/traccar/protocol/Ardi01Protocol.java +++ b/src/org/traccar/protocol/Ardi01Protocol.java @@ -33,7 +33,7 @@ public class Ardi01Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); diff --git a/src/org/traccar/protocol/ArknavProtocol.java b/src/org/traccar/protocol/ArknavProtocol.java index 3b288b5ab..6b9398f68 100644 --- a/src/org/traccar/protocol/ArknavProtocol.java +++ b/src/org/traccar/protocol/ArknavProtocol.java @@ -33,7 +33,7 @@ public class ArknavProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\r')); diff --git a/src/org/traccar/protocol/ArknavX8Protocol.java b/src/org/traccar/protocol/ArknavX8Protocol.java new file mode 100644 index 000000000..3b78a27ff --- /dev/null +++ b/src/org/traccar/protocol/ArknavX8Protocol.java @@ -0,0 +1,47 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; + +import java.util.List; + +public class ArknavX8Protocol extends BaseProtocol { + + public ArknavX8Protocol() { + super("arknavx8"); + } + + @Override + public void initTrackerServers(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ';')); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new ArknavX8ProtocolDecoder(ArknavX8Protocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java new file mode 100644 index 000000000..c0a18311e --- /dev/null +++ b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java @@ -0,0 +1,92 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.channel.Channel; +import org.traccar.BaseProtocolDecoder; +import org.traccar.DeviceSession; +import org.traccar.helper.DateBuilder; +import org.traccar.helper.Parser; +import org.traccar.helper.PatternBuilder; +import org.traccar.model.Position; + +import java.net.SocketAddress; +import java.util.regex.Pattern; + +public class ArknavX8ProtocolDecoder extends BaseProtocolDecoder { + + public ArknavX8ProtocolDecoder(ArknavX8Protocol protocol) { + super(protocol); + } + + private static final Pattern PATTERN = new PatternBuilder() + .expression("(..),") // type + .number("(dd)(dd)(dd)") // date (yymmdd) + .number("(dd)(dd)(dd),") // time + .expression("([AV]),") // validity + .number("(d+)(dd.d+)([NS]),") // latitude + .number("(d+)(dd.d+)([EW]),") // longitude + .number("(d+.d+),") // speed + .number("(d+),") // course + .number("(d+.d+),") // hdop + .number("(d+)") // status + .compile(); + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + String sentence = (String) msg; + + if (sentence.charAt(2) != ',') { + getDeviceSession(channel, remoteAddress, sentence.substring(0, 15)); + return null; + } + + Parser parser = new Parser(PATTERN, sentence); + if (!parser.matches()) { + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession == null) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + parser.next(); // type + + DateBuilder dateBuilder = new DateBuilder() + .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + position.setValid(parser.next().equals("A")); + position.setLatitude(parser.nextCoordinate()); + position.setLongitude(parser.nextCoordinate()); + position.setSpeed(parser.nextDouble()); + position.setCourse(parser.nextDouble()); + + position.set(Position.KEY_HDOP, parser.nextDouble()); + position.set(Position.KEY_STATUS, parser.next()); + + return position; + } + +} diff --git a/src/org/traccar/protocol/ArnaviProtocol.java b/src/org/traccar/protocol/ArnaviProtocol.java index 5bdb68e86..29661b8d4 100644 --- a/src/org/traccar/protocol/ArnaviProtocol.java +++ b/src/org/traccar/protocol/ArnaviProtocol.java @@ -33,7 +33,7 @@ public class ArnaviProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); diff --git a/src/org/traccar/protocol/AstraProtocol.java b/src/org/traccar/protocol/AstraProtocol.java index 0ff338599..461888c4f 100644 --- a/src/org/traccar/protocol/AstraProtocol.java +++ b/src/org/traccar/protocol/AstraProtocol.java @@ -32,14 +32,14 @@ public class AstraProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 1, 2, -3, 0)); pipeline.addLast("objectDecoder", new AstraProtocolDecoder(AstraProtocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("objectDecoder", new AstraProtocolDecoder(AstraProtocol.this)); diff --git a/src/org/traccar/protocol/AstraProtocolDecoder.java b/src/org/traccar/protocol/AstraProtocolDecoder.java index 1889fd3b9..d89a21082 100644 --- a/src/org/traccar/protocol/AstraProtocolDecoder.java +++ b/src/org/traccar/protocol/AstraProtocolDecoder.java @@ -68,6 +68,7 @@ public class AstraProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // index + position.setValid(true); position.setLatitude(buf.readInt() * 0.000001); position.setLongitude(buf.readInt() * 0.000001); diff --git a/src/org/traccar/protocol/AtrackProtocol.java b/src/org/traccar/protocol/AtrackProtocol.java index 356f7fc28..d61d31522 100644 --- a/src/org/traccar/protocol/AtrackProtocol.java +++ b/src/org/traccar/protocol/AtrackProtocol.java @@ -31,14 +31,14 @@ public class AtrackProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new AtrackFrameDecoder()); pipeline.addLast("objectDecoder", new AtrackProtocolDecoder(AtrackProtocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("objectDecoder", new AtrackProtocolDecoder(AtrackProtocol.this)); diff --git a/src/org/traccar/protocol/AuroProtocol.java b/src/org/traccar/protocol/AuroProtocol.java index e8fad85fd..e5635f12a 100644 --- a/src/org/traccar/protocol/AuroProtocol.java +++ b/src/org/traccar/protocol/AuroProtocol.java @@ -33,7 +33,7 @@ public class AuroProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); diff --git a/src/org/traccar/protocol/AutoFonProtocol.java b/src/org/traccar/protocol/AutoFonProtocol.java index dc2830edb..3e61b81a3 100644 --- a/src/org/traccar/protocol/AutoFonProtocol.java +++ b/src/org/traccar/protocol/AutoFonProtocol.java @@ -30,7 +30,7 @@ public class AutoFonProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new AutoFonFrameDecoder()); diff --git a/src/org/traccar/protocol/AutoGradeProtocol.java b/src/org/traccar/protocol/AutoGradeProtocol.java new file mode 100644 index 000000000..1fb6b1ce2 --- /dev/null +++ b/src/org/traccar/protocol/AutoGradeProtocol.java @@ -0,0 +1,47 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; + +import java.util.List; + +public class AutoGradeProtocol extends BaseProtocol { + + public AutoGradeProtocol() { + super("autograde"); + } + + @Override + public void initTrackerServers(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ')')); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("objectDecoder", new AutoGradeProtocolDecoder(AutoGradeProtocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/AutoGradeProtocolDecoder.java b/src/org/traccar/protocol/AutoGradeProtocolDecoder.java new file mode 100644 index 000000000..5c9dd7ece --- /dev/null +++ b/src/org/traccar/protocol/AutoGradeProtocolDecoder.java @@ -0,0 +1,102 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.channel.Channel; +import org.traccar.BaseProtocolDecoder; +import org.traccar.DeviceSession; +import org.traccar.helper.DateBuilder; +import org.traccar.helper.Parser; +import org.traccar.helper.PatternBuilder; +import org.traccar.model.Position; + +import java.net.SocketAddress; +import java.util.regex.Pattern; + +public class AutoGradeProtocolDecoder extends BaseProtocolDecoder { + + public AutoGradeProtocolDecoder(AutoGradeProtocol protocol) { + super(protocol); + } + + private static final Pattern PATTERN = new PatternBuilder() + .text("(") + .number("d{12}") // index + .number("(d{15})") // imei + .number("(dd)(dd)(dd)") // date + .expression("([AV])") // validity + .number("(d+)(dd.d+)([NS])") // latitude + .number("(d+)(dd.d+)([EW])") // longitude + .number("([d.]{5})") // speed + .number("(dd)(dd)(dd)") // time + .number("([d.]{6})") // course + .expression(".") // status + .number("A(xxxx)") + .number("B(xxxx)") + .number("C(xxxx)") + .number("D(xxxx)") + .number("E(xxxx)") + .number("K(xxxx)") + .number("L(xxxx)") + .number("M(xxxx)") + .number("N(xxxx)") + .number("O(xxxx)") + .any() + .compile(); + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + Parser parser = new Parser(PATTERN, (String) msg); + if (!parser.matches()) { + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + DateBuilder dateBuilder = new DateBuilder() + .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); + + position.setValid(parser.next().equals("A")); + position.setLatitude(parser.nextCoordinate()); + position.setLongitude(parser.nextCoordinate()); + position.setSpeed(parser.nextDouble()); + + dateBuilder.setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + position.setCourse(parser.nextDouble()); + + for (int i = 1; i <= 5; i++) { + position.set(Position.PREFIX_ADC + i, parser.next()); + } + + for (int i = 1; i <= 5; i++) { + position.set("can" + i, parser.next()); + } + + return position; + } + +} diff --git a/src/org/traccar/protocol/Avl301Protocol.java b/src/org/traccar/protocol/Avl301Protocol.java index 10ec5ae22..b8453cfb3 100644 --- a/src/org/traccar/protocol/Avl301Protocol.java +++ b/src/org/traccar/protocol/Avl301Protocol.java @@ -31,7 +31,7 @@ public class Avl301Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 2, 1, -3, 0)); diff --git a/src/org/traccar/protocol/BceProtocol.java b/src/org/traccar/protocol/BceProtocol.java index 06154c1c7..576eb6862 100644 --- a/src/org/traccar/protocol/BceProtocol.java +++ b/src/org/traccar/protocol/BceProtocol.java @@ -31,7 +31,7 @@ public class BceProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new BceFrameDecoder()); diff --git a/src/org/traccar/protocol/BlackKiteProtocol.java b/src/org/traccar/protocol/BlackKiteProtocol.java index 3f1890f88..ea5120b2b 100644 --- a/src/org/traccar/protocol/BlackKiteProtocol.java +++ b/src/org/traccar/protocol/BlackKiteProtocol.java @@ -32,7 +32,7 @@ public class BlackKiteProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new GalileoFrameDecoder()); diff --git a/src/org/traccar/protocol/BoxProtocol.java b/src/org/traccar/protocol/BoxProtocol.java index 33cfca282..6e60a0dd8 100644 --- a/src/org/traccar/protocol/BoxProtocol.java +++ b/src/org/traccar/protocol/BoxProtocol.java @@ -33,7 +33,7 @@ public class BoxProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\r')); diff --git a/src/org/traccar/protocol/CalAmpProtocol.java b/src/org/traccar/protocol/CalAmpProtocol.java index ccfd47cc4..a8eb59d0e 100644 --- a/src/org/traccar/protocol/CalAmpProtocol.java +++ b/src/org/traccar/protocol/CalAmpProtocol.java @@ -30,7 +30,7 @@ public class CalAmpProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("objectDecoder", new CalAmpProtocolDecoder(CalAmpProtocol.this)); diff --git a/src/org/traccar/protocol/CarTrackProtocol.java b/src/org/traccar/protocol/CarTrackProtocol.java index 8a60e3ebb..0244c0ce1 100644 --- a/src/org/traccar/protocol/CarTrackProtocol.java +++ b/src/org/traccar/protocol/CarTrackProtocol.java @@ -33,7 +33,7 @@ public class CarTrackProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "##")); diff --git a/src/org/traccar/protocol/CarcellProtocol.java b/src/org/traccar/protocol/CarcellProtocol.java index 5982e9cf8..1303b56b3 100644 --- a/src/org/traccar/protocol/CarcellProtocol.java +++ b/src/org/traccar/protocol/CarcellProtocol.java @@ -37,7 +37,7 @@ public class CarcellProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\r')); diff --git a/src/org/traccar/protocol/CarscopProtocol.java b/src/org/traccar/protocol/CarscopProtocol.java index 4432fb87a..23c597a5b 100644 --- a/src/org/traccar/protocol/CarscopProtocol.java +++ b/src/org/traccar/protocol/CarscopProtocol.java @@ -33,7 +33,7 @@ public class CarscopProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '^')); diff --git a/src/org/traccar/protocol/CastelProtocol.java b/src/org/traccar/protocol/CastelProtocol.java index 604ff4ecb..42f7cbb88 100644 --- a/src/org/traccar/protocol/CastelProtocol.java +++ b/src/org/traccar/protocol/CastelProtocol.java @@ -33,7 +33,7 @@ public class CastelProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 0)); @@ -43,7 +43,7 @@ public class CastelProtocol extends BaseProtocol { server.setEndianness(ByteOrder.LITTLE_ENDIAN); serverList.add(server); - server = new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + server = new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("objectDecoder", new CastelProtocolDecoder(CastelProtocol.this)); diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index 38fb11164..47df3735c 100644 --- a/src/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/org/traccar/protocol/CastelProtocolDecoder.java @@ -22,17 +22,53 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; +import org.traccar.helper.ObdDecoder; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; public class CastelProtocolDecoder extends BaseProtocolDecoder { + private static final Map<Integer, Integer> PID_LENGTH_MAP = new HashMap<>(); + + static { + int[] l1 = { + 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0b, 0x0d, + 0x0e, 0x0f, 0x11, 0x12, 0x13, 0x1c, 0x1d, 0x1e, 0x2c, + 0x2d, 0x2e, 0x2f, 0x30, 0x33, 0x43, 0x45, 0x46, + 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x51, 0x52, + 0x5a + }; + int[] l2 = { + 0x02, 0x03, 0x0a, 0x0c, 0x10, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1f, 0x21, 0x22, + 0x23, 0x31, 0x32, 0x3c, 0x3d, 0x3e, 0x3f, 0x42, + 0x44, 0x4d, 0x4e, 0x50, 0x53, 0x54, 0x55, 0x56, + 0x57, 0x58, 0x59 + }; + int[] l4 = { + 0x00, 0x01, 0x20, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x34, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3a, 0x3b, 0x40, 0x41, 0x4f + }; + for (int i : l1) { + PID_LENGTH_MAP.put(i, 1); + } + for (int i : l2) { + PID_LENGTH_MAP.put(i, 2); + } + for (int i : l4) { + PID_LENGTH_MAP.put(i, 4); + } + } + public CastelProtocolDecoder(CastelProtocol protocol) { super(protocol); } @@ -43,7 +79,13 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { private static final short MSG_SC_HEARTBEAT = 0x1003; private static final short MSG_SC_HEARTBEAT_RESPONSE = (short) 0x9003; private static final short MSG_SC_GPS = 0x4001; + private static final short MSG_SC_PID_DATA = 0x4002; + private static final short MSG_SC_SUPPORTED_PID = 0x4004; + private static final short MSG_SC_OBD_DATA = 0x4005; + private static final short MSG_SC_DTCS_PASSENGER = 0x4006; + private static final short MSG_SC_DTCS_COMMERCIAL = 0x400B; private static final short MSG_SC_ALARM = 0x4007; + private static final short MSG_SC_CELL = 0x4008; private static final short MSG_SC_GPS_SLEEP = 0x4009; private static final short MSG_SC_AGPS_REQUEST = 0x5101; private static final short MSG_SC_CURRENT_LOCATION = (short) 0xB001; @@ -84,6 +126,63 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { return position; } + private Position createPosition(DeviceSession deviceSession) { + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + return position; + } + + private void decodeObd(Position position, ChannelBuffer buf, boolean groups) { + + int count = buf.readUnsignedByte(); + + int[] pids = new int[count]; + for (int i = 0; i < count; i++) { + pids[i] = buf.readUnsignedShort() & 0xff; + } + + if (groups) { + buf.readUnsignedByte(); // group count + buf.readUnsignedByte(); // group size + } + + for (int i = 0; i < count; i++) { + int value; + switch (PID_LENGTH_MAP.get(pids[i])) { + case 1: + value = buf.readUnsignedByte(); + break; + case 2: + value = buf.readUnsignedShort(); + break; + case 4: + value = buf.readInt(); + break; + default: + value = 0; + break; + } + position.add(ObdDecoder.decodeData(pids[i], value, false)); + } + } + + private void decodeStat(Position position, ChannelBuffer buf) { + + buf.readUnsignedInt(); // ACC ON time + buf.readUnsignedInt(); // UTC time + position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + buf.readUnsignedInt(); // trip odometer + buf.readUnsignedInt(); // total fuel consumption + buf.readUnsignedShort(); // current fuel consumption + position.set(Position.KEY_STATUS, buf.readUnsignedInt()); + buf.skipBytes(8); + } + private void sendResponse( Channel channel, SocketAddress remoteAddress, int version, ChannelBuffer id, short type, ChannelBuffer content) { @@ -193,6 +292,50 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { return readPosition(deviceSession, buf); + } else if (type == MSG_SC_PID_DATA) { + + Position position = createPosition(deviceSession); + + decodeStat(position, buf); + + buf.readUnsignedShort(); // sample rate + decodeObd(position, buf, true); + + return position; + + } else if (type == MSG_SC_DTCS_PASSENGER) { + + Position position = createPosition(deviceSession); + + decodeStat(position, buf); + + buf.readUnsignedByte(); // flag + position.add(ObdDecoder.decodeCodes(ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedByte())))); + + return position; + + } else if (type == MSG_SC_OBD_DATA) { + + Position position = createPosition(deviceSession); + + decodeStat(position, buf); + + buf.readUnsignedByte(); // flag + decodeObd(position, buf, false); + + return position; + + } else if (type == MSG_SC_CELL) { + + Position position = createPosition(deviceSession); + + decodeStat(position, buf); + + position.set(Position.KEY_LAC, buf.readUnsignedShort()); + position.set(Position.KEY_CID, buf.readUnsignedShort()); + + return position; + } return null; diff --git a/src/org/traccar/protocol/CellocatorProtocol.java b/src/org/traccar/protocol/CellocatorProtocol.java index 22564d44f..e5f6ac8f6 100644 --- a/src/org/traccar/protocol/CellocatorProtocol.java +++ b/src/org/traccar/protocol/CellocatorProtocol.java @@ -15,6 +15,7 @@ */ package org.traccar.protocol; +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.ChannelPipeline; import org.traccar.BaseProtocol; @@ -31,7 +32,7 @@ public class CellocatorProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CellocatorFrameDecoder()); @@ -40,6 +41,15 @@ public class CellocatorProtocol extends BaseProtocol { }; server.setEndianness(ByteOrder.LITTLE_ENDIAN); serverList.add(server); + + server = new TrackerServer(new ConnectionlessBootstrap(), getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(CellocatorProtocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); } } diff --git a/src/org/traccar/protocol/CguardProtocol.java b/src/org/traccar/protocol/CguardProtocol.java new file mode 100644 index 000000000..1e6d212c8 --- /dev/null +++ b/src/org/traccar/protocol/CguardProtocol.java @@ -0,0 +1,47 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; + +import java.util.List; + +public class CguardProtocol extends BaseProtocol { + + public CguardProtocol() { + super("cguard"); + } + + @Override + public void initTrackerServers(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("objectDecoder", new CguardProtocolDecoder(CguardProtocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/CguardProtocolDecoder.java b/src/org/traccar/protocol/CguardProtocolDecoder.java new file mode 100644 index 000000000..1646363e5 --- /dev/null +++ b/src/org/traccar/protocol/CguardProtocolDecoder.java @@ -0,0 +1,91 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.channel.Channel; +import org.traccar.BaseProtocolDecoder; +import org.traccar.DeviceSession; +import org.traccar.helper.DateBuilder; +import org.traccar.helper.Parser; +import org.traccar.helper.PatternBuilder; +import org.traccar.helper.UnitsConverter; +import org.traccar.model.Position; + +import java.net.SocketAddress; +import java.util.regex.Pattern; + +public class CguardProtocolDecoder extends BaseProtocolDecoder { + + public CguardProtocolDecoder(CguardProtocol protocol) { + super(protocol); + } + + private static final Pattern PATTERN = new PatternBuilder() + .text("NV:") + .number("(dd)(dd)(dd) ") // date + .number("(dd)(dd)(dd):") // time + .number("(-?d+.d+):") // longitude + .number("(-?d+.d+):") // latitude + .number("(d+.?d*):") // speed + .number("(?:NAN|(d+.?d*)):") // accuracy + .number("(?:NAN|(d+.?d*)):") // course + .number("(?:NAN|(d+.?d*))") // altitude + .compile(); + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + String sentence = (String) msg; + + if (sentence.startsWith("ID:") || sentence.startsWith("IDRO:")) { + getDeviceSession(channel, remoteAddress, sentence.substring(sentence.indexOf(':') + 1)); + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession == null) { + return null; + } + + Parser parser = new Parser(PATTERN, (String) msg); + if (!parser.matches()) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + DateBuilder dateBuilder = new DateBuilder() + .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + position.setValid(true); + position.setLatitude(parser.nextDouble()); + position.setLongitude(parser.nextDouble()); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); + + position.set(Position.KEY_ACCURACY, parser.nextDouble()); + + position.setCourse(parser.nextDouble()); + position.setAltitude(parser.nextDouble()); + + return position; + } + +} diff --git a/src/org/traccar/protocol/CityeasyProtocol.java b/src/org/traccar/protocol/CityeasyProtocol.java index 82302d2d7..e22c964ce 100644 --- a/src/org/traccar/protocol/CityeasyProtocol.java +++ b/src/org/traccar/protocol/CityeasyProtocol.java @@ -37,7 +37,7 @@ public class CityeasyProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 0)); diff --git a/src/org/traccar/protocol/CradlepointProtocol.java b/src/org/traccar/protocol/CradlepointProtocol.java index ec938aa39..9b8de7fb8 100644 --- a/src/org/traccar/protocol/CradlepointProtocol.java +++ b/src/org/traccar/protocol/CradlepointProtocol.java @@ -33,7 +33,7 @@ public class CradlepointProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); diff --git a/src/org/traccar/protocol/DishaProtocol.java b/src/org/traccar/protocol/DishaProtocol.java index bb0d6cdf1..612316112 100644 --- a/src/org/traccar/protocol/DishaProtocol.java +++ b/src/org/traccar/protocol/DishaProtocol.java @@ -33,7 +33,7 @@ public class DishaProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); diff --git a/src/org/traccar/protocol/EasyTrackProtocol.java b/src/org/traccar/protocol/EasyTrackProtocol.java index d8bebeb5e..86ec530d4 100644 --- a/src/org/traccar/protocol/EasyTrackProtocol.java +++ b/src/org/traccar/protocol/EasyTrackProtocol.java @@ -33,7 +33,7 @@ public class EasyTrackProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#')); diff --git a/src/org/traccar/protocol/EelinkProtocol.java b/src/org/traccar/protocol/EelinkProtocol.java index 9579954f8..4da051159 100644 --- a/src/org/traccar/protocol/EelinkProtocol.java +++ b/src/org/traccar/protocol/EelinkProtocol.java @@ -31,7 +31,7 @@ public class EelinkProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 3, 2)); diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java index 24cd6b570..87d706aff 100644 --- a/src/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java @@ -66,31 +66,31 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { private String decodeAlarm(Short value) { switch (value) { - case 0x01: - return Position.ALARM_POWER_OFF; - case 0x02: - return Position.ALARM_SOS; - case 0x03: - return Position.ALARM_LOW_BATTERY; - case 0x04: - return Position.ALARM_VIBRATION; - case 0x08: - case 0x09: - return Position.ALARM_GPS_ANTENNA_CUT; - case 0x81: - return Position.ALARM_LOW_SPEED; - case 0x82: - return Position.ALARM_OVERSPEED; - case 0x83: - return Position.ALARM_GEOFENCE_ENTER; - case 0x84: - return Position.ALARM_GEOFENCE_EXIT; - case 0x85: - return Position.ALARM_ACCIDENT; - case 0x86: - return Position.ALARM_FALL_DOWN; - default: - return null; + case 0x01: + return Position.ALARM_POWER_OFF; + case 0x02: + return Position.ALARM_SOS; + case 0x03: + return Position.ALARM_LOW_BATTERY; + case 0x04: + return Position.ALARM_VIBRATION; + case 0x08: + case 0x09: + return Position.ALARM_GPS_ANTENNA_CUT; + case 0x81: + return Position.ALARM_LOW_SPEED; + case 0x82: + return Position.ALARM_OVERSPEED; + case 0x83: + return Position.ALARM_GEOFENCE_ENTER; + case 0x84: + return Position.ALARM_GEOFENCE_EXIT; + case 0x85: + return Position.ALARM_ACCIDENT; + case 0x86: + return Position.ALARM_FALL_DOWN; + default: + return null; } } @@ -126,7 +126,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { return position; } - private Position decodeNew(DeviceSession deviceSession, ChannelBuffer buf, int type, int index) { + private Position decodeNew(DeviceSession deviceSession, ChannelBuffer buf, int index) { Position position = new Position(); position.setDeviceId(deviceSession.getDeviceId()); @@ -206,7 +206,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { if (type == MSG_GPS || type == MSG_ALARM || type == MSG_STATE || type == MSG_SMS) { return decodeOld(deviceSession, buf, type, index); } else if (type >= MSG_NORMAL && type <= MSG_OBD_CODE) { - return decodeNew(deviceSession, buf, type, index); + return decodeNew(deviceSession, buf, index); } } diff --git a/src/org/traccar/protocol/EnforaProtocol.java b/src/org/traccar/protocol/EnforaProtocol.java index 3d8c11fcf..f4ca505ca 100644 --- a/src/org/traccar/protocol/EnforaProtocol.java +++ b/src/org/traccar/protocol/EnforaProtocol.java @@ -31,7 +31,7 @@ public class EnforaProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 0, 2, -2, 2)); diff --git a/src/org/traccar/protocol/FlextrackProtocol.java b/src/org/traccar/protocol/FlextrackProtocol.java index c17099fc7..d62c064d0 100644 --- a/src/org/traccar/protocol/FlextrackProtocol.java +++ b/src/org/traccar/protocol/FlextrackProtocol.java @@ -33,7 +33,7 @@ public class FlextrackProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "\r")); diff --git a/src/org/traccar/protocol/FoxProtocol.java b/src/org/traccar/protocol/FoxProtocol.java index bcda1e433..30b76ef25 100644 --- a/src/org/traccar/protocol/FoxProtocol.java +++ b/src/org/traccar/protocol/FoxProtocol.java @@ -33,7 +33,7 @@ public class FoxProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "</fox>")); diff --git a/src/org/traccar/protocol/FreedomProtocol.java b/src/org/traccar/protocol/FreedomProtocol.java index 2eb510cdb..0176d9781 100644 --- a/src/org/traccar/protocol/FreedomProtocol.java +++ b/src/org/traccar/protocol/FreedomProtocol.java @@ -33,7 +33,7 @@ public class FreedomProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); diff --git a/src/org/traccar/protocol/GalileoProtocol.java b/src/org/traccar/protocol/GalileoProtocol.java index 762bf0075..7d5b47bbb 100644 --- a/src/org/traccar/protocol/GalileoProtocol.java +++ b/src/org/traccar/protocol/GalileoProtocol.java @@ -31,7 +31,7 @@ public class GalileoProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new GalileoFrameDecoder()); diff --git a/src/org/traccar/protocol/GatorProtocol.java b/src/org/traccar/protocol/GatorProtocol.java index 3d899fa1f..e6b7161db 100644 --- a/src/org/traccar/protocol/GatorProtocol.java +++ b/src/org/traccar/protocol/GatorProtocol.java @@ -32,14 +32,14 @@ public class GatorProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 3, 2)); pipeline.addLast("objectDecoder", new GatorProtocolDecoder(GatorProtocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("objectDecoder", new GatorProtocolDecoder(GatorProtocol.this)); diff --git a/src/org/traccar/protocol/Gl100Protocol.java b/src/org/traccar/protocol/Gl100Protocol.java index f51834ea2..a78aff35f 100644 --- a/src/org/traccar/protocol/Gl100Protocol.java +++ b/src/org/traccar/protocol/Gl100Protocol.java @@ -34,7 +34,7 @@ public class Gl100Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\0')); @@ -43,7 +43,7 @@ public class Gl100Protocol extends BaseProtocol { pipeline.addLast("objectDecoder", new Gl100ProtocolDecoder(Gl100Protocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/Gl200Protocol.java b/src/org/traccar/protocol/Gl200Protocol.java index 701652e12..d38bdf8a9 100644 --- a/src/org/traccar/protocol/Gl200Protocol.java +++ b/src/org/traccar/protocol/Gl200Protocol.java @@ -40,7 +40,7 @@ public class Gl200Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "$", "\0")); @@ -50,7 +50,7 @@ public class Gl200Protocol extends BaseProtocol { pipeline.addLast("objectDecoder", new Gl200ProtocolDecoder(Gl200Protocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/GlobalSatProtocol.java b/src/org/traccar/protocol/GlobalSatProtocol.java index 592ba152e..25d7656f1 100644 --- a/src/org/traccar/protocol/GlobalSatProtocol.java +++ b/src/org/traccar/protocol/GlobalSatProtocol.java @@ -33,7 +33,7 @@ public class GlobalSatProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '!')); diff --git a/src/org/traccar/protocol/GnxProtocol.java b/src/org/traccar/protocol/GnxProtocol.java index ff2976286..aeef247c2 100644 --- a/src/org/traccar/protocol/GnxProtocol.java +++ b/src/org/traccar/protocol/GnxProtocol.java @@ -33,7 +33,7 @@ public class GnxProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "\n\r")); diff --git a/src/org/traccar/protocol/GnxProtocolDecoder.java b/src/org/traccar/protocol/GnxProtocolDecoder.java index a2ee5ae48..b88d306a8 100644 --- a/src/org/traccar/protocol/GnxProtocolDecoder.java +++ b/src/org/traccar/protocol/GnxProtocolDecoder.java @@ -71,13 +71,10 @@ public class GnxProtocolDecoder extends BaseProtocolDecoder { String type = sentence.substring(5, 8); Pattern pattern; - switch (type) { - case "MIF": - pattern = PATTERN_MIF; - break; - default: - pattern = PATTERN_OTHER; - break; + if (type.equals("MIF")) { + pattern = PATTERN_MIF; + } else { + pattern = PATTERN_OTHER; } Parser parser = new Parser(pattern, sentence); @@ -115,12 +112,8 @@ public class GnxProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); - switch (type) { - case "MIF": - position.set(Position.KEY_RFID, parser.next()); - break; - default: - break; + if (type.equals("MIF")) { + position.set(Position.KEY_RFID, parser.next()); } return position; diff --git a/src/org/traccar/protocol/GoSafeProtocol.java b/src/org/traccar/protocol/GoSafeProtocol.java index b45755fc3..54abacd42 100644 --- a/src/org/traccar/protocol/GoSafeProtocol.java +++ b/src/org/traccar/protocol/GoSafeProtocol.java @@ -33,7 +33,7 @@ public class GoSafeProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#')); diff --git a/src/org/traccar/protocol/GotopProtocol.java b/src/org/traccar/protocol/GotopProtocol.java index 303001756..6b31e1acf 100644 --- a/src/org/traccar/protocol/GotopProtocol.java +++ b/src/org/traccar/protocol/GotopProtocol.java @@ -33,7 +33,7 @@ public class GotopProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#')); diff --git a/src/org/traccar/protocol/Gps103Protocol.java b/src/org/traccar/protocol/Gps103Protocol.java index 6a2f8a7f9..559de3187 100644 --- a/src/org/traccar/protocol/Gps103Protocol.java +++ b/src/org/traccar/protocol/Gps103Protocol.java @@ -44,7 +44,7 @@ public class Gps103Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "\r\n", "\n", ";")); @@ -54,7 +54,7 @@ public class Gps103Protocol extends BaseProtocol { pipeline.addLast("objectDecoder", new Gps103ProtocolDecoder(Gps103Protocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index af7efa959..363834f89 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -104,20 +104,20 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { private String decodeAlarm(String value) { switch (value) { - case "tracker": - return null; - case "help me": - return Position.ALARM_SOS; - case "low battery": - return Position.ALARM_LOW_BATTERY; - case "stockade": - return Position.ALARM_GEOFENCE; - case "move": - return Position.ALARM_MOVEMENT; - case "speed": - return Position.ALARM_OVERSPEED; - default: - return null; + case "tracker": + return null; + case "help me": + return Position.ALARM_SOS; + case "low battery": + return Position.ALARM_LOW_BATTERY; + case "stockade": + return Position.ALARM_GEOFENCE; + case "move": + return Position.ALARM_MOVEMENT; + case "speed": + return Position.ALARM_OVERSPEED; + default: + return null; } } @@ -216,8 +216,14 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { String alarm = parser.next(); position.set(Position.KEY_ALARM, decodeAlarm(alarm)); - if (channel != null && alarm.equals("help me")) { - channel.write("**,imei:" + imei + ",E;", remoteAddress); + if (alarm.equals("help me")) { + if (channel != null) { + channel.write("**,imei:" + imei + ",E;", remoteAddress); + } + } else if (alarm.equals("acc on")) { + position.set(Position.KEY_IGNITION, true); + } else if (alarm.equals("acc off")) { + position.set(Position.KEY_IGNITION, false); } DateBuilder dateBuilder = new DateBuilder() diff --git a/src/org/traccar/protocol/GpsGateProtocol.java b/src/org/traccar/protocol/GpsGateProtocol.java index bfd3b2883..78a7588ad 100644 --- a/src/org/traccar/protocol/GpsGateProtocol.java +++ b/src/org/traccar/protocol/GpsGateProtocol.java @@ -33,7 +33,7 @@ public class GpsGateProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "\0", "\n", "\r\n")); diff --git a/src/org/traccar/protocol/GpsMarkerProtocol.java b/src/org/traccar/protocol/GpsMarkerProtocol.java index 69c2637bd..bb4b5b561 100644 --- a/src/org/traccar/protocol/GpsMarkerProtocol.java +++ b/src/org/traccar/protocol/GpsMarkerProtocol.java @@ -33,7 +33,7 @@ public class GpsMarkerProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "\r")); diff --git a/src/org/traccar/protocol/GpsmtaProtocol.java b/src/org/traccar/protocol/GpsmtaProtocol.java index d1eaa2fd3..51cce2650 100644 --- a/src/org/traccar/protocol/GpsmtaProtocol.java +++ b/src/org/traccar/protocol/GpsmtaProtocol.java @@ -32,7 +32,7 @@ public class GpsmtaProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/GranitProtocol.java b/src/org/traccar/protocol/GranitProtocol.java index fb9d10809..1e097c17b 100644 --- a/src/org/traccar/protocol/GranitProtocol.java +++ b/src/org/traccar/protocol/GranitProtocol.java @@ -36,7 +36,7 @@ public class GranitProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new GranitFrameDecoder()); diff --git a/src/org/traccar/protocol/GranitProtocolEncoder.java b/src/org/traccar/protocol/GranitProtocolEncoder.java index 961f183f5..805bfbe24 100644 --- a/src/org/traccar/protocol/GranitProtocolEncoder.java +++ b/src/org/traccar/protocol/GranitProtocolEncoder.java @@ -30,18 +30,18 @@ public class GranitProtocolEncoder extends BaseProtocolEncoder { String commandString = ""; switch (command.getType()) { - case Command.TYPE_IDENTIFICATION: - commandString = "BB+IDNT"; - break; - case Command.TYPE_REBOOT_DEVICE: - commandString = "BB+RESET"; - break; - case Command.TYPE_POSITION_SINGLE: - commandString = "BB+RRCD"; - break; - default: - Log.warning(new UnsupportedOperationException(command.getType())); - return null; + case Command.TYPE_IDENTIFICATION: + commandString = "BB+IDNT"; + break; + case Command.TYPE_REBOOT_DEVICE: + commandString = "BB+RESET"; + break; + case Command.TYPE_POSITION_SINGLE: + commandString = "BB+RRCD"; + break; + default: + Log.warning(new UnsupportedOperationException(command.getType())); + return null; } if (!commandString.isEmpty()) { ChannelBuffer commandBuf = ChannelBuffers.dynamicBuffer(); diff --git a/src/org/traccar/protocol/Gt02Protocol.java b/src/org/traccar/protocol/Gt02Protocol.java index e03727b4d..595e6649e 100644 --- a/src/org/traccar/protocol/Gt02Protocol.java +++ b/src/org/traccar/protocol/Gt02Protocol.java @@ -31,7 +31,7 @@ public class Gt02Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 2, 1, 2, 0)); diff --git a/src/org/traccar/protocol/Gt06Protocol.java b/src/org/traccar/protocol/Gt06Protocol.java index 7f6d5d914..e4c9ef2e0 100644 --- a/src/org/traccar/protocol/Gt06Protocol.java +++ b/src/org/traccar/protocol/Gt06Protocol.java @@ -34,7 +34,7 @@ public class Gt06Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new Gt06FrameDecoder()); diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 3df8a4686..4af814e24 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -165,24 +165,26 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { private String decodeAlarm(short value) { switch (value) { - case 0x01: - return Position.ALARM_SOS; - case 0x03: - case 0x09: - return Position.ALARM_VIBRATION; - case 0x04: - return Position.ALARM_GEOFENCE_ENTER; - case 0x05: - return Position.ALARM_GEOFENCE_EXIT; - case 0x06: - return Position.ALARM_OVERSPEED; - case 0x0E: - case 0x0F: - return Position.ALARM_LOW_BATTERY; - case 0x11: - return Position.ALARM_POWER_OFF; - default: - break; + case 0x01: + return Position.ALARM_SOS; + case 0x02: + return Position.ALARM_POWER_CUT; + case 0x03: + case 0x09: + return Position.ALARM_VIBRATION; + case 0x04: + return Position.ALARM_GEOFENCE_ENTER; + case 0x05: + return Position.ALARM_GEOFENCE_EXIT; + case 0x06: + return Position.ALARM_OVERSPEED; + case 0x0E: + case 0x0F: + return Position.ALARM_LOW_BATTERY; + case 0x11: + return Position.ALARM_POWER_OFF; + default: + break; } return null; } diff --git a/src/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/org/traccar/protocol/Gt06ProtocolEncoder.java index 3ef9b1313..e78a1b388 100644 --- a/src/org/traccar/protocol/Gt06ProtocolEncoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,11 @@ package org.traccar.protocol; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.traccar.BaseProtocolEncoder; +import org.traccar.Context; import org.traccar.helper.Checksum; import org.traccar.helper.Log; import org.traccar.model.Command; +import org.traccar.model.Device; import java.nio.charset.StandardCharsets; @@ -54,11 +56,19 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder { @Override protected Object encodeCommand(Command command) { + boolean alternative; + Device device = Context.getIdentityManager().getDeviceById(command.getDeviceId()); + if (device.getAttributes().containsKey("gt06.alternative")) { + alternative = Boolean.parseBoolean((String) device.getAttributes().get("gt06.alternative")); + } else { + alternative = Context.getConfig().getBoolean("gt06.alternative"); + } + switch (command.getType()) { case Command.TYPE_ENGINE_STOP: - return encodeContent("Relay,1#"); + return encodeContent(alternative ? "DYD,123456#" : "Relay,1#"); case Command.TYPE_ENGINE_RESUME: - return encodeContent("Relay,0#"); + return encodeContent(alternative ? "HFYD,123456#" : "Relay,0#"); default: Log.warning(new UnsupportedOperationException(command.getType())); break; diff --git a/src/org/traccar/protocol/H02FrameDecoder.java b/src/org/traccar/protocol/H02FrameDecoder.java index 79e33c0ca..feba8033d 100644 --- a/src/org/traccar/protocol/H02FrameDecoder.java +++ b/src/org/traccar/protocol/H02FrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2013 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,11 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder; public class H02FrameDecoder extends FrameDecoder { - private static final int MESSAGE_LENGTH = 32; + private int messageLength; + + public H02FrameDecoder(int messageLength) { + this.messageLength = messageLength; + } @Override protected Object decode( @@ -45,10 +49,10 @@ public class H02FrameDecoder extends FrameDecoder { return buf.readBytes(index + 1 - buf.readerIndex()); } - } else if (marker == '$' && buf.readableBytes() >= MESSAGE_LENGTH) { + } else if (marker == '$' && buf.readableBytes() >= messageLength) { // Return binary message - return buf.readBytes(MESSAGE_LENGTH); + return buf.readBytes(messageLength); } diff --git a/src/org/traccar/protocol/H02Protocol.java b/src/org/traccar/protocol/H02Protocol.java index 72b4f903d..06ac2a6fa 100644 --- a/src/org/traccar/protocol/H02Protocol.java +++ b/src/org/traccar/protocol/H02Protocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; +import org.traccar.Context; import org.traccar.TrackerServer; import org.traccar.model.Command; @@ -39,10 +40,11 @@ public class H02Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("frameDecoder", new H02FrameDecoder()); + int messageLength = Context.getConfig().getInteger(getName() + ".messageLength", 32); + pipeline.addLast("frameDecoder", new H02FrameDecoder(messageLength)); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("objectEncoder", new H02ProtocolEncoder()); pipeline.addLast("objectDecoder", new H02ProtocolDecoder(H02Protocol.this)); diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index fc6c9f17c..f876f40bc 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -79,6 +79,23 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_STATUS, status); } + private String decodeBattery(int value) { + switch (value) { + case 6: + return "100%"; + case 5: + return "80%"; + case 4: + return "60%"; + case 3: + return "20%"; + case 2: + return "10%"; + default: + return null; + } + } + private Position decodeBinary(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) { Position position = new Position(); @@ -103,7 +120,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { position.setTime(dateBuilder.getDate()); double latitude = readCoordinate(buf, false); - position.set(Position.KEY_POWER, buf.readByte()); + position.set(Position.KEY_BATTERY, decodeBattery(buf.readUnsignedByte())); double longitude = readCoordinate(buf, true); int flags = buf.readUnsignedByte() & 0x0f; @@ -129,7 +146,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { .text("*") .expression("..,") // manufacturer .number("(d+),") // imei - .number("Vd,") // version? + .expression("[^,]+,") .any() .number("(?:(dd)(dd)(dd))?,") // time .expression("([AV])?,") // validity @@ -148,6 +165,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { .number("(d+.?d*),") // speed .number("(d+.?d*)?,") // course .number("(?:(dd)(dd)(dd))?,") // date (ddmmyy) + .any() .number("(x{8})") // status .any() .compile(); diff --git a/src/org/traccar/protocol/HaicomProtocol.java b/src/org/traccar/protocol/HaicomProtocol.java index 344f9c1ae..71970d476 100644 --- a/src/org/traccar/protocol/HaicomProtocol.java +++ b/src/org/traccar/protocol/HaicomProtocol.java @@ -33,7 +33,7 @@ public class HaicomProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '*')); diff --git a/src/org/traccar/protocol/HomtecsProtocol.java b/src/org/traccar/protocol/HomtecsProtocol.java index 8e65f8572..e8a86fa37 100644 --- a/src/org/traccar/protocol/HomtecsProtocol.java +++ b/src/org/traccar/protocol/HomtecsProtocol.java @@ -32,7 +32,7 @@ public class HomtecsProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("stringDecoder", new StringDecoder()); diff --git a/src/org/traccar/protocol/HuaShengProtocol.java b/src/org/traccar/protocol/HuaShengProtocol.java index 53a77c603..dcef2bd69 100644 --- a/src/org/traccar/protocol/HuaShengProtocol.java +++ b/src/org/traccar/protocol/HuaShengProtocol.java @@ -30,7 +30,7 @@ public class HuaShengProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new HuaShengFrameDecoder()); diff --git a/src/org/traccar/protocol/HuabaoProtocol.java b/src/org/traccar/protocol/HuabaoProtocol.java index 9f41bb8c6..4a83689e3 100644 --- a/src/org/traccar/protocol/HuabaoProtocol.java +++ b/src/org/traccar/protocol/HuabaoProtocol.java @@ -30,7 +30,7 @@ public class HuabaoProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new HuabaoFrameDecoder()); diff --git a/src/org/traccar/protocol/HunterProProtocol.java b/src/org/traccar/protocol/HunterProProtocol.java index 1eb7d1a42..502a95e11 100644 --- a/src/org/traccar/protocol/HunterProProtocol.java +++ b/src/org/traccar/protocol/HunterProProtocol.java @@ -33,7 +33,7 @@ public class HunterProProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "\r")); diff --git a/src/org/traccar/protocol/IdplProtocol.java b/src/org/traccar/protocol/IdplProtocol.java index c35ae039d..88e106def 100644 --- a/src/org/traccar/protocol/IdplProtocol.java +++ b/src/org/traccar/protocol/IdplProtocol.java @@ -33,7 +33,7 @@ public class IdplProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); diff --git a/src/org/traccar/protocol/IntellitracProtocol.java b/src/org/traccar/protocol/IntellitracProtocol.java index a6caf770f..6db2b0011 100644 --- a/src/org/traccar/protocol/IntellitracProtocol.java +++ b/src/org/traccar/protocol/IntellitracProtocol.java @@ -32,7 +32,7 @@ public class IntellitracProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new IntellitracFrameDecoder(1024)); diff --git a/src/org/traccar/protocol/JpKorjarFrameDecoder.java b/src/org/traccar/protocol/JpKorjarFrameDecoder.java new file mode 100644 index 000000000..33a1b3f36 --- /dev/null +++ b/src/org/traccar/protocol/JpKorjarFrameDecoder.java @@ -0,0 +1,46 @@ +/* + * Copyright 2016 Nyash (nyashh@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.handler.codec.frame.FrameDecoder; + +public class JpKorjarFrameDecoder extends FrameDecoder { + + @Override + protected Object decode( + ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { + + if (buf.readableBytes() < 80) { + return null; + } + + int spaceIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ' '); + if (spaceIndex == -1) { + return null; + } + + int endIndex = buf.indexOf(spaceIndex, buf.writerIndex(), (byte) ','); + if (endIndex == -1) { + return null; + } + + return buf.readBytes(endIndex + 1); + } + +} diff --git a/src/org/traccar/protocol/JpKorjarProtocol.java b/src/org/traccar/protocol/JpKorjarProtocol.java new file mode 100644 index 000000000..c54994708 --- /dev/null +++ b/src/org/traccar/protocol/JpKorjarProtocol.java @@ -0,0 +1,45 @@ +/* + * Copyright 2016 Nyash (nyashh@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; + +import java.util.List; + +public class JpKorjarProtocol extends BaseProtocol { + + public JpKorjarProtocol() { + super("jpkorjar"); + } + + @Override + public void initTrackerServers(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + + pipeline.addLast("frameDecoder", new JpKorjarFrameDecoder()); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new JpKorjarProtocolDecoder(JpKorjarProtocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/JpKorjarProtocolDecoder.java b/src/org/traccar/protocol/JpKorjarProtocolDecoder.java new file mode 100644 index 000000000..e0fe0678d --- /dev/null +++ b/src/org/traccar/protocol/JpKorjarProtocolDecoder.java @@ -0,0 +1,93 @@ +/*
+ * Copyright 2016 Nyash (nyashh@gmail.com)
+ * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.protocol;
+
+import org.jboss.netty.channel.Channel;
+import org.traccar.BaseProtocolDecoder;
+import org.traccar.DeviceSession;
+import org.traccar.helper.DateBuilder;
+import org.traccar.helper.Parser;
+import org.traccar.helper.PatternBuilder;
+import org.traccar.model.Position;
+
+import java.net.SocketAddress;
+import java.util.regex.Pattern;
+
+public class JpKorjarProtocolDecoder extends BaseProtocolDecoder {
+
+ public JpKorjarProtocolDecoder(JpKorjarProtocol protocol) {
+ super(protocol);
+ }
+
+ private static final Pattern PATTERN = new PatternBuilder()
+ .text("KORJAR.PL,")
+ .number("(d+),") // imei
+ .number("(dd)(dd)(dd)") // date
+ .number("(dd)(dd)(dd),") // time
+ .number("(d+.d+)([NS]),") // latitude
+ .number("(d+.d+)([EW]),") // longitude
+ .number("(d+.d+),") // speed
+ .number("(d+),") // course
+ .number("[FL]:(d+.d+)V,") // battery
+ .number("([01]) ") // valid
+ .number("(d+) ") // mcc
+ .number("(d+) ") // mnc
+ .number("(x+) ") // lac
+ .number("(x+),") // cid
+ .compile();
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ Parser parser = new Parser(PATTERN, (String) msg);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
+
+ position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ position.setSpeed(parser.nextDouble());
+ position.setCourse(parser.nextDouble());
+
+ position.set(Position.KEY_BATTERY, parser.nextDouble());
+
+ position.setValid(parser.nextInt() == 1);
+
+ position.set(Position.KEY_MCC, parser.nextInt());
+ position.set(Position.KEY_MNC, parser.nextInt());
+ position.set(Position.KEY_LAC, parser.nextInt(16));
+ position.set(Position.KEY_CID, parser.nextInt(16));
+
+ return position;
+ }
+
+}
diff --git a/src/org/traccar/protocol/Jt600Protocol.java b/src/org/traccar/protocol/Jt600Protocol.java index 3207986bf..2df792b47 100644 --- a/src/org/traccar/protocol/Jt600Protocol.java +++ b/src/org/traccar/protocol/Jt600Protocol.java @@ -30,7 +30,7 @@ public class Jt600Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new Jt600FrameDecoder()); diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index b7193d24b..b30bd7b85 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { return degrees + minutes / 60; } - private Position decodeNormalMessage(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) { + private Position decodeBinary(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) { Position position = new Position(); position.setProtocol(getProtocolName()); @@ -120,7 +120,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { return position; } - private static final Pattern PATTERN = new PatternBuilder() + private static final Pattern PATTERN_W01 = new PatternBuilder() .text("(") .number("(d+),") // id .text("W01,") // type @@ -138,25 +138,22 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // gsm signal .number("(d+),") // alert type .any() - .text(")") .compile(); - private Position decodeAlertMessage(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) { + private Position decodeW01(String sentence, Channel channel, SocketAddress remoteAddress) { - Parser parser = new Parser(PATTERN, buf.toString(StandardCharsets.US_ASCII)); + Parser parser = new Parser(PATTERN_W01, sentence); if (!parser.matches()) { return null; } - Position position = new Position(); - position.setProtocol(getProtocolName()); - - position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); if (deviceSession == null) { return null; } + + Position position = new Position(); + position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); position.setLongitude(parser.nextCoordinate()); @@ -176,6 +173,68 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { return position; } + private static final Pattern PATTERN_U01 = new PatternBuilder() + .text("(") + .number("(d+),") // id + .number("Udd,") // type + .number("d+,").optional() // alarm + .number("(dd)(dd)(dd),") // date (ddmmyy) + .number("(dd)(dd)(dd),") // time + .expression("([TF]),") // validity + .number("(d+.d+),([NS]),") // latitude + .number("(d+.d+),([EW]),") // longitude + .number("(d+.?d*),") // speed + .number("(d+),") // course + .number("(d+),") // satellites + .number("(d+%),") // battery + .expression("([01]+),") // status + .number("(d+),") // cid + .number("(d+),") // lac + .number("(d+),") // gsm signal + .number("(d+),") // odometer + .number("(d+)") // index + .any() + .compile(); + + private Position decodeU01(String sentence, Channel channel, SocketAddress remoteAddress) { + + Parser parser = new Parser(PATTERN_U01, sentence); + if (!parser.matches()) { + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + DateBuilder dateBuilder = new DateBuilder() + .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + position.setValid(parser.next().equals("T")); + position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + + position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble())); + position.setCourse(parser.nextDouble()); + + position.set(Position.KEY_SATELLITES, parser.nextInt()); + position.set(Position.KEY_BATTERY, parser.next()); + position.set(Position.KEY_STATUS, parser.nextInt(2)); + position.set(Position.KEY_CID, parser.nextInt()); + position.set(Position.KEY_LAC, parser.nextInt()); + position.set(Position.KEY_GSM, parser.nextInt()); + position.set(Position.KEY_ODOMETER, parser.nextLong() * 1000); + position.set(Position.KEY_INDEX, parser.nextInt()); + + return position; + } @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -184,9 +243,14 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { char first = (char) buf.getByte(0); if (first == '$') { - return decodeNormalMessage(buf, channel, remoteAddress); + return decodeBinary(buf, channel, remoteAddress); } else if (first == '(') { - return decodeAlertMessage(buf, channel, remoteAddress); + String sentence = buf.toString(StandardCharsets.US_ASCII); + if (sentence.contains("W01")) { + return decodeW01(sentence, channel, remoteAddress); + } else { + return decodeU01(sentence, channel, remoteAddress); + } } return null; diff --git a/src/org/traccar/protocol/KhdProtocol.java b/src/org/traccar/protocol/KhdProtocol.java index 93edb0415..e5bcc1be3 100644 --- a/src/org/traccar/protocol/KhdProtocol.java +++ b/src/org/traccar/protocol/KhdProtocol.java @@ -35,7 +35,7 @@ public class KhdProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(512, 3, 2)); diff --git a/src/org/traccar/protocol/L100Protocol.java b/src/org/traccar/protocol/L100Protocol.java index 95a4dce68..418b9beb7 100644 --- a/src/org/traccar/protocol/L100Protocol.java +++ b/src/org/traccar/protocol/L100Protocol.java @@ -30,7 +30,7 @@ public class L100Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new L100FrameDecoder()); diff --git a/src/org/traccar/protocol/LaipacProtocol.java b/src/org/traccar/protocol/LaipacProtocol.java index c2e5c585e..f64204749 100644 --- a/src/org/traccar/protocol/LaipacProtocol.java +++ b/src/org/traccar/protocol/LaipacProtocol.java @@ -33,7 +33,7 @@ public class LaipacProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); diff --git a/src/org/traccar/protocol/M2mProtocol.java b/src/org/traccar/protocol/M2mProtocol.java index 1fac9118c..662aa3f0f 100644 --- a/src/org/traccar/protocol/M2mProtocol.java +++ b/src/org/traccar/protocol/M2mProtocol.java @@ -31,7 +31,7 @@ public class M2mProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new FixedLengthFrameDecoder(23)); diff --git a/src/org/traccar/protocol/ManPowerProtocol.java b/src/org/traccar/protocol/ManPowerProtocol.java index 647a1bea7..ce7045899 100644 --- a/src/org/traccar/protocol/ManPowerProtocol.java +++ b/src/org/traccar/protocol/ManPowerProtocol.java @@ -33,7 +33,7 @@ public class ManPowerProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ';')); diff --git a/src/org/traccar/protocol/MegastekProtocol.java b/src/org/traccar/protocol/MegastekProtocol.java index f61a4443c..77c2510bd 100644 --- a/src/org/traccar/protocol/MegastekProtocol.java +++ b/src/org/traccar/protocol/MegastekProtocol.java @@ -32,7 +32,7 @@ public class MegastekProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new MegastekFrameDecoder()); diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index a330947b1..3ea76536c 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -343,31 +343,31 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { private String decodeAlarm(String value) { switch (value) { - case "SOS": - case "Help": - return Position.ALARM_SOS; - case "Over Speed": - case "OverSpeed": - return Position.ALARM_OVERSPEED; - case "LowSpeed": - return Position.ALARM_LOW_SPEED; - case "Low Battery": - case "LowBattery": - return Position.ALARM_LOW_BATTERY; - case "VIB": - return Position.ALARM_VIBRATION; - case "Move in": - case "Geo in": - case "Geo1 in": - case "Geo2 in": - return Position.ALARM_GEOFENCE_ENTER; - case "Move out": - case "Geo out": - case "Geo1 out": - case "Geo2 out": - return Position.ALARM_GEOFENCE_EXIT; - default: - return null; + case "SOS": + case "Help": + return Position.ALARM_SOS; + case "Over Speed": + case "OverSpeed": + return Position.ALARM_OVERSPEED; + case "LowSpeed": + return Position.ALARM_LOW_SPEED; + case "Low Battery": + case "LowBattery": + return Position.ALARM_LOW_BATTERY; + case "VIB": + return Position.ALARM_VIBRATION; + case "Move in": + case "Geo in": + case "Geo1 in": + case "Geo2 in": + return Position.ALARM_GEOFENCE_ENTER; + case "Move out": + case "Geo out": + case "Geo1 out": + case "Geo2 out": + return Position.ALARM_GEOFENCE_EXIT; + default: + return null; } } diff --git a/src/org/traccar/protocol/MeiligaoProtocol.java b/src/org/traccar/protocol/MeiligaoProtocol.java index bce9b3196..2c61af5cb 100644 --- a/src/org/traccar/protocol/MeiligaoProtocol.java +++ b/src/org/traccar/protocol/MeiligaoProtocol.java @@ -40,7 +40,7 @@ public class MeiligaoProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new MeiligaoFrameDecoder()); @@ -48,7 +48,7 @@ public class MeiligaoProtocol extends BaseProtocol { pipeline.addLast("objectDecoder", new MeiligaoProtocolDecoder(MeiligaoProtocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("objectEncoder", new MeiligaoProtocolEncoder()); diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index 41e248791..f0e5032b4 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -80,6 +80,24 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { .expression("([EW])") .compile(); + private static final Pattern PATTERN_OBD = new PatternBuilder() + .number("(d+.d+),") // battery + .number("(d+),") // rpm + .number("(d+),") // speed + .number("(d+.d+),") // throttle + .number("(d+.d+),") // engine load + .number("(-?d+),") // coolant temp + .number("d+.d+,") // instantaneous fuel + .number("(d+.d+),") // average fuel + .number("(d+.d+),") // driving range + .number("(d+.?d*),") // odometer + .number("(d+.d+),") + .number("(d+.d+),") + .number("(d+),") // error code count + .number("d+,") // harsh acceleration count + .number("d+") // harsh break count + .compile(); + public static final int MSG_HEARTBEAT = 0x0001; public static final int MSG_SERVER = 0x0002; public static final int MSG_LOGIN = 0x5000; @@ -91,6 +109,8 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_RFID = 0x9966; + public static final int MSG_OBD_RT = 0x9901; + private DeviceSession identify(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) { StringBuilder builder = new StringBuilder(); @@ -142,7 +162,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { } } - private String getMeiligaoServer(Channel channel) { + private String getServer(Channel channel) { String server = Context.getConfig().getString(getProtocolName() + ".server"); if (server == null) { InetSocketAddress address = (InetSocketAddress) channel.getLocalAddress(); @@ -153,23 +173,123 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { private String decodeAlarm(short value) { switch (value) { - case 0x01: - return Position.ALARM_SOS; - case 0x10: - return Position.ALARM_LOW_BATTERY; - case 0x11: - return Position.ALARM_OVERSPEED; - case 0x12: - return Position.ALARM_MOVEMENT; - case 0x13: - return Position.ALARM_GEOFENCE_ENTER; - case 0x50: - return Position.ALARM_POWER_OFF; - case 0x53: - return Position.ALARM_GPS_ANTENNA_CUT; - default: + case 0x01: + return Position.ALARM_SOS; + case 0x10: + return Position.ALARM_LOW_BATTERY; + case 0x11: + return Position.ALARM_OVERSPEED; + case 0x12: + return Position.ALARM_MOVEMENT; + case 0x13: + return Position.ALARM_GEOFENCE_ENTER; + case 0x50: + return Position.ALARM_POWER_OFF; + case 0x53: + return Position.ALARM_GPS_ANTENNA_CUT; + default: + return null; + } + } + + private Position decodeRegular(Position position, String sentence) { + Parser parser = new Parser(PATTERN, sentence); + if (!parser.matches()) { + return null; + } + + DateBuilder dateBuilder = new DateBuilder() + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + if (parser.hasNext()) { + dateBuilder.setMillis(parser.nextInt()); + } + + position.setValid(parser.next().equals("A")); + position.setLatitude(parser.nextCoordinate()); + position.setLongitude(parser.nextCoordinate()); + + if (parser.hasNext()) { + position.setSpeed(parser.nextDouble()); + } + + if (parser.hasNext()) { + position.setCourse(parser.nextDouble()); + } + + dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + position.set(Position.KEY_HDOP, parser.next()); + + if (parser.hasNext()) { + position.setAltitude(parser.nextDouble()); + } + + position.set(Position.KEY_STATUS, parser.next()); + + for (int i = 1; i <= 8; i++) { + if (parser.hasNext()) { + position.set(Position.PREFIX_ADC + i, parser.nextInt(16)); + } + } + + if (parser.hasNext()) { + position.set(Position.KEY_GSM, parser.nextInt(16)); + } + + if (parser.hasNext()) { + position.set(Position.KEY_ODOMETER, parser.nextLong(16)); + } + if (parser.hasNext()) { + position.set(Position.KEY_ODOMETER, parser.nextLong(16)); + } + + if (parser.hasNext()) { + position.set(Position.KEY_RFID, parser.nextInt(16)); + } + + return position; + } + + private Position decodeRfid(Position position, String sentence) { + Parser parser = new Parser(PATTERN_RFID, sentence); + if (!parser.matches()) { return null; } + + DateBuilder dateBuilder = new DateBuilder() + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + position.setValid(true); + position.setLatitude(parser.nextCoordinate()); + position.setLongitude(parser.nextCoordinate()); + + return position; + } + + private Position decodeObd(Position position, String sentence) { + Parser parser = new Parser(PATTERN_OBD, sentence); + if (!parser.matches()) { + return null; + } + + getLastLocation(position, null); + + position.set(Position.KEY_BATTERY, parser.nextDouble()); + position.set(Position.KEY_RPM, parser.nextInt()); + position.set(Position.KEY_OBD_SPEED, parser.nextInt()); + position.set(Position.KEY_THROTTLE, parser.nextDouble()); + position.set("engineLoad", parser.nextDouble()); + position.set(Position.PREFIX_TEMP + 1, parser.nextInt()); + position.set(Position.KEY_FUEL_CONSUMPTION, parser.nextDouble()); + position.set("drivingRange", parser.nextDouble() * 1000); + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); + position.set("singleFuelConsumption", parser.nextDouble()); + position.set("totalFuelConsumption", parser.nextDouble()); + + return position; } @Override @@ -183,39 +303,25 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { int command = buf.readUnsignedShort(); ChannelBuffer response; - switch (command) { - case MSG_LOGIN: - if (channel != null) { - response = ChannelBuffers.wrappedBuffer(new byte[] {0x01}); - sendResponse(channel, remoteAddress, id, MSG_LOGIN_RESPONSE, response); - } + if (channel != null) { + if (command == MSG_LOGIN) { + response = ChannelBuffers.wrappedBuffer(new byte[] {0x01}); + sendResponse(channel, remoteAddress, id, MSG_LOGIN_RESPONSE, response); return null; - case MSG_HEARTBEAT: - if (channel != null) { - response = ChannelBuffers.wrappedBuffer(new byte[] {0x01}); - sendResponse(channel, remoteAddress, id, MSG_HEARTBEAT, response); - } + } else if (command == MSG_HEARTBEAT) { + response = ChannelBuffers.wrappedBuffer(new byte[] {0x01}); + sendResponse(channel, remoteAddress, id, MSG_HEARTBEAT, response); return null; - case MSG_SERVER: - if (channel != null) { - response = ChannelBuffers.copiedBuffer( - getMeiligaoServer(channel), StandardCharsets.US_ASCII); - sendResponse(channel, remoteAddress, id, MSG_SERVER, response); - } - return null; - case MSG_POSITION: - case MSG_POSITION_LOGGED: - case MSG_ALARM: - case MSG_RFID: - break; - default: + } else if (command == MSG_SERVER) { + response = ChannelBuffers.copiedBuffer(getServer(channel), StandardCharsets.US_ASCII); + sendResponse(channel, remoteAddress, id, MSG_SERVER, response); return null; + } } Position position = new Position(); position.setProtocol(getProtocolName()); - // Custom data if (command == MSG_ALARM) { position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte())); } else if (command == MSG_POSITION_LOGGED) { @@ -239,85 +345,17 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { } } - Pattern pattern; - if (command == MSG_RFID) { - pattern = PATTERN_RFID; - } else { - pattern = PATTERN; - } - - Parser parser = new Parser( - pattern, buf.toString(buf.readerIndex(), buf.readableBytes() - 4, StandardCharsets.US_ASCII)); - if (!parser.matches()) { - return null; - } - - if (command == MSG_RFID) { - - DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); - - position.setValid(true); - position.setLatitude(parser.nextCoordinate()); - position.setLongitude(parser.nextCoordinate()); - - } else { - - DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - if (parser.hasNext()) { - dateBuilder.setMillis(parser.nextInt()); - } - - position.setValid(parser.next().equals("A")); - position.setLatitude(parser.nextCoordinate()); - position.setLongitude(parser.nextCoordinate()); - - if (parser.hasNext()) { - position.setSpeed(parser.nextDouble()); - } - - if (parser.hasNext()) { - position.setCourse(parser.nextDouble()); - } - - dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); - - position.set(Position.KEY_HDOP, parser.next()); - - if (parser.hasNext()) { - position.setAltitude(parser.nextDouble()); - } - - position.set(Position.KEY_STATUS, parser.next()); - - for (int i = 1; i <= 8; i++) { - if (parser.hasNext()) { - position.set(Position.PREFIX_ADC + i, parser.nextInt(16)); - } - } - - if (parser.hasNext()) { - position.set(Position.KEY_GSM, parser.nextInt(16)); - } - - if (parser.hasNext()) { - position.set(Position.KEY_ODOMETER, parser.nextLong(16)); - } - if (parser.hasNext()) { - position.set(Position.KEY_ODOMETER, parser.nextLong(16)); - } - - if (parser.hasNext()) { - position.set(Position.KEY_RFID, parser.nextInt(16)); - } + String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 4, StandardCharsets.US_ASCII); + if (command == MSG_POSITION || command == MSG_POSITION_LOGGED || command == MSG_ALARM) { + return decodeRegular(position, sentence); + } else if (command == MSG_RFID) { + return decodeRfid(position, sentence); + } else if (command == MSG_OBD_RT) { + return decodeObd(position, sentence); } - return position; + return null; } } diff --git a/src/org/traccar/protocol/MeitrackProtocol.java b/src/org/traccar/protocol/MeitrackProtocol.java index 01fdcc08c..0c85c6203 100644 --- a/src/org/traccar/protocol/MeitrackProtocol.java +++ b/src/org/traccar/protocol/MeitrackProtocol.java @@ -42,7 +42,7 @@ public class MeitrackProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new MeitrackFrameDecoder()); @@ -53,7 +53,7 @@ public class MeitrackProtocol extends BaseProtocol { }; server.setEndianness(ByteOrder.LITTLE_ENDIAN); serverList.add(server); - server = new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + server = new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/MiniFinderProtocol.java b/src/org/traccar/protocol/MiniFinderProtocol.java index 8da621ee4..605633267 100644 --- a/src/org/traccar/protocol/MiniFinderProtocol.java +++ b/src/org/traccar/protocol/MiniFinderProtocol.java @@ -44,7 +44,7 @@ public class MiniFinderProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ';')); diff --git a/src/org/traccar/protocol/Mta6Protocol.java b/src/org/traccar/protocol/Mta6Protocol.java index ed578b2d7..cafda2bc6 100644 --- a/src/org/traccar/protocol/Mta6Protocol.java +++ b/src/org/traccar/protocol/Mta6Protocol.java @@ -33,7 +33,7 @@ public class Mta6Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("httpEncoder", new HttpResponseEncoder()); diff --git a/src/org/traccar/protocol/MtxProtocol.java b/src/org/traccar/protocol/MtxProtocol.java index e0bef8350..c549653d0 100644 --- a/src/org/traccar/protocol/MtxProtocol.java +++ b/src/org/traccar/protocol/MtxProtocol.java @@ -33,7 +33,7 @@ public class MtxProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); diff --git a/src/org/traccar/protocol/MxtProtocol.java b/src/org/traccar/protocol/MxtProtocol.java index 95223932c..a5d21e445 100644 --- a/src/org/traccar/protocol/MxtProtocol.java +++ b/src/org/traccar/protocol/MxtProtocol.java @@ -31,7 +31,7 @@ public class MxtProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new MxtFrameDecoder()); diff --git a/src/org/traccar/protocol/NavigilProtocol.java b/src/org/traccar/protocol/NavigilProtocol.java index 6d64761fc..7cf6f35ff 100644 --- a/src/org/traccar/protocol/NavigilProtocol.java +++ b/src/org/traccar/protocol/NavigilProtocol.java @@ -31,7 +31,7 @@ public class NavigilProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new NavigilFrameDecoder()); diff --git a/src/org/traccar/protocol/NavisProtocol.java b/src/org/traccar/protocol/NavisProtocol.java index 691a3d08c..d4cf40f1f 100644 --- a/src/org/traccar/protocol/NavisProtocol.java +++ b/src/org/traccar/protocol/NavisProtocol.java @@ -32,7 +32,7 @@ public class NavisProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(4 * 1024, 12, 2, 2, 0)); diff --git a/src/org/traccar/protocol/NoranProtocol.java b/src/org/traccar/protocol/NoranProtocol.java index 6bc15296e..eeddbdead 100644 --- a/src/org/traccar/protocol/NoranProtocol.java +++ b/src/org/traccar/protocol/NoranProtocol.java @@ -38,7 +38,7 @@ public class NoranProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("objectEncoder", new NoranProtocolEncoder()); diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java index aaecfc1db..e062a9907 100644 --- a/src/org/traccar/protocol/NoranProtocolDecoder.java +++ b/src/org/traccar/protocol/NoranProtocolDecoder.java @@ -92,20 +92,20 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { short alarm = buf.readUnsignedByte(); switch (alarm) { - case 1: - position.set(Position.KEY_ALARM, Position.ALARM_SOS); - break; - case 2: - position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); - break; - case 3: - position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_EXIT); - break; - case 9: - position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF); - break; - default: - break; + case 1: + position.set(Position.KEY_ALARM, Position.ALARM_SOS); + break; + case 2: + position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); + break; + case 3: + position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_EXIT); + break; + case 9: + position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF); + break; + default: + break; } if (newFormat) { diff --git a/src/org/traccar/protocol/NvsProtocol.java b/src/org/traccar/protocol/NvsProtocol.java index 9236668d2..4610e4abc 100644 --- a/src/org/traccar/protocol/NvsProtocol.java +++ b/src/org/traccar/protocol/NvsProtocol.java @@ -30,7 +30,7 @@ public class NvsProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new NvsFrameDecoder()); diff --git a/src/org/traccar/protocol/ObdDongleProtocol.java b/src/org/traccar/protocol/ObdDongleProtocol.java index e87f9a99a..d91eb765a 100644 --- a/src/org/traccar/protocol/ObdDongleProtocol.java +++ b/src/org/traccar/protocol/ObdDongleProtocol.java @@ -31,7 +31,7 @@ public class ObdDongleProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1099, 20, 2, 3, 0)); diff --git a/src/org/traccar/protocol/OigoProtocol.java b/src/org/traccar/protocol/OigoProtocol.java new file mode 100644 index 000000000..c60ee1be6 --- /dev/null +++ b/src/org/traccar/protocol/OigoProtocol.java @@ -0,0 +1,41 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; + +import java.util.List; + +public class OigoProtocol extends BaseProtocol { + + public OigoProtocol() { + super("oigo"); + } + + @Override + public void initTrackerServers(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("objectDecoder", new OigoProtocolDecoder(OigoProtocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/OigoProtocolDecoder.java b/src/org/traccar/protocol/OigoProtocolDecoder.java new file mode 100644 index 000000000..bbea38183 --- /dev/null +++ b/src/org/traccar/protocol/OigoProtocolDecoder.java @@ -0,0 +1,157 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +import org.jboss.netty.channel.Channel; +import org.traccar.BaseProtocolDecoder; +import org.traccar.DeviceSession; +import org.traccar.helper.BitUtil; +import org.traccar.helper.DateBuilder; +import org.traccar.helper.UnitsConverter; +import org.traccar.model.Position; + +import java.net.SocketAddress; +import java.nio.charset.StandardCharsets; + +public class OigoProtocolDecoder extends BaseProtocolDecoder { + + public OigoProtocolDecoder(OigoProtocol protocol) { + super(protocol); + } + + public static final int MSG_LOCATION = 0x00; + public static final int MSG_REMOTE_START = 0x10; + public static final int MSG_ACKNOWLEDGEMENT = 0xE0; + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + ChannelBuffer buf = (ChannelBuffer) msg; + + buf.skipBytes(1); // header + buf.readUnsignedShort(); // length + + int type = buf.readUnsignedByte(); + + int tag = buf.readUnsignedByte(); + + DeviceSession deviceSession; + switch (BitUtil.to(tag, 3)) { + case 0: + String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1); + deviceSession = getDeviceSession(channel, remoteAddress, imei); + break; + case 1: + buf.skipBytes(1); + String meid = buf.readBytes(14).toString(StandardCharsets.US_ASCII); + deviceSession = getDeviceSession(channel, remoteAddress, meid); + break; + default: + deviceSession = getDeviceSession(channel, remoteAddress); + break; + } + + if (deviceSession == null || type != MSG_LOCATION) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + position.set(Position.KEY_EVENT, buf.readUnsignedByte()); + + int mask = buf.readInt(); + + if (BitUtil.check(mask, 0)) { + position.set(Position.KEY_INDEX, buf.readUnsignedShort()); + } + + if (BitUtil.check(mask, 1)) { + int date = buf.readUnsignedByte(); + DateBuilder dateBuilder = new DateBuilder() + .setDate(BitUtil.between(date, 4, 8) + 2010, BitUtil.to(date, 4), buf.readUnsignedByte()) + .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()); + position.setTime(dateBuilder.getDate()); + } + + if (BitUtil.check(mask, 2)) { + buf.skipBytes(5); // device time + } + + if (BitUtil.check(mask, 3)) { + position.setLatitude(buf.readUnsignedInt() * 0.000001 - 90); + position.setLongitude(buf.readUnsignedInt() * 0.000001 - 180.0); + } + + if (BitUtil.check(mask, 4)) { + int status = buf.readUnsignedByte(); + position.setValid(BitUtil.between(status, 4, 8) != 0); + position.set(Position.KEY_SATELLITES, BitUtil.to(status, 4)); + position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1); + } + + if (BitUtil.check(mask, 5)) { + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + } + + if (BitUtil.check(mask, 6)) { + position.setCourse(buf.readUnsignedShort()); + } + + if (BitUtil.check(mask, 7)) { + position.setAltitude(buf.readShort()); + } + + if (BitUtil.check(mask, 8)) { + position.set(Position.KEY_GSM, buf.readUnsignedByte()); + } + + if (BitUtil.check(mask, 9)) { + position.set(Position.KEY_POWER, buf.readUnsignedShort() + "mV"); + } + + if (BitUtil.check(mask, 10)) { + position.set(Position.KEY_BATTERY, buf.readUnsignedShort() + "mV"); + } + + if (BitUtil.check(mask, 11)) { + buf.skipBytes(2); // gpio + } + + if (BitUtil.check(mask, 12)) { + position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000); + } + + if (BitUtil.check(mask, 13)) { + buf.skipBytes(6); // software version + } + + if (BitUtil.check(mask, 14)) { + buf.skipBytes(5); // hardware version + } + + if (BitUtil.check(mask, 15)) { + buf.readUnsignedShort(); // device config + } + + return position; + } + +} diff --git a/src/org/traccar/protocol/OrionProtocol.java b/src/org/traccar/protocol/OrionProtocol.java index 4113c4314..c0166b05d 100644 --- a/src/org/traccar/protocol/OrionProtocol.java +++ b/src/org/traccar/protocol/OrionProtocol.java @@ -31,7 +31,7 @@ public class OrionProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new OrionFrameDecoder()); diff --git a/src/org/traccar/protocol/OsmAndProtocol.java b/src/org/traccar/protocol/OsmAndProtocol.java index 3b473c435..7f5318576 100644 --- a/src/org/traccar/protocol/OsmAndProtocol.java +++ b/src/org/traccar/protocol/OsmAndProtocol.java @@ -32,7 +32,7 @@ public class OsmAndProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("httpEncoder", new HttpResponseEncoder()); diff --git a/src/org/traccar/protocol/PathAwayProtocol.java b/src/org/traccar/protocol/PathAwayProtocol.java index d7efdfaf6..2583670a2 100644 --- a/src/org/traccar/protocol/PathAwayProtocol.java +++ b/src/org/traccar/protocol/PathAwayProtocol.java @@ -32,7 +32,7 @@ public class PathAwayProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("httpEncoder", new HttpResponseEncoder()); diff --git a/src/org/traccar/protocol/PiligrimProtocol.java b/src/org/traccar/protocol/PiligrimProtocol.java index 11aafa412..0ab529d5c 100644 --- a/src/org/traccar/protocol/PiligrimProtocol.java +++ b/src/org/traccar/protocol/PiligrimProtocol.java @@ -33,7 +33,7 @@ public class PiligrimProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("httpEncoder", new HttpResponseEncoder()); diff --git a/src/org/traccar/protocol/ProgressProtocol.java b/src/org/traccar/protocol/ProgressProtocol.java index 35bdf9c9b..3fb702b7b 100644 --- a/src/org/traccar/protocol/ProgressProtocol.java +++ b/src/org/traccar/protocol/ProgressProtocol.java @@ -32,7 +32,7 @@ public class ProgressProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, 4, 0)); diff --git a/src/org/traccar/protocol/Pt3000Protocol.java b/src/org/traccar/protocol/Pt3000Protocol.java index 3a22be214..c4cb4129d 100644 --- a/src/org/traccar/protocol/Pt3000Protocol.java +++ b/src/org/traccar/protocol/Pt3000Protocol.java @@ -33,7 +33,7 @@ public class Pt3000Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, 'd')); // probably wrong diff --git a/src/org/traccar/protocol/Pt502Protocol.java b/src/org/traccar/protocol/Pt502Protocol.java index 1368dd7b7..b609927ac 100644 --- a/src/org/traccar/protocol/Pt502Protocol.java +++ b/src/org/traccar/protocol/Pt502Protocol.java @@ -39,7 +39,7 @@ public class Pt502Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new Pt502FrameDecoder()); diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index 7dc4fbe5e..24dc2094f 100644 --- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java @@ -91,10 +91,8 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { String type = parser.next();
- if (type.startsWith("PHO")) {
- if (channel != null) {
- channel.write("#PHD0," + type.substring(3) + "\r\n");
- }
+ if (type.startsWith("PHO") && channel != null) {
+ channel.write("#PHD0," + type.substring(3) + "\r\n");
}
position.set(Position.KEY_ALARM, decodeAlarm(type));
diff --git a/src/org/traccar/protocol/RaveonProtocol.java b/src/org/traccar/protocol/RaveonProtocol.java index 551f1683f..a81d52f0e 100644 --- a/src/org/traccar/protocol/RaveonProtocol.java +++ b/src/org/traccar/protocol/RaveonProtocol.java @@ -33,7 +33,7 @@ public class RaveonProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); diff --git a/src/org/traccar/protocol/RitiProtocol.java b/src/org/traccar/protocol/RitiProtocol.java index e968032ca..8a39c29e1 100644 --- a/src/org/traccar/protocol/RitiProtocol.java +++ b/src/org/traccar/protocol/RitiProtocol.java @@ -32,7 +32,7 @@ public class RitiProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 105, 2, 3, 0)); diff --git a/src/org/traccar/protocol/RuptelaProtocol.java b/src/org/traccar/protocol/RuptelaProtocol.java index d806c4c01..1fe7b02ad 100644 --- a/src/org/traccar/protocol/RuptelaProtocol.java +++ b/src/org/traccar/protocol/RuptelaProtocol.java @@ -34,7 +34,7 @@ public class RuptelaProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 0, 2, 2, 0)); diff --git a/src/org/traccar/protocol/SanavProtocol.java b/src/org/traccar/protocol/SanavProtocol.java index bb329ab70..0e7958b8e 100644 --- a/src/org/traccar/protocol/SanavProtocol.java +++ b/src/org/traccar/protocol/SanavProtocol.java @@ -33,7 +33,7 @@ public class SanavProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '*')); diff --git a/src/org/traccar/protocol/SkypatrolProtocol.java b/src/org/traccar/protocol/SkypatrolProtocol.java index 2791ba082..7d8240294 100644 --- a/src/org/traccar/protocol/SkypatrolProtocol.java +++ b/src/org/traccar/protocol/SkypatrolProtocol.java @@ -30,7 +30,7 @@ public class SkypatrolProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("objectDecoder", new SkypatrolProtocolDecoder(SkypatrolProtocol.this)); diff --git a/src/org/traccar/protocol/Stl060Protocol.java b/src/org/traccar/protocol/Stl060Protocol.java index e37f94b00..ccdd256d7 100644 --- a/src/org/traccar/protocol/Stl060Protocol.java +++ b/src/org/traccar/protocol/Stl060Protocol.java @@ -32,7 +32,7 @@ public class Stl060Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new Stl060FrameDecoder(1024)); diff --git a/src/org/traccar/protocol/SuntechProtocol.java b/src/org/traccar/protocol/SuntechProtocol.java index 4a40e1bfc..df6109722 100644 --- a/src/org/traccar/protocol/SuntechProtocol.java +++ b/src/org/traccar/protocol/SuntechProtocol.java @@ -40,7 +40,7 @@ public class SuntechProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\r')); diff --git a/src/org/traccar/protocol/SupermateProtocol.java b/src/org/traccar/protocol/SupermateProtocol.java index bcc2bed16..70c3c00e6 100755 --- a/src/org/traccar/protocol/SupermateProtocol.java +++ b/src/org/traccar/protocol/SupermateProtocol.java @@ -33,7 +33,7 @@ public class SupermateProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "#")); diff --git a/src/org/traccar/protocol/T55Protocol.java b/src/org/traccar/protocol/T55Protocol.java index 86f927e41..657155042 100644 --- a/src/org/traccar/protocol/T55Protocol.java +++ b/src/org/traccar/protocol/T55Protocol.java @@ -34,7 +34,7 @@ public class T55Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); @@ -43,7 +43,7 @@ public class T55Protocol extends BaseProtocol { pipeline.addLast("objectDecoder", new T55ProtocolDecoder(T55Protocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("stringDecoder", new StringDecoder()); diff --git a/src/org/traccar/protocol/T800xProtocolDecoder.java b/src/org/traccar/protocol/T800xProtocolDecoder.java index 8301450d5..d92145e05 100644 --- a/src/org/traccar/protocol/T800xProtocolDecoder.java +++ b/src/org/traccar/protocol/T800xProtocolDecoder.java @@ -62,19 +62,19 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder { private String decodeAlarm(short value) { switch (value) { - case 3: - return Position.ALARM_SOS; - case 4: - return Position.ALARM_OVERSPEED; - case 5: - return Position.ALARM_GEOFENCE_ENTER; - case 6: - return Position.ALARM_GEOFENCE_EXIT; - case 8: - case 10: - return Position.ALARM_VIBRATION; - default: - break; + case 3: + return Position.ALARM_SOS; + case 4: + return Position.ALARM_OVERSPEED; + case 5: + return Position.ALARM_GEOFENCE_ENTER; + case 6: + return Position.ALARM_GEOFENCE_EXIT; + case 8: + case 10: + return Position.ALARM_VIBRATION; + default: + break; } return null; } diff --git a/src/org/traccar/protocol/TaipProtocol.java b/src/org/traccar/protocol/TaipProtocol.java index e72639099..8b93eb42d 100644 --- a/src/org/traccar/protocol/TaipProtocol.java +++ b/src/org/traccar/protocol/TaipProtocol.java @@ -34,7 +34,7 @@ public class TaipProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '<')); @@ -43,7 +43,7 @@ public class TaipProtocol extends BaseProtocol { pipeline.addLast("objectDecoder", new TaipProtocolDecoder(TaipProtocol.this, true)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("stringDecoder", new StringDecoder()); diff --git a/src/org/traccar/protocol/TelicProtocol.java b/src/org/traccar/protocol/TelicProtocol.java index 1e27620ba..b55e16caf 100644 --- a/src/org/traccar/protocol/TelicProtocol.java +++ b/src/org/traccar/protocol/TelicProtocol.java @@ -33,7 +33,7 @@ public class TelicProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new TelicFrameDecoder()); diff --git a/src/org/traccar/protocol/TeltonikaProtocol.java b/src/org/traccar/protocol/TeltonikaProtocol.java index 5a550d4c0..c9c0f0f4d 100644 --- a/src/org/traccar/protocol/TeltonikaProtocol.java +++ b/src/org/traccar/protocol/TeltonikaProtocol.java @@ -34,7 +34,7 @@ public class TeltonikaProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new TeltonikaFrameDecoder()); @@ -42,7 +42,7 @@ public class TeltonikaProtocol extends BaseProtocol { pipeline.addLast("objectDecoder", new TeltonikaProtocolDecoder(TeltonikaProtocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("objectEncoder", new TeltonikaProtocolEncoder()); diff --git a/src/org/traccar/protocol/ThinkRaceProtocol.java b/src/org/traccar/protocol/ThinkRaceProtocol.java index c9d6c7fc1..add7d33d3 100644 --- a/src/org/traccar/protocol/ThinkRaceProtocol.java +++ b/src/org/traccar/protocol/ThinkRaceProtocol.java @@ -31,7 +31,7 @@ public class ThinkRaceProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2 + 12 + 1 + 1, 2, 2, 0)); diff --git a/src/org/traccar/protocol/Tk102Protocol.java b/src/org/traccar/protocol/Tk102Protocol.java index 1f4eda730..7310d23bd 100644 --- a/src/org/traccar/protocol/Tk102Protocol.java +++ b/src/org/traccar/protocol/Tk102Protocol.java @@ -33,7 +33,7 @@ public class Tk102Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ']')); diff --git a/src/org/traccar/protocol/Tk103Protocol.java b/src/org/traccar/protocol/Tk103Protocol.java index b14264091..3fe82ad8b 100644 --- a/src/org/traccar/protocol/Tk103Protocol.java +++ b/src/org/traccar/protocol/Tk103Protocol.java @@ -34,7 +34,7 @@ public class Tk103Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ')')); @@ -43,7 +43,7 @@ public class Tk103Protocol extends BaseProtocol { pipeline.addLast("objectDecoder", new Tk103ProtocolDecoder(Tk103Protocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("stringDecoder", new StringDecoder()); diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 90c80be71..c638e7f27 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -78,20 +78,20 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { private String decodeAlarm(int value) { switch (value) { - case 1: - return Position.ALARM_ACCIDENT; - case 2: - return Position.ALARM_SOS; - case 3: - return Position.ALARM_VIBRATION; - case 4: - return Position.ALARM_LOW_SPEED; - case 5: - return Position.ALARM_OVERSPEED; - case 6: - return Position.ALARM_GEOFENCE_EXIT; - default: - return null; + case 1: + return Position.ALARM_ACCIDENT; + case 2: + return Position.ALARM_SOS; + case 3: + return Position.ALARM_VIBRATION; + case 4: + return Position.ALARM_LOW_SPEED; + case 5: + return Position.ALARM_OVERSPEED; + case 6: + return Position.ALARM_GEOFENCE_EXIT; + default: + return null; } } @@ -111,11 +111,15 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { if (channel != null) { String id = sentence.substring(0, 12); String type = sentence.substring(12, 16); - if (type.equals("BP00")) { - String content = sentence.substring(sentence.length() - 3); - channel.write("(" + id + "AP01" + content + ")"); - } else if (type.equals("BP05")) { - channel.write("(" + id + "AP05)"); + if (type.equals("BP00") || type.equals("BP05")) { + String content = sentence.substring(16); + getDeviceSession(channel, remoteAddress, content.substring(0, 15)); + if (type.equals("BP00")) { + channel.write("(" + id + "AP01" + content.substring(15) + ")"); + return null; + } else if (type.equals("BP05")) { + channel.write("(" + id + "AP05)"); + } } } diff --git a/src/org/traccar/protocol/Tlt2hProtocol.java b/src/org/traccar/protocol/Tlt2hProtocol.java index 3a1bf99ff..e33b1b561 100644 --- a/src/org/traccar/protocol/Tlt2hProtocol.java +++ b/src/org/traccar/protocol/Tlt2hProtocol.java @@ -33,7 +33,7 @@ public class Tlt2hProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(32 * 1024, "##\r\n")); diff --git a/src/org/traccar/protocol/TopflytechProtocol.java b/src/org/traccar/protocol/TopflytechProtocol.java index ae250ad02..225cb66d7 100644 --- a/src/org/traccar/protocol/TopflytechProtocol.java +++ b/src/org/traccar/protocol/TopflytechProtocol.java @@ -33,7 +33,7 @@ public class TopflytechProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ')')); diff --git a/src/org/traccar/protocol/TotemProtocol.java b/src/org/traccar/protocol/TotemProtocol.java index e573adcc6..638755b7f 100644 --- a/src/org/traccar/protocol/TotemProtocol.java +++ b/src/org/traccar/protocol/TotemProtocol.java @@ -37,7 +37,7 @@ public class TotemProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new TotemFrameDecoder()); diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java index e7a689a8b..fbda41921 100644 --- a/src/org/traccar/protocol/TotemProtocolDecoder.java +++ b/src/org/traccar/protocol/TotemProtocolDecoder.java @@ -161,18 +161,18 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { private String decodeAlarm(Short value) { switch (value) { - case 0x01: - return Position.ALARM_SOS; - case 0x10: - return Position.ALARM_LOW_BATTERY; - case 0x11: - return Position.ALARM_OVERSPEED; - case 0x42: - return Position.ALARM_GEOFENCE_EXIT; - case 0x43: - return Position.ALARM_GEOFENCE_ENTER; - default: - return null; + case 0x01: + return Position.ALARM_SOS; + case 0x10: + return Position.ALARM_LOW_BATTERY; + case 0x11: + return Position.ALARM_OVERSPEED; + case 0x42: + return Position.ALARM_GEOFENCE_EXIT; + case 0x43: + return Position.ALARM_GEOFENCE_ENTER; + default: + return null; } } diff --git a/src/org/traccar/protocol/Tr20Protocol.java b/src/org/traccar/protocol/Tr20Protocol.java index 4e55d5f98..1c47db86a 100644 --- a/src/org/traccar/protocol/Tr20Protocol.java +++ b/src/org/traccar/protocol/Tr20Protocol.java @@ -33,7 +33,7 @@ public class Tr20Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); diff --git a/src/org/traccar/protocol/TrackboxProtocol.java b/src/org/traccar/protocol/TrackboxProtocol.java index 5477de852..b71eb3810 100644 --- a/src/org/traccar/protocol/TrackboxProtocol.java +++ b/src/org/traccar/protocol/TrackboxProtocol.java @@ -33,7 +33,7 @@ public class TrackboxProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); diff --git a/src/org/traccar/protocol/TramigoProtocol.java b/src/org/traccar/protocol/TramigoProtocol.java index 48892a78e..ea4ea7140 100644 --- a/src/org/traccar/protocol/TramigoProtocol.java +++ b/src/org/traccar/protocol/TramigoProtocol.java @@ -31,7 +31,7 @@ public class TramigoProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new TramigoFrameDecoder()); diff --git a/src/org/traccar/protocol/TrvProtocol.java b/src/org/traccar/protocol/TrvProtocol.java index af598ea02..585cb7cf6 100644 --- a/src/org/traccar/protocol/TrvProtocol.java +++ b/src/org/traccar/protocol/TrvProtocol.java @@ -33,7 +33,7 @@ public class TrvProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#')); diff --git a/src/org/traccar/protocol/Tt8850Protocol.java b/src/org/traccar/protocol/Tt8850Protocol.java index db41fae9f..5d188de60 100644 --- a/src/org/traccar/protocol/Tt8850Protocol.java +++ b/src/org/traccar/protocol/Tt8850Protocol.java @@ -33,7 +33,7 @@ public class Tt8850Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "$")); diff --git a/src/org/traccar/protocol/TytanProtocol.java b/src/org/traccar/protocol/TytanProtocol.java index 50918652a..b6608f925 100644 --- a/src/org/traccar/protocol/TytanProtocol.java +++ b/src/org/traccar/protocol/TytanProtocol.java @@ -30,7 +30,7 @@ public class TytanProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("objectDecoder", new TytanProtocolDecoder(TytanProtocol.this)); diff --git a/src/org/traccar/protocol/TzoneProtocol.java b/src/org/traccar/protocol/TzoneProtocol.java index fcf673a57..ca3e490d2 100644 --- a/src/org/traccar/protocol/TzoneProtocol.java +++ b/src/org/traccar/protocol/TzoneProtocol.java @@ -31,7 +31,7 @@ public class TzoneProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 2, 2, 2, 0)); diff --git a/src/org/traccar/protocol/TzoneProtocolDecoder.java b/src/org/traccar/protocol/TzoneProtocolDecoder.java index 4b530efa4..477dc6399 100644 --- a/src/org/traccar/protocol/TzoneProtocolDecoder.java +++ b/src/org/traccar/protocol/TzoneProtocolDecoder.java @@ -34,18 +34,18 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { private String decodeAlarm(Short value) { switch (value) { - case 0x01: - return Position.ALARM_SOS; - case 0x10: - return Position.ALARM_LOW_BATTERY; - case 0x11: - return Position.ALARM_OVERSPEED; - case 0x42: - return Position.ALARM_GEOFENCE_EXIT; - case 0x43: - return Position.ALARM_GEOFENCE_ENTER; - default: - return null; + case 0x01: + return Position.ALARM_SOS; + case 0x10: + return Position.ALARM_LOW_BATTERY; + case 0x11: + return Position.ALARM_OVERSPEED; + case 0x42: + return Position.ALARM_GEOFENCE_EXIT; + case 0x43: + return Position.ALARM_GEOFENCE_ENTER; + default: + return null; } } diff --git a/src/org/traccar/protocol/UlbotechProtocol.java b/src/org/traccar/protocol/UlbotechProtocol.java index d0413ecbe..ca31dffc9 100644 --- a/src/org/traccar/protocol/UlbotechProtocol.java +++ b/src/org/traccar/protocol/UlbotechProtocol.java @@ -30,7 +30,7 @@ public class UlbotechProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new UlbotechFrameDecoder()); diff --git a/src/org/traccar/protocol/UproProtocol.java b/src/org/traccar/protocol/UproProtocol.java index b62247761..8f940fa15 100644 --- a/src/org/traccar/protocol/UproProtocol.java +++ b/src/org/traccar/protocol/UproProtocol.java @@ -33,7 +33,7 @@ public class UproProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#')); diff --git a/src/org/traccar/protocol/V680Protocol.java b/src/org/traccar/protocol/V680Protocol.java index 4edff3772..83157790d 100644 --- a/src/org/traccar/protocol/V680Protocol.java +++ b/src/org/traccar/protocol/V680Protocol.java @@ -34,7 +34,7 @@ public class V680Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "##")); @@ -43,7 +43,7 @@ public class V680Protocol extends BaseProtocol { pipeline.addLast("objectDecoder", new V680ProtocolDecoder(V680Protocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("stringDecoder", new StringDecoder()); diff --git a/src/org/traccar/protocol/VisiontekProtocol.java b/src/org/traccar/protocol/VisiontekProtocol.java index 2d2a41e89..dde906370 100644 --- a/src/org/traccar/protocol/VisiontekProtocol.java +++ b/src/org/traccar/protocol/VisiontekProtocol.java @@ -33,7 +33,7 @@ public class VisiontekProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#')); diff --git a/src/org/traccar/protocol/WatchProtocol.java b/src/org/traccar/protocol/WatchProtocol.java index 3392e8cbc..8f28916f0 100644 --- a/src/org/traccar/protocol/WatchProtocol.java +++ b/src/org/traccar/protocol/WatchProtocol.java @@ -45,7 +45,7 @@ public class WatchProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ']')); diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index 326552e7f..d74fdbe81 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -25,6 +25,7 @@ import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; +import java.util.Date; import java.util.regex.Pattern; public class WatchProtocolDecoder extends BaseProtocolDecoder { @@ -146,6 +147,18 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel, manufacturer, id, "TKQ"); + } else if (type.equals("PULSE")) { + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + getLastLocation(position, new Date()); + position.setValid(false); + String pulse = content.substring(1); + position.set("pulse", pulse); + position.set(Position.KEY_RESULT, pulse); + return position; + } return null; diff --git a/src/org/traccar/protocol/WialonProtocol.java b/src/org/traccar/protocol/WialonProtocol.java index e0255c888..98af6973b 100644 --- a/src/org/traccar/protocol/WialonProtocol.java +++ b/src/org/traccar/protocol/WialonProtocol.java @@ -41,7 +41,7 @@ public class WialonProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(4 * 1024)); diff --git a/src/org/traccar/protocol/WialonProtocolEncoder.java b/src/org/traccar/protocol/WialonProtocolEncoder.java index b68dacd79..d3a0fc3b9 100644 --- a/src/org/traccar/protocol/WialonProtocolEncoder.java +++ b/src/org/traccar/protocol/WialonProtocolEncoder.java @@ -25,17 +25,17 @@ public class WialonProtocolEncoder extends StringProtocolEncoder { @Override protected Object encodeCommand(Command command) { switch (command.getType()) { - case Command.TYPE_REBOOT_DEVICE: - return formatCommand(command, "reboot\r\n"); - case Command.TYPE_SEND_USSD: - return formatCommand(command, "USSD:{%s}\r\n", Command.KEY_PHONE); - case Command.TYPE_IDENTIFICATION: - return formatCommand(command, "VER?\r\n"); - case Command.TYPE_OUTPUT_CONTROL: - return formatCommand(command, "L{%s}={%s}\r\n", Command.KEY_INDEX, Command.KEY_DATA); - default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + case Command.TYPE_REBOOT_DEVICE: + return formatCommand(command, "reboot\r\n"); + case Command.TYPE_SEND_USSD: + return formatCommand(command, "USSD:{%s}\r\n", Command.KEY_PHONE); + case Command.TYPE_IDENTIFICATION: + return formatCommand(command, "VER?\r\n"); + case Command.TYPE_OUTPUT_CONTROL: + return formatCommand(command, "L{%s}={%s}\r\n", Command.KEY_INDEX, Command.KEY_DATA); + default: + Log.warning(new UnsupportedOperationException(command.getType())); + break; } return null; } diff --git a/src/org/traccar/protocol/WondexProtocol.java b/src/org/traccar/protocol/WondexProtocol.java index 78e090f03..54b39a5c4 100644 --- a/src/org/traccar/protocol/WondexProtocol.java +++ b/src/org/traccar/protocol/WondexProtocol.java @@ -37,7 +37,7 @@ public class WondexProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new WondexFrameDecoder()); @@ -46,7 +46,7 @@ public class WondexProtocol extends BaseProtocol { pipeline.addLast("objectDecoder", new WondexProtocolDecoder(WondexProtocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/WondexProtocolEncoder.java b/src/org/traccar/protocol/WondexProtocolEncoder.java index 918c22cda..c350838d0 100644 --- a/src/org/traccar/protocol/WondexProtocolEncoder.java +++ b/src/org/traccar/protocol/WondexProtocolEncoder.java @@ -26,15 +26,15 @@ public class WondexProtocolEncoder extends StringProtocolEncoder { initDevicePassword(command, "0000"); switch (command.getType()) { - case Command.TYPE_REBOOT_DEVICE: - return formatCommand(command, "$WP+REBOOT={%s}", Command.KEY_DEVICE_PASSWORD); - case Command.TYPE_POSITION_SINGLE: - return formatCommand(command, "$WP+GETLOCATION={%s}", Command.KEY_DEVICE_PASSWORD); - case Command.TYPE_IDENTIFICATION: - return formatCommand(command, "$WP+VER={%s}", Command.KEY_DEVICE_PASSWORD); - default: - Log.warning(new UnsupportedOperationException(command.getType())); - break; + case Command.TYPE_REBOOT_DEVICE: + return formatCommand(command, "$WP+REBOOT={%s}", Command.KEY_DEVICE_PASSWORD); + case Command.TYPE_POSITION_SINGLE: + return formatCommand(command, "$WP+GETLOCATION={%s}", Command.KEY_DEVICE_PASSWORD); + case Command.TYPE_IDENTIFICATION: + return formatCommand(command, "$WP+VER={%s}", Command.KEY_DEVICE_PASSWORD); + default: + Log.warning(new UnsupportedOperationException(command.getType())); + break; } return null; diff --git a/src/org/traccar/protocol/XexunProtocol.java b/src/org/traccar/protocol/XexunProtocol.java index 14afaf4cb..ecaf18db4 100644 --- a/src/org/traccar/protocol/XexunProtocol.java +++ b/src/org/traccar/protocol/XexunProtocol.java @@ -34,7 +34,7 @@ public class XexunProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { boolean full = Context.getConfig().getBoolean(getName() + ".extended"); diff --git a/src/org/traccar/protocol/XexunProtocolDecoder.java b/src/org/traccar/protocol/XexunProtocolDecoder.java index 69100f54b..06f255b91 100644 --- a/src/org/traccar/protocol/XexunProtocolDecoder.java +++ b/src/org/traccar/protocol/XexunProtocolDecoder.java @@ -37,13 +37,13 @@ public class XexunProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_BASIC = new PatternBuilder() .expression("G[PN]RMC,") - .number("(dd)(dd)(dd).(d+),") // time + .number("(?:(dd)(dd)(dd))?.(d+),") // time .expression("([AV]),") // validity .number("(d*?)(d?d.d+),([NS]),") // latitude .number("(d*?)(d?d.d+),([EW])?,") // longitude .number("(d+.?d*),") // speed .number("(d+.?d*)?,") // course - .number("(dd)(dd)(dd),") // date + .number("(?:(dd)(dd)(dd))?,") // date .expression("[^*]*").text("*") .number("xx") // checksum .expression("\\r\\n").optional() @@ -67,15 +67,15 @@ public class XexunProtocolDecoder extends BaseProtocolDecoder { private String decodeAlarm(String value) { if (value != null) { switch (value) { - case "help me!": - return Position.ALARM_SOS; - case "low battery": - return Position.ALARM_LOW_BATTERY; - case "move!": - case "moved!": - return Position.ALARM_MOVEMENT; - default: - break; + case "help me!": + return Position.ALARM_SOS; + case "low battery": + return Position.ALARM_LOW_BATTERY; + case "move!": + case "moved!": + return Position.ALARM_MOVEMENT; + default: + break; } } return null; diff --git a/src/org/traccar/protocol/XirgoProtocol.java b/src/org/traccar/protocol/XirgoProtocol.java index c5ef27f54..9298f71ad 100644 --- a/src/org/traccar/protocol/XirgoProtocol.java +++ b/src/org/traccar/protocol/XirgoProtocol.java @@ -34,7 +34,7 @@ public class XirgoProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "##")); @@ -43,7 +43,7 @@ public class XirgoProtocol extends BaseProtocol { pipeline.addLast("objectDecoder", new XirgoProtocolDecoder(XirgoProtocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/Xt013Protocol.java b/src/org/traccar/protocol/Xt013Protocol.java index b11256b7d..db9d21333 100644 --- a/src/org/traccar/protocol/Xt013Protocol.java +++ b/src/org/traccar/protocol/Xt013Protocol.java @@ -33,7 +33,7 @@ public class Xt013Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); diff --git a/src/org/traccar/protocol/YwtProtocol.java b/src/org/traccar/protocol/YwtProtocol.java index 3fa154ec0..e24c8b02e 100644 --- a/src/org/traccar/protocol/YwtProtocol.java +++ b/src/org/traccar/protocol/YwtProtocol.java @@ -33,7 +33,7 @@ public class YwtProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); |