From b19f1a505f7088ff48f467b32b5f1c207aa3be01 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 12 Jul 2017 14:22:03 +0500 Subject: - Handle rfid attributes and populate driverUniqueId - Add Driver Name to Trip report --- src/org/traccar/model/Position.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/org/traccar/model/Position.java') diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 5835310ae..97b3f365f 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -81,6 +81,8 @@ public class Position extends Message { public static final String KEY_RESULT = "result"; + public static final String KEY_DRIVER_UNIQUE_ID = "driverUniqueId"; + // Start with 1 not 0 public static final String PREFIX_TEMP = "temp"; public static final String PREFIX_ADC = "adc"; -- cgit v1.2.3 From 9949cadcdf3f07a4590742e2f0303d82efb653f9 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 14 Jul 2017 11:34:58 +0500 Subject: Save driver identification (rfid/ibutton etc.) as driverUniqueId attribute --- src/org/traccar/model/Position.java | 1 - src/org/traccar/protocol/AplicomProtocolDecoder.java | 2 +- src/org/traccar/protocol/AstraProtocolDecoder.java | 2 +- src/org/traccar/protocol/AtrackProtocolDecoder.java | 2 +- src/org/traccar/protocol/FifotrackProtocolDecoder.java | 2 +- src/org/traccar/protocol/Gl200ProtocolDecoder.java | 2 +- src/org/traccar/protocol/GnxProtocolDecoder.java | 2 +- src/org/traccar/protocol/Gps103ProtocolDecoder.java | 2 +- src/org/traccar/protocol/MegastekProtocolDecoder.java | 2 +- src/org/traccar/protocol/MeiligaoProtocolDecoder.java | 4 ++-- src/org/traccar/protocol/MeitrackProtocolDecoder.java | 2 +- src/org/traccar/protocol/MxtProtocolDecoder.java | 2 +- src/org/traccar/protocol/OsmAndProtocolDecoder.java | 2 +- src/org/traccar/protocol/Pt502ProtocolDecoder.java | 2 +- src/org/traccar/protocol/StarLinkProtocolDecoder.java | 2 +- src/org/traccar/protocol/Stl060ProtocolDecoder.java | 2 +- src/org/traccar/protocol/TeltonikaProtocolDecoder.java | 2 +- src/org/traccar/protocol/TmgProtocolDecoder.java | 2 +- src/org/traccar/protocol/UlbotechProtocolDecoder.java | 3 ++- src/org/traccar/protocol/VisiontekProtocolDecoder.java | 2 +- src/org/traccar/protocol/WialonProtocolDecoder.java | 2 +- test/org/traccar/ProtocolTest.java | 4 ++-- 22 files changed, 24 insertions(+), 24 deletions(-) (limited to 'src/org/traccar/model/Position.java') diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 97b3f365f..9e7bac932 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -49,7 +49,6 @@ public class Position extends Message { public static final String KEY_FUEL_LEVEL = "fuel"; // liters public static final String KEY_FUEL_CONSUMPTION = "fuelConsumption"; // liters/hour - public static final String KEY_RFID = "rfid"; public static final String KEY_VERSION_FW = "versionFw"; public static final String KEY_VERSION_HW = "versionHw"; public static final String KEY_TYPE = "type"; diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java index 448cd94fc..6f63d0c17 100644 --- a/src/org/traccar/protocol/AplicomProtocolDecoder.java +++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java @@ -263,7 +263,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } if ((selector & 0x0200) != 0) { - position.set(Position.KEY_RFID, + position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(((long) buf.readUnsignedShort()) << 32) + buf.readUnsignedInt()); } diff --git a/src/org/traccar/protocol/AstraProtocolDecoder.java b/src/org/traccar/protocol/AstraProtocolDecoder.java index ea6aa7b30..8d86cd2be 100644 --- a/src/org/traccar/protocol/AstraProtocolDecoder.java +++ b/src/org/traccar/protocol/AstraProtocolDecoder.java @@ -105,7 +105,7 @@ public class AstraProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // geofence events if (BitUtil.check(status, 8)) { - position.set(Position.KEY_RFID, buf.readBytes(7).toString(StandardCharsets.US_ASCII)); + position.set(Position.KEY_DRIVER_UNIQUE_ID, buf.readBytes(7).toString(StandardCharsets.US_ASCII)); position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium() * 1000); position.set(Position.KEY_HOURS, buf.readUnsignedShort()); } diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java index 79b3c36cc..23cb67e15 100644 --- a/src/org/traccar/protocol/AtrackProtocolDecoder.java +++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java @@ -327,7 +327,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_OUTPUT, buf.readUnsignedByte()); position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort() * 0.001); - position.set("driver", readString(buf)); + position.set(Position.KEY_DRIVER_UNIQUE_ID, readString(buf)); position.set(Position.PREFIX_TEMP + 1, buf.readShort() * 0.1); position.set(Position.PREFIX_TEMP + 2, buf.readShort() * 0.1); diff --git a/src/org/traccar/protocol/FifotrackProtocolDecoder.java b/src/org/traccar/protocol/FifotrackProtocolDecoder.java index f8f4fb078..304f6a2c3 100644 --- a/src/org/traccar/protocol/FifotrackProtocolDecoder.java +++ b/src/org/traccar/protocol/FifotrackProtocolDecoder.java @@ -110,7 +110,7 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder { position.set(Position.PREFIX_ADC + (i + 1), Integer.parseInt(adc[i], 16)); } - position.set(Position.KEY_RFID, parser.next()); + position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next()); if (parser.hasNext()) { String[] sensors = parser.next().split("\\|"); diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index a3062c942..140d3300a 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -644,7 +644,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { return null; } - position.set(Position.KEY_RFID, parser.next()); + position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next()); decodeLocation(position, parser); diff --git a/src/org/traccar/protocol/GnxProtocolDecoder.java b/src/org/traccar/protocol/GnxProtocolDecoder.java index 070d394e8..2274ec164 100644 --- a/src/org/traccar/protocol/GnxProtocolDecoder.java +++ b/src/org/traccar/protocol/GnxProtocolDecoder.java @@ -102,7 +102,7 @@ public class GnxProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); if (type.equals("MIF")) { - position.set(Position.KEY_RFID, parser.next()); + position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next()); } return position; diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index f5ba3cff7..a9a72b110 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -258,7 +258,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { String rfid = parser.next(); if (alarm.equals("rfid")) { - position.set(Position.KEY_RFID, rfid); + position.set(Position.KEY_DRIVER_UNIQUE_ID, rfid); } String utcHours = parser.next(); diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index 15a384cc0..994e2d983 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -327,7 +327,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { } } - position.set(Position.KEY_RFID, parser.next()); + position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next()); String battery = parser.next(); if (battery != null) { diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index 77e117262..dbbf61f71 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -253,7 +253,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { } if (parser.hasNext()) { - position.set(Position.KEY_RFID, String.valueOf(parser.nextHexInt(0))); + position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(parser.nextHexInt(0))); } return position; @@ -370,7 +370,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { if (rfid != 0) { String card = String.format("%010d", rfid); position.set("card" + (i + 1), card); - position.set(Position.KEY_RFID, card); + position.set(Position.KEY_DRIVER_UNIQUE_ID, card); } } } diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index 38ecde519..711697fc4 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -201,7 +201,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { if (eventData != null && !eventData.isEmpty()) { switch (event) { case 37: - position.set(Position.KEY_RFID, eventData); + position.set(Position.KEY_DRIVER_UNIQUE_ID, eventData); break; default: position.set("eventData", eventData); diff --git a/src/org/traccar/protocol/MxtProtocolDecoder.java b/src/org/traccar/protocol/MxtProtocolDecoder.java index 49987ce57..6d82e4a4b 100644 --- a/src/org/traccar/protocol/MxtProtocolDecoder.java +++ b/src/org/traccar/protocol/MxtProtocolDecoder.java @@ -159,7 +159,7 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder { } if (BitUtil.check(infoGroups, 7)) { - position.set(Position.KEY_RFID, buf.readUnsignedInt()); + position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedInt())); } buf.readerIndex(buf.writerIndex() - 3); diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java index 20cd54b2f..cb324aa86 100644 --- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java +++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java @@ -129,7 +129,7 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_BATTERY_LEVEL, Double.parseDouble(value)); break; case "rfid": - position.set(Position.KEY_RFID, value); + position.set(Position.KEY_DRIVER_UNIQUE_ID, value); break; default: try { diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index b1851f8ca..e12bbdf28 100644 --- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java @@ -129,7 +129,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { } position.set(Position.KEY_ODOMETER, parser.nextInt(0)); - position.set(Position.KEY_RFID, parser.next()); + position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next()); if (parser.hasNext()) { int value = parser.nextHexInt(0); diff --git a/src/org/traccar/protocol/StarLinkProtocolDecoder.java b/src/org/traccar/protocol/StarLinkProtocolDecoder.java index e90dde455..38f6980f6 100644 --- a/src/org/traccar/protocol/StarLinkProtocolDecoder.java +++ b/src/org/traccar/protocol/StarLinkProtocolDecoder.java @@ -196,7 +196,7 @@ public class StarLinkProtocolDecoder extends BaseProtocolDecoder { if (rfid.matches("0+")) { rfid = data[data.length - 2]; } - position.set(Position.KEY_RFID, rfid); + position.set(Position.KEY_DRIVER_UNIQUE_ID, rfid); } return position; diff --git a/src/org/traccar/protocol/Stl060ProtocolDecoder.java b/src/org/traccar/protocol/Stl060ProtocolDecoder.java index c81e83aab..26817a5c8 100644 --- a/src/org/traccar/protocol/Stl060ProtocolDecoder.java +++ b/src/org/traccar/protocol/Stl060ProtocolDecoder.java @@ -104,7 +104,7 @@ public class Stl060ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_CHARGE, parser.nextInt(0) == 1); position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1); position.set(Position.KEY_INPUT, parser.nextInt(0)); - position.set(Position.KEY_RFID, parser.next()); + position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next()); position.set(Position.KEY_ODOMETER, parser.nextInt(0)); position.set(Position.PREFIX_TEMP + 1, parser.nextInt(0)); position.set(Position.KEY_FUEL_LEVEL, parser.nextInt(0)); diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index f1fd55d98..72e06c083 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -114,7 +114,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { position.set(Position.PREFIX_TEMP + 3, readValue(buf, length, true) * 0.1); break; case 78: - position.set(Position.KEY_RFID, String.valueOf(readValue(buf, length, false))); + position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(readValue(buf, length, false))); break; case 182: position.set(Position.KEY_HDOP, readValue(buf, length, false) * 0.1); diff --git a/src/org/traccar/protocol/TmgProtocolDecoder.java b/src/org/traccar/protocol/TmgProtocolDecoder.java index c10523117..b8458dd52 100644 --- a/src/org/traccar/protocol/TmgProtocolDecoder.java +++ b/src/org/traccar/protocol/TmgProtocolDecoder.java @@ -144,7 +144,7 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder { position.set(Position.PREFIX_ADC + 1, parser.nextDouble(0)); position.set(Position.PREFIX_ADC + 2, parser.nextDouble(0)); position.set(Position.KEY_VERSION_FW, parser.next()); - position.set(Position.KEY_RFID, parser.next()); + position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next()); return position; } diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java index 1b22eeb75..31a3d2cfe 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java @@ -308,7 +308,8 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { break; case DATA_RFID: - position.set(Position.KEY_RFID, buf.readBytes(length - 1).toString(StandardCharsets.US_ASCII)); + position.set(Position.KEY_DRIVER_UNIQUE_ID, + buf.readBytes(length - 1).toString(StandardCharsets.US_ASCII)); position.set("authorized", buf.readUnsignedByte() != 0); break; diff --git a/src/org/traccar/protocol/VisiontekProtocolDecoder.java b/src/org/traccar/protocol/VisiontekProtocolDecoder.java index 636a3d640..f32c9fbfe 100644 --- a/src/org/traccar/protocol/VisiontekProtocolDecoder.java +++ b/src/org/traccar/protocol/VisiontekProtocolDecoder.java @@ -130,7 +130,7 @@ public class VisiontekProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.next().equals("A")); - position.set(Position.KEY_RFID, parser.next()); + position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next()); return position; } diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java index 82098413b..4eb3b9b8e 100644 --- a/src/org/traccar/protocol/WialonProtocolDecoder.java +++ b/src/org/traccar/protocol/WialonProtocolDecoder.java @@ -109,7 +109,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { } } - position.set(Position.KEY_RFID, parser.next()); + position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next()); if (parser.hasNext()) { String[] values = parser.next().split(","); diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java index dc4f70981..cb9cdf759 100644 --- a/test/org/traccar/ProtocolTest.java +++ b/test/org/traccar/ProtocolTest.java @@ -245,8 +245,8 @@ public class ProtocolTest extends BaseTest { Assert.assertTrue(attributes.get(Position.KEY_ARCHIVE) instanceof Boolean); } - if (attributes.containsKey(Position.KEY_RFID)) { - Assert.assertTrue(attributes.get(Position.KEY_RFID) instanceof String); + if (attributes.containsKey(Position.KEY_DRIVER_UNIQUE_ID)) { + Assert.assertTrue(attributes.get(Position.KEY_DRIVER_UNIQUE_ID) instanceof String); } if (position.getNetwork() != null && position.getNetwork().getCellTowers() != null) { -- cgit v1.2.3 From a7c2aa4a3faddb007a82523b2119134eaa45bea7 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 18 Jul 2017 07:28:00 +1200 Subject: Implement additional Syrus data --- src/org/traccar/model/Position.java | 1 + src/org/traccar/protocol/TaipProtocolDecoder.java | 40 +++++++++++++++++----- .../traccar/protocol/TaipProtocolDecoderTest.java | 3 ++ 3 files changed, 36 insertions(+), 8 deletions(-) (limited to 'src/org/traccar/model/Position.java') diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 9e7bac932..4412b012c 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -111,6 +111,7 @@ public class Position extends Message { public static final String ALARM_TOW = "tow"; public static final String ALARM_ACCELERATION = "hardAcceleration"; public static final String ALARM_BREAKING = "hardBreaking"; + public static final String ALARM_CORNERING = "hardCornering"; public static final String ALARM_FATIGUE_DRIVING = "fatigueDriving"; public static final String ALARM_POWER_CUT = "powerCut"; public static final String ALARM_POWER_RESTORED = "powerRestored"; diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java index a08bb6f2b..6edf4a93e 100644 --- a/src/org/traccar/protocol/TaipProtocolDecoder.java +++ b/src/org/traccar/protocol/TaipProtocolDecoder.java @@ -18,6 +18,7 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; +import org.traccar.helper.BitUtil; import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.DateUtil; @@ -118,7 +119,24 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { } if (event != null) { - position.set(Position.KEY_EVENT, event); + switch (event) { + case 22: + position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); + break; + case 23: + position.set(Position.KEY_ALARM, Position.ALARM_BREAKING); + break; + case 24: + position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); + break; + case 26: + case 28: + position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); + break; + default: + position.set(Position.KEY_EVENT, event); + break; + } } if (parser.hasNext(6)) { @@ -173,7 +191,6 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { String key = attribute.substring(0, index).toLowerCase(); String value = attribute.substring(index + 1); switch (key) { - case "id": uniqueId = value; deviceSession = getDeviceSession(channel, remoteAddress, value); @@ -181,23 +198,30 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); } break; - + case "io": + position.set(Position.KEY_IGNITION, BitUtil.check(value.charAt(0) - '0', 0)); + position.set(Position.KEY_CHARGE, BitUtil.check(value.charAt(0) - '0', 1)); + position.set(Position.KEY_OUTPUT, value.charAt(1) - '0'); + position.set(Position.KEY_INPUT, value.charAt(2) - '0'); + break; + case "ix": + position.set(Position.PREFIX_IO + 1, value); + break; + case "ad": + position.set(Position.PREFIX_ADC + 1, Integer.parseInt(value)); + break; case "sv": position.set(Position.KEY_SATELLITES, Integer.parseInt(value)); break; - case "bl": - position.set(Position.KEY_BATTERY, Integer.parseInt(value)); + position.set(Position.KEY_BATTERY, Integer.parseInt(value) * 0.001); break; - case "vo": position.set(Position.KEY_ODOMETER, Long.parseLong(value)); break; - default: position.set(key, value); break; - } } else if (attribute.startsWith("#")) { messageIndex = attribute; diff --git a/test/org/traccar/protocol/TaipProtocolDecoderTest.java b/test/org/traccar/protocol/TaipProtocolDecoderTest.java index 6d24a504f..e2de26ec0 100644 --- a/test/org/traccar/protocol/TaipProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TaipProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class TaipProtocolDecoderTest extends ProtocolTest { TaipProtocolDecoder decoder = new TaipProtocolDecoder(new TaipProtocol()); + verifyPosition(decoder, text( + ">REV001958003965+0307178+1016144900031532;IO=300;SV=8;BL=4159;CF=8161,C,13;AD=14145;IX=10233040;FF=0,0,0,0;VO=338578;ID=357042063052352<")); + verifyPosition(decoder, text( ">REV011958000369+0307185+1016144400000032;IO=200;SV=9;BL=4158;CF=0,0,0;AD=12347;IX=10213040;FF=0,0,0,0;VO=338572;ID=357042063052352<")); -- cgit v1.2.3 From ae76cbf971bfc9e47ef21e87606dacc7c0e3ddc6 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 31 Jul 2017 14:08:36 +0500 Subject: Implement SQL requests construction --- schema/changelog-3.14.xml | 4 +- setup/default.xml | 406 +-------------------- src/org/traccar/Config.java | 4 + src/org/traccar/api/resource/EventResource.java | 2 +- src/org/traccar/api/resource/PositionResource.java | 2 +- src/org/traccar/database/DataManager.java | 210 ++++++++--- src/org/traccar/database/QueryAdditional.java | 27 ++ src/org/traccar/database/StatisticsManager.java | 2 +- src/org/traccar/model/Device.java | 7 + src/org/traccar/model/Position.java | 9 + src/org/traccar/model/Server.java | 2 + src/org/traccar/model/User.java | 6 + test/org/traccar/database/DataManagerTest.java | 79 ++++ 13 files changed, 299 insertions(+), 461 deletions(-) create mode 100644 src/org/traccar/database/QueryAdditional.java create mode 100644 test/org/traccar/database/DataManagerTest.java (limited to 'src/org/traccar/model/Position.java') diff --git a/schema/changelog-3.14.xml b/schema/changelog-3.14.xml index 7965bc020..f6cda4c1f 100644 --- a/schema/changelog-3.14.xml +++ b/schema/changelog-3.14.xml @@ -61,5 +61,7 @@ + + - \ No newline at end of file + diff --git a/setup/default.xml b/setup/default.xml index f0f9ef4a3..ea8c32fbd 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -29,163 +29,16 @@ true ./schema/changelog-master.xml - - - SELECT * FROM server - - - - UPDATE server SET - registration = :registration, - readonly = :readonly, - deviceReadonly = :deviceReadonly, - map = :map, - bingKey = :bingKey, - mapUrl = :mapUrl, - distanceUnit = :distanceUnit, - speedUnit = :speedUnit, - latitude = :latitude, - longitude = :longitude, - zoom = :zoom, - twelveHourFormat = :twelveHourFormat, - coordinateFormat = :coordinateFormat, - forceSettings = :forceSettings, - timezone = :timezone, - attributes = :attributes - WHERE id = :id - - + SELECT * FROM users WHERE email = :email - - SELECT * FROM users - - - - INSERT INTO users (name, email, phone, hashedPassword, salt, readonly, admin, map, distanceUnit, speedUnit, latitude, longitude, zoom, twelveHourFormat, coordinateFormat, disabled, expirationTime, deviceLimit, userLimit, deviceReadonly, token, timezone, attributes) - VALUES (:name, :email, :phone, :hashedPassword, :salt, :readonly, :admin, :map, :distanceUnit, :speedUnit, :latitude, :longitude, :zoom, :twelveHourFormat, :coordinateFormat, :disabled, :expirationTime, :deviceLimit, :userLimit, :deviceReadonly, :token, :timezone, :attributes) - - - - UPDATE users SET - name = :name, - email = :email, - phone = :phone, - readonly = :readonly, - admin = :admin, - map = :map, - distanceUnit = :distanceUnit, - speedUnit = :speedUnit, - latitude = :latitude, - longitude = :longitude, - zoom = :zoom, - twelveHourFormat = :twelveHourFormat, - coordinateFormat = :coordinateFormat, - disabled = :disabled, - expirationTime = :expirationTime, - deviceLimit = :deviceLimit, - userLimit = :userLimit, - deviceReadonly = :deviceReadonly, - token = :token, - timezone = :timezone, - attributes = :attributes - WHERE id = :id - - - - UPDATE users SET hashedPassword = :hashedPassword, salt = :salt WHERE id = :id - - - - DELETE FROM users WHERE id = :id - - - - SELECT userId, deviceId FROM user_device - - - - SELECT userId, groupId FROM user_group - - - - SELECT * FROM devices - - - - INSERT INTO devices (name, uniqueId, groupId, attributes, phone, model, contact, category) - VALUES (:name, :uniqueId, :groupId, :attributes, :phone, :model, :contact, :category) - - - - UPDATE devices SET - name = :name, - uniqueId = :uniqueId, - groupId = :groupId, - attributes = :attributes, - phone = :phone, - model = :model, - contact = :contact, - category = :category - WHERE id = :id - - - - UPDATE devices SET lastUpdate = :lastUpdate WHERE id = :id - - - - DELETE FROM devices WHERE id = :id - - - - INSERT INTO user_device (userId, deviceId) VALUES (:userId, :deviceId) - - - - DELETE FROM user_device WHERE userId = :userId AND deviceId = :deviceId - - - - SELECT * FROM groups - - - - INSERT INTO groups (name, groupId, attributes) VALUES (:name, :groupId, :attributes) - - - - UPDATE groups SET name = :name, groupId = :groupId, attributes = :attributes WHERE id = :id - - - - DELETE FROM groups WHERE id = :id - - - - INSERT INTO user_group (userId, groupId) VALUES (:userId, :groupId) - - - - DELETE FROM user_group WHERE userId = :userId AND groupId = :groupId - - SELECT * FROM positions WHERE deviceId = :deviceId AND fixTime BETWEEN :from AND :to ORDER BY fixTime - - SELECT * FROM positions WHERE id = :id - - - - INSERT INTO positions (deviceId, protocol, serverTime, deviceTime, fixTime, valid, latitude, longitude, altitude, speed, course, address, attributes, accuracy, network) - VALUES (:deviceId, :protocol, :now, :deviceTime, :fixTime, :valid, :latitude, :longitude, :altitude, :speed, :course, :address, :attributes, :accuracy, :network) - - SELECT positions.* FROM positions INNER JOIN devices ON positions.id = devices.positionid; @@ -194,102 +47,10 @@ UPDATE devices SET positionId = :id WHERE id = :deviceId - - SELECT * FROM events WHERE id = :id - - - - INSERT INTO events (type, serverTime, deviceId, positionId, geofenceId, attributes) - VALUES (:type, :serverTime, :deviceId, :positionId, :geofenceId, :attributes) - - SELECT * FROM events WHERE deviceId = :deviceId AND serverTime BETWEEN :from AND :to ORDER BY serverTime - - SELECT * FROM geofences - - - - INSERT INTO geofences (name, description, calendarid, area, attributes) - VALUES (:name, :description, :calendarid, :area, :attributes) - - - - UPDATE geofences SET - name = :name, - description = :description, - calendarid = :calendarid, - area = :area, - attributes = :attributes - WHERE id = :id - - - - DELETE FROM geofences WHERE id = :id - - - - SELECT userId, geofenceId FROM user_geofence - - - - INSERT INTO user_geofence (userId, geofenceId) VALUES (:userId, :geofenceId) - - - - DELETE FROM user_geofence WHERE userId = :userId AND geofenceId = :geofenceId - - - - SELECT groupId, geofenceId FROM group_geofence - - - - INSERT INTO group_geofence (groupId, geofenceId) VALUES (:groupId, :geofenceId) - - - - DELETE FROM group_geofence WHERE groupId = :groupId AND geofenceId = :geofenceId - - - - SELECT deviceId, geofenceId FROM device_geofence - - - - INSERT INTO device_geofence (deviceId, geofenceId) VALUES (:deviceId, :geofenceId) - - - - DELETE FROM device_geofence WHERE deviceId = :deviceId AND geofenceId = :geofenceId - - - - SELECT * FROM notifications - - - - INSERT INTO notifications (userId, type, web, mail, sms, attributes) - VALUES (:userId, :type, :web, :mail, :sms, :attributes) - - - - UPDATE notifications SET - userId = :userId, - type = :type, - web = :web, - mail = :mail, - sms = :sms, - attributes = :attributes - WHERE id = :id - - - - DELETE FROM notifications WHERE id = :id - - DELETE FROM positions WHERE serverTime < :serverTime AND id NOT IN (SELECT positionId FROM devices) @@ -323,171 +84,6 @@ SELECT * FROM statistics WHERE captureTime BETWEEN :from AND :to ORDER BY captureTime - - INSERT INTO statistics (captureTime, activeUsers, activeDevices, requests, messagesReceived, messagesStored, mailSent, smsSent, geocoderRequests, geolocationRequests, attributes) - VALUES (:captureTime, :activeUsers, :activeDevices, :requests, :messagesReceived, :messagesStored, :mailSent, :smsSent, :geocoderRequests, :geolocationRequests, :attributes) - - - - SELECT * FROM calendars - - - - INSERT INTO calendars (name, data, attributes) - VALUES (:name, :data, :attributes) - - - - UPDATE calendars SET - name = :name, - data = :data, - attributes = :attributes - WHERE id = :id - - - - DELETE FROM calendars WHERE id = :id - - - - SELECT userId, calendarId FROM user_calendar - - - - INSERT INTO user_calendar (userId, calendarId) VALUES (:userId, :calendarId) - - - - DELETE FROM user_calendar WHERE userId = :userId AND calendarId = :calendarId - - - - SELECT userId, managedUserId FROM user_user - - - - INSERT INTO user_user (userId, managedUserId) VALUES (:userId, :managedUserId) - - - - DELETE FROM user_user WHERE userId = :userId AND managedUserId = :managedUserId - - - - SELECT * FROM attributes - - - - INSERT INTO attributes (description, type, attribute, expression) - VALUES (:description, :type, :attribute, :expression) - - - - UPDATE attributes SET - description = :description, - type = :type, - attribute = :attribute, - expression = :expression - WHERE id = :id - - - - DELETE FROM attributes WHERE id = :id - - - - SELECT userId, attributeId FROM user_attribute - - - - INSERT INTO user_attribute (userId, attributeId) VALUES (:userId, :attributeId) - - - - DELETE FROM user_attribute WHERE userId = :userId AND attributeId = :attributeId - - - - SELECT groupId, attributeId FROM group_attribute - - - - INSERT INTO group_attribute (groupId, attributeId) VALUES (:groupId, :attributeId) - - - - DELETE FROM group_attribute WHERE groupId = :groupId AND attributeId = :attributeId - - - - SELECT deviceId, attributeId FROM device_attribute - - - - INSERT INTO device_attribute (deviceId, attributeId) VALUES (:deviceId, :attributeId) - - - - DELETE FROM device_attribute WHERE deviceId = :deviceId AND attributeId = :attributeId - - - - SELECT * FROM drivers - - - - INSERT INTO drivers (name, uniqueId, attributes) - VALUES (:name, :uniqueId, :attributes) - - - - UPDATE drivers SET - name = :name, - uniqueId = :uniqueId, - attributes = :attributes - WHERE id = :id - - - - DELETE FROM drivers WHERE id = :id - - - - SELECT userId, driverId FROM user_driver - - - - INSERT INTO user_driver (userId, driverId) VALUES (:userId, :driverId) - - - - DELETE FROM user_driver WHERE userId = :userId AND driverId = :driverId - - - - SELECT groupId, driverId FROM group_driver - - - - INSERT INTO group_driver (groupId, driverId) VALUES (:groupId, :driverId) - - - - DELETE FROM group_driver WHERE groupId = :groupId AND driverId = :driverId - - - - SELECT deviceId, driverId FROM device_driver - - - - INSERT INTO device_driver (deviceId, driverId) VALUES (:deviceId, :driverId) - - - - DELETE FROM device_driver WHERE deviceId = :deviceId AND driverId = :driverId - - 5001 diff --git a/src/org/traccar/Config.java b/src/org/traccar/Config.java index 0bc3cafaa..a0f3f8c2e 100644 --- a/src/org/traccar/Config.java +++ b/src/org/traccar/Config.java @@ -96,4 +96,8 @@ public class Config { return key.replaceAll("\\.", "_").replaceAll("(\\p{Lu})", "_$1").toUpperCase(); } + public void setString(String key, String value) { + properties.putIfAbsent(key, value); + } + } diff --git a/src/org/traccar/api/resource/EventResource.java b/src/org/traccar/api/resource/EventResource.java index b7fda6f73..a7cf9edbd 100644 --- a/src/org/traccar/api/resource/EventResource.java +++ b/src/org/traccar/api/resource/EventResource.java @@ -23,7 +23,7 @@ public class EventResource extends BaseResource { @Path("{id}") @GET public Event get(@PathParam("id") long id) throws SQLException { - Event event = Context.getDataManager().getEvent(id); + Event event = Context.getDataManager().getObject(Event.class, id); Context.getPermissionsManager().checkDevice(getUserId(), event.getDeviceId()); if (event.getGeofenceId() != 0) { Context.getPermissionsManager().checkPermission(Geofence.class, getUserId(), event.getGeofenceId()); diff --git a/src/org/traccar/api/resource/PositionResource.java b/src/org/traccar/api/resource/PositionResource.java index 6dab51744..c031b842f 100644 --- a/src/org/traccar/api/resource/PositionResource.java +++ b/src/org/traccar/api/resource/PositionResource.java @@ -54,7 +54,7 @@ public class PositionResource extends BaseResource { if (!positionIds.isEmpty()) { ArrayList positions = new ArrayList<>(); for (Long positionId : positionIds) { - Position position = Context.getDataManager().getPosition(positionId); + Position position = Context.getDataManager().getObject(Position.class, positionId); Context.getPermissionsManager().checkDevice(getUserId(), position.getDeviceId()); positions.add(position); } diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 07ad0be44..a753c311b 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -21,8 +21,11 @@ import java.net.URL; import java.net.URLClassLoader; import java.sql.SQLException; import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Collection; import java.util.Date; +import java.util.HashSet; +import java.util.Set; import javax.naming.InitialContext; import javax.sql.DataSource; @@ -58,6 +61,12 @@ import com.zaxxer.hikari.HikariDataSource; public class DataManager { + public static final String ACTION_SELECT_ALL = "selectAll"; + public static final String ACTION_SELECT = "select"; + public static final String ACTION_INSERT = "insert"; + public static final String ACTION_UPDATE = "update"; + public static final String ACTION_DELETE = "delete"; + private final Config config; private DataSource dataSource; @@ -115,6 +124,73 @@ public class DataManager { } } + public static String constructObjectQuery(String action, Class clazz, boolean additional) { + switch (action) { + case ACTION_INSERT: + case ACTION_UPDATE: + StringBuilder result = new StringBuilder(); + StringBuilder fields = new StringBuilder(); + StringBuilder values = new StringBuilder(); + + Set methods = new HashSet<>(Arrays.asList(clazz.getMethods())); + methods.removeAll(Arrays.asList(Object.class.getMethods())); + methods.removeAll(Arrays.asList(BaseModel.class.getMethods())); + for (Method method : methods) { + if (method.getName().startsWith("get") && method.getParameterTypes().length == 0 + && (additional ? method.isAnnotationPresent(QueryAdditional.class) + : !method.isAnnotationPresent(QueryIgnore.class) + && !method.isAnnotationPresent(QueryAdditional.class))) { + String name = method.getName().substring(3, 4).toLowerCase() + + method.getName().substring(4); + if (action.equals(ACTION_INSERT)) { + fields.append(name).append(", "); + values.append(":").append(name).append(", "); + } else { + fields.append(name).append(" = :").append(name).append(",\n"); + } + } + } + fields.setLength(fields.length() - 2); + if (action.equals(ACTION_INSERT)) { + values.setLength(values.length() - 2); + result.append("INSERT INTO ").append(getObjectsTableName(clazz)).append(" ("); + result.append(fields).append(")\n"); + result.append("VALUES (").append(values).append(")"); + } else { + result.append("UPDATE ").append(getObjectsTableName(clazz)).append(" SET\n"); + result.append(fields); + result.append("\nWHERE id = :id"); + } + return result.toString(); + case ACTION_SELECT_ALL: + return "SELECT * FROM " + getObjectsTableName(clazz); + case ACTION_SELECT: + return "SELECT * FROM " + getObjectsTableName(clazz) + " WHERE id = :id"; + case ACTION_DELETE: + return "DELETE FROM " + getObjectsTableName(clazz) + " WHERE id = :id"; + default: + throw new IllegalArgumentException("Unknown action"); + } + } + + public static String constructPermissionQuery(String action, Class owner, Class property) { + switch (action) { + case ACTION_SELECT_ALL: + return "SELECT " + makeNameId(owner) + ", " + makeNameId(property) + " FROM " + + getPermissionsTableName(owner, property); + case ACTION_INSERT: + return "INSERT INTO " + getPermissionsTableName(owner, property) + + " (" + makeNameId(owner) + ", " + makeNameId(property) + ") VALUES (:" + + makeNameId(owner) + ", :" + makeNameId(property) + ")"; + case ACTION_DELETE: + return "DELETE FROM " + getPermissionsTableName(owner, property) + + " WHERE " + makeNameId(owner) + " = :" + makeNameId(owner) + + " AND " + makeNameId(property) + " = :" + makeNameId(property); + default: + throw new IllegalArgumentException("Unknown action"); + } + } + private String getQuery(String key) { String query = config.getString(key); if (query == null) { @@ -123,6 +199,59 @@ public class DataManager { return query; } + public String getQuery(String action, Class clazz) { + return getQuery(action, clazz, false); + } + + public String getQuery(String action, Class clazz, boolean additional) { + String queryName; + if (action.equals(ACTION_SELECT_ALL)) { + queryName = "database.select" + clazz.getSimpleName() + "s"; + } else { + queryName = "database." + action.toLowerCase() + clazz.getSimpleName(); + } + String query = config.getString(queryName); + if (query == null) { + query = constructObjectQuery(action, clazz, additional); + config.setString(queryName, query); + } + + return query; + } + + public String getQuery(String action, Class owner, Class property) { + String queryName; + if (action.equals(ACTION_SELECT_ALL)) { + queryName = "database.select" + owner.getSimpleName() + property.getSimpleName() + "s"; + } else if (action.equals(ACTION_INSERT)) { + queryName = "database.link" + owner.getSimpleName() + property.getSimpleName(); + } else { + queryName = "database.unlink" + owner.getSimpleName() + property.getSimpleName(); + } + String query = config.getString(queryName); + if (query == null) { + query = constructPermissionQuery(action, owner, property.equals(User.class) ? ManagedUser.class : property); + config.setString(queryName, query); + } + + return query; + } + + private static String getPermissionsTableName(Class owner, Class property) { + String ownerName = owner.getSimpleName(); + String propertyName = property.getSimpleName(); + if (propertyName.equals("ManagedUser")) { + propertyName = "User"; + } + return ownerName.substring(0, 1).toLowerCase() + ownerName.substring(1) + "_" + + propertyName.substring(0, 1).toLowerCase() + propertyName.substring(1); + } + + private static String getObjectsTableName(Class clazz) { + String name = clazz.getSimpleName(); + return name.substring(0, 1).toLowerCase() + name.substring(1) + "s"; + } + private void initDatabaseSchema() throws SQLException, LiquibaseException { if (config.hasKey("database.changelog")) { @@ -155,19 +284,8 @@ public class DataManager { } } - public void updateUser(User user) throws SQLException { - QueryBuilder.create(dataSource, getQuery("database.updateUser")) - .setObject(user) - .executeUpdate(); - if (user.getHashedPassword() != null) { - QueryBuilder.create(dataSource, getQuery("database.updateUserPassword")) - .setObject(user) - .executeUpdate(); - } - } - public void updateDeviceStatus(Device device) throws SQLException { - QueryBuilder.create(dataSource, getQuery("database.updateDeviceStatus")) + QueryBuilder.create(dataSource, getQuery(ACTION_UPDATE, Device.class, true)) .setObject(device) .executeUpdate(); } @@ -180,16 +298,10 @@ public class DataManager { .executeQuery(Position.class); } - public Position getPosition(long positionId) throws SQLException { - return QueryBuilder.create(dataSource, getQuery("database.selectPosition")) - .setLong("id", positionId) - .executeQuerySingle(Position.class); - } - public void addPosition(Position position) throws SQLException { - position.setId(QueryBuilder.create(dataSource, getQuery("database.insertPosition"), true) - .setDate("now", new Date()) + position.setId(QueryBuilder.create(dataSource, getQuery(ACTION_INSERT, Position.class), true) .setObject(position) + .setDate("serverTime", new Date()) .executeUpdate()); } @@ -220,16 +332,10 @@ public class DataManager { } public Server getServer() throws SQLException { - return QueryBuilder.create(dataSource, getQuery("database.selectServers")) + return QueryBuilder.create(dataSource, getQuery(ACTION_SELECT_ALL, Server.class)) .executeQuerySingle(Server.class); } - public Event getEvent(long eventId) throws SQLException { - return QueryBuilder.create(dataSource, getQuery("database.selectEvent")) - .setLong("id", eventId) - .executeQuerySingle(Event.class); - } - public Collection getEvents(long deviceId, Date from, Date to) throws SQLException { return QueryBuilder.create(dataSource, getQuery("database.selectEvents")) .setLong("deviceId", deviceId) @@ -268,12 +374,6 @@ public class DataManager { .executeQuery(Statistics.class); } - public void addStatistics(Statistics statistics) throws SQLException { - statistics.setId(QueryBuilder.create(dataSource, getQuery("database.insertStatistics"), true) - .setObject(statistics) - .executeUpdate()); - } - public static Class getClassByName(String name) throws ClassNotFoundException { switch (name.toLowerCase().replace("id", "")) { case "device": @@ -302,44 +402,50 @@ public class DataManager { return name.substring(0, 1).toLowerCase() + name.substring(1) + (name.indexOf("Id") == -1 ? "Id" : ""); } + public Collection getPermissions(Class owner, Class property) + throws SQLException, ClassNotFoundException { + return QueryBuilder.create(dataSource, getQuery(ACTION_SELECT_ALL, owner, property)) + .executePermissionsQuery(); + } + public void linkObject(Class owner, long ownerId, Class property, long propertyId, boolean link) throws SQLException { - String query = "database." + (link ? "link" : "unlink") + owner.getSimpleName() + property.getSimpleName(); - QueryBuilder queryBuilder = QueryBuilder.create(dataSource, getQuery(query)); - - queryBuilder.setLong(makeNameId(owner), ownerId); - queryBuilder.setLong(makeNameId(property), propertyId); - queryBuilder.executeUpdate(); + QueryBuilder.create(dataSource, getQuery(link ? ACTION_INSERT : ACTION_DELETE, owner, property)) + .setLong(makeNameId(owner), ownerId) + .setLong(makeNameId(property), propertyId) + .executeUpdate(); } - public Collection getObjects(Class clazz) throws SQLException { - String query = "database.select" + clazz.getSimpleName() + "s"; - return QueryBuilder.create(dataSource, getQuery(query)).executeQuery(clazz); + public T getObject(Class clazz, long entityId) throws SQLException { + return QueryBuilder.create(dataSource, getQuery(ACTION_SELECT, clazz)) + .setLong("id", entityId) + .executeQuerySingle(clazz); } - public Collection getPermissions(Class owner, - Class property) throws SQLException, ClassNotFoundException { - String query = "database.select" + owner.getSimpleName() + property.getSimpleName() + "s"; - return QueryBuilder.create(dataSource, getQuery(query)).executePermissionsQuery(); + public Collection getObjects(Class clazz) throws SQLException { + return QueryBuilder.create(dataSource, getQuery(ACTION_SELECT_ALL, clazz)) + .executeQuery(clazz); } public void addObject(BaseModel entity) throws SQLException { - String query = "database.insert" + entity.getClass().getSimpleName(); - entity.setId(QueryBuilder.create(dataSource, getQuery(query), true) + entity.setId(QueryBuilder.create(dataSource, getQuery(ACTION_INSERT, entity.getClass()), true) .setObject(entity) .executeUpdate()); } public void updateObject(BaseModel entity) throws SQLException { - String query = "database.update" + entity.getClass().getSimpleName(); - QueryBuilder.create(dataSource, getQuery(query)) + QueryBuilder.create(dataSource, getQuery(ACTION_UPDATE, entity.getClass())) .setObject(entity) .executeUpdate(); + if (entity instanceof User && ((User) entity).getHashedPassword() != null) { + QueryBuilder.create(dataSource, getQuery(ACTION_UPDATE, User.class, true)) + .setObject(entity) + .executeUpdate(); + } } public void removeObject(Class clazz, long entityId) throws SQLException { - String query = "database.delete" + clazz.getSimpleName(); - QueryBuilder.create(dataSource, getQuery(query)) + QueryBuilder.create(dataSource, getQuery(ACTION_DELETE, clazz)) .setLong("id", entityId) .executeUpdate(); } diff --git a/src/org/traccar/database/QueryAdditional.java b/src/org/traccar/database/QueryAdditional.java new file mode 100644 index 000000000..7a42c1875 --- /dev/null +++ b/src/org/traccar/database/QueryAdditional.java @@ -0,0 +1,27 @@ +/* + * Copyright 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2017 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. + * 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.database; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface QueryAdditional { +} diff --git a/src/org/traccar/database/StatisticsManager.java b/src/org/traccar/database/StatisticsManager.java index 5b42416ad..06a3e7b35 100644 --- a/src/org/traccar/database/StatisticsManager.java +++ b/src/org/traccar/database/StatisticsManager.java @@ -61,7 +61,7 @@ public class StatisticsManager { statistics.setGeolocationRequests(geolocationRequests); try { - Context.getDataManager().addStatistics(statistics); + Context.getDataManager().addObject(statistics); } catch (SQLException e) { Log.warning(e); } diff --git a/src/org/traccar/model/Device.java b/src/org/traccar/model/Device.java index 6a13c2b77..cd5dd12c4 100644 --- a/src/org/traccar/model/Device.java +++ b/src/org/traccar/model/Device.java @@ -18,6 +18,9 @@ package org.traccar.model; import java.util.Date; import java.util.List; +import org.traccar.database.QueryAdditional; +import org.traccar.database.QueryIgnore; + public class Device extends ExtendedModel { private String name; @@ -46,6 +49,7 @@ public class Device extends ExtendedModel { private String status; + @QueryIgnore public String getStatus() { return status != null ? status : STATUS_OFFLINE; } @@ -56,6 +60,7 @@ public class Device extends ExtendedModel { private Date lastUpdate; + @QueryAdditional public Date getLastUpdate() { if (lastUpdate != null) { return new Date(lastUpdate.getTime()); @@ -74,6 +79,7 @@ public class Device extends ExtendedModel { private long positionId; + @QueryIgnore public long getPositionId() { return positionId; } @@ -94,6 +100,7 @@ public class Device extends ExtendedModel { private List geofenceIds; + @QueryIgnore public List getGeofenceIds() { return geofenceIds; } diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 4412b012c..66a6f91ce 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -17,6 +17,8 @@ package org.traccar.model; import java.util.Date; +import org.traccar.database.QueryIgnore; + public class Position extends Message { public static final String KEY_ORIGINAL = "raw"; @@ -196,6 +198,7 @@ public class Position extends Message { private boolean outdated; + @QueryIgnore public boolean getOutdated() { return outdated; } @@ -294,4 +297,10 @@ public class Position extends Message { this.network = network; } + @Override + @QueryIgnore + public String getType() { + return super.getType(); + } + } diff --git a/src/org/traccar/model/Server.java b/src/org/traccar/model/Server.java index cd5b0624e..246be0b4f 100644 --- a/src/org/traccar/model/Server.java +++ b/src/org/traccar/model/Server.java @@ -17,10 +17,12 @@ package org.traccar.model; import java.util.TimeZone; +import org.traccar.database.QueryIgnore; import org.traccar.helper.Log; public class Server extends ExtendedModel { + @QueryIgnore public String getVersion() { return Log.getAppVersion(); } diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java index 6e6a079c2..72b53ee5d 100644 --- a/src/org/traccar/model/User.java +++ b/src/org/traccar/model/User.java @@ -16,6 +16,9 @@ package org.traccar.model; import com.fasterxml.jackson.annotation.JsonIgnore; + +import org.traccar.database.QueryAdditional; +import org.traccar.database.QueryIgnore; import org.traccar.helper.Hashing; import java.util.Date; @@ -228,6 +231,7 @@ public class User extends ExtendedModel { } } + @QueryIgnore public String getPassword() { return null; } @@ -243,6 +247,7 @@ public class User extends ExtendedModel { private String hashedPassword; @JsonIgnore + @QueryAdditional public String getHashedPassword() { return hashedPassword; } @@ -254,6 +259,7 @@ public class User extends ExtendedModel { private String salt; @JsonIgnore + @QueryAdditional public String getSalt() { return salt; } diff --git a/test/org/traccar/database/DataManagerTest.java b/test/org/traccar/database/DataManagerTest.java new file mode 100644 index 000000000..3383c3d22 --- /dev/null +++ b/test/org/traccar/database/DataManagerTest.java @@ -0,0 +1,79 @@ +package org.traccar.database; + +import org.junit.Assert; +import org.junit.Test; +import org.traccar.model.Attribute; +import org.traccar.model.Device; +import org.traccar.model.Driver; +import org.traccar.model.Geofence; +import org.traccar.model.Group; +import org.traccar.model.ManagedUser; +import org.traccar.model.Position; +import org.traccar.model.User; + +public class DataManagerTest { + + @Test + public void constructObjectQuery() { + Assert.assertEquals("SELECT * FROM users", + DataManager.constructObjectQuery(DataManager.ACTION_SELECT_ALL, User.class, false)); + Assert.assertEquals("DELETE FROM groups WHERE id = :id", + DataManager.constructObjectQuery(DataManager.ACTION_DELETE, Group.class, false)); + Assert.assertEquals("SELECT * FROM positions WHERE id = :id", + DataManager.constructObjectQuery(DataManager.ACTION_SELECT, Position.class, false)); + + String insertDevice = DataManager.constructObjectQuery(DataManager.ACTION_INSERT, Device.class, false); + Assert.assertFalse(insertDevice.contains("class")); + Assert.assertFalse(insertDevice.contains("id")); + Assert.assertFalse(insertDevice.contains("status")); + Assert.assertFalse(insertDevice.contains("lastUpdate")); + Assert.assertFalse(insertDevice.contains("geofenceIds")); + + String updateDeviceStatus = DataManager.constructObjectQuery("update", Device.class, true); + Assert.assertTrue(updateDeviceStatus.contains("lastUpdate")); + + String updateUser = DataManager.constructObjectQuery(DataManager.ACTION_UPDATE, User.class, false); + Assert.assertFalse(updateUser.contains("class")); + Assert.assertFalse(updateUser.contains("password")); + Assert.assertFalse(updateUser.contains("salt")); + + String updateUserPassword = DataManager.constructObjectQuery(DataManager.ACTION_UPDATE, User.class, true); + Assert.assertFalse(updateUserPassword.contains("name")); + Assert.assertTrue(updateUserPassword.contains("hashedPassword")); + Assert.assertTrue(updateUserPassword.contains("salt")); + + String insertPosition = DataManager.constructObjectQuery(DataManager.ACTION_INSERT, Position.class, false); + Assert.assertFalse(insertPosition.contains("type")); + Assert.assertFalse(insertPosition.contains("outdated")); + + } + + @Test + public void constructPermissionsQuery() { + Assert.assertEquals("SELECT userId, deviceId FROM user_device", + DataManager.constructPermissionQuery(DataManager.ACTION_SELECT_ALL, User.class, Device.class)); + + Assert.assertEquals("SELECT userId, managedUserId FROM user_user", + DataManager.constructPermissionQuery(DataManager.ACTION_SELECT_ALL, User.class, ManagedUser.class)); + + Assert.assertEquals("SELECT deviceId, driverId FROM device_driver", + DataManager.constructPermissionQuery(DataManager.ACTION_SELECT_ALL, Device.class, Driver.class)); + + Assert.assertEquals("SELECT groupId, geofenceId FROM group_geofence", + DataManager.constructPermissionQuery(DataManager.ACTION_SELECT_ALL, Group.class, Geofence.class)); + + Assert.assertEquals("INSERT INTO user_device (userId, deviceId) VALUES (:userId, :deviceId)", + DataManager.constructPermissionQuery(DataManager.ACTION_INSERT, User.class, Device.class)); + + Assert.assertEquals("DELETE FROM user_user WHERE userId = :userId AND managedUserId = :managedUserId", + DataManager.constructPermissionQuery(DataManager.ACTION_DELETE, User.class, ManagedUser.class)); + + Assert.assertEquals("INSERT INTO device_geofence (deviceId, geofenceId) VALUES (:deviceId, :geofenceId)", + DataManager.constructPermissionQuery(DataManager.ACTION_INSERT, Device.class, Geofence.class)); + + Assert.assertEquals("DELETE FROM group_attribute WHERE groupId = :groupId AND attributeId = :attributeId", + DataManager.constructPermissionQuery(DataManager.ACTION_DELETE, Group.class, Attribute.class)); + + } + +} -- cgit v1.2.3 From e90e38d8c5db452adc5ab704a6f9dd84db16ce20 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 19 Aug 2017 12:01:27 +1200 Subject: Advanced TK103 attributes --- src/org/traccar/model/Position.java | 1 + src/org/traccar/protocol/Gt06ProtocolDecoder.java | 2 +- src/org/traccar/protocol/Tk103ProtocolDecoder.java | 44 ++++++++++++++++++---- src/org/traccar/protocol/TytanProtocolDecoder.java | 2 +- .../traccar/protocol/Tk103ProtocolDecoderTest.java | 3 ++ 5 files changed, 42 insertions(+), 10 deletions(-) (limited to 'src/org/traccar/model/Position.java') diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 66a6f91ce..c188124af 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -75,6 +75,7 @@ public class Position extends Message { public static final String KEY_OPERATOR = "operator"; public static final String KEY_COMMAND = "command"; public static final String KEY_BLOCKED = "blocked"; + public static final String KEY_DOOR = "door"; public static final String KEY_DTCS = "dtcs"; public static final String KEY_OBD_SPEED = "obdSpeed"; // knots diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 186867b9d..4cf4a79eb 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -531,7 +531,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } else if (subType == 0x05) { int flags = buf.readUnsignedByte(); - position.set("door", BitUtil.check(flags, 0)); + position.set(Position.KEY_DOOR, BitUtil.check(flags, 0)); position.set(Position.PREFIX_IO + 1, BitUtil.check(flags, 2)); return position; diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 0106e5bf3..14278085b 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -50,7 +50,14 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { .number("(d+.d)(?:d*,)?") // speed .number("(dd)(dd)(dd),?") // time (hhmmss) .number("(d+.?d{1,2}),?") // course - .number("(?:([01]{8})|(x{8}))?,?") // state + .groupBegin() + .number("([01])") // charge + .number("([01])") // ignition + .number("(x)") // io + .number("(x)") // io + .number("(x)") // io + .number("(xxx),?") // fuel + .groupEnd("?") .number("(?:L(x+))?") // odometer .any() .number("([+-]ddd.d)?") // temperature @@ -260,15 +267,36 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { position.setCourse(parser.nextDouble(0)); - String status = parser.next(); - if (status != null) { - position.set(Position.KEY_STATUS, status); // binary status + if (parser.hasNext(6)) { + position.set(Position.KEY_CHARGE, parser.nextInt() == 0); + position.set(Position.KEY_IGNITION, parser.nextInt() == 1); - int value = Integer.parseInt(new StringBuilder(status).reverse().toString(), 2); - position.set(Position.KEY_CHARGE, !BitUtil.check(value, 0)); - position.set(Position.KEY_IGNITION, BitUtil.check(value, 1)); + int mask1 = parser.nextHexInt(); + position.set(Position.PREFIX_IN + 2, BitUtil.check(mask1, 0)); + position.set(Position.PREFIX_OUT + 2, BitUtil.check(mask1, 2)); + if (BitUtil.check(mask1, 3)) { + position.set(Position.KEY_BLOCKED, true); + } + + int mask2 = parser.nextHexInt(); + for (int i = 0; i < 3; i++) { + if (BitUtil.check(mask2, i)) { + position.set("hs" + (3 - i), true); + } + } + if (BitUtil.check(mask2, 3)) { + position.set(Position.KEY_DOOR, true); + } + + int mask3 = parser.nextHexInt(); + for (int i = 1; i <= 3; i++) { + if (BitUtil.check(mask3, i)) { + position.set("hs" + (3 - i + 1), true); + } + } + + position.set(Position.KEY_FUEL_LEVEL, parser.nextHexInt()); } - position.set(Position.KEY_STATUS, parser.next()); // hex status if (parser.hasNext()) { position.set(Position.KEY_ODOMETER, parser.nextLong(16, 0)); diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java index 030fbce78..0ae669784 100644 --- a/src/org/traccar/protocol/TytanProtocolDecoder.java +++ b/src/org/traccar/protocol/TytanProtocolDecoder.java @@ -111,7 +111,7 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 5); break; case 150: - position.set("door", buf.readUnsignedByte()); + position.set(Position.KEY_DOOR, buf.readUnsignedByte()); break; default: buf.skipBytes(length); diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java index f2ee8ffe5..a69ff8856 100644 --- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class Tk103ProtocolDecoderTest extends ProtocolTest { Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(new Tk103Protocol()); + verifyPosition(decoder, text( + "(007611121184BR00170816A2401.5217N07447.0788E000.0221352232.340000004FL0030F14F)")); + verifyNull(decoder, text( "(027044702512BP00027044702512HSO01A4)")); -- cgit v1.2.3 From 62e2696c2d8e619d90cb978fa60f714312649866 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 24 Sep 2017 14:45:14 +1300 Subject: Support additional eeLink parameters --- src/org/traccar/model/Position.java | 1 + .../traccar/protocol/EelinkProtocolDecoder.java | 41 ++++++++++++++++++++++ src/org/traccar/protocol/H02ProtocolDecoder.java | 2 +- src/org/traccar/protocol/WatchProtocolDecoder.java | 2 +- .../protocol/EelinkProtocolDecoderTest.java | 3 ++ 5 files changed, 47 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/model/Position.java') diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index c188124af..31af3d38a 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -37,6 +37,7 @@ public class Position extends Message { public static final String KEY_ODOMETER_SERVICE = "serviceOdometer"; // meters public static final String KEY_ODOMETER_TRIP = "tripOdometer"; // meters public static final String KEY_HOURS = "hours"; + public static final String KEY_STEPS = "steps"; public static final String KEY_INPUT = "input"; public static final String KEY_OUTPUT = "output"; public static final String KEY_IMAGE = "image"; diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java index 2526282b1..8d0f8016a 100644 --- a/src/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java @@ -217,6 +217,45 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(7); // bss2 } + if (buf.readableBytes() >= 2) { + int status = buf.readUnsignedShort(); + position.setValid(BitUtil.check(status, 0)); + if (BitUtil.check(status, 1)) { + position.set(Position.KEY_IGNITION, BitUtil.check(status, 2)); + } + position.set(Position.KEY_STATUS, status); + } + + if (buf.readableBytes() >= 2) { + position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001); + } + + if (buf.readableBytes() >= 4) { + position.set(Position.PREFIX_ADC + 0, buf.readUnsignedShort()); + position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort()); + } + + if (buf.readableBytes() >= 4) { + position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + } + + if (buf.readableBytes() >= 4) { + buf.readUnsignedShort(); // gsm counter + buf.readUnsignedShort(); // gps counter + } + + if (buf.readableBytes() >= 4) { + position.set(Position.KEY_STEPS, buf.readUnsignedShort()); + buf.readUnsignedShort(); // walking time + } + + if (buf.readableBytes() >= 12) { + position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShort() / 256.0); + position.set("humidity", buf.readUnsignedShort() * 0.1); + position.set("illuminance", buf.readUnsignedInt() / 256.0); + position.set("co2", buf.readUnsignedInt()); + } + return position; } @@ -240,6 +279,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { getDeviceSession(channel, remoteAddress, ChannelBuffers.hexDump(buf.readBytes(8)).substring(1)); } else { + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); if (deviceSession == null) { return null; @@ -262,6 +302,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { return position; } + } return null; diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index aea8f0b3b..e4b18e277 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -392,7 +392,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_RSSI, parser.nextInt()); position.set(Position.KEY_SATELLITES, parser.nextInt()); position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt()); - position.set("steps", parser.nextInt()); + position.set(Position.KEY_STEPS, parser.nextInt()); position.set("turnovers", parser.nextInt()); dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index adab65245..86dc9456d 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -205,7 +205,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_RSSI, parser.nextInt(0)); position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0)); - position.set("steps", parser.nextInt(0)); + position.set(Position.KEY_STEPS, parser.nextInt(0)); int status = parser.nextHexInt(0); position.set(Position.KEY_ALARM, decodeAlarm(status)); diff --git a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java index ca2bb463e..115eef1a3 100644 --- a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java +++ b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java @@ -13,6 +13,9 @@ public class EelinkProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "676701000c007b03525440717505180104")); + verifyPosition(decoder, binary( + "6767120048000559c1829213059a7400008e277d000c000000000800cc00080d2a000034df3cf0b429dd82cad3048910320000000000007b7320d005ba0000000019a000000000000000000000")); + verifyPosition(decoder, binary( "6767050020213b59c6aecdff41dce70b8b977d00000001fe000a36e30078fe010159c6aecd")); -- cgit v1.2.3 From 2e4fe0f4201ff43f65e36fb1ba386a1fa26b9aab Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 26 Sep 2017 14:17:28 +0500 Subject: Added intermediate "decodeParameter" function and KEY_ROAMING attribute --- src/org/traccar/model/Position.java | 1 + .../traccar/protocol/TeltonikaProtocolDecoder.java | 32 ++++++++++------------ test/org/traccar/ProtocolTest.java | 4 +++ 3 files changed, 19 insertions(+), 18 deletions(-) (limited to 'src/org/traccar/model/Position.java') diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 31af3d38a..93456b1b0 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -30,6 +30,7 @@ public class Position extends Message { public static final String KEY_SATELLITES_VISIBLE = "satVisible"; public static final String KEY_RSSI = "rssi"; public static final String KEY_GPS = "gps"; + public static final String KEY_ROAMING = "roaming"; public static final String KEY_EVENT = "event"; public static final String KEY_ALARM = "alarm"; public static final String KEY_STATUS = "status"; diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index 3dd00ead7..8754d7d81 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -93,7 +93,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } } - private void decodeParameter(Position position, int id, ChannelBuffer buf, int length) { + private void decodeOtherParameter(Position position, int id, ChannelBuffer buf, int length) { switch (id) { case 1: case 2: @@ -199,7 +199,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_MOTION, readValue(buf, length, false) == 1); break; case 244: - position.set("roaming", readValue(buf, length, false) == 1); + position.set(Position.KEY_ROAMING, readValue(buf, length, false) == 1); break; default: position.set(Position.PREFIX_IO + id, readValue(buf, length, false)); @@ -207,6 +207,14 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } } + private void decodeParameter(Position position, int id, ChannelBuffer buf, int length, int codec) { + if (codec == CODEC_GH3000) { + decodeGh3000Parameter(position, id, buf, length); + } else { + decodeOtherParameter(position, id, buf, length); + } + } + private void decodeNetwork(Position position) { long cid = position.getLong(Position.PREFIX_IO + 205); int lac = position.getInteger(Position.PREFIX_IO + 206); @@ -315,11 +323,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(globalMask, 1)) { int cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - if (codec == CODEC_GH3000) { - decodeGh3000Parameter(position, buf.readUnsignedByte(), buf, 1); - } else { - decodeParameter(position, buf.readUnsignedByte(), buf, 1); - } + decodeParameter(position, buf.readUnsignedByte(), buf, 1, codec); } } @@ -327,11 +331,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(globalMask, 2)) { int cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - if (codec == CODEC_GH3000) { - decodeGh3000Parameter(position, buf.readUnsignedByte(), buf, 2); - } else { - decodeParameter(position, buf.readUnsignedByte(), buf, 2); - } + decodeParameter(position, buf.readUnsignedByte(), buf, 2, codec); } } @@ -339,11 +339,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(globalMask, 3)) { int cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - if (codec == CODEC_GH3000) { - decodeGh3000Parameter(position, buf.readUnsignedByte(), buf, 4); - } else { - decodeParameter(position, buf.readUnsignedByte(), buf, 4); - } + decodeParameter(position, buf.readUnsignedByte(), buf, 4, codec); } } @@ -351,7 +347,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (codec == CODEC_FM4X00) { int cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - decodeParameter(position, buf.readUnsignedByte(), buf, 8); + decodeOtherParameter(position, buf.readUnsignedByte(), buf, 8); } } diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java index 01395fc11..1daefabd6 100644 --- a/test/org/traccar/ProtocolTest.java +++ b/test/org/traccar/ProtocolTest.java @@ -261,6 +261,10 @@ public class ProtocolTest extends BaseTest { Assert.assertTrue(attributes.get(Position.KEY_STEPS) instanceof Number); } + if (attributes.containsKey(Position.KEY_ROAMING)) { + Assert.assertTrue(attributes.get(Position.KEY_ROAMING) instanceof Boolean); + } + if (position.getNetwork() != null && position.getNetwork().getCellTowers() != null) { for (CellTower cellTower : position.getNetwork().getCellTowers()) { checkInteger(cellTower.getMobileCountryCode(), 0, 999); -- cgit v1.2.3 From 4ef26b62cb97fc2afa5fdcf260c5fffbdc454c25 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 27 Sep 2017 15:27:10 +1300 Subject: Fix typo in alarm name --- src/org/traccar/model/Position.java | 2 +- src/org/traccar/protocol/AplicomProtocolDecoder.java | 2 +- src/org/traccar/protocol/AquilaProtocolDecoder.java | 4 ++-- src/org/traccar/protocol/MeiligaoProtocolDecoder.java | 14 +++++++------- src/org/traccar/protocol/Pt502ProtocolDecoder.java | 2 +- src/org/traccar/protocol/SuntechProtocolDecoder.java | 2 +- src/org/traccar/protocol/TaipProtocolDecoder.java | 2 +- src/org/traccar/protocol/TzoneProtocolDecoder.java | 2 +- src/org/traccar/protocol/Vt200ProtocolDecoder.java | 2 +- src/org/traccar/protocol/VtfmsProtocolDecoder.java | 2 +- 10 files changed, 17 insertions(+), 17 deletions(-) (limited to 'src/org/traccar/model/Position.java') diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 93456b1b0..099e6d686 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -115,7 +115,7 @@ public class Position extends Message { public static final String ALARM_ACCIDENT = "accident"; public static final String ALARM_TOW = "tow"; public static final String ALARM_ACCELERATION = "hardAcceleration"; - public static final String ALARM_BREAKING = "hardBreaking"; + public static final String ALARM_BRAKING = "hardBraking"; public static final String ALARM_CORNERING = "hardCornering"; public static final String ALARM_FATIGUE_DRIVING = "fatigueDriving"; public static final String ALARM_POWER_CUT = "powerCut"; diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java index 94d12c633..154451b5b 100644 --- a/src/org/traccar/protocol/AplicomProtocolDecoder.java +++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java @@ -568,7 +568,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte()); position.set("speedMax", buf.readUnsignedByte()); position.set("speedMin", buf.readUnsignedByte()); - position.set("hardBreaking", buf.readUnsignedByte()); + position.set("hardBraking", buf.readUnsignedByte()); } if ((selector & 0x0200) != 0) { diff --git a/src/org/traccar/protocol/AquilaProtocolDecoder.java b/src/org/traccar/protocol/AquilaProtocolDecoder.java index 5ff974a7d..773210b04 100644 --- a/src/org/traccar/protocol/AquilaProtocolDecoder.java +++ b/src/org/traccar/protocol/AquilaProtocolDecoder.java @@ -81,7 +81,7 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder { .number("[01],") // corner packet .number("(?:d+,){6}") // reserved .number("[01],") // hard acceleration - .number("[01],") // hard breaking + .number("[01],") // hard braking .number("[01],[01],[01],[01],") // course bits .number("(d+),") // external voltage .number("(d+),") // internal voltage @@ -115,7 +115,7 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder { .number("[01],") // do 1 .number("[01],") // reserved .number("[01],") // hard acceleration - .number("[01],") // hard breaking + .number("[01],") // hard braking .number("(?:[01],){4}") // reserved .number("(d+),") // external voltage .number("(d+),") // internal voltage diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index b9725337b..e41a42843 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -94,8 +94,8 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { .number("(d+.d+),") // single fuel consumption .number("(d+.d+),") // total fuel consumption .number("(d+),") // error code count - .number("(d+),") // harsh acceleration count - .number("(d+)") // harsh break count + .number("(d+),") // hard acceleration count + .number("(d+)") // hard brake count .compile(); private static final Pattern PATTERN_OBDA = new PatternBuilder() @@ -106,8 +106,8 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // average speed .number("(d+),") // history highest speed .number("(d+),") // history highest rpm - .number("(d+),") // total harsh acceleration - .number("(d+)") // total harsh break n0 + .number("(d+),") // total hard acceleration + .number("(d+)") // total hard brake .compile(); public static final int MSG_HEARTBEAT = 0x0001; @@ -201,7 +201,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { case 0x53: return Position.ALARM_GPS_ANTENNA_CUT; case 0x72: - return Position.ALARM_BREAKING; + return Position.ALARM_BRAKING; case 0x73: return Position.ALARM_ACCELERATION; default: @@ -301,8 +301,8 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { position.set("singleFuelConsumption", parser.nextDouble()); position.set("totalFuelConsumption", parser.nextDouble()); position.set(Position.KEY_DTCS, parser.nextInt()); - position.set("harshAcelerationNo", parser.nextInt()); - position.set("harshBreakerNo", parser.nextInt()); + position.set("hardAccelerationCount", parser.nextInt()); + position.set("hardBrakingCount", parser.nextInt()); return position; } diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index e12bbdf28..fef5d9b39 100644 --- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java @@ -67,7 +67,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { case "HDA": return Position.ALARM_ACCELERATION; case "HDB": - return Position.ALARM_BREAKING; + return Position.ALARM_BRAKING; case "FDA": return Position.ALARM_FATIGUE_DRIVING; case "SKA": diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java index 320df9c94..6dfc6f77f 100644 --- a/src/org/traccar/protocol/SuntechProtocolDecoder.java +++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java @@ -147,7 +147,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { case 46: return Position.ALARM_ACCELERATION; case 47: - return Position.ALARM_BREAKING; + return Position.ALARM_BRAKING; case 48: return Position.ALARM_ACCIDENT; case 50: diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java index 6edf4a93e..c6220ab1d 100644 --- a/src/org/traccar/protocol/TaipProtocolDecoder.java +++ b/src/org/traccar/protocol/TaipProtocolDecoder.java @@ -124,7 +124,7 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); break; case 23: - position.set(Position.KEY_ALARM, Position.ALARM_BREAKING); + position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); break; case 24: position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); diff --git a/src/org/traccar/protocol/TzoneProtocolDecoder.java b/src/org/traccar/protocol/TzoneProtocolDecoder.java index 69aa916df..76903c90c 100644 --- a/src/org/traccar/protocol/TzoneProtocolDecoder.java +++ b/src/org/traccar/protocol/TzoneProtocolDecoder.java @@ -43,7 +43,7 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { case 0x11: return Position.ALARM_OVERSPEED; case 0x14: - return Position.ALARM_BREAKING; + return Position.ALARM_BRAKING; case 0x15: return Position.ALARM_ACCELERATION; case 0x30: diff --git a/src/org/traccar/protocol/Vt200ProtocolDecoder.java b/src/org/traccar/protocol/Vt200ProtocolDecoder.java index 6be70c3c1..2ae24efbb 100644 --- a/src/org/traccar/protocol/Vt200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Vt200ProtocolDecoder.java @@ -124,7 +124,7 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder { position.set("maxRpm", buf.readUnsignedShort()); position.set("maxTemp", buf.readUnsignedByte() - 40); position.set("hardAccelerationCount", buf.readUnsignedByte()); - position.set("hardBreakingCount", buf.readUnsignedByte()); + position.set("hardBrakingCount", buf.readUnsignedByte()); for (String speedType : Arrays.asList("over", "high", "normal", "low")) { position.set(speedType + "SpeedTime", buf.readUnsignedShort()); diff --git a/src/org/traccar/protocol/VtfmsProtocolDecoder.java b/src/org/traccar/protocol/VtfmsProtocolDecoder.java index 852b9a749..5fb687e6d 100644 --- a/src/org/traccar/protocol/VtfmsProtocolDecoder.java +++ b/src/org/traccar/protocol/VtfmsProtocolDecoder.java @@ -84,7 +84,7 @@ public class VtfmsProtocolDecoder extends BaseProtocolDecoder { case 15: return Position.ALARM_POWER_RESTORED; case 32: - return Position.ALARM_BREAKING; + return Position.ALARM_BRAKING; case 33: return Position.ALARM_ACCELERATION; default: -- cgit v1.2.3