From 82eace30ab2bd8742301519e6157c8ef238f4885 Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Wed, 14 Mar 2018 15:04:57 +0100 Subject: Working on laipac2 --- src/org/traccar/protocol/Laipac2Protocol.java | 47 ++++++++ .../traccar/protocol/Laipac2ProtocolDecoder.java | 123 +++++++++++++++++++++ .../traccar/protocol/OsmAndProtocolDecoder.java | 3 +- 3 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 src/org/traccar/protocol/Laipac2Protocol.java create mode 100644 src/org/traccar/protocol/Laipac2ProtocolDecoder.java (limited to 'src') diff --git a/src/org/traccar/protocol/Laipac2Protocol.java b/src/org/traccar/protocol/Laipac2Protocol.java new file mode 100644 index 000000000..5f132f626 --- /dev/null +++ b/src/org/traccar/protocol/Laipac2Protocol.java @@ -0,0 +1,47 @@ +/* + * Copyright 2015 Anton Tananaev (anton@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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 Laipac2Protocol extends BaseProtocol { + + public Laipac2Protocol() { + super("laipac2"); + } + + @Override + public void initTrackerServers(List serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new Laipac2ProtocolDecoder(Laipac2Protocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/Laipac2ProtocolDecoder.java b/src/org/traccar/protocol/Laipac2ProtocolDecoder.java new file mode 100644 index 000000000..ba40c0dce --- /dev/null +++ b/src/org/traccar/protocol/Laipac2ProtocolDecoder.java @@ -0,0 +1,123 @@ +/* + * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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.Checksum; +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 Laipac2ProtocolDecoder extends BaseProtocolDecoder { + + public Laipac2ProtocolDecoder(Laipac2Protocol protocol) { + super(protocol); + } + + private static final Pattern PATTERN = new PatternBuilder() + .text("$AVRMC,") + .expression("([^,]+),") // identifier + .number("(dd)(dd)(dd),") // time (hhmmss) + .expression("([AVRPavrp]),") // validity + .number("(dd)(dd.d+),") // latitude + .expression("([NS]),") + .number("(ddd)(dd.d+),") // longitude + .number("([EW]),") + .number("(d+.d+),") // speed + .number("(d+.d+),") // course + .number("(dd)(dd)(dd),") // date (ddmmyy) + .expression("([abZXMHE86430]),") // event code + .number("(d+),") // battery voltage + .number("(d+),") // current mileage + .number("(d),") // GPS on/off (1 = on, 0 = off) + .number("(d),") // Analog port 1 + .number("(d+),") // Analog port 2 + .expression("([0-9a-fA-F]{4})") // Cell 1 - Cell Net Code + .expression("([0-9a-fA-F]{4}),") // Cell 1 - Cell ID Code + .number("(d+)") // Cell 2 + .text("*") + .number("(xx)") // checksum + .compile(); + + @Override + protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + String sentence = (String) msg; + + if (sentence.startsWith("$ECHK") && channel != null) { + channel.write(sentence + "\r\n"); // heartbeat + return null; + } + + Parser parser = new Parser(PATTERN, sentence); + if (!parser.matches()) { + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + DateBuilder dateBuilder = new DateBuilder() + .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); + + String status = parser.next(); + position.setValid(status.toUpperCase().equals("A")); + + position.setLatitude(parser.nextCoordinate()); + position.setLongitude(parser.nextCoordinate()); + position.setSpeed(parser.nextDouble(0)); + position.setCourse(parser.nextDouble(0)); + + dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); + position.setTime(dateBuilder.getDate()); + + String type = parser.next(); + position.set(Position.KEY_BATTERY_LEVEL, parser.nextDouble()); + //position.set(Position.KEY_, parser.nextDouble()); + String checksum = parser.next(); + + if (channel != null) { + + if (Character.isLowerCase(status.charAt(0))) { + String response = "$EAVACK," + type + "," + checksum; + response += Checksum.nmea(response); + channel.write(response); + } + + if (type.equals("S") || type.equals("T")) { + channel.write("$AVCFG,00000000,t*21"); + } else if (type.equals("3")) { + channel.write("$AVCFG,00000000,d*31"); + } else if (type.equals("X") || type.equals("4")) { + channel.write("$AVCFG,00000000,x*2D"); + } + + } + + return position; + } + +} diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java index 03abdd588..014ebb233 100644 --- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java +++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java @@ -42,8 +42,7 @@ public class OsmAndProtocolDecoder extends BaseHttpProtocolDecoder { } @Override - protected Object decode( - Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { HttpRequest request = (HttpRequest) msg; QueryStringDecoder decoder = new QueryStringDecoder(request.getUri()); -- cgit v1.2.3 From 2bc0b397c1aeb28bb82b887a78ceb8c8de940e8c Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Wed, 14 Mar 2018 16:42:09 +0100 Subject: Added extra info for laipac --- setup/default.xml | 3 +- src/org/traccar/model/Position.java | 7 +- src/org/traccar/protocol/Laipac2Protocol.java | 47 -------- .../traccar/protocol/Laipac2ProtocolDecoder.java | 123 -------------------- .../traccar/protocol/LaipacSFKamelProtocol.java | 47 ++++++++ .../protocol/LaipacSFKamelProtocolDecoder.java | 128 +++++++++++++++++++++ .../protocol/LaipacSFKamelProtocolDecoderTest.java | 35 ++++++ 7 files changed, 218 insertions(+), 172 deletions(-) delete mode 100644 src/org/traccar/protocol/Laipac2Protocol.java delete mode 100644 src/org/traccar/protocol/Laipac2ProtocolDecoder.java create mode 100644 src/org/traccar/protocol/LaipacSFKamelProtocol.java create mode 100644 src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java create mode 100644 test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java (limited to 'src') diff --git a/setup/default.xml b/setup/default.xml index 6be2c08e3..515abf61d 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -116,7 +116,8 @@ 5045 5046 5047 - 5048 + + 5048 5049 5050 5051 diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 981c2292f..fdecb7e20 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -52,6 +52,8 @@ public class Position extends Message { public static final String KEY_BATTERY_LEVEL = "batteryLevel"; // percentage public static final String KEY_FUEL_LEVEL = "fuel"; // liters public static final String KEY_FUEL_CONSUMPTION = "fuelConsumption"; // liters/hour + public static final String KEY_ANALOG_1 = "analog 1"; // volts + public static final String KEY_ANALOG_2 = "analog 2"; // volts public static final String KEY_VERSION_FW = "versionFw"; public static final String KEY_VERSION_HW = "versionHw"; @@ -88,6 +90,10 @@ public class Position extends Message { public static final String KEY_DRIVER_UNIQUE_ID = "driverUniqueId"; + public static final String KEY_CELL_NET_CODE = "cellNetCode"; + public static final String KEY_CELL_ID_CODE = "cellIdCode"; + public static final String KEY_COUNTRY_CODE = "countryCode"; + // Start with 1 not 0 public static final String PREFIX_TEMP = "temp"; public static final String PREFIX_ADC = "adc"; @@ -290,5 +296,4 @@ public class Position extends Message { public String getType() { return super.getType(); } - } diff --git a/src/org/traccar/protocol/Laipac2Protocol.java b/src/org/traccar/protocol/Laipac2Protocol.java deleted file mode 100644 index 5f132f626..000000000 --- a/src/org/traccar/protocol/Laipac2Protocol.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2015 Anton Tananaev (anton@traccar.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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 Laipac2Protocol extends BaseProtocol { - - public Laipac2Protocol() { - super("laipac2"); - } - - @Override - public void initTrackerServers(List serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { - @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); - pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("objectDecoder", new Laipac2ProtocolDecoder(Laipac2Protocol.this)); - } - }); - } - -} diff --git a/src/org/traccar/protocol/Laipac2ProtocolDecoder.java b/src/org/traccar/protocol/Laipac2ProtocolDecoder.java deleted file mode 100644 index ba40c0dce..000000000 --- a/src/org/traccar/protocol/Laipac2ProtocolDecoder.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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.Checksum; -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 Laipac2ProtocolDecoder extends BaseProtocolDecoder { - - public Laipac2ProtocolDecoder(Laipac2Protocol protocol) { - super(protocol); - } - - private static final Pattern PATTERN = new PatternBuilder() - .text("$AVRMC,") - .expression("([^,]+),") // identifier - .number("(dd)(dd)(dd),") // time (hhmmss) - .expression("([AVRPavrp]),") // validity - .number("(dd)(dd.d+),") // latitude - .expression("([NS]),") - .number("(ddd)(dd.d+),") // longitude - .number("([EW]),") - .number("(d+.d+),") // speed - .number("(d+.d+),") // course - .number("(dd)(dd)(dd),") // date (ddmmyy) - .expression("([abZXMHE86430]),") // event code - .number("(d+),") // battery voltage - .number("(d+),") // current mileage - .number("(d),") // GPS on/off (1 = on, 0 = off) - .number("(d),") // Analog port 1 - .number("(d+),") // Analog port 2 - .expression("([0-9a-fA-F]{4})") // Cell 1 - Cell Net Code - .expression("([0-9a-fA-F]{4}),") // Cell 1 - Cell ID Code - .number("(d+)") // Cell 2 - .text("*") - .number("(xx)") // checksum - .compile(); - - @Override - protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - String sentence = (String) msg; - - if (sentence.startsWith("$ECHK") && channel != null) { - channel.write(sentence + "\r\n"); // heartbeat - return null; - } - - Parser parser = new Parser(PATTERN, sentence); - if (!parser.matches()) { - return null; - } - - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); - if (deviceSession == null) { - return null; - } - - Position position = new Position(getProtocolName()); - position.setDeviceId(deviceSession.getDeviceId()); - - DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); - - String status = parser.next(); - position.setValid(status.toUpperCase().equals("A")); - - position.setLatitude(parser.nextCoordinate()); - position.setLongitude(parser.nextCoordinate()); - position.setSpeed(parser.nextDouble(0)); - position.setCourse(parser.nextDouble(0)); - - dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); - position.setTime(dateBuilder.getDate()); - - String type = parser.next(); - position.set(Position.KEY_BATTERY_LEVEL, parser.nextDouble()); - //position.set(Position.KEY_, parser.nextDouble()); - String checksum = parser.next(); - - if (channel != null) { - - if (Character.isLowerCase(status.charAt(0))) { - String response = "$EAVACK," + type + "," + checksum; - response += Checksum.nmea(response); - channel.write(response); - } - - if (type.equals("S") || type.equals("T")) { - channel.write("$AVCFG,00000000,t*21"); - } else if (type.equals("3")) { - channel.write("$AVCFG,00000000,d*31"); - } else if (type.equals("X") || type.equals("4")) { - channel.write("$AVCFG,00000000,x*2D"); - } - - } - - return position; - } - -} diff --git a/src/org/traccar/protocol/LaipacSFKamelProtocol.java b/src/org/traccar/protocol/LaipacSFKamelProtocol.java new file mode 100644 index 000000000..5e1beabbd --- /dev/null +++ b/src/org/traccar/protocol/LaipacSFKamelProtocol.java @@ -0,0 +1,47 @@ +/* + * Copyright 2015 Anton Tananaev (anton@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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 LaipacSFKamelProtocol extends BaseProtocol { + + public LaipacSFKamelProtocol() { + super("laipacsfkamel"); + } + + @Override + public void initTrackerServers(List serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new LaipacSFKamelProtocolDecoder(LaipacSFKamelProtocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java b/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java new file mode 100644 index 000000000..decf279df --- /dev/null +++ b/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java @@ -0,0 +1,128 @@ +/* + * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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.Checksum; +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 LaipacSFKamelProtocolDecoder extends BaseProtocolDecoder { + + public LaipacSFKamelProtocolDecoder(LaipacSFKamelProtocol protocol) { + super(protocol); + } + + private static final Pattern PATTERN = new PatternBuilder() + .text("$AVRMC,") + .expression("([^,]+),") // identifier + .number("(dd)(dd)(dd),") // time (hhmmss) + .expression("([AVRPavrp]),") // validity + .number("(dd)(dd.d+),") // latitude + .expression("([NS]),") + .number("(ddd)(dd.d+),") // longitude + .number("([EW]),") + .number("(d+.d+),") // speed + .number("(d+.d+),") // course + .number("(dd)(dd)(dd),") // date (ddmmyy) + .expression("([abZXMHE86430]),") // event code + .number("(d+),") // battery voltage + .number("(d+),") // current mileage + .number("(d),") // GPS on/off (1 = on, 0 = off) + .number("(d+),") // Analog port 1 + .number("(d+),") // Analog port 2 + .expression("([0-9a-fA-F]{4})") // Cell 1 - Cell Net Code + .expression("([0-9a-fA-F]{4}),") // Cell 1 - Cell ID Code + .number("(d{3})") // Cell 2 - Country Code + .number("(d{3})") // Cell 2 - Operator Code + .text("*") + .number("(xx)") // checksum + .compile(); + + @Override + protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + String sentence = (String) msg; + + if (sentence.startsWith("$ECHK") && channel != null) { + channel.write(sentence + "\r\n"); // heartbeat + return null; + } + + Parser parser = new Parser(PATTERN, sentence); + if (!parser.matches()) { + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + DateBuilder dateBuilder = new DateBuilder() + .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); + + String status = parser.next(); + position.setValid(status.toUpperCase().equals("A")); + + position.setLatitude(parser.nextCoordinate()); + position.setLongitude(parser.nextCoordinate()); + position.setSpeed(parser.nextDouble(0)); + position.setCourse(parser.nextDouble(0)); + + dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); + position.setTime(dateBuilder.getDate()); + + String eventCode = parser.next(); + position.set(Position.KEY_EVENT, eventCode); + position.set(Position.KEY_BATTERY, parser.nextDouble() * 0.001); + position.set(Position.KEY_TOTAL_DISTANCE, parser.nextDouble()); + position.set(Position.KEY_GPS, parser.nextInt()); + position.set(Position.KEY_ANALOG_1, parser.nextDouble() * 0.001); + position.set(Position.KEY_ANALOG_2, parser.nextDouble() * 0.001); + position.set(Position.KEY_CELL_NET_CODE, parser.next()); + position.set(Position.KEY_CELL_ID_CODE, parser.next()); + position.set(Position.KEY_COUNTRY_CODE, parser.next()); + position.set(Position.KEY_OPERATOR, parser.next()); + String checksum = parser.next(); + + if (channel != null) { + if (Character.isLowerCase(status.charAt(0))) { + String response = "$EAVACK," + eventCode + "," + checksum; + response += Checksum.nmea(response); + channel.write(response); + } + + if (eventCode.equals("3")) { + channel.write("$AVCFG,00000000,d*31"); + } else if (eventCode.equals("X") || eventCode.equals("4")) { + channel.write("$AVCFG,00000000,x*2D"); + } + } + + return position; + } + +} diff --git a/test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java b/test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java new file mode 100644 index 000000000..05de5dcbe --- /dev/null +++ b/test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java @@ -0,0 +1,35 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class LaipacSFKamelProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + LaipacSFKamelProtocolDecoder decoder = new LaipacSFKamelProtocolDecoder(new LaipacSFKamelProtocol()); + + verifyPosition(decoder, text( + "$AVRMC,358174067149865,084514,r,5050.1314,N,00419.9719,E,0.68,306.39,120318,0,3882,84,1,0,0,3EE4A617,020610*4E")); + + verifyNull(decoder, text( + "$AVSYS,99999999,V1.50,SN0000103,32768*15")); + + verifyNull(decoder, text( + "$ECHK,99999999,0*35")); + + verifyNull(decoder, text( + "$AVSYS,MSG00002,14406,7046811160,64*1A")); + + verifyNull(decoder, text( + "$EAVSYS,MSG00002,8931086013104404999,,Owner,0x52014406*76")); + + verifyNull(decoder, text( + "$ECHK,MSG00002,0*5E")); + + verifyPosition(decoder, text( + "$AVRMC,358174067149865,111602,r,5050.1262,N,00419.9660,E,0.00,0.00,120318,0,3843,95,1,0,0,3EE4A617,020610*44")); + } + +} -- cgit v1.2.3 From b9fac418d0de3c472ff5603294d9ce3713c05291 Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Thu, 15 Mar 2018 10:42:15 +0100 Subject: Fixed ack message and added optional cell params --- .../protocol/LaipacSFKamelProtocolDecoder.java | 33 ++++++++++++++-------- 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java b/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java index decf279df..0966e83ff 100644 --- a/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java @@ -55,6 +55,7 @@ public class LaipacSFKamelProtocolDecoder extends BaseProtocolDecoder { .expression("([0-9a-fA-F]{4}),") // Cell 1 - Cell ID Code .number("(d{3})") // Cell 2 - Country Code .number("(d{3})") // Cell 2 - Operator Code + .optional(4) .text("*") .number("(xx)") // checksum .compile(); @@ -102,27 +103,35 @@ public class LaipacSFKamelProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_GPS, parser.nextInt()); position.set(Position.KEY_ANALOG_1, parser.nextDouble() * 0.001); position.set(Position.KEY_ANALOG_2, parser.nextDouble() * 0.001); - position.set(Position.KEY_CELL_NET_CODE, parser.next()); - position.set(Position.KEY_CELL_ID_CODE, parser.next()); - position.set(Position.KEY_COUNTRY_CODE, parser.next()); - position.set(Position.KEY_OPERATOR, parser.next()); + String checksum = parser.next(); + if (parser.hasNext()) { + position.set(Position.KEY_CELL_NET_CODE, checksum); + position.set(Position.KEY_CELL_ID_CODE, parser.next()); + position.set(Position.KEY_COUNTRY_CODE, parser.next()); + position.set(Position.KEY_OPERATOR, parser.next()); + checksum = parser.next(); + } + + String result = sentence.replaceAll("^\\$(.*)\\*[0-9a-fA-F]{2}$", "$1"); + if (Integer.parseInt(checksum, 16) != Checksum.xor(result)) + { + return null; + } if (channel != null) { - if (Character.isLowerCase(status.charAt(0))) { + if (eventCode.equals("3")) { + channel.write("$AVCFG,00000000,d*31\r\n"); + } else if (eventCode.equals("X") || eventCode.equals("4")) { + channel.write("$AVCFG,00000000,x*2D\r\n"); + } else if (Character.isLowerCase(status.charAt(0))) { String response = "$EAVACK," + eventCode + "," + checksum; response += Checksum.nmea(response); + response += "\r\n"; channel.write(response); } - - if (eventCode.equals("3")) { - channel.write("$AVCFG,00000000,d*31"); - } else if (eventCode.equals("X") || eventCode.equals("4")) { - channel.write("$AVCFG,00000000,x*2D"); - } } return position; } - } -- cgit v1.2.3 From 9c13bf44cd83c3d2489b763a6c5af6d04d26ad48 Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Thu, 15 Mar 2018 16:24:33 +0100 Subject: Changed event to alarm codes, and added cfg for event code Z --- .../protocol/LaipacSFKamelProtocolDecoder.java | 34 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java b/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java index 0966e83ff..0d3995144 100644 --- a/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java @@ -50,8 +50,8 @@ public class LaipacSFKamelProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // current mileage .number("(d),") // GPS on/off (1 = on, 0 = off) .number("(d+),") // Analog port 1 - .number("(d+),") // Analog port 2 - .expression("([0-9a-fA-F]{4})") // Cell 1 - Cell Net Code + .number("(d+)") // Analog port 2 + .expression(",([0-9a-fA-F]{4})") // Cell 1 - Cell Net Code .expression("([0-9a-fA-F]{4}),") // Cell 1 - Cell ID Code .number("(d{3})") // Cell 2 - Country Code .number("(d{3})") // Cell 2 - Operator Code @@ -87,6 +87,7 @@ public class LaipacSFKamelProtocolDecoder extends BaseProtocolDecoder { String status = parser.next(); position.setValid(status.toUpperCase().equals("A")); + position.set(Position.KEY_STATUS, status); position.setLatitude(parser.nextCoordinate()); position.setLongitude(parser.nextCoordinate()); @@ -97,6 +98,10 @@ public class LaipacSFKamelProtocolDecoder extends BaseProtocolDecoder { position.setTime(dateBuilder.getDate()); String eventCode = parser.next(); + String decodedAlarm = decodeAlarm(eventCode); + if (decodedAlarm != null) { + position.set(Position.KEY_ALARM, decodeAlarm(eventCode)); + } position.set(Position.KEY_EVENT, eventCode); position.set(Position.KEY_BATTERY, parser.nextDouble() * 0.001); position.set(Position.KEY_TOTAL_DISTANCE, parser.nextDouble()); @@ -124,6 +129,8 @@ public class LaipacSFKamelProtocolDecoder extends BaseProtocolDecoder { channel.write("$AVCFG,00000000,d*31\r\n"); } else if (eventCode.equals("X") || eventCode.equals("4")) { channel.write("$AVCFG,00000000,x*2D\r\n"); + } else if (eventCode.equals("Z")) { + channel.write("$AVCFG,00000000,z*2F\r\n"); } else if (Character.isLowerCase(status.charAt(0))) { String response = "$EAVACK," + eventCode + "," + checksum; response += Checksum.nmea(response); @@ -134,4 +141,27 @@ public class LaipacSFKamelProtocolDecoder extends BaseProtocolDecoder { return position; } + + private String decodeAlarm(String event) { + if (event.equals('Z')) { + return Position.ALARM_LOW_BATTERY; + } else if (event.equals('X')) { + return Position.ALARM_GEOFENCE_ENTER; + } else if (event.equals('T')) { + return Position.ALARM_TAMPERING; + } else if(event.equals("H")) { + return Position.ALARM_POWER_OFF; + } else if (event.equals('X')) { + return Position.ALARM_GEOFENCE_ENTER; + } else if (event.equals('8')) { + return Position.ALARM_SHOCK; + } else if (event.equals('7') && event.equals('4')) { + return Position.ALARM_GEOFENCE_EXIT; + } else if (event.equals('6')) { + return Position.ALARM_OVERSPEED; + } else if (event.equals('3')) { + return Position.ALARM_SOS; + } + return null; + } } -- cgit v1.2.3 From 901c331745c8aed5593ca80f3faff5ee4d06d2a8 Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Fri, 16 Mar 2018 12:13:02 +0100 Subject: Added null check --- src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java | 3 ++- test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java b/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java index 0d3995144..dc169c668 100644 --- a/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java @@ -118,8 +118,9 @@ public class LaipacSFKamelProtocolDecoder extends BaseProtocolDecoder { checksum = parser.next(); } + String result = sentence.replaceAll("^\\$(.*)\\*[0-9a-fA-F]{2}$", "$1"); - if (Integer.parseInt(checksum, 16) != Checksum.xor(result)) + if (checksum == null || Integer.parseInt(checksum, 16) != Checksum.xor(result)) { return null; } diff --git a/test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java b/test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java index 05de5dcbe..69c4243ab 100644 --- a/test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java +++ b/test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java @@ -2,6 +2,7 @@ package org.traccar.protocol; import org.junit.Test; import org.traccar.ProtocolTest; +import org.traccar.helper.Checksum; public class LaipacSFKamelProtocolDecoderTest extends ProtocolTest { @@ -11,7 +12,7 @@ public class LaipacSFKamelProtocolDecoderTest extends ProtocolTest { LaipacSFKamelProtocolDecoder decoder = new LaipacSFKamelProtocolDecoder(new LaipacSFKamelProtocol()); verifyPosition(decoder, text( - "$AVRMC,358174067149865,084514,r,5050.1314,N,00419.9719,E,0.68,306.39,120318,0,3882,84,1,0,0,3EE4A617,020610*4E")); + "$AVRMC,999999999999999,084514,r,5050.1314,N,00419.9719,E,0.68,306.39,120318,0,3882,84,1,0,0,3EE4A617,020610*4D")); verifyNull(decoder, text( "$AVSYS,99999999,V1.50,SN0000103,32768*15")); @@ -29,7 +30,6 @@ public class LaipacSFKamelProtocolDecoderTest extends ProtocolTest { "$ECHK,MSG00002,0*5E")); verifyPosition(decoder, text( - "$AVRMC,358174067149865,111602,r,5050.1262,N,00419.9660,E,0.00,0.00,120318,0,3843,95,1,0,0,3EE4A617,020610*44")); + "$AVRMC,999999999999999,111602,r,5050.1262,N,00419.9660,E,0.00,0.00,120318,0,3843,95,1,0,0,3EE4A617,020610*47")); } - } -- cgit v1.2.3 From b34cf25b5ac1f178d783a512d3b95faed4bdb010 Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Fri, 16 Mar 2018 13:31:18 +0100 Subject: Fixed style issues --- src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java b/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java index dc169c668..60a6b2468 100644 --- a/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java @@ -120,8 +120,7 @@ public class LaipacSFKamelProtocolDecoder extends BaseProtocolDecoder { String result = sentence.replaceAll("^\\$(.*)\\*[0-9a-fA-F]{2}$", "$1"); - if (checksum == null || Integer.parseInt(checksum, 16) != Checksum.xor(result)) - { + if (checksum == null || Integer.parseInt(checksum, 16) != Checksum.xor(result)) { return null; } @@ -150,7 +149,7 @@ public class LaipacSFKamelProtocolDecoder extends BaseProtocolDecoder { return Position.ALARM_GEOFENCE_ENTER; } else if (event.equals('T')) { return Position.ALARM_TAMPERING; - } else if(event.equals("H")) { + } else if (event.equals("H")) { return Position.ALARM_POWER_OFF; } else if (event.equals('X')) { return Position.ALARM_GEOFENCE_ENTER; -- cgit v1.2.3 From 4f08521052188bc0de0be2f1a62f2bc07f70c8a4 Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Fri, 16 Mar 2018 15:33:46 +0100 Subject: Fixed build error on char array --- src/org/traccar/helper/DataConverter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/org/traccar/helper/DataConverter.java b/src/org/traccar/helper/DataConverter.java index 7abd4ae93..0df0219ad 100644 --- a/src/org/traccar/helper/DataConverter.java +++ b/src/org/traccar/helper/DataConverter.java @@ -26,7 +26,7 @@ public final class DataConverter { public static byte[] parseHex(String string) { try { - return Hex.decodeHex(string); + return Hex.decodeHex(string.toCharArray()); } catch (DecoderException e) { throw new RuntimeException(e); } -- cgit v1.2.3 From 5c73dbe4b4af5176c25ddabb7788833f67b22500 Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Mon, 19 Mar 2018 10:02:43 +0100 Subject: Cleanup of repo for merge --- src/org/traccar/helper/DataConverter.java | 2 +- tools/translate.py | 35 ------------------------------- 2 files changed, 1 insertion(+), 36 deletions(-) delete mode 100644 tools/translate.py (limited to 'src') diff --git a/src/org/traccar/helper/DataConverter.java b/src/org/traccar/helper/DataConverter.java index 0df0219ad..7abd4ae93 100644 --- a/src/org/traccar/helper/DataConverter.java +++ b/src/org/traccar/helper/DataConverter.java @@ -26,7 +26,7 @@ public final class DataConverter { public static byte[] parseHex(String string) { try { - return Hex.decodeHex(string.toCharArray()); + return Hex.decodeHex(string); } catch (DecoderException e) { throw new RuntimeException(e); } diff --git a/tools/translate.py b/tools/translate.py deleted file mode 100644 index e8324a61a..000000000 --- a/tools/translate.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/python - -import os -import optparse -import urllib2 -import json -import base64 - -parser = optparse.OptionParser() -parser.add_option("-u", "--user", dest="username", help="transifex user login") -parser.add_option("-p", "--password", dest="password", help="transifex user password") - -(options, args) = parser.parse_args() - -if not options.username or not options.password: - parser.error('User name and password are required') - -os.chdir(os.path.dirname(os.path.abspath(__file__))) - -path = "../web/l10n/" - -def request(url): - req = urllib2.Request(url) - auth = base64.encodestring("%s:%s" % (options.username, options.password)).replace("\n", "") - req.add_header("Authorization", "Basic %s" % auth) - return urllib2.urlopen(req) - -resource = json.load(request("https://www.transifex.com/api/2/project/traccar/resource/web/?details")) - -for language in resource["available_languages"]: - code = language["code"] - data = request("https://www.transifex.com/api/2/project/traccar/resource/web/translation/" + code + "?file") - file = open(path + code + ".json", "wb") - file.write(data.read()) - file.close() -- cgit v1.2.3 From 97f42f8ecd5f8c9792354c5253273b56d12c0282 Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Mon, 19 Mar 2018 10:32:28 +0100 Subject: Fixed not usefull change --- src/org/traccar/protocol/OsmAndProtocolDecoder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java index 014ebb233..a9e411978 100644 --- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java +++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java @@ -42,7 +42,8 @@ public class OsmAndProtocolDecoder extends BaseHttpProtocolDecoder { } @Override - protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { HttpRequest request = (HttpRequest) msg; QueryStringDecoder decoder = new QueryStringDecoder(request.getUri()); -- cgit v1.2.3 From 7297c042cc1df171b4ca8959b46001d898c2373c Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Mon, 19 Mar 2018 10:41:35 +0100 Subject: Fixed analog keys --- src/org/traccar/model/Position.java | 2 -- src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java | 7 ++++--- src/org/traccar/protocol/OsmAndProtocolDecoder.java | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 0e8bd9a6e..65bd03de6 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -52,8 +52,6 @@ public class Position extends Message { public static final String KEY_BATTERY_LEVEL = "batteryLevel"; // percentage public static final String KEY_FUEL_LEVEL = "fuel"; // liters public static final String KEY_FUEL_CONSUMPTION = "fuelConsumption"; // liters/hour - public static final String KEY_ANALOG_1 = "analog 1"; // volts - public static final String KEY_ANALOG_2 = "analog 2"; // volts public static final String KEY_VERSION_FW = "versionFw"; public static final String KEY_VERSION_HW = "versionHw"; diff --git a/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java b/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java index 60a6b2468..925b032a9 100644 --- a/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java @@ -61,7 +61,8 @@ public class LaipacSFKamelProtocolDecoder extends BaseProtocolDecoder { .compile(); @Override - protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { String sentence = (String) msg; if (sentence.startsWith("$ECHK") && channel != null) { @@ -106,8 +107,8 @@ public class LaipacSFKamelProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_BATTERY, parser.nextDouble() * 0.001); position.set(Position.KEY_TOTAL_DISTANCE, parser.nextDouble()); position.set(Position.KEY_GPS, parser.nextInt()); - position.set(Position.KEY_ANALOG_1, parser.nextDouble() * 0.001); - position.set(Position.KEY_ANALOG_2, parser.nextDouble() * 0.001); + position.set(Position.PREFIX_ADC + 1, parser.nextDouble() * 0.001); + position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001); String checksum = parser.next(); if (parser.hasNext()) { diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java index a9e411978..03abdd588 100644 --- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java +++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java @@ -43,7 +43,7 @@ public class OsmAndProtocolDecoder extends BaseHttpProtocolDecoder { @Override protected Object decode( - Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { HttpRequest request = (HttpRequest) msg; QueryStringDecoder decoder = new QueryStringDecoder(request.getUri()); -- cgit v1.2.3 From 694b5ce8dd817e3f1c9bb94a43e9f52cdc4f6845 Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Mon, 19 Mar 2018 16:04:38 +0100 Subject: Merged laipac and laipac kamel protocol to one --- src/org/traccar/helper/DataConverter.java | 2 +- .../traccar/protocol/LaipacProtocolDecoder.java | 116 +++++++++++--- .../traccar/protocol/LaipacSFKamelProtocol.java | 47 ------ .../protocol/LaipacSFKamelProtocolDecoder.java | 168 --------------------- .../protocol/LaipacProtocolDecoderTest.java | 28 +++- .../protocol/LaipacSFKamelProtocolDecoderTest.java | 35 ----- 6 files changed, 118 insertions(+), 278 deletions(-) delete mode 100644 src/org/traccar/protocol/LaipacSFKamelProtocol.java delete mode 100644 src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java delete mode 100644 test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java (limited to 'src') diff --git a/src/org/traccar/helper/DataConverter.java b/src/org/traccar/helper/DataConverter.java index 7abd4ae93..0df0219ad 100644 --- a/src/org/traccar/helper/DataConverter.java +++ b/src/org/traccar/helper/DataConverter.java @@ -26,7 +26,7 @@ public final class DataConverter { public static byte[] parseHex(String string) { try { - return Hex.decodeHex(string); + return Hex.decodeHex(string.toCharArray()); } catch (DecoderException e) { throw new RuntimeException(e); } diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index 99189d012..dc7c394e4 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -35,25 +35,34 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("$AVRMC,") - .expression("([^,]+),") // identifier - .number("(dd)(dd)(dd),") // time (hhmmss) - .expression("([AVRPavrp]),") // validity - .number("(dd)(dd.d+),") // latitude + .expression("([^,]+),") // identifier + .number("(dd)(dd)(dd),") // time (hhmmss) + .expression("([AVRPavrp]),") // validity + .number("(dd)(dd.d+),") // latitude .expression("([NS]),") - .number("(ddd)(dd.d+),") // longitude + .number("(ddd)(dd.d+),") // longitude .number("([EW]),") - .number("(d+.d+),") // speed - .number("(d+.d+),") // course - .number("(dd)(dd)(dd),") // date (ddmmyy) - .expression("(.),") // type - .expression("[^*]+").text("*") - .number("(xx)") // checksum + .number("(d+.d+),") // speed + .number("(d+.d+),") // course + .number("(dd)(dd)(dd),") // date (ddmmyy) + .expression("([abZXTSMHFE86430]),") // event code + .number("(d+)").expression("(\\.?)").number("(d*),") // battery voltage + .number("(d+),") // current mileage + .number("(d),") // GPS on/off (1 = on, 0 = off) + .number("(d+),") // Analog port 1 + .number("(d+)") // Analog port 2 + .expression(",([0-9a-fA-F]{4})") // Cell 1 - Cell Net Code + .expression("([0-9a-fA-F]{4}),") // Cell 1 - Cell ID Code + .number("(d{3})") // Cell 2 - Country Code + .number("(d{3})") // Cell 2 - Operator Code + .optional(4) + .text("*") + .number("(xx)") // checksum .compile(); @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - String sentence = (String) msg; if (sentence.startsWith("$ECHK") && channel != null) { @@ -79,6 +88,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { String status = parser.next(); position.setValid(status.toUpperCase().equals("A")); + position.set(Position.KEY_STATUS, status); position.setLatitude(parser.nextCoordinate()); position.setLongitude(parser.nextCoordinate()); @@ -88,28 +98,84 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); position.setTime(dateBuilder.getDate()); - String type = parser.next(); + String eventCode = parser.next(); + String decodedAlarm = decodeAlarm(eventCode); + if (decodedAlarm != null) { + position.set(Position.KEY_ALARM, decodeAlarm(eventCode)); + } + position.set(Position.KEY_EVENT, eventCode); + + double batteryVoltage = parser.nextDouble(); + if (parser.next().isEmpty()) { + parser.next(); + batteryVoltage *= 0.001; + } else { + batteryVoltage += parser.nextDouble() * 0.001; + } + position.set(Position.KEY_BATTERY, batteryVoltage); + + position.set(Position.KEY_TOTAL_DISTANCE, parser.nextDouble()); + position.set(Position.KEY_GPS, parser.nextInt()); + position.set(Position.PREFIX_ADC + 1, parser.nextDouble() * 0.001); + position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001); + + setNextValue(parser, position, Position.KEY_CELL_NET_CODE); + setNextValue(parser, position, Position.KEY_CELL_ID_CODE); + setNextValue(parser, position, Position.KEY_COUNTRY_CODE); + setNextValue(parser, position, Position.KEY_OPERATOR); + String checksum = parser.next(); + String result = sentence.replaceAll("^\\$(.*)\\*[0-9a-fA-F]{2}$", "$1"); + if (checksum == null || Integer.parseInt(checksum, 16) != Checksum.xor(result)) { + return null; + } if (channel != null) { - - if (Character.isLowerCase(status.charAt(0))) { - String response = "$EAVACK," + type + "," + checksum; + if (eventCode.equals("3")) { + channel.write("$AVCFG,00000000,d*31\r\n"); + } else if (eventCode.equals("X") || eventCode.equals("4")) { + channel.write("$AVCFG,00000000,x*2D\r\n"); + } else if (eventCode.equals("Z")) { + channel.write("$AVCFG,00000000,z*2F\r\n"); + } else if (Character.isLowerCase(status.charAt(0))) { + String response = "$EAVACK," + eventCode + "," + checksum; response += Checksum.nmea(response); + response += "\r\n"; channel.write(response); } - - if (type.equals("S") || type.equals("T")) { - channel.write("$AVCFG,00000000,t*21"); - } else if (type.equals("3")) { - channel.write("$AVCFG,00000000,d*31"); - } else if (type.equals("X") || type.equals("4")) { - channel.write("$AVCFG,00000000,x*2D"); - } - } return position; } + private void setNextValue(Parser parser, Position position, String key) + { + String value = parser.next(); + if (value != null) { + position.set(key, value); + } + } + + private String decodeAlarm(String event) { + if (event.equals('Z')) { + return Position.ALARM_LOW_BATTERY; + } else if (event.equals('X')) { + return Position.ALARM_GEOFENCE_ENTER; + } else if (event.equals('T')) { + return Position.ALARM_TAMPERING; + } else if (event.equals("H")) { + return Position.ALARM_POWER_OFF; + } else if (event.equals('X')) { + return Position.ALARM_GEOFENCE_ENTER; + } else if (event.equals('8')) { + return Position.ALARM_SHOCK; + } else if (event.equals('7') && event.equals('4')) { + return Position.ALARM_GEOFENCE_EXIT; + } else if (event.equals('6')) { + return Position.ALARM_OVERSPEED; + } else if (event.equals('3')) { + return Position.ALARM_SOS; + } + return null; + } } diff --git a/src/org/traccar/protocol/LaipacSFKamelProtocol.java b/src/org/traccar/protocol/LaipacSFKamelProtocol.java deleted file mode 100644 index 5e1beabbd..000000000 --- a/src/org/traccar/protocol/LaipacSFKamelProtocol.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2015 Anton Tananaev (anton@traccar.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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 LaipacSFKamelProtocol extends BaseProtocol { - - public LaipacSFKamelProtocol() { - super("laipacsfkamel"); - } - - @Override - public void initTrackerServers(List serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { - @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); - pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("objectDecoder", new LaipacSFKamelProtocolDecoder(LaipacSFKamelProtocol.this)); - } - }); - } - -} diff --git a/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java b/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java deleted file mode 100644 index 925b032a9..000000000 --- a/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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.Checksum; -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 LaipacSFKamelProtocolDecoder extends BaseProtocolDecoder { - - public LaipacSFKamelProtocolDecoder(LaipacSFKamelProtocol protocol) { - super(protocol); - } - - private static final Pattern PATTERN = new PatternBuilder() - .text("$AVRMC,") - .expression("([^,]+),") // identifier - .number("(dd)(dd)(dd),") // time (hhmmss) - .expression("([AVRPavrp]),") // validity - .number("(dd)(dd.d+),") // latitude - .expression("([NS]),") - .number("(ddd)(dd.d+),") // longitude - .number("([EW]),") - .number("(d+.d+),") // speed - .number("(d+.d+),") // course - .number("(dd)(dd)(dd),") // date (ddmmyy) - .expression("([abZXMHE86430]),") // event code - .number("(d+),") // battery voltage - .number("(d+),") // current mileage - .number("(d),") // GPS on/off (1 = on, 0 = off) - .number("(d+),") // Analog port 1 - .number("(d+)") // Analog port 2 - .expression(",([0-9a-fA-F]{4})") // Cell 1 - Cell Net Code - .expression("([0-9a-fA-F]{4}),") // Cell 1 - Cell ID Code - .number("(d{3})") // Cell 2 - Country Code - .number("(d{3})") // Cell 2 - Operator Code - .optional(4) - .text("*") - .number("(xx)") // checksum - .compile(); - - @Override - protected Object decode( - Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - String sentence = (String) msg; - - if (sentence.startsWith("$ECHK") && channel != null) { - channel.write(sentence + "\r\n"); // heartbeat - return null; - } - - Parser parser = new Parser(PATTERN, sentence); - if (!parser.matches()) { - return null; - } - - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); - if (deviceSession == null) { - return null; - } - - Position position = new Position(getProtocolName()); - position.setDeviceId(deviceSession.getDeviceId()); - - DateBuilder dateBuilder = new DateBuilder() - .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); - - String status = parser.next(); - position.setValid(status.toUpperCase().equals("A")); - position.set(Position.KEY_STATUS, status); - - position.setLatitude(parser.nextCoordinate()); - position.setLongitude(parser.nextCoordinate()); - position.setSpeed(parser.nextDouble(0)); - position.setCourse(parser.nextDouble(0)); - - dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); - position.setTime(dateBuilder.getDate()); - - String eventCode = parser.next(); - String decodedAlarm = decodeAlarm(eventCode); - if (decodedAlarm != null) { - position.set(Position.KEY_ALARM, decodeAlarm(eventCode)); - } - position.set(Position.KEY_EVENT, eventCode); - position.set(Position.KEY_BATTERY, parser.nextDouble() * 0.001); - position.set(Position.KEY_TOTAL_DISTANCE, parser.nextDouble()); - position.set(Position.KEY_GPS, parser.nextInt()); - position.set(Position.PREFIX_ADC + 1, parser.nextDouble() * 0.001); - position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001); - - String checksum = parser.next(); - if (parser.hasNext()) { - position.set(Position.KEY_CELL_NET_CODE, checksum); - position.set(Position.KEY_CELL_ID_CODE, parser.next()); - position.set(Position.KEY_COUNTRY_CODE, parser.next()); - position.set(Position.KEY_OPERATOR, parser.next()); - checksum = parser.next(); - } - - - String result = sentence.replaceAll("^\\$(.*)\\*[0-9a-fA-F]{2}$", "$1"); - if (checksum == null || Integer.parseInt(checksum, 16) != Checksum.xor(result)) { - return null; - } - - if (channel != null) { - if (eventCode.equals("3")) { - channel.write("$AVCFG,00000000,d*31\r\n"); - } else if (eventCode.equals("X") || eventCode.equals("4")) { - channel.write("$AVCFG,00000000,x*2D\r\n"); - } else if (eventCode.equals("Z")) { - channel.write("$AVCFG,00000000,z*2F\r\n"); - } else if (Character.isLowerCase(status.charAt(0))) { - String response = "$EAVACK," + eventCode + "," + checksum; - response += Checksum.nmea(response); - response += "\r\n"; - channel.write(response); - } - } - - return position; - } - - private String decodeAlarm(String event) { - if (event.equals('Z')) { - return Position.ALARM_LOW_BATTERY; - } else if (event.equals('X')) { - return Position.ALARM_GEOFENCE_ENTER; - } else if (event.equals('T')) { - return Position.ALARM_TAMPERING; - } else if (event.equals("H")) { - return Position.ALARM_POWER_OFF; - } else if (event.equals('X')) { - return Position.ALARM_GEOFENCE_ENTER; - } else if (event.equals('8')) { - return Position.ALARM_SHOCK; - } else if (event.equals('7') && event.equals('4')) { - return Position.ALARM_GEOFENCE_EXIT; - } else if (event.equals('6')) { - return Position.ALARM_OVERSPEED; - } else if (event.equals('3')) { - return Position.ALARM_SOS; - } - return null; - } -} diff --git a/test/org/traccar/protocol/LaipacProtocolDecoderTest.java b/test/org/traccar/protocol/LaipacProtocolDecoderTest.java index 787f33e65..c8a23a5a7 100644 --- a/test/org/traccar/protocol/LaipacProtocolDecoderTest.java +++ b/test/org/traccar/protocol/LaipacProtocolDecoderTest.java @@ -28,8 +28,7 @@ public class LaipacProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, text( "$ECHK,MSG00002,0*5E")); - verifyPosition(decoder, text( - "$AVRMC,99999999,164339,A,4351.0542,N,07923.5445,W,0.29,78.66,180703,0,3.727,17,1,0,0*37"), + verifyPosition(decoder, text("$AVRMC,99999999,164339,A,4351.0542,N,07923.5445,W,0.29,78.66,180703,0,3.727,17,1,0,0*37"), position("2003-07-18 16:43:39.000", true, 43.85090, -79.39241)); verifyPosition(decoder, text( @@ -95,6 +94,31 @@ public class LaipacProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, text( "$AVRMC,96414215,170046,p,4310.7965,N,07652.0816,E,0.00,0.00,071016,0,4069,98,1,0,0*04")); + verifyPosition(decoder, text( + "$AVRMC,999999999999999,111602,r,5050.1262,N,00419.9660,E,0.00,0.00,120318,0,3843,95,1,0,0,3EE4A617,020610*47")); + + verifyPosition(decoder, text( + "$AVRMC,358174067149865,143456,R,5050.1285,N,00420.0620,E,0.00,309.27,190318,0,3455,119,1,0,0,3EE4A617,020610*54")); + + verifyPosition(decoder, text( + "$AVRMC,999999999999999,084514,r,5050.1314,N,00419.9719,E,0.68,306.39,120318,0,3882,84,1,0,0,3EE4A617,020610*4D")); + + //Alarm button + verifyPosition(decoder, text( + "$AVRMC,358174067149865,142945,R,5050.1254,N,00420.0490,E,0.00,0.00,190318,3,3455,119,1,0,0,3EE4A617,020610*53")); + + //G-Sensor + verifyPosition(decoder, text( + "$AVRMC,358174067149865,143407,R,5050.1254,N,00420.0490,E,0.00,0.00,190318,8,3455,119,1,0,0,3EE4A617,020610*52")); + + //Powered off + verifyPosition(decoder, text( + "$AVRMC,358174067149865,143648,A,5050.1141,N,00420.0525,E,1.24,174.38,190318,H,3455,119,1,0,0,3EE4A617,020610*3E")); + + //No network + verifyPosition(decoder, text( + "$AVRMC,358174067149865,143747,R,5050.1124,N,00420.0542,E,1.34,161.96,190318,a,3416,119,1,0,0*7D")); + } } diff --git a/test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java b/test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java deleted file mode 100644 index 69c4243ab..000000000 --- a/test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.traccar.protocol; - -import org.junit.Test; -import org.traccar.ProtocolTest; -import org.traccar.helper.Checksum; - -public class LaipacSFKamelProtocolDecoderTest extends ProtocolTest { - - @Test - public void testDecode() throws Exception { - - LaipacSFKamelProtocolDecoder decoder = new LaipacSFKamelProtocolDecoder(new LaipacSFKamelProtocol()); - - verifyPosition(decoder, text( - "$AVRMC,999999999999999,084514,r,5050.1314,N,00419.9719,E,0.68,306.39,120318,0,3882,84,1,0,0,3EE4A617,020610*4D")); - - verifyNull(decoder, text( - "$AVSYS,99999999,V1.50,SN0000103,32768*15")); - - verifyNull(decoder, text( - "$ECHK,99999999,0*35")); - - verifyNull(decoder, text( - "$AVSYS,MSG00002,14406,7046811160,64*1A")); - - verifyNull(decoder, text( - "$EAVSYS,MSG00002,8931086013104404999,,Owner,0x52014406*76")); - - verifyNull(decoder, text( - "$ECHK,MSG00002,0*5E")); - - verifyPosition(decoder, text( - "$AVRMC,999999999999999,111602,r,5050.1262,N,00419.9660,E,0.00,0.00,120318,0,3843,95,1,0,0,3EE4A617,020610*47")); - } -} -- cgit v1.2.3 From 04dc588d2fac50a864542b63a29cd10f19d72345 Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Mon, 19 Mar 2018 16:08:10 +0100 Subject: Fixed build errors --- src/org/traccar/protocol/LaipacProtocolDecoder.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index dc7c394e4..7f26f225b 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -148,8 +148,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { return position; } - private void setNextValue(Parser parser, Position position, String key) - { + private void setNextValue(Parser parser, Position position, String key) { String value = parser.next(); if (value != null) { position.set(key, value); -- cgit v1.2.3 From 98e9a26fd916bcdace022af1d9f7dd80d1a2d2fe Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Tue, 20 Mar 2018 09:14:19 +0100 Subject: Fixed formatting --- .../traccar/protocol/LaipacProtocolDecoder.java | 37 +++++++++++----------- 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index 7f26f225b..4fc0201ef 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -35,34 +35,35 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN = new PatternBuilder() .text("$AVRMC,") - .expression("([^,]+),") // identifier - .number("(dd)(dd)(dd),") // time (hhmmss) - .expression("([AVRPavrp]),") // validity - .number("(dd)(dd.d+),") // latitude + .expression("([^,]+),") // identifier + .number("(dd)(dd)(dd),") // time (hhmmss) + .expression("([AVRPavrp]),") // validity + .number("(dd)(dd.d+),") // latitude .expression("([NS]),") - .number("(ddd)(dd.d+),") // longitude + .number("(ddd)(dd.d+),") // longitude .number("([EW]),") - .number("(d+.d+),") // speed - .number("(d+.d+),") // course - .number("(dd)(dd)(dd),") // date (ddmmyy) - .expression("([abZXTSMHFE86430]),") // event code + .number("(d+.d+),") // speed + .number("(d+.d+),") // course + .number("(dd)(dd)(dd),") // date (ddmmyy) + .expression("([abZXTSMHFE86430]),") // event code .number("(d+)").expression("(\\.?)").number("(d*),") // battery voltage - .number("(d+),") // current mileage - .number("(d),") // GPS on/off (1 = on, 0 = off) - .number("(d+),") // Analog port 1 - .number("(d+)") // Analog port 2 - .expression(",([0-9a-fA-F]{4})") // Cell 1 - Cell Net Code - .expression("([0-9a-fA-F]{4}),") // Cell 1 - Cell ID Code - .number("(d{3})") // Cell 2 - Country Code - .number("(d{3})") // Cell 2 - Operator Code + .number("(d+),") // current mileage + .number("(d),") // GPS on/off (1 = on, 0 = off) + .number("(d+),") // Analog port 1 + .number("(d+)") // Analog port 2 + .expression(",([0-9a-fA-F]{4})") // Cell 1 - Cell Net Code + .expression("([0-9a-fA-F]{4}),") // Cell 1 - Cell ID Code + .number("(d{3})") // Cell 2 - Country Code + .number("(d{3})") // Cell 2 - Operator Code .optional(4) .text("*") - .number("(xx)") // checksum + .number("(xx)") // checksum .compile(); @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + String sentence = (String) msg; if (sentence.startsWith("$ECHK") && channel != null) { -- cgit v1.2.3 From 2ff1d912fad21a8b5014459300221171c3b836d2 Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Tue, 20 Mar 2018 10:15:00 +0100 Subject: Cleanup for cell info --- setup/default.xml | 5 +++-- src/org/traccar/model/Position.java | 4 ---- src/org/traccar/protocol/LaipacProtocolDecoder.java | 11 ++++++++--- 3 files changed, 11 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/setup/default.xml b/setup/default.xml index da12467cc..455e84ae1 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -33,7 +33,7 @@ true ./schema/changelog-master.xml - + SELECT * FROM users WHERE email = :email OR login = :email @@ -231,4 +231,5 @@ 5159 5160 5161 - + + \ No newline at end of file diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 65bd03de6..fa303c500 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -88,10 +88,6 @@ public class Position extends Message { public static final String KEY_DRIVER_UNIQUE_ID = "driverUniqueId"; - public static final String KEY_CELL_NET_CODE = "cellNetCode"; - public static final String KEY_CELL_ID_CODE = "cellIdCode"; - public static final String KEY_COUNTRY_CODE = "countryCode"; - // Start with 1 not 0 public static final String PREFIX_TEMP = "temp"; public static final String PREFIX_ADC = "adc"; diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index 4fc0201ef..5221e46ad 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -22,6 +22,8 @@ import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -120,9 +122,12 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { position.set(Position.PREFIX_ADC + 1, parser.nextDouble() * 0.001); position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001); - setNextValue(parser, position, Position.KEY_CELL_NET_CODE); - setNextValue(parser, position, Position.KEY_CELL_ID_CODE); - setNextValue(parser, position, Position.KEY_COUNTRY_CODE); + int cellNetCode = Integer.parseInt(parser.next(), 16); + Long cellId = Long.parseLong(parser.next(), 16); + int countryCode = parser.nextInt(); + + position.setNetwork(new Network(CellTower.from(countryCode, cellNetCode, 0, cellId))); + setNextValue(parser, position, Position.KEY_OPERATOR); String checksum = parser.next(); -- cgit v1.2.3 From 11a5078af4f323f7132a50f3838c02b6e7f71a42 Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Tue, 20 Mar 2018 16:25:29 +0100 Subject: Switched network to differnt object --- .../traccar/protocol/LaipacProtocolDecoder.java | 25 ++++++++++------------ 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index 5221e46ad..e7698dc95 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -122,13 +122,17 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { position.set(Position.PREFIX_ADC + 1, parser.nextDouble() * 0.001); position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001); - int cellNetCode = Integer.parseInt(parser.next(), 16); - Long cellId = Long.parseLong(parser.next(), 16); - int countryCode = parser.nextInt(); - - position.setNetwork(new Network(CellTower.from(countryCode, cellNetCode, 0, cellId))); - - setNextValue(parser, position, Position.KEY_OPERATOR); + String cellNetCodeString = parser.next(); + String cellIdString = parser.next(); + String countryCodeString = parser.next(); + String operatorCodeString = parser.next(); + if (cellNetCodeString != null && cellIdString != null && countryCodeString != null && operatorCodeString != null) { + int cellNetCode = Integer.parseInt(cellNetCodeString, 16); + Long cellId = Long.parseLong(cellIdString, 16); + int countryCode = Integer.parseInt(countryCodeString); + int operatorCode = Integer.parseInt(operatorCodeString); + position.setNetwork(new Network(CellTower.from(countryCode, operatorCode, cellNetCode, cellId))); + } String checksum = parser.next(); String result = sentence.replaceAll("^\\$(.*)\\*[0-9a-fA-F]{2}$", "$1"); @@ -154,13 +158,6 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { return position; } - private void setNextValue(Parser parser, Position position, String key) { - String value = parser.next(); - if (value != null) { - position.set(key, value); - } - } - private String decodeAlarm(String event) { if (event.equals('Z')) { return Position.ALARM_LOW_BATTERY; -- cgit v1.2.3 From 7e7dca780552c7f34a4a7d8a6159d64e3b23a68b Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Tue, 20 Mar 2018 16:32:52 +0100 Subject: Format line longer then 120 characters --- src/org/traccar/protocol/LaipacProtocolDecoder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index e7698dc95..16ed6b750 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -126,7 +126,8 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { String cellIdString = parser.next(); String countryCodeString = parser.next(); String operatorCodeString = parser.next(); - if (cellNetCodeString != null && cellIdString != null && countryCodeString != null && operatorCodeString != null) { + if (cellNetCodeString != null && cellIdString != null && + countryCodeString != null && operatorCodeString != null) { int cellNetCode = Integer.parseInt(cellNetCodeString, 16); Long cellId = Long.parseLong(cellIdString, 16); int countryCode = Integer.parseInt(countryCodeString); -- cgit v1.2.3 From 69f270e4b80803e919f16495b0102dd0f5d6acfe Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Tue, 20 Mar 2018 16:44:25 +0100 Subject: Fixed formatting --- src/org/traccar/protocol/LaipacProtocolDecoder.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index 16ed6b750..b6d3dd8b2 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -126,8 +126,10 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { String cellIdString = parser.next(); String countryCodeString = parser.next(); String operatorCodeString = parser.next(); - if (cellNetCodeString != null && cellIdString != null && - countryCodeString != null && operatorCodeString != null) { + if (cellNetCodeString != null + && cellIdString != null + && countryCodeString != null + && operatorCodeString != null) { int cellNetCode = Integer.parseInt(cellNetCodeString, 16); Long cellId = Long.parseLong(cellIdString, 16); int countryCode = Integer.parseInt(countryCodeString); -- cgit v1.2.3 From 917e631284d8e4054f9036eb39c249fe6bdf4248 Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Wed, 21 Mar 2018 09:04:15 +0100 Subject: Fixed small laipac issues --- src/org/traccar/model/Position.java | 1 + .../traccar/protocol/LaipacProtocolDecoder.java | 74 ++++++++++------------ 2 files changed, 34 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index fa303c500..49e3231c3 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -291,4 +291,5 @@ public class Position extends Message { public String getType() { return super.getType(); } + } diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index b6d3dd8b2..c319c96c0 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -102,10 +102,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { position.setTime(dateBuilder.getDate()); String eventCode = parser.next(); - String decodedAlarm = decodeAlarm(eventCode); - if (decodedAlarm != null) { - position.set(Position.KEY_ALARM, decodeAlarm(eventCode)); - } + position.set(Position.KEY_ALARM, decodeAlarm(eventCode)); position.set(Position.KEY_EVENT, eventCode); double batteryVoltage = parser.nextDouble(); @@ -117,31 +114,24 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { } position.set(Position.KEY_BATTERY, batteryVoltage); - position.set(Position.KEY_TOTAL_DISTANCE, parser.nextDouble()); + position.set(Position.KEY_ODOMETER, parser.nextDouble()); position.set(Position.KEY_GPS, parser.nextInt()); position.set(Position.PREFIX_ADC + 1, parser.nextDouble() * 0.001); position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001); - String cellNetCodeString = parser.next(); - String cellIdString = parser.next(); - String countryCodeString = parser.next(); - String operatorCodeString = parser.next(); - if (cellNetCodeString != null - && cellIdString != null - && countryCodeString != null - && operatorCodeString != null) { - int cellNetCode = Integer.parseInt(cellNetCodeString, 16); - Long cellId = Long.parseLong(cellIdString, 16); - int countryCode = Integer.parseInt(countryCodeString); - int operatorCode = Integer.parseInt(operatorCodeString); - position.setNetwork(new Network(CellTower.from(countryCode, operatorCode, cellNetCode, cellId))); + String lac = parser.next(); + String cid = parser.next(); + String mcc = parser.next(); + String mnc = parser.next(); + if (lac != null + && cid != null + && mcc != null + && mnc != null) { + position.setNetwork(new Network(CellTower.from(Integer.parseInt(mcc), Integer.parseInt(mnc), + Integer.parseInt(lac, 16), Long.parseLong(cid, 16)))); } String checksum = parser.next(); - String result = sentence.replaceAll("^\\$(.*)\\*[0-9a-fA-F]{2}$", "$1"); - if (checksum == null || Integer.parseInt(checksum, 16) != Checksum.xor(result)) { - return null; - } if (channel != null) { if (eventCode.equals("3")) { @@ -162,25 +152,27 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { } private String decodeAlarm(String event) { - if (event.equals('Z')) { - return Position.ALARM_LOW_BATTERY; - } else if (event.equals('X')) { - return Position.ALARM_GEOFENCE_ENTER; - } else if (event.equals('T')) { - return Position.ALARM_TAMPERING; - } else if (event.equals("H")) { - return Position.ALARM_POWER_OFF; - } else if (event.equals('X')) { - return Position.ALARM_GEOFENCE_ENTER; - } else if (event.equals('8')) { - return Position.ALARM_SHOCK; - } else if (event.equals('7') && event.equals('4')) { - return Position.ALARM_GEOFENCE_EXIT; - } else if (event.equals('6')) { - return Position.ALARM_OVERSPEED; - } else if (event.equals('3')) { - return Position.ALARM_SOS; + switch (event) + { + case "Z": + return Position.ALARM_LOW_BATTERY; + case "X": + return Position.ALARM_GEOFENCE_ENTER; + case "T": + return Position.ALARM_TAMPERING; + case "H": + return Position.ALARM_POWER_OFF; + case "8": + return Position.ALARM_SHOCK; + case "7": + case "4": + return Position.ALARM_GEOFENCE_EXIT; + case "6": + return Position.ALARM_OVERSPEED; + case "3": + return Position.ALARM_SOS; + default: + return null; } - return null; } } -- cgit v1.2.3 From 8cc019cf5c43af6dc741138511623551a772b739 Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Wed, 21 Mar 2018 09:13:22 +0100 Subject: Fixed formatting issue --- src/org/traccar/protocol/LaipacProtocolDecoder.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index c319c96c0..f243fc629 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -152,8 +152,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { } private String decodeAlarm(String event) { - switch (event) - { + switch (event) { case "Z": return Position.ALARM_LOW_BATTERY; case "X": -- cgit v1.2.3 From 64e342442d74116c2247d85467e49722b7ab45ef Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Wed, 21 Mar 2018 10:37:48 +0100 Subject: Simplify battery voltage --- src/org/traccar/helper/DataConverter.java | 2 +- src/org/traccar/protocol/LaipacProtocolDecoder.java | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/org/traccar/helper/DataConverter.java b/src/org/traccar/helper/DataConverter.java index 0df0219ad..7abd4ae93 100644 --- a/src/org/traccar/helper/DataConverter.java +++ b/src/org/traccar/helper/DataConverter.java @@ -26,7 +26,7 @@ public final class DataConverter { public static byte[] parseHex(String string) { try { - return Hex.decodeHex(string.toCharArray()); + return Hex.decodeHex(string); } catch (DecoderException e) { throw new RuntimeException(e); } diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index f243fc629..0a7df26fa 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -48,7 +48,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { .number("(d+.d+),") // course .number("(dd)(dd)(dd),") // date (ddmmyy) .expression("([abZXTSMHFE86430]),") // event code - .number("(d+)").expression("(\\.?)").number("(d*),") // battery voltage + .number("(d.+),") // battery voltage .number("(d+),") // current mileage .number("(d),") // GPS on/off (1 = on, 0 = off) .number("(d+),") // Analog port 1 @@ -105,14 +105,9 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ALARM, decodeAlarm(eventCode)); position.set(Position.KEY_EVENT, eventCode); - double batteryVoltage = parser.nextDouble(); - if (parser.next().isEmpty()) { - parser.next(); - batteryVoltage *= 0.001; - } else { - batteryVoltage += parser.nextDouble() * 0.001; - } - position.set(Position.KEY_BATTERY, batteryVoltage); + String batteryVoltage = parser.next(); + batteryVoltage = batteryVoltage.replaceAll("\\.",""); + position.set(Position.KEY_BATTERY, Double.parseDouble(batteryVoltage) * 0.001); position.set(Position.KEY_ODOMETER, parser.nextDouble()); position.set(Position.KEY_GPS, parser.nextInt()); -- cgit v1.2.3 From 38d7bd680614d02dec49d6f53b5e054380e374d6 Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Wed, 21 Mar 2018 10:38:43 +0100 Subject: Fixed battery regex --- src/org/traccar/protocol/LaipacProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index 0a7df26fa..3e6037422 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -48,7 +48,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { .number("(d+.d+),") // course .number("(dd)(dd)(dd),") // date (ddmmyy) .expression("([abZXTSMHFE86430]),") // event code - .number("(d.+),") // battery voltage + .expression("([\\d.]+),") // battery voltage .number("(d+),") // current mileage .number("(d),") // GPS on/off (1 = on, 0 = off) .number("(d+),") // Analog port 1 -- cgit v1.2.3 From cd943017616c491509d354a0d95bea5ec161da94 Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Wed, 21 Mar 2018 10:40:37 +0100 Subject: Fixed formatting of the battery voltage comment --- src/org/traccar/protocol/LaipacProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index 3e6037422..a204f19bc 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -48,7 +48,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { .number("(d+.d+),") // course .number("(dd)(dd)(dd),") // date (ddmmyy) .expression("([abZXTSMHFE86430]),") // event code - .expression("([\\d.]+),") // battery voltage + .expression("([\\d.]+),") // battery voltage .number("(d+),") // current mileage .number("(d),") // GPS on/off (1 = on, 0 = off) .number("(d+),") // Analog port 1 -- cgit v1.2.3 From 277b14899879e882869552acc7847d63a03effcf Mon Sep 17 00:00:00 2001 From: Kevin Goos Date: Wed, 21 Mar 2018 10:48:20 +0100 Subject: Fixed formatting --- src/org/traccar/protocol/LaipacProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index a204f19bc..9357123c8 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -106,7 +106,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_EVENT, eventCode); String batteryVoltage = parser.next(); - batteryVoltage = batteryVoltage.replaceAll("\\.",""); + batteryVoltage = batteryVoltage.replaceAll("\\.", ""); position.set(Position.KEY_BATTERY, Double.parseDouble(batteryVoltage) * 0.001); position.set(Position.KEY_ODOMETER, parser.nextDouble()); -- cgit v1.2.3