From 7568adcc9350dfaeb23645a92b5d63663509ddc6 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 13 Mar 2016 09:45:52 +1300 Subject: Adjust watch decoder to accept spaces --- src/org/traccar/protocol/WatchProtocolDecoder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index 6b5d47023..0c35ef3a0 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -47,9 +47,9 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { .number("(dd)(dd)(dd),") // date (ddmmyy) .number("(dd)(dd)(dd),") // time .expression("([AV]),") // validity - .number("-?(d+.d+),") // latitude + .number(" *-?(d+.d+),") // latitude .expression("([NS]),") - .number("-?(d+.d+),") // longitude + .number(" *-?(d+.d+),") // longitude .expression("([EW])?,") .number("(d+.d+),") // speed .number("(d+.?d*),") // course -- cgit v1.2.3 From 810faf1d9b5420a5a5b80e90f024c96c018e7844 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 13 Mar 2016 10:58:22 +1300 Subject: Add ignition support for Tramigo (fix #1771) --- .../traccar/protocol/TramigoProtocolDecoder.java | 8 +++++++- .../protocol/TramigoProtocolDecoderTest.java | 23 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/TramigoProtocolDecoder.java b/src/org/traccar/protocol/TramigoProtocolDecoder.java index 10bab3d6c..1fd427ecf 100644 --- a/src/org/traccar/protocol/TramigoProtocolDecoder.java +++ b/src/org/traccar/protocol/TramigoProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 - 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2014 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -130,6 +130,12 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder { position.setTime(DateUtil.correctYear( dateFormat.parse(matcher.group(1) + " " + Calendar.getInstance().get(Calendar.YEAR)))); + if (sentence.contains("Ignition on detected")) { + position.set(Event.KEY_IGNITION, true); + } else if (sentence.contains("Ignition off detected")) { + position.set(Event.KEY_IGNITION, false); + } + return position; } diff --git a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java index 9ac02a7ad..a11e69a6a 100644 --- a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java @@ -11,7 +11,28 @@ public class TramigoProtocolDecoderTest extends ProtocolTest { public void testDecode() throws Exception { TramigoProtocolDecoder decoder = new TramigoProtocolDecoder(new TramigoProtocol()); - + + verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "8000853eb000b8000101fcff032f14665a89e2564176656e7369732053797353657276653a2049676e6974696f6e206f6e2064657465637465642c206d6f76696e672c20302e3135206b6d205357206f66204261626120416e696d61736861756e205374726565742d426f64652054686f6d61732053742e2c20537572756c6572652c204c61676f7320436974792c204e472c20362e34383736352c20332e33343735352c2031303a3031204d6172203131202020454f46")); + + verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "8000973eb000b90001012128032f14667794e2564176656e7369732053797353657276653a2049676e6974696f6e206f6e2064657465637465642c2073746f707065642c20302e3134206b6d205357206f66204261626120416e696d61736861756e205374726565742d426f64652054686f6d61732053742e2c20537572756c6572652c204c61676f7320436974792c204e472c20362e34383736372c20332e33343737332c2031303a3438204d6172203131202020454f46")); + + verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "8000b73eb000ad000101fdd2032f1466c9cbe2564176656e7369732053797353657276653a2049676e6974696f6e206f6e2064657465637465642c206d6f76696e672c20302e3131206b6d2045206f6620416c68616a69204d6173686120526f616420466f6f746272696467652c20537572756c6572652c204c61676f7320436974792c204e472c20362e35303031342c20332e33353434332c2031343a3434204d6172203131202020454f46")); + + verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "8000883eb000d3000101b223032f1466fc89e2564176656e7369732053797353657276653a2049676e6974696f6e206f66662064657465637465642c2049676e4f6e506572696f643a2030303a30323a34312c2073746f707065642c20302e3039206b6d205345206f66204a696e616475205072696d617279205363686f6f6c20416465204f6e6974696d6572696e2053742e2c20537572756c6572652c204c61676f7320436974792c204e472c20362e34383639332c20332e33343636302c2031303a3033204d6172203131202020454f46")); + + verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "80009a3eb000d300010109ff032f1466b195e2564176656e7369732053797353657276653a2049676e6974696f6e206f66662064657465637465642c2049676e4f6e506572696f643a2030303a30353a31342c2073746f707065642c20302e3039206b6d205345206f66204a696e616475205072696d617279205363686f6f6c20416465204f6e6974696d6572696e2053742e2c20537572756c6572652c204c61676f7320436974792c204e472c20362e34383639312c20332e33343636322c2031303a3533204d6172203131202020454f46")); + + verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "8000bc3eb000ba000101622c032f1466bacce2564176656e7369732053797353657276653a2049676e6974696f6e206f66662064657465637465642c2049676e4f6e506572696f643a2030303a30343a30302c206d6f76696e672c20617420416b6572656c6520526f61642d4f67756e6c616e612044726976652c20537572756c6572652c204c61676f7320436974792c204e472c20362e35303630332c20332e33353232382c2031343a3438204d6172203131202020454f46")); + + verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "80001d3cb000b3000101160f032f1466b475e0564176656e7369732053797353657276653a205374617475732c204750533a203931252c2047534d3a203737252c20475052533a20436f6e6e65637465642c20626174746572793a20313030252c207265706f7274733a2049676e6974696f6e20286f6666292c205374617475732028352c322e302c3732302c3330292c20362e34393239382c20332e33343836352c2031393a3038204d6172203920454f46")); + verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, "80005408b000af000101b23903677f00c8436d3842616c697365204f6e653a20416c6c756d616765206d61726368652064e974656374e92c20676172e92c20302e3735206b6d20452064652045636f6c65204175746f726f757465206465204b696e73686173612c2056696c6c65206465204b696e73686173612c204b696e73686173612c2043442c202d342e33343130362c2031352e33343931352c2030313a3030204a616e2031202020454f46")); -- cgit v1.2.3 From 984feba192d0b347b99c550009ec6fd078728ca2 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 13 Mar 2016 12:18:15 +1300 Subject: Add twelve hour format preference --- database/changelog-3.5.xml | 12 ++++++++++++ debug.xml | 6 ++++-- src/org/traccar/model/Server.java | 10 ++++++++++ src/org/traccar/model/User.java | 10 ++++++++++ web/app/model/Server.js | 3 +++ web/app/model/User.js | 3 +++ web/app/view/ServerDialog.js | 5 +++++ web/app/view/UserDialog.js | 5 +++++ web/l10n/en.json | 1 + 9 files changed, 53 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/database/changelog-3.5.xml b/database/changelog-3.5.xml index f754b532f..3d1fa6b41 100644 --- a/database/changelog-3.5.xml +++ b/database/changelog-3.5.xml @@ -38,5 +38,17 @@ + + + + + + + + + + + + diff --git a/debug.xml b/debug.xml index 8e0b70fbf..e16f5f5be 100644 --- a/debug.xml +++ b/debug.xml @@ -67,7 +67,8 @@ speedUnit = :speedUnit, latitude = :latitude, longitude = :longitude, - zoom = :zoom + zoom = :zoom, + twelveHourFormat = :twelveHourFormat WHERE id = :id; @@ -101,7 +102,8 @@ speedUnit = :speedUnit, latitude = :latitude, longitude = :longitude, - zoom = :zoom + zoom = :zoom, + twelveHourFormat = :twelveHourFormat WHERE id = :id; diff --git a/src/org/traccar/model/Server.java b/src/org/traccar/model/Server.java index 00b1f60d0..f03a0aa60 100644 --- a/src/org/traccar/model/Server.java +++ b/src/org/traccar/model/Server.java @@ -137,4 +137,14 @@ public class Server { this.zoom = zoom; } + private boolean twelveHourFormat; + + public boolean getTwelveHourFormat() { + return twelveHourFormat; + } + + public void setTwelveHourFormat(boolean twelveHourFormat) { + this.twelveHourFormat = twelveHourFormat; + } + } diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java index 1531ba9e4..e58311834 100644 --- a/src/org/traccar/model/User.java +++ b/src/org/traccar/model/User.java @@ -140,6 +140,16 @@ public class User { this.zoom = zoom; } + private boolean twelveHourFormat; + + public boolean getTwelveHourFormat() { + return twelveHourFormat; + } + + public void setTwelveHourFormat(boolean twelveHourFormat) { + this.twelveHourFormat = twelveHourFormat; + } + private String password; public String getPassword() { diff --git a/web/app/model/Server.js b/web/app/model/Server.js index 9b4b5b2b6..796ff58d6 100644 --- a/web/app/model/Server.js +++ b/web/app/model/Server.js @@ -54,6 +54,9 @@ Ext.define('Traccar.model.Server', { }, { name: 'zoom', type: 'int' + }, { + name: 'twelveHourFormat', + type: 'boolean' }], proxy: { diff --git a/web/app/model/User.js b/web/app/model/User.js index b00918bc8..237a4d269 100644 --- a/web/app/model/User.js +++ b/web/app/model/User.js @@ -54,6 +54,9 @@ Ext.define('Traccar.model.User', { }, { name: 'zoom', type: 'int' + }, { + name: 'twelveHourFormat', + type: 'boolean' }], proxy: { diff --git a/web/app/view/ServerDialog.js b/web/app/view/ServerDialog.js index 9fbbed920..67f3a7ab2 100644 --- a/web/app/view/ServerDialog.js +++ b/web/app/view/ServerDialog.js @@ -79,6 +79,11 @@ Ext.define('Traccar.view.ServerDialog', { xtype: 'numberfield', name: 'zoom', fieldLabel: Strings.serverZoom + }, { + xtype: 'checkboxfield', + name: 'twelveHourFormat', + fieldLabel: Strings.settingsTwelveHourFormat, + allowBlank: false }] } }); diff --git a/web/app/view/UserDialog.js b/web/app/view/UserDialog.js index c1ed2fece..d0e8bda52 100644 --- a/web/app/view/UserDialog.js +++ b/web/app/view/UserDialog.js @@ -84,6 +84,11 @@ Ext.define('Traccar.view.UserDialog', { xtype: 'numberfield', name: 'zoom', fieldLabel: Strings.serverZoom + }, { + xtype: 'checkboxfield', + name: 'twelveHourFormat', + fieldLabel: Strings.settingsTwelveHourFormat, + allowBlank: false }] } }); diff --git a/web/l10n/en.json b/web/l10n/en.json index b0ea6ad26..4fb72c670 100644 --- a/web/l10n/en.json +++ b/web/l10n/en.json @@ -44,6 +44,7 @@ "settingsUsers": "Users", "settingsDistanceUnit": "Distance", "settingsSpeedUnit": "Speed", + "settingsTwelveHourFormat": "12-hour Format", "reportTitle": "Reports", "reportDevice": "Device", "reportFrom": "From", -- cgit v1.2.3 From 655d7cba4a63db2058d08f04fe5a7cdcb4067017 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 13 Mar 2016 23:58:47 +1300 Subject: Improve OpenCage reverse decoder --- .../traccar/geocode/BingMapsReverseGeocoder.java | 4 -- .../traccar/geocode/FactualReverseGeocoder.java | 4 -- .../traccar/geocode/MapQuestReverseGeocoder.java | 4 -- .../traccar/geocode/OpenCageReverseGeocoder.java | 14 +++++-- test/org/traccar/geocode/ReverseGeocoderTest.java | 48 ++++++++++++++++++---- 5 files changed, 49 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/org/traccar/geocode/BingMapsReverseGeocoder.java b/src/org/traccar/geocode/BingMapsReverseGeocoder.java index a5ebbd420..69148875a 100644 --- a/src/org/traccar/geocode/BingMapsReverseGeocoder.java +++ b/src/org/traccar/geocode/BingMapsReverseGeocoder.java @@ -20,10 +20,6 @@ import javax.json.JsonObject; public class BingMapsReverseGeocoder extends JsonReverseGeocoder { - public BingMapsReverseGeocoder() { - this("http://dev.virtualearth.net/REST/v1", "ABCDE", 0); - } - public BingMapsReverseGeocoder(String url, String key, int cacheSize) { super(url + "/Locations/%f,%f?key=" + key + "&include=ciso2", cacheSize); } diff --git a/src/org/traccar/geocode/FactualReverseGeocoder.java b/src/org/traccar/geocode/FactualReverseGeocoder.java index 6e5a48423..15211f74a 100644 --- a/src/org/traccar/geocode/FactualReverseGeocoder.java +++ b/src/org/traccar/geocode/FactualReverseGeocoder.java @@ -19,10 +19,6 @@ import javax.json.JsonObject; public class FactualReverseGeocoder extends JsonReverseGeocoder { - public FactualReverseGeocoder() { - this("https://api.factual.com/geotag", "ABCDE", 0); - } - public FactualReverseGeocoder(String url, String key, int cacheSize) { super(url + "?latitude=%f&longitude=%f&KEY=" + key, cacheSize); } diff --git a/src/org/traccar/geocode/MapQuestReverseGeocoder.java b/src/org/traccar/geocode/MapQuestReverseGeocoder.java index be3f51b04..93edfdd09 100644 --- a/src/org/traccar/geocode/MapQuestReverseGeocoder.java +++ b/src/org/traccar/geocode/MapQuestReverseGeocoder.java @@ -20,10 +20,6 @@ import javax.json.JsonObject; public class MapQuestReverseGeocoder extends JsonReverseGeocoder { - public MapQuestReverseGeocoder() { - this("http://www.mapquestapi.com/geocoding/v1/reverse", "ABCDE", 0); - } - public MapQuestReverseGeocoder(String url, String key, int cacheSize) { super(url + "?key=" + key + "&location=%f,%f", cacheSize); } diff --git a/src/org/traccar/geocode/OpenCageReverseGeocoder.java b/src/org/traccar/geocode/OpenCageReverseGeocoder.java index 3104cb56a..b5b31179e 100644 --- a/src/org/traccar/geocode/OpenCageReverseGeocoder.java +++ b/src/org/traccar/geocode/OpenCageReverseGeocoder.java @@ -1,5 +1,6 @@ /* * Copyright 2014 - 2015 Stefaan Van Dooren (stefaan.vandooren@gmail.com) + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +21,6 @@ import javax.json.JsonObject; public class OpenCageReverseGeocoder extends JsonReverseGeocoder { - public OpenCageReverseGeocoder() { - this("https://api.opencagedata.com/geocode/v1", "ABCDE", 0); - } - public OpenCageReverseGeocoder(String url, String key, int cacheSize) { super(url + "/json?q=%f,%f&key=" + key, cacheSize); } @@ -36,12 +33,21 @@ public class OpenCageReverseGeocoder extends JsonReverseGeocoder { if (location != null) { Address address = new Address(); + if (location.containsKey("building")) { + address.setHouse(location.getString("building")); + } if (location.containsKey("house_number")) { address.setHouse(location.getString("house_number")); } if (location.containsKey("road")) { address.setStreet(location.getString("road")); } + if (location.containsKey("suburb")) { + address.setSuburb(location.getString("suburb")); + } + if (location.containsKey("city")) { + address.setSettlement(location.getString("city")); + } if (location.containsKey("city_district")) { address.setSettlement(location.getString("city_district")); } diff --git a/test/org/traccar/geocode/ReverseGeocoderTest.java b/test/org/traccar/geocode/ReverseGeocoderTest.java index a572b0456..ada0afbbe 100644 --- a/test/org/traccar/geocode/ReverseGeocoderTest.java +++ b/test/org/traccar/geocode/ReverseGeocoderTest.java @@ -8,45 +8,75 @@ public class ReverseGeocoderTest { private boolean enable = false; @Test - public void test() { + public void test() throws InterruptedException { if (enable) { testGoogle(); - testNominatim(); - testGisgraphy(); } } - public void testGoogle() { + private String address; + + private synchronized String waitAddress() { + try { + wait(5000); + return address; + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + + private synchronized void setAddress(String address) { + this.address = address; + notifyAll(); + } + + public void testGoogle() throws InterruptedException { ReverseGeocoder reverseGeocoder = new GoogleReverseGeocoder(); reverseGeocoder.getAddress(new AddressFormat(), 37.4217550, -122.0846330, new ReverseGeocoder.ReverseGeocoderCallback() { @Override public void onResult(String address) { - Assert.assertEquals("1600 Amphitheatre Pkwy, Mountain View, CA, US", address); + setAddress(address); } }); + Assert.assertEquals("1600 Amphitheatre Pkwy, Mountain View, CA, US", waitAddress()); } - public void testNominatim() { + public void testNominatim() throws InterruptedException { ReverseGeocoder reverseGeocoder = new NominatimReverseGeocoder(); reverseGeocoder.getAddress(new AddressFormat(), 40.7337807, -73.9974401, new ReverseGeocoder.ReverseGeocoderCallback() { @Override public void onResult(String address) { - Assert.assertEquals("35 West 9th Street, NYC, New York, US", address); + setAddress(address); } }); + Assert.assertEquals("35 West 9th Street, NYC, New York, US", waitAddress()); } - public void testGisgraphy() { + public void testGisgraphy() throws InterruptedException { ReverseGeocoder reverseGeocoder = new GisgraphyReverseGeocoder(); reverseGeocoder.getAddress(new AddressFormat(), 48.8530000, 2.3400000, new ReverseGeocoder.ReverseGeocoderCallback() { @Override public void onResult(String address) { - Assert.assertEquals("Rue du Jardinet, Paris, FR", address); + setAddress(address); + } + }); + Assert.assertEquals("Rue du Jardinet, Paris, FR", waitAddress()); + } + + public void testOpenCage() throws InterruptedException { + ReverseGeocoder reverseGeocoder = new OpenCageReverseGeocoder( + "http://api.opencagedata.com/geocode/v1", "SECRET", 0); + + reverseGeocoder.getAddress(new AddressFormat(), 34.116302, -118.051519, new ReverseGeocoder.ReverseGeocoderCallback() { + @Override + public void onResult(String address) { + setAddress(address); } }); + Assert.assertEquals("Charleston Road, California, US", waitAddress()); } } -- cgit v1.2.3 From 40bf728938311fa9619ad2bb0eb89b21c16e9585 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 14 Mar 2016 14:24:41 +1300 Subject: Implement Fox Lite protocol --- debug.xml | 1 + src/org/traccar/protocol/FoxProtocol.java | 47 ++++++++++ src/org/traccar/protocol/FoxProtocolDecoder.java | 103 +++++++++++++++++++++ .../traccar/protocol/FoxProtocolDecoderTest.java | 27 ++++++ 4 files changed, 178 insertions(+) create mode 100644 src/org/traccar/protocol/FoxProtocol.java create mode 100644 src/org/traccar/protocol/FoxProtocolDecoder.java create mode 100644 test/org/traccar/protocol/FoxProtocolDecoderTest.java (limited to 'src') diff --git a/debug.xml b/debug.xml index e16f5f5be..c1a348376 100644 --- a/debug.xml +++ b/debug.xml @@ -300,5 +300,6 @@ 5102 5103 5104 + 5105 diff --git a/src/org/traccar/protocol/FoxProtocol.java b/src/org/traccar/protocol/FoxProtocol.java new file mode 100644 index 000000000..25190e967 --- /dev/null +++ b/src/org/traccar/protocol/FoxProtocol.java @@ -0,0 +1,47 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; + +import java.util.List; + +public class FoxProtocol extends BaseProtocol { + + public FoxProtocol() { + super("fox"); + } + + @Override + public void initTrackerServers(List serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "")); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new FoxProtocolDecoder(FoxProtocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/FoxProtocolDecoder.java b/src/org/traccar/protocol/FoxProtocolDecoder.java new file mode 100644 index 000000000..b88da573f --- /dev/null +++ b/src/org/traccar/protocol/FoxProtocolDecoder.java @@ -0,0 +1,103 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.channel.Channel; +import org.traccar.BaseProtocolDecoder; +import org.traccar.helper.DateBuilder; +import org.traccar.helper.Parser; +import org.traccar.helper.PatternBuilder; +import org.traccar.helper.UnitsConverter; +import org.traccar.model.Position; + +import java.net.SocketAddress; +import java.util.regex.Pattern; + +public class FoxProtocolDecoder extends BaseProtocolDecoder { + + public FoxProtocolDecoder(FoxProtocol protocol) { + super(protocol); + } + + private static final Pattern PATTERN = new PatternBuilder() + .number("d+,") // status id + .expression("([AV]),") // validity + .number("(dd)(dd)(dd),") // date + .number("(dd)(dd)(dd),") // time + .number("(dd)(dd.d+),") // latitude + .expression("([NS]),") + .number("(ddd)(dd.d+),") // longitude + .expression("([EW]),") + .number("(d+.?d*)?,") // speed + .number("(d+.?d*)?,") // course + .any() + .compile(); + + private String getAttribute(String xml, String key) { + int start = xml.indexOf(key + "=\""); + if (start != -1) { + start += key.length() + 2; + int end = xml.indexOf("\"", start); + if (end != -1) { + return xml.substring(start, end); + } + } + return null; + } + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + String xml = (String) msg; + String id = getAttribute(xml, "id"); + String data = getAttribute(xml, "data"); + + if (id != null && data != null) { + + if (!identify(id, channel, remoteAddress)) { + return null; + } + + Parser parser = new Parser(PATTERN, data); + if (!parser.matches()) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(getDeviceId()); + + position.setValid(parser.next().equals("A")); + + DateBuilder dateBuilder = new DateBuilder() + .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + position.setLatitude(parser.nextCoordinate()); + position.setLongitude(parser.nextCoordinate()); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); + position.setCourse(parser.nextDouble()); + + return position; + + } + + return null; + } + +} diff --git a/test/org/traccar/protocol/FoxProtocolDecoderTest.java b/test/org/traccar/protocol/FoxProtocolDecoderTest.java new file mode 100644 index 000000000..304db1891 --- /dev/null +++ b/test/org/traccar/protocol/FoxProtocolDecoderTest.java @@ -0,0 +1,27 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class FoxProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + FoxProtocolDecoder decoder = new FoxProtocolDecoder(new FoxProtocol()); + + verifyPosition(decoder, text( + "")); + + verifyPosition(decoder, text( + "")); + + verifyPosition(decoder, text( + "")); + + verifyPosition(decoder, text( + "")); + + } + +} -- cgit v1.2.3 From 0a1019b59481b6bf8ee8989feb23cef084b6caf5 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 14 Mar 2016 14:48:39 +1300 Subject: Fix PMD and CheckStyle issues --- src/org/traccar/api/resource/GroupResource.java | 1 - src/org/traccar/database/GroupTree.java | 16 ++++++---------- src/org/traccar/protocol/FoxProtocol.java | 2 -- src/org/traccar/protocol/MiniFinderProtocolEncoder.java | 2 -- 4 files changed, 6 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/org/traccar/api/resource/GroupResource.java b/src/org/traccar/api/resource/GroupResource.java index 49f839499..e22796645 100644 --- a/src/org/traccar/api/resource/GroupResource.java +++ b/src/org/traccar/api/resource/GroupResource.java @@ -17,7 +17,6 @@ package org.traccar.api.resource; import org.traccar.Context; import org.traccar.api.BaseResource; -import org.traccar.model.Device; import org.traccar.model.Group; import javax.ws.rs.Consumes; diff --git a/src/org/traccar/database/GroupTree.java b/src/org/traccar/database/GroupTree.java index b383b1501..4a2321f58 100644 --- a/src/org/traccar/database/GroupTree.java +++ b/src/org/traccar/database/GroupTree.java @@ -33,11 +33,11 @@ public class GroupTree { private Device device; private Collection children = new HashSet<>(); - public TreeNode(Group group) { + TreeNode(Group group) { this.group = group; } - public TreeNode(Device device) { + TreeNode(Device device) { this.device = device; } @@ -59,14 +59,10 @@ public class GroupTree { if (other == this) { return true; } - if (group != null) { - if (other.group != null) { - return group.getId() == other.group.getId(); - } - } else if (device != null) { - if (other.device != null) { - return device.getId() == other.device.getId(); - } + if (group != null && other.group != null) { + return group.getId() == other.group.getId(); + } else if (device != null && other.device != null) { + return device.getId() == other.device.getId(); } return false; } diff --git a/src/org/traccar/protocol/FoxProtocol.java b/src/org/traccar/protocol/FoxProtocol.java index 25190e967..cc069692b 100644 --- a/src/org/traccar/protocol/FoxProtocol.java +++ b/src/org/traccar/protocol/FoxProtocol.java @@ -17,9 +17,7 @@ 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.CharacterDelimiterFrameDecoder; import org.traccar.TrackerServer; diff --git a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java index 729c57573..e5762f5dd 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java @@ -21,8 +21,6 @@ import org.traccar.model.Command; public class MiniFinderProtocolEncoder extends StringProtocolEncoder { - private static final String prefix = "123456"; - @Override protected Object encodeCommand(Command command) { -- cgit v1.2.3