From 96f005aeece3b1374991a3fb691687bde9eb8109 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 4 Jun 2018 00:44:54 +1200 Subject: Increase default future filtering value --- setup/default.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setup/default.xml') diff --git a/setup/default.xml b/setup/default.xml index 5d79f563f..badc03086 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -19,7 +19,7 @@ ./logs/tracker-server.log true - 3600 + 86400 true true -- cgit v1.2.3 From 36a253b19764613e03b538a2b1a48eaa6408f4d5 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 4 Jun 2018 16:36:49 +1200 Subject: Implement Wialon Retranslator protocol --- setup/default.xml | 1 + .../traccar/protocol/RetranslatorFrameDecoder.java | 38 +++++++ src/org/traccar/protocol/RetranslatorProtocol.java | 42 ++++++++ .../protocol/RetranslatorProtocolDecoder.java | 119 +++++++++++++++++++++ .../protocol/RetranslatorProtocolDecoderTest.java | 21 ++++ 5 files changed, 221 insertions(+) create mode 100644 src/org/traccar/protocol/RetranslatorFrameDecoder.java create mode 100644 src/org/traccar/protocol/RetranslatorProtocol.java create mode 100644 src/org/traccar/protocol/RetranslatorProtocolDecoder.java create mode 100644 test/org/traccar/protocol/RetranslatorProtocolDecoderTest.java (limited to 'setup/default.xml') diff --git a/setup/default.xml b/setup/default.xml index badc03086..66c72a877 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -242,5 +242,6 @@ 5164 5165 5166 + 5167 diff --git a/src/org/traccar/protocol/RetranslatorFrameDecoder.java b/src/org/traccar/protocol/RetranslatorFrameDecoder.java new file mode 100644 index 000000000..1836fb26e --- /dev/null +++ b/src/org/traccar/protocol/RetranslatorFrameDecoder.java @@ -0,0 +1,38 @@ +/* + * Copyright 2018 Anton Tananaev (anton@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.handler.codec.frame.FrameDecoder; + +public class RetranslatorFrameDecoder extends FrameDecoder { + + @Override + protected Object decode( + ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { + + int length = 4 + ChannelBuffers.swapInt(buf.getInt(buf.readerIndex())); + if (buf.readableBytes() >= length) { + return buf.readBytes(length); + } else { + return null; + } + } + +} diff --git a/src/org/traccar/protocol/RetranslatorProtocol.java b/src/org/traccar/protocol/RetranslatorProtocol.java new file mode 100644 index 000000000..0421390b2 --- /dev/null +++ b/src/org/traccar/protocol/RetranslatorProtocol.java @@ -0,0 +1,42 @@ +/* + * Copyright 2018 Anton Tananaev (anton@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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.traccar.BaseProtocol; +import org.traccar.TrackerServer; + +import java.util.List; + +public class RetranslatorProtocol extends BaseProtocol { + + public RetranslatorProtocol() { + super("retranslator"); + } + + @Override + public void initTrackerServers(List serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new RetranslatorFrameDecoder()); + pipeline.addLast("objectDecoder", new RetranslatorProtocolDecoder(RetranslatorProtocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/RetranslatorProtocolDecoder.java b/src/org/traccar/protocol/RetranslatorProtocolDecoder.java new file mode 100644 index 000000000..756b0bcaf --- /dev/null +++ b/src/org/traccar/protocol/RetranslatorProtocolDecoder.java @@ -0,0 +1,119 @@ +/* + * Copyright 2018 Anton Tananaev (anton@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +import org.jboss.netty.channel.Channel; +import org.traccar.BaseProtocolDecoder; +import org.traccar.DeviceSession; +import org.traccar.model.Position; + +import java.net.SocketAddress; +import java.nio.ByteOrder; +import java.nio.charset.StandardCharsets; +import java.util.Date; + +public class RetranslatorProtocolDecoder extends BaseProtocolDecoder { + + public RetranslatorProtocolDecoder(RetranslatorProtocol protocol) { + super(protocol); + } + + private double readDouble(ChannelBuffer buf) { + byte[] bytes = new byte[8]; + buf.readBytes(bytes); + return ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, bytes).readDouble(); + } + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + if (channel != null) { + channel.write(ChannelBuffers.wrappedBuffer(new byte[]{0x11})); + } + + ChannelBuffer buf = (ChannelBuffer) msg; + + buf.readUnsignedInt(); // length + + int idLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x00) - buf.readerIndex(); + String id = buf.readBytes(idLength).toString(StandardCharsets.US_ASCII); + buf.readByte(); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); + if (deviceSession == null) { + return null; + } + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + position.setTime(new Date(buf.readUnsignedInt() * 1000)); + + buf.readUnsignedInt(); // bit flags + + while (buf.readable()) { + + buf.readUnsignedShort(); // block type + int blockEnd = buf.readInt() + buf.readerIndex(); + buf.readUnsignedByte(); // security attribute + int dataType = buf.readUnsignedByte(); + + int nameLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x00) - buf.readerIndex(); + String name = buf.readBytes(nameLength).toString(StandardCharsets.US_ASCII); + buf.readByte(); + + if (name.equals("posinfo")) { + position.setValid(true); + position.setLongitude(readDouble(buf)); + position.setLatitude(readDouble(buf)); + position.setAltitude(readDouble(buf)); + position.setSpeed(buf.readShort()); + position.setCourse(buf.readShort()); + position.set(Position.KEY_SATELLITES, buf.readByte()); + } else { + switch (dataType) { + case 1: + int len = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x00) - buf.readerIndex(); + position.set(name, buf.readBytes(len).toString(StandardCharsets.US_ASCII)); + buf.readByte(); + break; + case 3: + position.set(name, buf.readInt()); + break; + case 4: + position.set(name, readDouble(buf)); + break; + case 5: + position.set(name, buf.readLong()); + break; + default: + break; + } + } + + buf.readerIndex(blockEnd); + + } + + if (position.getLatitude() == 0 && position.getLongitude() == 0) { + getLastLocation(position, position.getDeviceTime()); + } + + return position; + } + +} diff --git a/test/org/traccar/protocol/RetranslatorProtocolDecoderTest.java b/test/org/traccar/protocol/RetranslatorProtocolDecoderTest.java new file mode 100644 index 000000000..680570763 --- /dev/null +++ b/test/org/traccar/protocol/RetranslatorProtocolDecoderTest.java @@ -0,0 +1,21 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class RetranslatorProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + RetranslatorProtocolDecoder decoder = new RetranslatorProtocolDecoder(new RetranslatorProtocol()); + + verifyPosition(decoder, binary( + "74000000333533393736303133343435343835004B0BFB70000000030BBB000000270102706F73696E666F00A027AFDF5D9848403AC7253383DD4B400000000000805A40003601460B0BBB0000001200047077725F657874002B8716D9CE973B400BBB00000011010361766C5F696E707574730000000001")); + + verifyPosition(decoder, binary( + "1f010000333533353439303930303934373330005b129b5f000000010bbb000000270102706f73696e666f004e3be14e5ec356c0e0e92f6201282c400000000000000000000000130d0bbb0000000a00036d636300000002c00bbb0000000a00036d6e6300000000010bbb0000000a00036c616300000001490bbb0000000e000363656c6c5f696400000056590bbb0000000a000361636300000000000bbb000000100003646174615f6d6f6465000000000e0bbb0000001200036770735f7265616c5f757000000000000bbb0000000d000373657269616c000000089b0bbb0000001000016d73675f747970650030783232000bbb000000110004637573746f6d0000000000000033400bbb0000001200046d696c65616765000000000000000000")); + + } + +} -- cgit v1.2.3 From acf93dbe1b5c03df4f8f82ffb7fb0cace767a416 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 8 Jun 2018 14:05:41 +1200 Subject: Clean up Svias decoder --- setup/default.xml | 1 + src/org/traccar/protocol/SviasProtocol.java | 4 +- src/org/traccar/protocol/SviasProtocolDecoder.java | 125 ++++++++------------- src/org/traccar/protocol/SviasProtocolEncoder.java | 5 +- .../traccar/protocol/SviasProtocolDecoderTest.java | 8 +- 5 files changed, 61 insertions(+), 82 deletions(-) (limited to 'setup/default.xml') diff --git a/setup/default.xml b/setup/default.xml index 66c72a877..ee80fb4df 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -243,5 +243,6 @@ 5165 5166 5167 + 5168 diff --git a/src/org/traccar/protocol/SviasProtocol.java b/src/org/traccar/protocol/SviasProtocol.java index 8a45f43cb..badf3d091 100644 --- a/src/org/traccar/protocol/SviasProtocol.java +++ b/src/org/traccar/protocol/SviasProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.handler.codec.string.StringDecoder; import org.jboss.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; import org.traccar.TrackerServer; import java.util.List; @@ -45,6 +46,7 @@ public class SviasProtocol extends BaseProtocol { serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "]")); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("objectEncoder", new SviasProtocolEncoder()); diff --git a/src/org/traccar/protocol/SviasProtocolDecoder.java b/src/org/traccar/protocol/SviasProtocolDecoder.java index bc459de25..9375038ed 100644 --- a/src/org/traccar/protocol/SviasProtocolDecoder.java +++ b/src/org/traccar/protocol/SviasProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,12 +17,10 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; +import org.traccar.helper.BitUtil; import org.traccar.helper.PatternBuilder; import java.net.SocketAddress; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.TimeZone; import java.util.regex.Pattern; import org.traccar.DeviceSession; import org.traccar.helper.Parser; @@ -36,99 +34,70 @@ public class SviasProtocolDecoder extends BaseProtocolDecoder { } private static final Pattern PATTERN = new PatternBuilder() - .text("[") // delimiter init - .any() - .number("(dddddddd),") // imei - .any() - .number("(d+),") // date (yyyymmdd) - .number("(d+),") // time (hhmmss) - .number("(-?d+),") // longitude - .number("(-?d+),") // latitude - .number("(d+),") // speed - .number("(d+),") // course - .number("(d+),") // odometer - .number("(d+),") // input - .number("(d+),") // output / status - .any() - .number("(ddddd),") // main power voltage - .number("(d+),") // percentual power internal battery - .number("(d+),") // RSSID + .text("[") // delimiter + .number("d{4},") // hardware version + .number("d{4},") // software version + .number("d+,") // index + .number("(d+),") // imei + .number("d+,") // hour meter + .number("(d+)(dd)(dd),") // date (dmmyy) + .number("(d+)(dd)(dd),") // time (hmmss) + .number("(-?)(d+)(dd)(d{5}),") // latitude + .number("(-?)(d+)(dd)(d{5}),") // longitude + .number("(d+),") // speed + .number("(d+),") // course + .number("(d+),") // odometer + .number("(d+),") // input + .number("(d+),") // output / status + .number("(d),") + .number("(d),") + .number("(d+),") // power + .number("(d+),") // battery level + .number("(d+),") // rssi .any() .compile(); - private double convertCoordinates(long v) { - return Double.valueOf(((float) ((((float) v / 1.0E7F) - - ((int) (v / 10000000L))) * 1.6666666666666667D)) + ((int) (v / 10000000L))); - } - @Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - String sentence = (String) msg; - Object result = null; - - if (!sentence.contains(":")) { - - Parser parser = new Parser(PATTERN, (String) sentence); - if (!parser.matches()) { - return null; - } - - Position position = new Position(getProtocolName()); - - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); - if (deviceSession == null) { - return null; - } - - position.setDeviceId(deviceSession.getDeviceId()); - - DateFormat dateFormat = new SimpleDateFormat("ddMMyyHHmmss"); - dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); - - String date = String.format("%06d", parser.nextInt()); - String time = String.format("%06d", parser.nextInt()); - - position.setTime(dateFormat.parse(date + time)); - - position.setLatitude(convertCoordinates(parser.nextLong())); - position.setLongitude(convertCoordinates(parser.nextLong())); - position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0) / 100)); - position.setCourse(parser.nextDouble(0) / 100); - position.setAltitude(0); - - position.set(Position.KEY_ODOMETER, parser.nextInt()); - - String input = new StringBuilder(String.format("%08d", - Integer.parseInt(Integer.toString(parser.nextInt(), 2)))).reverse().toString(); - - String output = new StringBuilder(String.format("%08d", - Integer.parseInt(Integer.toString(parser.nextInt(), 2)))).reverse().toString(); + Parser parser = new Parser(PATTERN, (String) msg); + if (!parser.matches()) { + return null; + } - position.set(Position.KEY_ALARM, (input.substring(0, 1).equals("1") - ? Position.ALARM_SOS : null)); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } - position.set(Position.KEY_IGNITION, input.substring(4, 5).equals("1")); + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); - position.setValid(output.substring(0, 1).equals("1")); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); + position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_MIN)); + position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_MIN)); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble() * 0.01)); + position.setCourse(parser.nextDouble() * 0.01); - position.set(Position.KEY_POWER, parser.nextDouble(0) / 1000); + position.set(Position.KEY_ODOMETER, parser.nextInt() * 100); - position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt()); + int input = parser.nextInt(); + int output = parser.nextInt(); - position.set(Position.KEY_RSSI, parser.nextInt()); + position.set(Position.KEY_ALARM, BitUtil.check(input, 0) ? Position.ALARM_SOS : null); + position.set(Position.KEY_IGNITION, BitUtil.check(input, 4)); + position.setValid(BitUtil.check(output, 0)); - result = position; - - } + position.set(Position.KEY_POWER, parser.nextInt() * 0.001); + position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt()); + position.set(Position.KEY_RSSI, parser.nextInt()); if (channel != null) { channel.write("@"); } - return result; - + return position; } } diff --git a/src/org/traccar/protocol/SviasProtocolEncoder.java b/src/org/traccar/protocol/SviasProtocolEncoder.java index 518268cab..c26ee2032 100644 --- a/src/org/traccar/protocol/SviasProtocolEncoder.java +++ b/src/org/traccar/protocol/SviasProtocolEncoder.java @@ -1,6 +1,6 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) - * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org) + * Copyright 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2018 Andrey Kunitsyn (andrey@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,4 +47,5 @@ public class SviasProtocolEncoder extends StringProtocolEncoder { } return null; } + } diff --git a/test/org/traccar/protocol/SviasProtocolDecoderTest.java b/test/org/traccar/protocol/SviasProtocolDecoderTest.java index 064ab16f1..3bf355a15 100644 --- a/test/org/traccar/protocol/SviasProtocolDecoderTest.java +++ b/test/org/traccar/protocol/SviasProtocolDecoderTest.java @@ -11,7 +11,13 @@ public class SviasProtocolDecoderTest extends ProtocolTest { SviasProtocolDecoder decoder = new SviasProtocolDecoder(new SviasProtocol()); verifyPosition(decoder, text( - "[7061,3041,57,20324277,710,40618,141342,-93155840,-371754060,0,20469,0,16,1,0,0,11323,100,9,,32,4695]")); + "[7061,3041,57,20324277,710,40618,141342,-93155840,-371754060,0,20469,0,16,1,0,0,11323,100,9,,32,4695")); + + verifyPosition(decoder, text( + "[7041,3041,8629,20856286,710,60618,201027,-92268040,-371346250,7994,31844,38271,16,1,0,0,13416,100,0,0,5089")); + + verifyPosition(decoder, text( + "[7051,3041,15270,30179873,710,70618,40335,-94679080,-360604930,0,35454,23148,0,1,0,0,12542,100,13,32,4971")); } -- cgit v1.2.3 From 37868cf0b5be5b99e48b28d1aafacdc74c2aff9e Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 8 Jun 2018 10:00:28 +0500 Subject: Rename all tables to avoid using reserved words --- schema/changelog-4.0.xml | 56 +++++++++++++++++++++++++++++++ schema/changelog-master.xml | 1 + setup/default.xml | 16 ++++----- src/org/traccar/database/DataManager.java | 5 +-- 4 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 schema/changelog-4.0.xml (limited to 'setup/default.xml') diff --git a/schema/changelog-4.0.xml b/schema/changelog-4.0.xml new file mode 100644 index 000000000..04e9fe0c4 --- /dev/null +++ b/schema/changelog-4.0.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/schema/changelog-master.xml b/schema/changelog-master.xml index 3e7944238..e8fbc0c4b 100644 --- a/schema/changelog-master.xml +++ b/schema/changelog-master.xml @@ -18,4 +18,5 @@ + diff --git a/setup/default.xml b/setup/default.xml index ee80fb4df..c427217f7 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -41,36 +41,36 @@ ./schema/changelog-master.xml - SELECT * FROM users + SELECT * FROM tc_users WHERE email = :email OR login = :email - SELECT * FROM positions WHERE deviceId = :deviceId AND fixTime BETWEEN :from AND :to ORDER BY fixTime + SELECT * FROM tc_positions WHERE deviceId = :deviceId AND fixTime BETWEEN :from AND :to ORDER BY fixTime - SELECT positions.* FROM positions INNER JOIN devices ON positions.id = devices.positionid; + SELECT tc_positions.* FROM tc_positions INNER JOIN tc_devices ON tc_positions.id = tc_devices.positionid; - UPDATE devices SET positionId = :id WHERE id = :deviceId + UPDATE tc_devices SET positionId = :id WHERE id = :deviceId - SELECT * FROM events WHERE deviceId = :deviceId AND serverTime BETWEEN :from AND :to ORDER BY serverTime + SELECT * FROM tc_events WHERE deviceId = :deviceId AND serverTime BETWEEN :from AND :to ORDER BY serverTime - DELETE FROM positions WHERE serverTime < :serverTime AND id NOT IN (SELECT positionId FROM devices WHERE positionId IS NOT NULL) + DELETE FROM tc_positions WHERE serverTime < :serverTime AND id NOT IN (SELECT positionId FROM tc_devices WHERE positionId IS NOT NULL) - DELETE FROM events WHERE serverTime < :serverTime + DELETE FROM tc_events WHERE serverTime < :serverTime - SELECT * FROM statistics WHERE captureTime BETWEEN :from AND :to ORDER BY captureTime + SELECT * FROM tc_statistics WHERE captureTime BETWEEN :from AND :to ORDER BY captureTime diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index ae5ec2d5f..06dd26b17 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -273,11 +273,12 @@ public class DataManager { if (propertyName.equals("ManagedUser")) { propertyName = "User"; } - return Introspector.decapitalize(owner.getSimpleName()) + "_" + Introspector.decapitalize(propertyName); + return "tc_" + Introspector.decapitalize(owner.getSimpleName()) + + "_" + Introspector.decapitalize(propertyName); } private static String getObjectsTableName(Class clazz) { - String result = Introspector.decapitalize(clazz.getSimpleName()); + String result = "tc_" + Introspector.decapitalize(clazz.getSimpleName()); // Add "s" ending if object name is not plural already if (!result.endsWith("s")) { result += "s"; -- cgit v1.2.3 From f56db9b1d895c027d983696db7daed900ca881ab Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 9 Jun 2018 22:22:01 +1200 Subject: Implement eSeal CT-C protocol --- setup/default.xml | 1 + src/org/traccar/model/Position.java | 2 + src/org/traccar/protocol/EsealProtocol.java | 47 +++++++ src/org/traccar/protocol/EsealProtocolDecoder.java | 154 +++++++++++++++++++++ .../traccar/protocol/EsealProtocolDecoderTest.java | 33 +++++ 5 files changed, 237 insertions(+) create mode 100644 src/org/traccar/protocol/EsealProtocol.java create mode 100644 src/org/traccar/protocol/EsealProtocolDecoder.java create mode 100644 test/org/traccar/protocol/EsealProtocolDecoderTest.java (limited to 'setup/default.xml') diff --git a/setup/default.xml b/setup/default.xml index c427217f7..15d169f63 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -244,5 +244,6 @@ 5166 5167 5168 + 5169 diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index b0fe7a79b..4b327cbd2 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -112,6 +112,8 @@ public class Position extends Message { public static final String ALARM_POWER_OFF = "powerOff"; public static final String ALARM_POWER_ON = "powerOn"; public static final String ALARM_DOOR = "door"; + public static final String ALARM_LOCK = "lock"; + public static final String ALARM_UNLOCK = "unlock"; public static final String ALARM_GEOFENCE = "geofence"; public static final String ALARM_GEOFENCE_ENTER = "geofenceEnter"; public static final String ALARM_GEOFENCE_EXIT = "geofenceExit"; diff --git a/src/org/traccar/protocol/EsealProtocol.java b/src/org/traccar/protocol/EsealProtocol.java new file mode 100644 index 000000000..534e3d0c4 --- /dev/null +++ b/src/org/traccar/protocol/EsealProtocol.java @@ -0,0 +1,47 @@ +/* + * Copyright 2018 Anton Tananaev (anton@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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 EsealProtocol extends BaseProtocol { + + public EsealProtocol() { + super("eseal"); + } + + @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 EsealProtocolDecoder(EsealProtocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/EsealProtocolDecoder.java b/src/org/traccar/protocol/EsealProtocolDecoder.java new file mode 100644 index 000000000..67b45b33f --- /dev/null +++ b/src/org/traccar/protocol/EsealProtocolDecoder.java @@ -0,0 +1,154 @@ +/* + * Copyright 2018 Anton Tananaev (anton@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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.Context; +import org.traccar.DeviceSession; +import org.traccar.helper.Parser; +import org.traccar.helper.PatternBuilder; +import org.traccar.helper.UnitsConverter; +import org.traccar.model.Position; + +import java.net.SocketAddress; +import java.util.regex.Pattern; + +public class EsealProtocolDecoder extends BaseProtocolDecoder { + + private String config; + + public EsealProtocolDecoder(EsealProtocol protocol) { + super(protocol); + config = Context.getConfig().getString(getProtocolName() + ".config"); + } + + private static final Pattern PATTERN = new PatternBuilder() + .text("##S,") + .expression("[^,]+,") // device type + .number("(d+),") // device id + .number("d+,") // customer id + .expression("[^,]+,") // firmware version + .expression("([^,]+),") // type + .number("(d+),") // index + .number("(dddd)-(dd)-(dd),") // date + .number("(dd):(dd):(dd),") // time + .number("d+,") // interval + .expression("([AV]),") // validity + .number("(d+.d+)([NS]) ") // latitude + .number("(d+.d+)([EW]),") // longitude + .number("(d+),") // course + .number("(d+),") // speed + .expression("([^,]+),") // door + .number("(d+.d+),") // acceleration + .expression("([^,]+),") // nfc + .number("(d+.d+),") // battery + .number("(-?d+),") // rssi + .text("E##") + .compile(); + + private void sendResponse(Channel channel, String prefix, String type, String payload) { + if (channel != null) { + channel.write(prefix + type + "," + payload + ",E##\r\n"); + } + } + + private String decodeAlarm(String type) { + switch (type) { + case "Event-Door": + return Position.ALARM_DOOR; + case "Event-Shock": + return Position.ALARM_SHOCK; + case "Event-Drop": + return Position.ALARM_FALL_DOWN; + case "Event-Lock": + return Position.ALARM_LOCK; + case "Event-RC-Unlock": + return Position.ALARM_UNLOCK; + default: + return null; + } + } + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + String sentence = (String) msg; + 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()); + + String type = parser.next(); + String prefix = sentence.substring(0, sentence.indexOf(type)); + int index = parser.nextInt(); + + position.set(Position.KEY_INDEX, index); + position.set(Position.KEY_ALARM, decodeAlarm(type)); + + switch (type) { + case "Startup": + sendResponse(channel, prefix, type + " ACK", index + "," + config); + break; + case "Normal": + case "Termination": + case "Event-Door": + case "Event-Shock": + case "Event-Drop": + case "Event-Lock": + case "Event-RC-Unlock": + sendResponse(channel, prefix, type + " ACK", String.valueOf(index)); + break; + default: + break; + } + + position.setTime(parser.nextDateTime()); + position.setValid(parser.next().equals("A")); + position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setCourse(parser.nextInt()); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt())); + + switch (parser.next()) { + case "Open": + position.set(Position.KEY_DOOR, true); + break; + case "Close": + position.set(Position.KEY_DOOR, false); + break; + default: + break; + } + + position.set(Position.KEY_ACCELERATION, parser.nextDouble()); + position.set("nfc", parser.next()); + position.set(Position.KEY_BATTERY, parser.nextDouble()); + position.set(Position.KEY_RSSI, parser.nextInt()); + + return position; + } + +} diff --git a/test/org/traccar/protocol/EsealProtocolDecoderTest.java b/test/org/traccar/protocol/EsealProtocolDecoderTest.java new file mode 100644 index 000000000..c14652dd1 --- /dev/null +++ b/test/org/traccar/protocol/EsealProtocolDecoderTest.java @@ -0,0 +1,33 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class EsealProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + EsealProtocolDecoder decoder = new EsealProtocolDecoder(new EsealProtocol()); + + verifyPosition(decoder, text( + "##S,eSeal,1000821,256,3.0.6,Normal,34,2017-08-31,08:14:40,15,A,25.708828N 100.372870W,10,0,Close,0.71,0:0:3:0,3.8,-73,E##")); + + verifyPosition(decoder, text( + "##S,eSeal,1000821,256,3.0.6,Startup,1,2017-08-31,02:01:19,3,V,0.000000N 0.000000E,0,0,Close,3.25,0:0:5:0,3.8,-93,E##")); + + verifyNull(decoder, text( + "##S,eSeal,1000821,256,3.0.6,Startup OK,1,180,30,30,16,1,E##")); + + verifyNull(decoder, text( + "##S,eSeal,1000821,256,3.0.6,Startup OK,1,180,30,30,16,1,E##")); + + verifyPosition(decoder, text( + "##S,eSeal,1000898,256,3.0.6,Normal,6,2017-09-06,23:48:39,3,V,0.000000N 0.000000E,0,0,Close,1.0,0:0:3:0,4.0,-81,E##")); + + verifyNull(decoder, text( + "##S,eSeal,1000898,256,3.0.6,RC-NFC DEL ACK,,E##")); + + } + +} -- cgit v1.2.3 From 86ad45c63c9a9e9bee59a8cc621416e1396f9c89 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 11 Jun 2018 22:00:45 +1200 Subject: Implement Freematics UDP protocol --- setup/default.xml | 1 + src/org/traccar/protocol/FreematicsProtocol.java | 43 +++++++++ .../protocol/FreematicsProtocolDecoder.java | 103 +++++++++++++++++++++ .../protocol/FreematicsProtocolDecoderTest.java | 18 ++++ 4 files changed, 165 insertions(+) create mode 100644 src/org/traccar/protocol/FreematicsProtocol.java create mode 100644 src/org/traccar/protocol/FreematicsProtocolDecoder.java create mode 100644 test/org/traccar/protocol/FreematicsProtocolDecoderTest.java (limited to 'setup/default.xml') diff --git a/setup/default.xml b/setup/default.xml index 15d169f63..1ced20f38 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -245,5 +245,6 @@ 5167 5168 5169 + 5170 diff --git a/src/org/traccar/protocol/FreematicsProtocol.java b/src/org/traccar/protocol/FreematicsProtocol.java new file mode 100644 index 000000000..551c7e619 --- /dev/null +++ b/src/org/traccar/protocol/FreematicsProtocol.java @@ -0,0 +1,43 @@ +/* + * Copyright 2018 Anton Tananaev (anton@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; + +import java.util.List; + +public class FreematicsProtocol extends BaseProtocol { + + public FreematicsProtocol() { + super("freematics"); + } + + @Override + public void initTrackerServers(List serverList) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new FreematicsProtocolDecoder(FreematicsProtocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/FreematicsProtocolDecoder.java b/src/org/traccar/protocol/FreematicsProtocolDecoder.java new file mode 100644 index 000000000..66e451d6d --- /dev/null +++ b/src/org/traccar/protocol/FreematicsProtocolDecoder.java @@ -0,0 +1,103 @@ +/* + * Copyright 2018 Anton Tananaev (anton@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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.UnitsConverter; +import org.traccar.model.Position; + +import java.net.SocketAddress; +import java.util.Date; + +public class FreematicsProtocolDecoder extends BaseProtocolDecoder { + + public FreematicsProtocolDecoder(FreematicsProtocol protocol) { + super(protocol); + } + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + String sentence = (String) msg; + int startIndex = sentence.indexOf('#'); + int endIndex = sentence.indexOf('*'); + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, sentence.substring(0, startIndex)); + if (deviceSession == null) { + return null; + } + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + position.setValid(true); + + DateBuilder dateBuilder = new DateBuilder(new Date()); + + for (String pair : sentence.substring(startIndex + 1, endIndex).split(",")) { + String[] data = pair.split("="); + int key = Integer.parseInt(data[0], 16); + String value = data[1]; + switch (key) { + case 0x11: + value = ("000000" + value).substring(value.length()); + dateBuilder.setDateReverse( + Integer.parseInt(value.substring(0, 2)), + Integer.parseInt(value.substring(2, 4)), + Integer.parseInt(value.substring(4))); + break; + case 0x10: + value = ("00000000" + value).substring(value.length()); + dateBuilder.setTime( + Integer.parseInt(value.substring(0, 2)), + Integer.parseInt(value.substring(2, 4)), + Integer.parseInt(value.substring(4, 6)), + Integer.parseInt(value.substring(6)) * 10); + break; + case 0xA: + position.setLatitude(Double.parseDouble(value)); + break; + case 0xB: + position.setLongitude(Double.parseDouble(value)); + break; + case 0xC: + position.setAltitude(Integer.parseInt(value)); + break; + case 0xD: + position.setLatitude(UnitsConverter.knotsFromKph(Integer.parseInt(value))); + break; + case 0xE: + position.setCourse(Integer.parseInt(value)); + break; + case 0xF: + position.set(Position.KEY_SATELLITES, Integer.parseInt(value)); + break; + default: + position.set(data[0], value); + break; + } + + } + + position.setTime(dateBuilder.getDate()); + + return position; + } + +} diff --git a/test/org/traccar/protocol/FreematicsProtocolDecoderTest.java b/test/org/traccar/protocol/FreematicsProtocolDecoderTest.java new file mode 100644 index 000000000..f629f68df --- /dev/null +++ b/test/org/traccar/protocol/FreematicsProtocolDecoderTest.java @@ -0,0 +1,18 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class FreematicsProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + FreematicsProtocolDecoder decoder = new FreematicsProtocolDecoder(new FreematicsProtocol()); + + verifyPosition(decoder, text( + "1#0=68338,10D=79,30=1010,105=199,10C=4375,104=56,111=62,20=0;-1;95,10=6454200,A=-32.727482,B=150.150301,C=159,D=0,F=5,24=1250*7A")); + + } + +} -- cgit v1.2.3