diff options
-rw-r--r-- | setup/default.xml | 1 | ||||
-rw-r--r-- | src/org/traccar/api/resource/SessionResource.java | 15 | ||||
-rw-r--r-- | src/org/traccar/protocol/AplicomProtocolDecoder.java | 64 | ||||
-rw-r--r-- | src/org/traccar/protocol/AquilaProtocolDecoder.java | 2 | ||||
-rw-r--r-- | src/org/traccar/protocol/MeitrackProtocolDecoder.java | 2 | ||||
-rw-r--r-- | src/org/traccar/protocol/SiwiProtocol.java | 45 | ||||
-rw-r--r-- | src/org/traccar/protocol/SiwiProtocolDecoder.java | 100 | ||||
-rw-r--r-- | src/org/traccar/protocol/TotemProtocolDecoder.java | 2 | ||||
-rw-r--r-- | src/org/traccar/smpp/SmppClient.java | 8 | ||||
-rw-r--r-- | test/org/traccar/ProtocolTest.java | 4 | ||||
-rw-r--r-- | test/org/traccar/protocol/AplicomProtocolDecoderTest.java | 3 | ||||
-rw-r--r-- | test/org/traccar/protocol/SiwiProtocolDecoderTest.java | 33 | ||||
-rw-r--r-- | test/org/traccar/protocol/Tk103ProtocolDecoderTest.java | 6 |
13 files changed, 275 insertions, 10 deletions
diff --git a/setup/default.xml b/setup/default.xml index 80351f6a6..a146a6d63 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -505,5 +505,6 @@ <entry key='tmg.port'>5132</entry> <entry key='pretrace.port'>5133</entry> <entry key='pricol.port'>5134</entry> + <entry key='siwi.port'>5135</entry> </properties> diff --git a/src/org/traccar/api/resource/SessionResource.java b/src/org/traccar/api/resource/SessionResource.java index 5f1c597d1..acdbb7c87 100644 --- a/src/org/traccar/api/resource/SessionResource.java +++ b/src/org/traccar/api/resource/SessionResource.java @@ -33,6 +33,11 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import javax.xml.bind.DatatypeConverter; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.sql.SQLException; @Path("session") @@ -49,7 +54,7 @@ public class SessionResource extends BaseResource { @PermitAll @GET - public User get(@QueryParam("token") String token) throws SQLException { + public User get(@QueryParam("token") String token) throws SQLException, UnsupportedEncodingException { Long userId = (Long) request.getSession().getAttribute(USER_ID_KEY); if (userId == null) { Cookie[] cookies = request.getCookies(); @@ -57,10 +62,14 @@ public class SessionResource extends BaseResource { if (cookies != null) { for (int i = 0; i < cookies.length; i++) { if (cookies[i].getName().equals(USER_COOKIE_KEY)) { - email = cookies[i].getValue(); + byte[] emailBytes = DatatypeConverter.parseBase64Binary( + URLDecoder.decode(cookies[i].getValue(), StandardCharsets.US_ASCII.name())); + email = new String(emailBytes, StandardCharsets.UTF_8); } if (cookies[i].getName().equals(PASS_COOKIE_KEY)) { - password = cookies[i].getValue(); + byte[] passwordBytes = DatatypeConverter.parseBase64Binary( + URLDecoder.decode(cookies[i].getValue(), StandardCharsets.US_ASCII.name())); + password = new String(passwordBytes, StandardCharsets.UTF_8); } } } diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java index daa8844b4..fbd868b86 100644 --- a/src/org/traccar/protocol/AplicomProtocolDecoder.java +++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2016 Anton Tananaev (anton@traccar.org) + * 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. @@ -78,6 +78,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { private static final int DEFAULT_SELECTOR_D = 0x0002fC; private static final int DEFAULT_SELECTOR_E = 0x007ffc; + private static final int DEFAULT_SELECTOR_F = 0x0007fd; private static final int EVENT_DATA = 119; @@ -498,6 +499,63 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } } + private void decodeF(Position position, ChannelBuffer buf, int selector) { + + getLastLocation(position, null); + + buf.readUnsignedShort(); // event + + if ((selector & 0x0004) != 0) { + buf.skipBytes(4); // snapshot time + } + + buf.readUnsignedByte(); // data validity + + if ((selector & 0x0008) != 0) { + position.set(Position.KEY_RPM, buf.readUnsignedShort()); + position.set("rpmMax", buf.readUnsignedShort()); + position.set("rpmMin", buf.readUnsignedShort()); + } + + if ((selector & 0x0010) != 0) { + position.set("engineTemp", buf.readShort()); + position.set("engineTempMax", buf.readShort()); + position.set("engineTempMin", buf.readShort()); + } + + if ((selector & 0x0020) != 0) { + position.set(Position.KEY_HOURS, buf.readUnsignedInt()); + position.set("serviceDistance", buf.readInt()); + buf.readUnsignedByte(); // driver activity + position.set(Position.KEY_THROTTLE, buf.readUnsignedByte()); + position.set(Position.KEY_FUEL, buf.readUnsignedByte()); + } + + if ((selector & 0x0040) != 0) { + position.set("totalFuelUsed", buf.readUnsignedInt()); + } + + if ((selector & 0x0080) != 0) { + position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + } + + if ((selector & 0x0100) != 0) { + position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte()); + position.set("speedMax", buf.readUnsignedByte()); + position.set("speedMin", buf.readUnsignedByte()); + position.set("hardBreaking", buf.readUnsignedByte()); + } + + if ((selector & 0x0200) != 0) { + buf.readUnsignedByte(); // tachograph based speed + buf.readUnsignedByte(); // driver 1 state + buf.readUnsignedByte(); // driver 2 state + buf.readUnsignedByte(); // tachograph status + position.set("overspeedCount", buf.readUnsignedByte()); + } + + } + @Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -518,6 +576,8 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { int selector = DEFAULT_SELECTOR_D; if (protocol == 'E') { selector = DEFAULT_SELECTOR_E; + } else if (protocol == 'F') { + selector = DEFAULT_SELECTOR_F; } if ((version & 0x40) != 0) { selector = buf.readUnsignedMedium(); @@ -541,6 +601,8 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { decodeE(position, buf, selector); } else if (protocol == 'H') { decodeH(position, buf, selector); + } else if (protocol == 'F') { + decodeF(position, buf, selector); } else { return null; } diff --git a/src/org/traccar/protocol/AquilaProtocolDecoder.java b/src/org/traccar/protocol/AquilaProtocolDecoder.java index e1cebd20d..11ab15c86 100644 --- a/src/org/traccar/protocol/AquilaProtocolDecoder.java +++ b/src/org/traccar/protocol/AquilaProtocolDecoder.java @@ -132,7 +132,7 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); - position.set(Position.KEY_ODOMETER, parser.next()); + position.set(Position.KEY_ODOMETER, parser.nextInt()); if (parser.hasNext(9)) { diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index 4862b4937..f5253566b 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -124,7 +124,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { position.setAltitude(parser.nextDouble()); - position.set(Position.KEY_ODOMETER, parser.next()); + position.set(Position.KEY_ODOMETER, parser.nextInt()); position.set("runtime", parser.next()); position.setNetwork(new Network( diff --git a/src/org/traccar/protocol/SiwiProtocol.java b/src/org/traccar/protocol/SiwiProtocol.java new file mode 100644 index 000000000..667e083f1 --- /dev/null +++ b/src/org/traccar/protocol/SiwiProtocol.java @@ -0,0 +1,45 @@ +/* + * Copyright 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.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.traccar.BaseProtocol; +import org.traccar.TrackerServer; + +import java.util.List; + +public class SiwiProtocol extends BaseProtocol { + + public SiwiProtocol() { + super("siwi"); + } + + @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("objectDecoder", new SiwiProtocolDecoder(SiwiProtocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/SiwiProtocolDecoder.java b/src/org/traccar/protocol/SiwiProtocolDecoder.java new file mode 100644 index 000000000..9c9e71e2e --- /dev/null +++ b/src/org/traccar/protocol/SiwiProtocolDecoder.java @@ -0,0 +1,100 @@ +/* + * Copyright 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.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.TimeZone; +import java.util.regex.Pattern; + +public class SiwiProtocolDecoder extends BaseProtocolDecoder { + + public SiwiProtocolDecoder(SiwiProtocol protocol) { + super(protocol); + } + + private static final Pattern PATTERN = new PatternBuilder() + .text("$").expression("[A-Z]+,") // header + .number("(d+),") // device id + .number("d+,") // unit no + .expression("([A-Z]),") // reason + .number("d+,") // command code + .number("[^,]*,") // command value + .expression("([01]),") // ignition + .expression("[01],") // power cut + .expression("[01],") // box open + .number("d+,") // message key + .number("(d+),") // odometer + .number("(d+),") // speed + .number("(d+),") // satellites + .expression("([AV]),") // valid + .number("(-?d+.d+),") // latitude + .number("(-?d+.d+),") // longitude + .number("(-?d+),") // altitude + .number("(d+),") // course + .number("(dd)(dd)(dd),") // time + .number("(dd)(dd)(dd),") // date + .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()); + + position.set(Position.KEY_EVENT, parser.next()); + position.set(Position.KEY_IGNITION, parser.next().equals("1")); + position.set(Position.KEY_ODOMETER, parser.nextInt()); + + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt())); + + position.set(Position.KEY_SATELLITES, parser.nextInt()); + + position.setValid(parser.next().equals("A")); + position.setLatitude(parser.nextDouble()); + position.setLongitude(parser.nextDouble()); + position.setAltitude(parser.nextDouble()); + + DateBuilder dateBuilder = new DateBuilder(TimeZone.getTimeZone("IST")) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + return position; + } + +} diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java index 6a4b2052c..f36ef8143 100644 --- a/src/org/traccar/protocol/TotemProtocolDecoder.java +++ b/src/org/traccar/protocol/TotemProtocolDecoder.java @@ -290,7 +290,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { position.setCourse(parser.nextDouble()); position.setSpeed(parser.nextDouble()); position.set("pdop", parser.next()); - position.set(Position.KEY_ODOMETER, parser.next()); + position.set(Position.KEY_ODOMETER, parser.nextInt() * 1000); position.setLatitude(parser.nextCoordinate()); position.setLongitude(parser.nextCoordinate()); diff --git a/src/org/traccar/smpp/SmppClient.java b/src/org/traccar/smpp/SmppClient.java index 006f86e53..317d6debf 100644 --- a/src/org/traccar/smpp/SmppClient.java +++ b/src/org/traccar/smpp/SmppClient.java @@ -157,9 +157,11 @@ public class SmppClient { } public void scheduleReconnect() { - reconnectionTask = reconnectionExecutor.scheduleWithFixedDelay( - new ReconnectionTask(this), - reconnectionDelay, reconnectionDelay, TimeUnit.MILLISECONDS); + if (reconnectionTask == null || reconnectionTask.isDone()) { + reconnectionTask = reconnectionExecutor.scheduleWithFixedDelay( + new ReconnectionTask(this), + reconnectionDelay, reconnectionDelay, TimeUnit.MILLISECONDS); + } } private void stopReconnectionkTask() { diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java index f4072ad24..faf27071d 100644 --- a/test/org/traccar/ProtocolTest.java +++ b/test/org/traccar/ProtocolTest.java @@ -176,6 +176,10 @@ public class ProtocolTest extends BaseTest { Assert.assertFalse("no attributes", attributes.isEmpty()); } + if (attributes.containsKey(Position.KEY_ODOMETER)) { + Assert.assertTrue(attributes.get(Position.KEY_ODOMETER) instanceof Number); + } + if (position.getNetwork() != null && position.getNetwork().getCellTowers() != null) { for (CellTower cellTower : position.getNetwork().getCellTowers()) { checkInteger(cellTower.getMobileCountryCode(), 0, 999); diff --git a/test/org/traccar/protocol/AplicomProtocolDecoderTest.java b/test/org/traccar/protocol/AplicomProtocolDecoderTest.java index cb39b5d2e..38ac1c43f 100644 --- a/test/org/traccar/protocol/AplicomProtocolDecoderTest.java +++ b/test/org/traccar/protocol/AplicomProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class AplicomProtocolDecoderTest extends ProtocolTest { AplicomProtocolDecoder decoder = new AplicomProtocolDecoder(new AplicomProtocol());
verifyAttributes(decoder, binary(
+ "46c30144f667c1711f00340007ff75005891601401025707b50236003b003b003500000a9300006bd50100640000a5250167d2f9034c01010107020400021a901004"));
+
+ verifyAttributes(decoder, binary(
"48C1014143B4493145004900203F6D014B5557C20003000015060110FF00C800000000000000003D01141E283C500100260404010200000000000000000000000000C8000000000000010200110019001E0064019003E8"));
verifyAttributes(decoder, binary(
diff --git a/test/org/traccar/protocol/SiwiProtocolDecoderTest.java b/test/org/traccar/protocol/SiwiProtocolDecoderTest.java new file mode 100644 index 000000000..c5c93b7d0 --- /dev/null +++ b/test/org/traccar/protocol/SiwiProtocolDecoderTest.java @@ -0,0 +1,33 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class SiwiProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + SiwiProtocolDecoder decoder = new SiwiProtocolDecoder(new SiwiProtocol()); + + verifyPosition(decoder, text( + "$SIWI,2845,1320,Q,10,airtelgprs.com,1,1,0,0,876578,43,9,A,19.0123456,72.65347,45,0,055929,071107,22,5,1,0,3700,1210,0,2500,1230,321,0,1.1,4.0,1!")); + + verifyPosition(decoder, text( + "$SIWI,9803849,953,R,9,,0,1,1,0,0,0,8,A,19.066145,73.002278,213,178,122738,210217,28,5,12,6,4066,1,0,2,0,0,0,1.0,3.1CHKS_4.82,0")); + + verifyPosition(decoder, text( + "$EIT,9803849,953,R,9,,0,1,1,0,0,0,8,A,19.066145,73.002278,213,178,122738,210217,28,5,12,6,4066,1,0,2,0,0,0,1.0,3.1CHKS_4.82,0")); + + verifyPosition(decoder, text( + "$SIWI,9803849,954,E,0,,0,1,1,0,0,0,0,V,0.000000,0.000000,0,0,122855,210217,29,5,12,5,4104,1,0,2,0,0,0,1.0,3.1CHKS_4.82,0")); + + verifyPosition(decoder, text( + "$SIWI,2845,1320,A,0,,1,1,0,0,876578,43,10,A,19.0123456,72.65347,45,0,055929,071107,22,5,1,0,3700,1210,0,2500,1230,321,0,1.1,4.0,1!")); + + verifyPosition(decoder, text( + "$SIWI,9803849,956,E,0,,0,1,1,0,0,0,3,V,19.066935,73.003383,0,111,123037,210217,28,5,12,5,4071,1,0,2,0,0,0,1.0,3.1CHKS_4.82,0")); + + } + +} diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java index e6ca3f218..da412e9a7 100644 --- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -10,6 +10,12 @@ public class Tk103ProtocolDecoderTest extends ProtocolTest { Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(new Tk103Protocol()); + verifyNothing(decoder, text( + "(357593060760397BP02,G,2,170304A6015.7466N01101.8460E001.609445591.048,7)")); + + verifyPosition(decoder, text( + "(325031693849BR00170228A5750.8012N02700.7476E000.2154529000.0000000200L00000000,170228,194530)")); + verifyPosition(decoder, text( "(087073803649BR00170221A6142.0334N02712.2197E000.3203149000.00,00000000L00000000)")); |