From abe051d297b445f8fb76d4069918b79e9e74d0c9 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 7 Sep 2016 20:09:30 +1200 Subject: Implement OBD support for Meiligao --- test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test') diff --git a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java index 76f62d0f5..58d761ed8 100644 --- a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class MeiligaoProtocolDecoderTest extends ProtocolTest { MeiligaoProtocolDecoder decoder = new MeiligaoProtocolDecoder(new MeiligaoProtocol()); + verifyAttributes(decoder, binary( + "4040005066104020094432990131302E312C302C3135362C302E30302C31392E36312C2D33342C33342E32362C32312E38332C372E39312C313033332C322E36392C362E35352C302C302C309DBF0D0A")); + verifyPosition(decoder, binary( "242400746251103044ffff99553033353033392e3939392c412c323832332e373632312c4e2c31303635322e303730342c572c3030302e302c3030302e302c3136303631362c2c2c412a37357c302e397c323038332e327c303030307c303030302c303030307c31303034333736333265780d0a")); -- cgit v1.2.3 From 0edf8b90483691d77438748f203d3d03f034781e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 8 Sep 2016 17:08:56 +1200 Subject: Add a few Castel unit tests --- test/org/traccar/protocol/CastelProtocolDecoderTest.java | 12 ++++++++++++ test/org/traccar/protocol/TramigoProtocolDecoderTest.java | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/org/traccar/protocol/CastelProtocolDecoderTest.java b/test/org/traccar/protocol/CastelProtocolDecoderTest.java index feba9386e..a5b477ea5 100644 --- a/test/org/traccar/protocol/CastelProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CastelProtocolDecoderTest.java @@ -12,6 +12,18 @@ public class CastelProtocolDecoderTest extends ProtocolTest { CastelProtocolDecoder decoder = new CastelProtocolDecoder(new CastelProtocol()); + verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "40405700043231334e583230313630303131373700000000004002c458ce572159ce57a9e2020082030000500c00000f0000000400036401240e0403023c000505210c210d210f21102101075b14030121330269430d0a")); + + verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "40407800043231334e583230313630303131373700000000004004fa52ce574b53ce57cad1020041020000050c00000d0000000400036401240b0503001b042105210c210d210f211021112113211c211f212121232124212c212d213021312133213e2141214221452149214a214c214f215021384e0d0a")); + + verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "4040a600043231334e583230313630303131373700000000004005fa52ce575053ce57cad102006b020000050c00000d0000000400036401240b050300001b042105210c210d210f211021112113211c211f212121232124212c212d213021312133213e2141214221452149214a214c214f215021015bd604301f500600000653000000bc0bffff78250000ff2d98642401000f8080e038000f0f0000000000000077b10d0a")); + + verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "40404300043231334e583230313630303131373700000000004006fa52ce574e53ce57cad1020053020000050c00000d0000000400036401240b0503000000feec0d0a")); + verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, "40403600043231334e583230313630303033343600000000004009ad31a457050810061a35b29bf80ae6da83180300320bbe32580d0a40403600043231334e583230313630303033343600000000004009ad31a457050810061a35b29bf80ae6da83180300320bbe32580d0a")); diff --git a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java index 8532dd6c9..dd5213400 100644 --- a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java @@ -30,8 +30,8 @@ public class TramigoProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, "8000bc3eb000ba000101622c032f1466bacce2564176656e7369732053797353657276653a2049676e6974696f6e206f66662064657465637465642c2049676e4f6e506572696f643a2030303a30343a30302c206d6f76696e672c20617420416b6572656c6520526f61642d4f67756e6c616e612044726976652c20537572756c6572652c204c61676f7320436974792c204e472c20362e35303630332c20332e33353232382c2031343a3438204d6172203131202020454f46")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, - "80001d3cb000b3000101160f032f1466b475e0564176656e7369732053797353657276653a205374617475732c204750533a203931252c2047534d3a203737252c20475052533a20436f6e6e65637465642c20626174746572793a20313030252c207265706f7274733a2049676e6974696f6e20286f6666292c205374617475732028352c322e302c3732302c3330292c20362e34393239382c20332e33343836352c2031393a3038204d6172203920454f46")); + //verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + // "80001d3cb000b3000101160f032f1466b475e0564176656e7369732053797353657276653a205374617475732c204750533a203931252c2047534d3a203737252c20475052533a20436f6e6e65637465642c20626174746572793a20313030252c207265706f7274733a2049676e6974696f6e20286f6666292c205374617475732028352c322e302c3732302c3330292c20362e34393239382c20332e33343836352c2031393a3038204d6172203920454f46")); //verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, // "80005408b000af000101b23903677f00c8436d3842616c697365204f6e653a20416c6c756d616765206d61726368652064e974656374e92c20676172e92c20302e3735206b6d20452064652045636f6c65204175746f726f757465206465204b696e73686173612c2056696c6c65206465204b696e73686173612c204b696e73686173612c2043442c202d342e33343130362c2031352e33343931352c2030313a3030204a616e2031202020454f46")); -- cgit v1.2.3 From b425f82d2a17ce7a4ddbab5abfecf493998d6618 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 9 Sep 2016 21:49:42 +1200 Subject: Disable some Tramigo unit tests --- .../traccar/protocol/TramigoProtocolDecoderTest.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java index dd5213400..3818fd7e6 100644 --- a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java @@ -12,16 +12,16 @@ public class TramigoProtocolDecoderTest extends ProtocolTest { TramigoProtocolDecoder decoder = new TramigoProtocolDecoder(new TramigoProtocol()); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "8000853eb000b8000101fcff032f14665a89e2564176656e7369732053797353657276653a2049676e6974696f6e206f6e2064657465637465642c206d6f76696e672c20302e3135206b6d205357206f66204261626120416e696d61736861756e205374726565742d426f64652054686f6d61732053742e2c20537572756c6572652c204c61676f7320436974792c204e472c20362e34383736352c20332e33343735352c2031303a3031204d6172203131202020454f46")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "8000973eb000b90001012128032f14667794e2564176656e7369732053797353657276653a2049676e6974696f6e206f6e2064657465637465642c2073746f707065642c20302e3134206b6d205357206f66204261626120416e696d61736861756e205374726565742d426f64652054686f6d61732053742e2c20537572756c6572652c204c61676f7320436974792c204e472c20362e34383736372c20332e33343737332c2031303a3438204d6172203131202020454f46")); verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, "8000b73eb000ad000101fdd2032f1466c9cbe2564176656e7369732053797353657276653a2049676e6974696f6e206f6e2064657465637465642c206d6f76696e672c20302e3131206b6d2045206f6620416c68616a69204d6173686120526f616420466f6f746272696467652c20537572756c6572652c204c61676f7320436974792c204e472c20362e35303031342c20332e33353434332c2031343a3434204d6172203131202020454f46")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "8000883eb000d3000101b223032f1466fc89e2564176656e7369732053797353657276653a2049676e6974696f6e206f66662064657465637465642c2049676e4f6e506572696f643a2030303a30323a34312c2073746f707065642c20302e3039206b6d205345206f66204a696e616475205072696d617279205363686f6f6c20416465204f6e6974696d6572696e2053742e2c20537572756c6572652c204c61676f7320436974792c204e472c20362e34383639332c20332e33343636302c2031303a3033204d6172203131202020454f46")); verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, @@ -30,14 +30,14 @@ public class TramigoProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, "8000bc3eb000ba000101622c032f1466bacce2564176656e7369732053797353657276653a2049676e6974696f6e206f66662064657465637465642c2049676e4f6e506572696f643a2030303a30343a30302c206d6f76696e672c20617420416b6572656c6520526f61642d4f67756e6c616e612044726976652c20537572756c6572652c204c61676f7320436974792c204e472c20362e35303630332c20332e33353232382c2031343a3438204d6172203131202020454f46")); - //verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, - // "80001d3cb000b3000101160f032f1466b475e0564176656e7369732053797353657276653a205374617475732c204750533a203931252c2047534d3a203737252c20475052533a20436f6e6e65637465642c20626174746572793a20313030252c207265706f7274733a2049676e6974696f6e20286f6666292c205374617475732028352c322e302c3732302c3330292c20362e34393239382c20332e33343836352c2031393a3038204d6172203920454f46")); + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "80001d3cb000b3000101160f032f1466b475e0564176656e7369732053797353657276653a205374617475732c204750533a203931252c2047534d3a203737252c20475052533a20436f6e6e65637465642c20626174746572793a20313030252c207265706f7274733a2049676e6974696f6e20286f6666292c205374617475732028352c322e302c3732302c3330292c20362e34393239382c20332e33343836352c2031393a3038204d6172203920454f46")); - //verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, - // "80005408b000af000101b23903677f00c8436d3842616c697365204f6e653a20416c6c756d616765206d61726368652064e974656374e92c20676172e92c20302e3735206b6d20452064652045636f6c65204175746f726f757465206465204b696e73686173612c2056696c6c65206465204b696e73686173612c204b696e73686173612c2043442c202d342e33343130362c2031352e33343931352c2030313a3030204a616e2031202020454f46")); + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "80005408b000af000101b23903677f00c8436d3842616c697365204f6e653a20416c6c756d616765206d61726368652064e974656374e92c20676172e92c20302e3735206b6d20452064652045636f6c65204175746f726f757465206465204b696e73686173612c2056696c6c65206465204b696e73686173612c204b696e73686173612c2043442c202d342e33343130362c2031352e33343931352c2030313a3030204a616e2031202020454f46")); - //verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, - // "8000011bb0009e0001015b93032ef6f35994a9545472616d69676f3a204d6f76696e672c20302e3930206b6d205345206f66204372616e6562726f6f6b20466972652053746174696f6e2c2050656e726974682c205379646e65792c2041552c202d33332e37303732322c203135302e37313735392c2053452077697468207370656564203337206b6d2f682c2031393a3438204a616e20342020454f46")); + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "8000011bb0009e0001015b93032ef6f35994a9545472616d69676f3a204d6f76696e672c20302e3930206b6d205345206f66204372616e6562726f6f6b20466972652053746174696f6e2c2050656e726974682c205379646e65792c2041552c202d33332e37303732322c203135302e37313735392c2053452077697468207370656564203337206b6d2f682c2031393a3438204a616e20342020454f46")); // Tramigo: Parked, 0.12 km E of McDonald's H.V. dela Costa, Makati, 11:07 Mar 27 // Tramigo: Moving, 0.90 km SE of Cranebrook Fire Station, Penrith, Sydney, AU, -33.70722, 150.71759, SE with speed 37 km/h, 19:48 Jan 4 EOF -- cgit v1.2.3 From b4185cbf84bdff2927f7d9a8b0cde9f4ea889353 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 9 Sep 2016 15:32:20 +0500 Subject: Store pulse for watch protocol --- src/org/traccar/protocol/WatchProtocolDecoder.java | 11 +++++++++++ test/org/traccar/protocol/WatchProtocolDecoderTest.java | 3 +++ 2 files changed, 14 insertions(+) (limited to 'test') diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index 326552e7f..488d05a3c 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -25,6 +25,7 @@ import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; +import java.util.Date; import java.util.regex.Pattern; public class WatchProtocolDecoder extends BaseProtocolDecoder { @@ -146,6 +147,16 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel, manufacturer, id, "TKQ"); + } else if (type.equals("PULSE")) { + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + getLastLocation(position, new Date()); + position.setValid(false); + position.set("pulse", content.split(",")[1]); + return position; + } return null; diff --git a/test/org/traccar/protocol/WatchProtocolDecoderTest.java b/test/org/traccar/protocol/WatchProtocolDecoderTest.java index a8f7b12bc..6116c2c2b 100644 --- a/test/org/traccar/protocol/WatchProtocolDecoderTest.java +++ b/test/org/traccar/protocol/WatchProtocolDecoderTest.java @@ -54,6 +54,9 @@ public class WatchProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, text( "[SG*8800000015*0087*AL,220414,134652,A,22.571707,N,113.8613968,E,0.1,0.0,100,7,60,90,1000,50,0001,4,1,460,0,9360,4082,131,9360,4092,148,9360,4091,143,9360,4153,141")); + verifyAttributes(decoder, text( + "[CS*8800000015*0008*PULSE,72")); + } } -- cgit v1.2.3 From 746b3b34a6ff8b28d8ce43c6257ad458a13dde52 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 10 Sep 2016 11:31:18 +1200 Subject: Disable rest of Tramigo unit tests --- test/org/traccar/protocol/TramigoProtocolDecoderTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java index 3818fd7e6..9cf7b9006 100644 --- a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java @@ -18,16 +18,16 @@ public class TramigoProtocolDecoderTest extends ProtocolTest { verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "8000973eb000b90001012128032f14667794e2564176656e7369732053797353657276653a2049676e6974696f6e206f6e2064657465637465642c2073746f707065642c20302e3134206b6d205357206f66204261626120416e696d61736861756e205374726565742d426f64652054686f6d61732053742e2c20537572756c6572652c204c61676f7320436974792c204e472c20362e34383736372c20332e33343737332c2031303a3438204d6172203131202020454f46")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "8000b73eb000ad000101fdd2032f1466c9cbe2564176656e7369732053797353657276653a2049676e6974696f6e206f6e2064657465637465642c206d6f76696e672c20302e3131206b6d2045206f6620416c68616a69204d6173686120526f616420466f6f746272696467652c20537572756c6572652c204c61676f7320436974792c204e472c20362e35303031342c20332e33353434332c2031343a3434204d6172203131202020454f46")); verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "8000883eb000d3000101b223032f1466fc89e2564176656e7369732053797353657276653a2049676e6974696f6e206f66662064657465637465642c2049676e4f6e506572696f643a2030303a30323a34312c2073746f707065642c20302e3039206b6d205345206f66204a696e616475205072696d617279205363686f6f6c20416465204f6e6974696d6572696e2053742e2c20537572756c6572652c204c61676f7320436974792c204e472c20362e34383639332c20332e33343636302c2031303a3033204d6172203131202020454f46")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "80009a3eb000d300010109ff032f1466b195e2564176656e7369732053797353657276653a2049676e6974696f6e206f66662064657465637465642c2049676e4f6e506572696f643a2030303a30353a31342c2073746f707065642c20302e3039206b6d205345206f66204a696e616475205072696d617279205363686f6f6c20416465204f6e6974696d6572696e2053742e2c20537572756c6572652c204c61676f7320436974792c204e472c20362e34383639312c20332e33343636322c2031303a3533204d6172203131202020454f46")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "8000bc3eb000ba000101622c032f1466bacce2564176656e7369732053797353657276653a2049676e6974696f6e206f66662064657465637465642c2049676e4f6e506572696f643a2030303a30343a30302c206d6f76696e672c20617420416b6572656c6520526f61642d4f67756e6c616e612044726976652c20537572756c6572652c204c61676f7320436974792c204e472c20362e35303630332c20332e33353232382c2031343a3438204d6172203131202020454f46")); verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, -- cgit v1.2.3 From d454901a5ff831eaee30db23df12556b6442693a Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 13 Sep 2016 23:11:45 +1200 Subject: Improve H02 decoder text pattern --- src/org/traccar/protocol/H02ProtocolDecoder.java | 3 ++- test/org/traccar/protocol/H02ProtocolDecoderTest.java | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index fc6c9f17c..a0c646900 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -129,7 +129,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { .text("*") .expression("..,") // manufacturer .number("(d+),") // imei - .number("Vd,") // version? + .expression("[^,]+,") .any() .number("(?:(dd)(dd)(dd))?,") // time .expression("([AV])?,") // validity @@ -148,6 +148,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { .number("(d+.?d*),") // speed .number("(d+.?d*)?,") // course .number("(?:(dd)(dd)(dd))?,") // date (ddmmyy) + .any() .number("(x{8})") // status .any() .compile(); diff --git a/test/org/traccar/protocol/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java index d147cdec2..e4db2f56f 100644 --- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class H02ProtocolDecoderTest extends ProtocolTest { H02ProtocolDecoder decoder = new H02ProtocolDecoder(new H02Protocol()); + verifyPosition(decoder, buffer( + "*HQ,4209917484,V19,093043,V,5052.9749,N,00426.4322,E,000.00,000,130916,,0032475874141,8944538530000543700F,FFFFFBFF#")); + verifyPosition(decoder, buffer( "*HQ,353505220873067,V1,,V,4605.75732,N,01430.73863,E,0.00,0,,FFFFFFEF,125,194, 64,d3#")); -- cgit v1.2.3 From 0aeeac33163640bbbe23560cbd108ddf290ac873 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 13 Sep 2016 23:17:23 +1200 Subject: Message length parameter for H02 frame decoder --- src/org/traccar/protocol/H02FrameDecoder.java | 19 ++++++++----------- src/org/traccar/protocol/H02Protocol.java | 6 ++++-- test/org/traccar/protocol/H02FrameDecoderTest.java | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/src/org/traccar/protocol/H02FrameDecoder.java b/src/org/traccar/protocol/H02FrameDecoder.java index 79e33c0ca..572ac979e 100644 --- a/src/org/traccar/protocol/H02FrameDecoder.java +++ b/src/org/traccar/protocol/H02FrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2013 - 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. @@ -22,7 +22,11 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder; public class H02FrameDecoder extends FrameDecoder { - private static final int MESSAGE_LENGTH = 32; + private int messageLength; + + public H02FrameDecoder(int messageLength) { + this.messageLength = messageLength; + } @Override protected Object decode( @@ -30,13 +34,6 @@ public class H02FrameDecoder extends FrameDecoder { char marker = (char) buf.getByte(buf.readerIndex()); - while (marker != '*' && marker != '$' && buf.readableBytes() > 0) { - buf.skipBytes(1); - if (buf.readableBytes() > 0) { - marker = (char) buf.getByte(buf.readerIndex()); - } - } - if (marker == '*') { // Return text message @@ -45,10 +42,10 @@ public class H02FrameDecoder extends FrameDecoder { return buf.readBytes(index + 1 - buf.readerIndex()); } - } else if (marker == '$' && buf.readableBytes() >= MESSAGE_LENGTH) { + } else if (marker == '$' && buf.readableBytes() >= messageLength) { // Return binary message - return buf.readBytes(MESSAGE_LENGTH); + return buf.readBytes(messageLength); } diff --git a/src/org/traccar/protocol/H02Protocol.java b/src/org/traccar/protocol/H02Protocol.java index 72b4f903d..cdc2d11bb 100644 --- a/src/org/traccar/protocol/H02Protocol.java +++ b/src/org/traccar/protocol/H02Protocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 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. @@ -19,6 +19,7 @@ import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; +import org.traccar.Context; import org.traccar.TrackerServer; import org.traccar.model.Command; @@ -42,7 +43,8 @@ public class H02Protocol extends BaseProtocol { serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("frameDecoder", new H02FrameDecoder()); + int messageLength = Context.getConfig().getInteger(getName() + ".messageLength", 32); + pipeline.addLast("frameDecoder", new H02FrameDecoder(messageLength)); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("objectEncoder", new H02ProtocolEncoder()); pipeline.addLast("objectDecoder", new H02ProtocolDecoder(H02Protocol.this)); diff --git a/test/org/traccar/protocol/H02FrameDecoderTest.java b/test/org/traccar/protocol/H02FrameDecoderTest.java index e8b045048..a8417341a 100644 --- a/test/org/traccar/protocol/H02FrameDecoderTest.java +++ b/test/org/traccar/protocol/H02FrameDecoderTest.java @@ -9,7 +9,7 @@ public class H02FrameDecoderTest extends ProtocolTest { @Test public void testDecode() throws Exception { - H02FrameDecoder decoder = new H02FrameDecoder(); + H02FrameDecoder decoder = new H02FrameDecoder(32); Assert.assertEquals( binary("2a48512c3335333538383036303031353536382c56312c3139333530352c412c3830392e303031302c532c333435342e383939372c572c302e30302c302e30302c3239313031332c65666666666266662c3030303264342c3030303030622c3030353338352c3030353261612c323523"), -- cgit v1.2.3 From 38bbab77b848989b1065a41666518bef64d147e5 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 14 Sep 2016 02:47:00 +1200 Subject: Support Xexun messages without time --- src/org/traccar/protocol/XexunProtocolDecoder.java | 4 ++-- test/org/traccar/protocol/XexunProtocolDecoderTest.java | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/src/org/traccar/protocol/XexunProtocolDecoder.java b/src/org/traccar/protocol/XexunProtocolDecoder.java index 69100f54b..7ec2685fa 100644 --- a/src/org/traccar/protocol/XexunProtocolDecoder.java +++ b/src/org/traccar/protocol/XexunProtocolDecoder.java @@ -37,13 +37,13 @@ public class XexunProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_BASIC = new PatternBuilder() .expression("G[PN]RMC,") - .number("(dd)(dd)(dd).(d+),") // time + .number("(?:(dd)(dd)(dd))?.(d+),") // time .expression("([AV]),") // validity .number("(d*?)(d?d.d+),([NS]),") // latitude .number("(d*?)(d?d.d+),([EW])?,") // longitude .number("(d+.?d*),") // speed .number("(d+.?d*)?,") // course - .number("(dd)(dd)(dd),") // date + .number("(?:(dd)(dd)(dd))?,") // date .expression("[^*]*").text("*") .number("xx") // checksum .expression("\\r\\n").optional() diff --git a/test/org/traccar/protocol/XexunProtocolDecoderTest.java b/test/org/traccar/protocol/XexunProtocolDecoderTest.java index ac90daec5..e94fb62e8 100644 --- a/test/org/traccar/protocol/XexunProtocolDecoderTest.java +++ b/test/org/traccar/protocol/XexunProtocolDecoderTest.java @@ -1,6 +1,5 @@ package org.traccar.protocol; - import org.junit.Test; import org.traccar.ProtocolTest; @@ -11,6 +10,9 @@ public class XexunProtocolDecoderTest extends ProtocolTest { XexunProtocolDecoder decoder = new XexunProtocolDecoder(new XexunProtocol(), false); + verifyAttributes(decoder, text( + "GPRMC,.000,A,0.000000,S,0.0000,W,0.00,0.00,,00,0000.0,A*55,L,,imei:353579010727036,")); + verifyPosition(decoder, text( "GPRMC,113518.000,A,5303.4150,N,10.2368,E,60.73,207.42,260216,00,0000.0,A*74,F,,imei:351525018007873,")); -- cgit v1.2.3 From 5a3cad30d5b2fa5a4be6cba0eed6df135f496165 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 14 Sep 2016 07:53:15 +1200 Subject: Implement more Castel message types --- src/org/traccar/helper/ObdDecoder.java | 14 +++--- .../traccar/protocol/CastelProtocolDecoder.java | 51 ++++++++++++++++++++++ .../protocol/CastelProtocolDecoderTest.java | 12 ++--- 3 files changed, 66 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/src/org/traccar/helper/ObdDecoder.java b/src/org/traccar/helper/ObdDecoder.java index 4686aa682..6ffe39662 100644 --- a/src/org/traccar/helper/ObdDecoder.java +++ b/src/org/traccar/helper/ObdDecoder.java @@ -25,9 +25,9 @@ public final class ObdDecoder { private ObdDecoder() { } - public static final int MODE_CURRENT = 0x01; - public static final int MODE_FREEZE_FRAME = 0x02; - public static final int MODE_CODES = 0x03; + private static final int MODE_CURRENT = 0x01; + private static final int MODE_FREEZE_FRAME = 0x02; + private static final int MODE_CODES = 0x03; private static final int PID_ENGINE_LOAD = 0x04; private static final int PID_COOLANT_TEMPERATURE = 0x05; @@ -54,7 +54,7 @@ public final class ObdDecoder { return new AbstractMap.SimpleEntry<>(key, value); } - private static Map.Entry decodeCodes(String value) { + public static Map.Entry decodeCodes(String value) { StringBuilder codes = new StringBuilder(); for (int i = 0; i < value.length() / 4; i++) { int numValue = Integer.parseInt(value.substring(i * 4, (i + 1) * 4), 16); @@ -75,7 +75,11 @@ public final class ObdDecoder { } codes.append(String.format("%04X", numValue & 0x3FFF)); } - return createEntry("dtcs", codes.toString().replaceFirst(",", "")); + if (codes.length() > 0) { + return createEntry("dtcs", codes.toString().replaceFirst(",", "")); + } else { + return null; + } } private static Map.Entry decodeData(int pid, String value) { diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index 38fb11164..b8faed077 100644 --- a/src/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/org/traccar/protocol/CastelProtocolDecoder.java @@ -22,6 +22,7 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; +import org.traccar.helper.ObdDecoder; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; @@ -43,7 +44,13 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { private static final short MSG_SC_HEARTBEAT = 0x1003; private static final short MSG_SC_HEARTBEAT_RESPONSE = (short) 0x9003; private static final short MSG_SC_GPS = 0x4001; + private static final short MSG_SC_PID_DATA = 0x4002; + private static final short MSG_SC_SUPPORTED_PID = 0x4004; + private static final short MSG_SC_OBD_DATA = 0x4005; + private static final short MSG_SC_DTCS_PASSENGER = 0x4006; + private static final short MSG_SC_DTCS_COMMERCIAL = 0x400B; private static final short MSG_SC_ALARM = 0x4007; + private static final short MSG_SC_CELL = 0x4008; private static final short MSG_SC_GPS_SLEEP = 0x4009; private static final short MSG_SC_AGPS_REQUEST = 0x5101; private static final short MSG_SC_CURRENT_LOCATION = (short) 0xB001; @@ -193,6 +200,50 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { return readPosition(deviceSession, buf); + } else if (type == MSG_SC_DTCS_PASSENGER) { + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + buf.skipBytes(6 * 4 + 2 + 8); + + buf.readUnsignedByte(); // flag + position.add(ObdDecoder.decodeCodes(ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedByte())))); + + return position; + + } else if (type == MSG_SC_OBD_DATA) { + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + buf.skipBytes(6 * 4 + 2 + 8); + + // decode data + + return position; + + } else if (type == MSG_SC_CELL) { + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + buf.skipBytes(6 * 4 + 2 + 8); + + position.set(Position.KEY_LAC, buf.readUnsignedShort()); + position.set(Position.KEY_CID, buf.readUnsignedShort()); + + return position; + } return null; diff --git a/test/org/traccar/protocol/CastelProtocolDecoderTest.java b/test/org/traccar/protocol/CastelProtocolDecoderTest.java index a5b477ea5..ccdd6f726 100644 --- a/test/org/traccar/protocol/CastelProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CastelProtocolDecoderTest.java @@ -18,10 +18,10 @@ public class CastelProtocolDecoderTest extends ProtocolTest { verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, "40407800043231334e583230313630303131373700000000004004fa52ce574b53ce57cad1020041020000050c00000d0000000400036401240b0503001b042105210c210d210f211021112113211c211f212121232124212c212d213021312133213e2141214221452149214a214c214f215021384e0d0a")); - verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040a600043231334e583230313630303131373700000000004005fa52ce575053ce57cad102006b020000050c00000d0000000400036401240b050300001b042105210c210d210f211021112113211c211f212121232124212c212d213021312133213e2141214221452149214a214c214f215021015bd604301f500600000653000000bc0bffff78250000ff2d98642401000f8080e038000f0f0000000000000077b10d0a")); - verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, "40404300043231334e583230313630303131373700000000004006fa52ce574e53ce57cad1020053020000050c00000d0000000400036401240b0503000000feec0d0a")); verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, @@ -54,10 +54,10 @@ public class CastelProtocolDecoderTest extends ProtocolTest { verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, "40405900043130303131313235323939383700000000000000400101C1F06952E7F069529C9111000000000069830000070000000400036401014C00030001190A0D0412041480D60488C57218000000009F01E803ED9A0D0A")); - verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040B9000431303031313132353239393837000000000000004005C1F069521BF169529C9111000000000069830000130000000400036401014C0003000022032104210521062107210C210D210E210F2110211121132115211C211F21212124212E212F2130213121322133213C214221432144214521472149214A214C214D214E210100643B6232E803003E64280A3C24FE00010E010F00D5805A483C640000000000010000E02E000000066400000500000000A7710D0A")); - verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, "404043000431303031313132353239393837000000000000004006C1F0695209F169529C91110000000000698300000D0000000400036401014C00030000009AF40D0A")); verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, @@ -72,7 +72,7 @@ public class CastelProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, "40405c000c363131313530303030393536000000000000000040011c0a0f0e362dca53cd0860831303000000000300000000ff000000000000007ba083a650542d3639305f56312e312e320050542d3639302056312e32008a020d0a")); - verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040450004323132474c31313433303035303033000000000040082ca89b55a6a99b555c57000000000000c40200000b0000001400036401111f000302f5533bd653f10d0a")); verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, @@ -81,7 +81,7 @@ public class CastelProtocolDecoderTest extends ProtocolTest { verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040420004323132474c31313433303035303033000000000010022ca89b55cca99b555c57000000000000cf0200000b0000000000036401111f0000020013be0d0a")); - verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040870004323132474c31313433303035303033000000000040052ca89b55e3a89b555c57000000000000c4020000040000001400036401111f0003000012042105210b210c210d210f211021112113211c2121212321242133213421422146214f212b50663603003ce9030dff060000600dffffc25865ffff9e02b43624000000003cbc0d0a")); verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, -- cgit v1.2.3 From 49754dbd853cd35876d74d7d8781c97a3c1413f7 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 15 Sep 2016 06:53:37 +1200 Subject: Implement Arknav X8 series support --- debug.xml | 1 + src/org/traccar/protocol/ArknavX8Protocol.java | 47 +++++++++++ .../traccar/protocol/ArknavX8ProtocolDecoder.java | 95 ++++++++++++++++++++++ .../protocol/ArknavX8ProtocolDecoderTest.java | 33 ++++++++ 4 files changed, 176 insertions(+) create mode 100644 src/org/traccar/protocol/ArknavX8Protocol.java create mode 100644 src/org/traccar/protocol/ArknavX8ProtocolDecoder.java create mode 100644 test/org/traccar/protocol/ArknavX8ProtocolDecoderTest.java (limited to 'test') diff --git a/debug.xml b/debug.xml index 9e2f495aa..2c2d0b334 100644 --- a/debug.xml +++ b/debug.xml @@ -453,5 +453,6 @@ 5116 5117 5118 + 5119 diff --git a/src/org/traccar/protocol/ArknavX8Protocol.java b/src/org/traccar/protocol/ArknavX8Protocol.java new file mode 100644 index 000000000..cf6708c73 --- /dev/null +++ b/src/org/traccar/protocol/ArknavX8Protocol.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.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 ArknavX8Protocol extends BaseProtocol { + + public ArknavX8Protocol() { + super("arknavx8"); + } + + @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("stringEncoder", new StringEncoder()); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new ArknavX8ProtocolDecoder(ArknavX8Protocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java new file mode 100644 index 000000000..931cb1d14 --- /dev/null +++ b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java @@ -0,0 +1,95 @@ +/* + * 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.DeviceSession; +import org.traccar.helper.DateBuilder; +import org.traccar.helper.Parser; +import org.traccar.helper.PatternBuilder; +import org.traccar.helper.PatternUtil; +import org.traccar.model.Position; + +import java.net.SocketAddress; +import java.util.regex.Pattern; + +public class ArknavX8ProtocolDecoder extends BaseProtocolDecoder { + + public ArknavX8ProtocolDecoder(ArknavX8Protocol protocol) { + super(protocol); + } + + private static final Pattern PATTERN = new PatternBuilder() + .expression("(..),") // type + .number("(dd)(dd)(dd)") // date (yymmdd) + .number("(dd)(dd)(dd),") // time + .expression("([AV]),") // validity + .number("(d+)(dd.d+)([NS]),") // latitude + .number("(d+)(dd.d+)([EW]),") // longitude + .number("(d+.d+),") // speed + .number("(d+),") // course + .number("(d+.d+),") // hdop + .number("(d+)") // status + .compile(); + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + String sentence = (String) msg; + + if (sentence.charAt(2) != ',') { + getDeviceSession(channel, remoteAddress, sentence.substring(0, 15)); + return null; + } + + PatternUtil.MatchResult r = PatternUtil.checkPattern(PATTERN.pattern(), sentence); + + Parser parser = new Parser(PATTERN, sentence); + if (!parser.matches()) { + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession == null) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + parser.next(); // type + + DateBuilder dateBuilder = new DateBuilder() + .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + position.setValid(parser.next().equals("A")); + position.setLatitude(parser.nextCoordinate()); + position.setLongitude(parser.nextCoordinate()); + position.setSpeed(parser.nextDouble()); + position.setCourse(parser.nextDouble()); + + position.set(Position.KEY_HDOP, parser.nextDouble()); + position.set(Position.KEY_STATUS, parser.next()); + + return position; + } + +} diff --git a/test/org/traccar/protocol/ArknavX8ProtocolDecoderTest.java b/test/org/traccar/protocol/ArknavX8ProtocolDecoderTest.java new file mode 100644 index 000000000..a28e71c64 --- /dev/null +++ b/test/org/traccar/protocol/ArknavX8ProtocolDecoderTest.java @@ -0,0 +1,33 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class ArknavX8ProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + ArknavX8ProtocolDecoder decoder = new ArknavX8ProtocolDecoder(new ArknavX8Protocol()); + + verifyNothing(decoder, text( + "351856040005407,240101")); + + verifyPosition(decoder, text( + "1R,110509053244,A,2457.9141N,12126.3321E,220.0,315,10.0,00000000")); + + verifyNothing(decoder, text( + "2R,110509053244,837493,,998372,,,")); + + verifyPosition(decoder, text( + "1G,110509053245,A,2457.9141N,12126.3192E,3.1,35,2.0,00000001")); + + verifyPosition(decoder, text( + "1G,110509053246,A,2457.9121N,12126.3415E,2.0,288,1.7,00000000")); + + verifyPosition(decoder, text( + "1M,110509053247,A,2457.9118N,12126.3522E,1.0,55,2.2,00000000")); + + } + +} -- cgit v1.2.3 From 722327b482e51d8b48fd4bab1e6a27fe972fc167 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 15 Sep 2016 08:20:45 +1200 Subject: Implement AutoGrade device protocol --- debug.xml | 1 + src/org/traccar/protocol/AutoGradeProtocol.java | 47 ++++++++++ .../traccar/protocol/AutoGradeProtocolDecoder.java | 102 +++++++++++++++++++++ .../protocol/AutoGradeProtocolDecoderTest.java | 18 ++++ 4 files changed, 168 insertions(+) create mode 100644 src/org/traccar/protocol/AutoGradeProtocol.java create mode 100644 src/org/traccar/protocol/AutoGradeProtocolDecoder.java create mode 100644 test/org/traccar/protocol/AutoGradeProtocolDecoderTest.java (limited to 'test') diff --git a/debug.xml b/debug.xml index 2c2d0b334..b9b32a639 100644 --- a/debug.xml +++ b/debug.xml @@ -454,5 +454,6 @@ 5117 5118 5119 + 5120 diff --git a/src/org/traccar/protocol/AutoGradeProtocol.java b/src/org/traccar/protocol/AutoGradeProtocol.java new file mode 100644 index 000000000..1fb6b1ce2 --- /dev/null +++ b/src/org/traccar/protocol/AutoGradeProtocol.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.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 AutoGradeProtocol extends BaseProtocol { + + public AutoGradeProtocol() { + super("autograde"); + } + + @Override + public void initTrackerServers(List serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ')')); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("objectDecoder", new AutoGradeProtocolDecoder(AutoGradeProtocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/AutoGradeProtocolDecoder.java b/src/org/traccar/protocol/AutoGradeProtocolDecoder.java new file mode 100644 index 000000000..5c9dd7ece --- /dev/null +++ b/src/org/traccar/protocol/AutoGradeProtocolDecoder.java @@ -0,0 +1,102 @@ +/* + * 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.DeviceSession; +import org.traccar.helper.DateBuilder; +import org.traccar.helper.Parser; +import org.traccar.helper.PatternBuilder; +import org.traccar.model.Position; + +import java.net.SocketAddress; +import java.util.regex.Pattern; + +public class AutoGradeProtocolDecoder extends BaseProtocolDecoder { + + public AutoGradeProtocolDecoder(AutoGradeProtocol protocol) { + super(protocol); + } + + private static final Pattern PATTERN = new PatternBuilder() + .text("(") + .number("d{12}") // index + .number("(d{15})") // imei + .number("(dd)(dd)(dd)") // date + .expression("([AV])") // validity + .number("(d+)(dd.d+)([NS])") // latitude + .number("(d+)(dd.d+)([EW])") // longitude + .number("([d.]{5})") // speed + .number("(dd)(dd)(dd)") // time + .number("([d.]{6})") // course + .expression(".") // status + .number("A(xxxx)") + .number("B(xxxx)") + .number("C(xxxx)") + .number("D(xxxx)") + .number("E(xxxx)") + .number("K(xxxx)") + .number("L(xxxx)") + .number("M(xxxx)") + .number("N(xxxx)") + .number("O(xxxx)") + .any() + .compile(); + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + Parser parser = new Parser(PATTERN, (String) msg); + if (!parser.matches()) { + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + DateBuilder dateBuilder = new DateBuilder() + .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); + + position.setValid(parser.next().equals("A")); + position.setLatitude(parser.nextCoordinate()); + position.setLongitude(parser.nextCoordinate()); + position.setSpeed(parser.nextDouble()); + + dateBuilder.setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + position.setCourse(parser.nextDouble()); + + for (int i = 1; i <= 5; i++) { + position.set(Position.PREFIX_ADC + i, parser.next()); + } + + for (int i = 1; i <= 5; i++) { + position.set("can" + i, parser.next()); + } + + return position; + } + +} diff --git a/test/org/traccar/protocol/AutoGradeProtocolDecoderTest.java b/test/org/traccar/protocol/AutoGradeProtocolDecoderTest.java new file mode 100644 index 000000000..58e2e4065 --- /dev/null +++ b/test/org/traccar/protocol/AutoGradeProtocolDecoderTest.java @@ -0,0 +1,18 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class AutoGradeProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + AutoGradeProtocolDecoder decoder = new AutoGradeProtocolDecoder(new AutoGradeProtocol()); + + verifyPosition(decoder, text( + "(000000007322865733022629240170415A1001.1971N07618.1375E0.000145312128.59?A0024B0024C0000D0000E0000K0000L0000M0000N0000O0000")); + + } + +} -- cgit v1.2.3 From 17f9739cf7f9db0ac974598b76eee1d3082174f4 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 16 Sep 2016 07:14:37 +1200 Subject: Add new Noran test cases --- test/org/traccar/protocol/NoranProtocolDecoderTest.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test') diff --git a/test/org/traccar/protocol/NoranProtocolDecoderTest.java b/test/org/traccar/protocol/NoranProtocolDecoderTest.java index abe21c68e..1b7287e7b 100644 --- a/test/org/traccar/protocol/NoranProtocolDecoderTest.java +++ b/test/org/traccar/protocol/NoranProtocolDecoderTest.java @@ -12,6 +12,12 @@ public class NoranProtocolDecoderTest extends ProtocolTest { NoranProtocolDecoder decoder = new NoranProtocolDecoder(new NoranProtocol()); + verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "0d0a2a4b57000d000080010d0a")); + + verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "34000800010b0000000000003f43bb8da6c2ebe229424e523039423233343439000031362d30392d31352030373a30303a303700")); + verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, "28003200c380000000469458408c4ad340ad381e3f4e52303947313336303900000001ff00002041")); -- cgit v1.2.3 From d18e293a891c3ef1f3ab2ff9a3b663320a7f4f0b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 16 Sep 2016 17:36:45 +1200 Subject: Implement SinoCastel OBD decoding --- src/org/traccar/helper/ObdDecoder.java | 23 ++-- .../traccar/protocol/CastelProtocolDecoder.java | 130 ++++++++++++++++++--- .../protocol/CastelProtocolDecoderTest.java | 16 +-- 3 files changed, 131 insertions(+), 38 deletions(-) (limited to 'test') diff --git a/src/org/traccar/helper/ObdDecoder.java b/src/org/traccar/helper/ObdDecoder.java index 6ffe39662..8383a2b1a 100644 --- a/src/org/traccar/helper/ObdDecoder.java +++ b/src/org/traccar/helper/ObdDecoder.java @@ -42,7 +42,9 @@ public final class ObdDecoder { switch (mode) { case MODE_CURRENT: case MODE_FREEZE_FRAME: - return decodeData(Integer.parseInt(value.substring(0, 2), 16), value.substring(2)); + return decodeData( + Integer.parseInt(value.substring(0, 2), 16), + Integer.parseInt(value.substring(2), 16)); case MODE_CODES: return decodeCodes(value); default: @@ -82,25 +84,24 @@ public final class ObdDecoder { } } - private static Map.Entry decodeData(int pid, String value) { - int intValue = Integer.parseInt(value, 16); + public static Map.Entry decodeData(int pid, int value) { switch (pid) { case PID_ENGINE_LOAD: - return createEntry("engineLoad", intValue * 100 / 255); + return createEntry("engineLoad", value * 100 / 255); case PID_COOLANT_TEMPERATURE: - return createEntry("coolantTemperature", intValue - 40); + return createEntry("coolantTemperature", value - 40); case PID_ENGINE_RPM: - return createEntry(Position.KEY_RPM, intValue / 4); + return createEntry(Position.KEY_RPM, value / 4); case PID_VEHICLE_SPEED: - return createEntry(Position.KEY_OBD_SPEED, intValue); + return createEntry(Position.KEY_OBD_SPEED, value); case PID_THROTTLE_POSITION: - return createEntry("throttle", intValue * 100 / 255); + return createEntry("throttle", value * 100 / 255); case PID_MIL_DISTANCE: - return createEntry("milDistance", intValue); + return createEntry("milDistance", value); case PID_FUEL_LEVEL: - return createEntry(Position.KEY_FUEL, intValue * 100 / 255); + return createEntry(Position.KEY_FUEL, value * 100 / 255); case PID_DISTANCE_CLEARED: - return createEntry("clearedDistance", intValue); + return createEntry("clearedDistance", value); default: return null; } diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index b8faed077..ee5fac5e6 100644 --- a/src/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/org/traccar/protocol/CastelProtocolDecoder.java @@ -29,11 +29,46 @@ import org.traccar.model.Position; import java.net.SocketAddress; import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; public class CastelProtocolDecoder extends BaseProtocolDecoder { + private static final Map PID_LENGTH_MAP = new HashMap<>(); + + static { + int[] l1 = { + 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0b, 0x0d, + 0x0e, 0x0f, 0x11, 0x12, 0x13, 0x1c, 0x1d, 0x1e, 0x2c, + 0x2d, 0x2e, 0x2f, 0x30, 0x33, 0x43, 0x45, 0x46, + 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x51, 0x52, + 0x5a + }; + int[] l2 = { + 0x02, 0x03, 0x0a, 0x0c, 0x10, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1f, 0x21, 0x22, + 0x23, 0x31, 0x32, 0x3c, 0x3d, 0x3e, 0x3f, 0x42, + 0x44, 0x4d, 0x4e, 0x50, 0x53, 0x54, 0x55, 0x56, + 0x57, 0x58, 0x59 + }; + int[] l4 = { + 0x00, 0x01, 0x20, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x34, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3a, 0x3b, 0x40, 0x41, 0x4f + }; + for (int i : l1) { + PID_LENGTH_MAP.put(i, 1); + } + for (int i : l2) { + PID_LENGTH_MAP.put(i, 2); + } + for (int i : l4) { + PID_LENGTH_MAP.put(i, 4); + } + } + public CastelProtocolDecoder(CastelProtocol protocol) { super(protocol); } @@ -91,6 +126,63 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { return position; } + private Position createPosition(DeviceSession deviceSession) { + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + return position; + } + + private void decodeObd(Position position, ChannelBuffer buf, boolean groups) { + + int count = buf.readUnsignedByte(); + + int[] pids = new int[count]; + for (int i = 0; i < count; i++) { + pids[i] = buf.readUnsignedShort() & 0xff; + } + + if (groups) { + buf.readUnsignedByte(); // group count + buf.readUnsignedByte(); // group size + } + + for (int i = 0; i < count; i++) { + int value; + switch (PID_LENGTH_MAP.get(pids[i])) { + case 1: + value = buf.readUnsignedByte(); + break; + case 2: + value = buf.readUnsignedShort(); + break; + case 4: + value = buf.readInt(); + break; + default: + value = 0; + break; + } + position.add(ObdDecoder.decodeData(pids[i], value)); + } + } + + private void decodeStat(Position position, ChannelBuffer buf) { + + buf.readUnsignedInt(); // ACC ON time + buf.readUnsignedInt(); // UTC time + position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + buf.readUnsignedInt(); // trip odometer + buf.readUnsignedInt(); // total fuel consumption + buf.readUnsignedShort(); // current fuel consumption + position.set(Position.KEY_STATUS, buf.readUnsignedInt()); + buf.skipBytes(8); + } + private void sendResponse( Channel channel, SocketAddress remoteAddress, int version, ChannelBuffer id, short type, ChannelBuffer content) { @@ -200,15 +292,22 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { return readPosition(deviceSession, buf); - } else if (type == MSG_SC_DTCS_PASSENGER) { + } else if (type == MSG_SC_PID_DATA) { - Position position = new Position(); - position.setProtocol(getProtocolName()); - position.setDeviceId(deviceSession.getDeviceId()); + Position position = createPosition(deviceSession); - getLastLocation(position, null); + decodeStat(position, buf); - buf.skipBytes(6 * 4 + 2 + 8); + buf.readUnsignedShort(); // sample rate + decodeObd(position, buf, true); + + return position; + + } else if (type == MSG_SC_DTCS_PASSENGER) { + + Position position = createPosition(deviceSession); + + decodeStat(position, buf); buf.readUnsignedByte(); // flag position.add(ObdDecoder.decodeCodes(ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedByte())))); @@ -217,27 +316,20 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { } else if (type == MSG_SC_OBD_DATA) { - Position position = new Position(); - position.setProtocol(getProtocolName()); - position.setDeviceId(deviceSession.getDeviceId()); - - getLastLocation(position, null); + Position position = createPosition(deviceSession); - buf.skipBytes(6 * 4 + 2 + 8); + decodeStat(position, buf); - // decode data + buf.readUnsignedByte(); // flag + decodeObd(position, buf, false); return position; } else if (type == MSG_SC_CELL) { - Position position = new Position(); - position.setProtocol(getProtocolName()); - position.setDeviceId(deviceSession.getDeviceId()); - - getLastLocation(position, null); + Position position = createPosition(deviceSession); - buf.skipBytes(6 * 4 + 2 + 8); + decodeStat(position, buf); position.set(Position.KEY_LAC, buf.readUnsignedShort()); position.set(Position.KEY_CID, buf.readUnsignedShort()); diff --git a/test/org/traccar/protocol/CastelProtocolDecoderTest.java b/test/org/traccar/protocol/CastelProtocolDecoderTest.java index ccdd6f726..e2f2c26bf 100644 --- a/test/org/traccar/protocol/CastelProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CastelProtocolDecoderTest.java @@ -12,16 +12,16 @@ public class CastelProtocolDecoderTest extends ProtocolTest { CastelProtocolDecoder decoder = new CastelProtocolDecoder(new CastelProtocol()); - verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "40405700043231334e583230313630303131373700000000004002c458ce572159ce57a9e2020082030000500c00000f0000000400036401240e0403023c000505210c210d210f21102101075b14030121330269430d0a")); verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, "40407800043231334e583230313630303131373700000000004004fa52ce574b53ce57cad1020041020000050c00000d0000000400036401240b0503001b042105210c210d210f211021112113211c211f212121232124212c212d213021312133213e2141214221452149214a214c214f215021384e0d0a")); - verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040a600043231334e583230313630303131373700000000004005fa52ce575053ce57cad102006b020000050c00000d0000000400036401240b050300001b042105210c210d210f211021112113211c211f212121232124212c212d213021312133213e2141214221452149214a214c214f215021015bd604301f500600000653000000bc0bffff78250000ff2d98642401000f8080e038000f0f0000000000000077b10d0a")); - verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "40404300043231334e583230313630303131373700000000004006fa52ce574e53ce57cad1020053020000050c00000d0000000400036401240b0503000000feec0d0a")); verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, @@ -48,16 +48,16 @@ public class CastelProtocolDecoderTest extends ProtocolTest { verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, "40406000043130303131313235323939383700000000000000400705000000C1F0695249F469529C9111000000000069830000D80040000400036401014C04030001190A0D04201E1480D60488C5721800000000AF0101060F000F00EA1E0D0A")); - verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "404057000431303031313132353239393837000000000000004002C1F06952F0F169529C9111000000000069830000470000000400036401014C01030078000505210C210D210F21102101073BE8030064280AEB930D0A")); verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, "40405900043130303131313235323939383700000000000000400101C1F06952E7F069529C9111000000000069830000070000000400036401014C00030001190A0D0412041480D60488C57218000000009F01E803ED9A0D0A")); - verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040B9000431303031313132353239393837000000000000004005C1F069521BF169529C9111000000000069830000130000000400036401014C0003000022032104210521062107210C210D210E210F2110211121132115211C211F21212124212E212F2130213121322133213C214221432144214521472149214A214C214D214E210100643B6232E803003E64280A3C24FE00010E010F00D5805A483C640000000000010000E02E000000066400000500000000A7710D0A")); - verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "404043000431303031313132353239393837000000000000004006C1F0695209F169529C91110000000000698300000D0000000400036401014C00030000009AF40D0A")); verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, @@ -72,7 +72,7 @@ public class CastelProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, "40405c000c363131313530303030393536000000000000000040011c0a0f0e362dca53cd0860831303000000000300000000ff000000000000007ba083a650542d3639305f56312e312e320050542d3639302056312e32008a020d0a")); - verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040450004323132474c31313433303035303033000000000040082ca89b55a6a99b555c57000000000000c40200000b0000001400036401111f000302f5533bd653f10d0a")); verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, @@ -81,7 +81,7 @@ public class CastelProtocolDecoderTest extends ProtocolTest { verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040420004323132474c31313433303035303033000000000010022ca89b55cca99b555c57000000000000cf0200000b0000000000036401111f0000020013be0d0a")); - verifyNotNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "4040870004323132474c31313433303035303033000000000040052ca89b55e3a89b555c57000000000000c4020000040000001400036401111f0003000012042105210b210c210d210f211021112113211c2121212321242133213421422146214f212b50663603003ce9030dff060000600dffffc25865ffff9e02b43624000000003cbc0d0a")); verifyNothing(decoder, binary(ByteOrder.LITTLE_ENDIAN, -- cgit v1.2.3 From ef234432c20772b1eaf7fccf6bab7fa536fb47db Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 17 Sep 2016 16:41:58 +1200 Subject: Implement OIGO device protocol --- debug.xml | 1 + src/org/traccar/protocol/OigoProtocol.java | 41 ++++++ src/org/traccar/protocol/OigoProtocolDecoder.java | 155 +++++++++++++++++++++ .../traccar/protocol/OigoProtocolDecoderTest.java | 21 +++ 4 files changed, 218 insertions(+) create mode 100644 src/org/traccar/protocol/OigoProtocol.java create mode 100644 src/org/traccar/protocol/OigoProtocolDecoder.java create mode 100644 test/org/traccar/protocol/OigoProtocolDecoderTest.java (limited to 'test') diff --git a/debug.xml b/debug.xml index b9b32a639..6ad830402 100644 --- a/debug.xml +++ b/debug.xml @@ -455,5 +455,6 @@ 5118 5119 5120 + 5121 diff --git a/src/org/traccar/protocol/OigoProtocol.java b/src/org/traccar/protocol/OigoProtocol.java new file mode 100644 index 000000000..c60ee1be6 --- /dev/null +++ b/src/org/traccar/protocol/OigoProtocol.java @@ -0,0 +1,41 @@ +/* + * 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.ConnectionlessBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; + +import java.util.List; + +public class OigoProtocol extends BaseProtocol { + + public OigoProtocol() { + super("oigo"); + } + + @Override + public void initTrackerServers(List serverList) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("objectDecoder", new OigoProtocolDecoder(OigoProtocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/OigoProtocolDecoder.java b/src/org/traccar/protocol/OigoProtocolDecoder.java new file mode 100644 index 000000000..799f47ea3 --- /dev/null +++ b/src/org/traccar/protocol/OigoProtocolDecoder.java @@ -0,0 +1,155 @@ +/* + * 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.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +import org.jboss.netty.channel.Channel; +import org.traccar.BaseProtocolDecoder; +import org.traccar.DeviceSession; +import org.traccar.helper.BitUtil; +import org.traccar.helper.DateBuilder; +import org.traccar.helper.UnitsConverter; +import org.traccar.model.Position; + +import java.net.SocketAddress; +import java.nio.charset.StandardCharsets; + +public class OigoProtocolDecoder extends BaseProtocolDecoder { + + public OigoProtocolDecoder(OigoProtocol protocol) { + super(protocol); + } + + public static final int MSG_LOCATION = 0x00; + public static final int MSG_REMOTE_START = 0x10; + public static final int MSG_ACKNOWLEDGEMENT = 0xE0; + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + ChannelBuffer buf = (ChannelBuffer) msg; + + buf.skipBytes(1); // header + buf.readUnsignedShort(); // length + + int type = buf.readUnsignedByte(); + + int tag = buf.readUnsignedByte(); + + DeviceSession deviceSession; + switch (BitUtil.to(tag, 3)) { + case 0: + String imei = ChannelBuffers.hexDump(buf.readBytes(9)).substring(1, 1 + 15); + deviceSession = getDeviceSession(channel, remoteAddress, imei); + break; + case 1: + buf.skipBytes(1); + String meid = buf.readBytes(14).toString(StandardCharsets.US_ASCII); + deviceSession = getDeviceSession(channel, remoteAddress, meid); + break; + default: + deviceSession = getDeviceSession(channel, remoteAddress); + break; + } + + if (deviceSession == null || type != MSG_LOCATION) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + int mask = buf.readInt(); + + if (BitUtil.check(mask, 0)) { + position.set(Position.KEY_INDEX, buf.readUnsignedShort()); + } + + if (BitUtil.check(mask, 1)) { + int date = buf.readUnsignedByte(); + DateBuilder dateBuilder = new DateBuilder() + .setDate(BitUtil.between(date, 4, 8) + 2010, BitUtil.to(date, 4), buf.readUnsignedByte()) + .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()); + position.setTime(dateBuilder.getDate()); + } + + if (BitUtil.check(mask, 2)) { + buf.skipBytes(5); // device time + } + + if (BitUtil.check(mask, 3)) { + position.setLatitude(buf.readUnsignedInt() * 0.000001 - 90); + position.setLongitude(buf.readUnsignedInt() * 0.000001 - 180.0); + } + + if (BitUtil.check(mask, 4)) { + int status = buf.readUnsignedByte(); + position.setValid(BitUtil.between(status, 4, 8) != 0); + position.set(Position.KEY_SATELLITES, BitUtil.to(status, 4)); + position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1); + } + + if (BitUtil.check(mask, 5)) { + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + } + + if (BitUtil.check(mask, 6)) { + position.setCourse(buf.readUnsignedShort()); + } + + if (BitUtil.check(mask, 7)) { + position.setAltitude(buf.readShort()); + } + + if (BitUtil.check(mask, 8)) { + position.set(Position.KEY_GSM, buf.readUnsignedByte()); + } + + if (BitUtil.check(mask, 9)) { + position.set(Position.KEY_POWER, buf.readUnsignedShort() + "mV"); + } + + if (BitUtil.check(mask, 10)) { + position.set(Position.KEY_BATTERY, buf.readUnsignedShort() + "mV"); + } + + if (BitUtil.check(mask, 11)) { + buf.skipBytes(2); // gpio + } + + if (BitUtil.check(mask, 12)) { + position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000); + } + + if (BitUtil.check(mask, 13)) { + buf.skipBytes(6); // software version + } + + if (BitUtil.check(mask, 14)) { + buf.skipBytes(5); // hardware version + } + + if (BitUtil.check(mask, 15)) { + buf.readUnsignedShort(); // device config + } + + return position; + } + +} diff --git a/test/org/traccar/protocol/OigoProtocolDecoderTest.java b/test/org/traccar/protocol/OigoProtocolDecoderTest.java new file mode 100644 index 000000000..b75f3162b --- /dev/null +++ b/test/org/traccar/protocol/OigoProtocolDecoderTest.java @@ -0,0 +1,21 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class OigoProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + OigoProtocolDecoder decoder = new OigoProtocolDecoder(new OigoProtocol()); + + verifyPosition(decoder, binary( + "7e004200000014631000258257000000ffff02d0690e000220690e0002200696dbd204bdfde31a070000b307101135de106e05f500000000010908010402200104ffff8001")); + + verifyPosition(decoder, binary( + "7e004200000014631000258257000000ffff02d1690e00051f690e00051f0696dbd204bdfde31a070000b307100f35c0106305f500000000010908010402200104ffff8001")); + + } + +} -- cgit v1.2.3 From 3a0a2ec7c2a3cd418300c90e7e44c0d86499476c Mon Sep 17 00:00:00 2001 From: nyash Date: Sun, 18 Sep 2016 14:42:13 +0200 Subject: Add jpkorjar protocol decoder test --- .../traccar/protocol/JpKorjarProtocolDecoderTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/org/traccar/protocol/JpKorjarProtocolDecoderTest.java (limited to 'test') diff --git a/test/org/traccar/protocol/JpKorjarProtocolDecoderTest.java b/test/org/traccar/protocol/JpKorjarProtocolDecoderTest.java new file mode 100644 index 000000000..d253af99c --- /dev/null +++ b/test/org/traccar/protocol/JpKorjarProtocolDecoderTest.java @@ -0,0 +1,19 @@ +package org.traccar.protocol; + + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class JpKorjarProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + JpKorjarProtocolDecoder decoder = new JpKorjarProtocolDecoder(new JpKorjarProtocol()); + + verifyPosition(decoder, text( + "KORJAR.PL,329587014519383,160910144240,52.247254N,021.013375E,0.00,1,F:4.18V,1 260 01 794B 3517,")); + + } + +} -- cgit v1.2.3 From a0c125575a4b5d400790e2290d3212799355b498 Mon Sep 17 00:00:00 2001 From: nyash Date: Mon, 19 Sep 2016 12:18:30 +0200 Subject: Add jpkorjar tests showcasing changing attributes --- test/org/traccar/protocol/JpKorjarProtocolDecoderTest.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test') diff --git a/test/org/traccar/protocol/JpKorjarProtocolDecoderTest.java b/test/org/traccar/protocol/JpKorjarProtocolDecoderTest.java index d253af99c..44cdbe2f2 100644 --- a/test/org/traccar/protocol/JpKorjarProtocolDecoderTest.java +++ b/test/org/traccar/protocol/JpKorjarProtocolDecoderTest.java @@ -14,6 +14,12 @@ public class JpKorjarProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, text( "KORJAR.PL,329587014519383,160910144240,52.247254N,021.013375E,0.00,1,F:4.18V,1 260 01 794B 3517,")); + verifyPosition(decoder, text( + "KORJAR.PL,329587014519383,160910144240,52.895515N,021.949151E,6.30,212,F:3.94V,0 260 01 794B 3519,")); + + verifyPosition(decoder, text( + "KORJAR.PL,329587014519383,160910144240,52.895596N,021.949343E,12.46,087,L:2.18V,1 260 01 794B 3517,")); + } } -- cgit v1.2.3 From 56a4fe28c4d72b8ec1f55fce4c8de18c1ef71f73 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 19 Sep 2016 23:04:34 +1200 Subject: Remove debug code from ArknavX8 --- src/org/traccar/protocol/ArknavX8ProtocolDecoder.java | 3 --- test/org/traccar/protocol/ArknavX8ProtocolDecoderTest.java | 6 ++++++ 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java index 931cb1d14..c0a18311e 100644 --- a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java +++ b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java @@ -21,7 +21,6 @@ import org.traccar.DeviceSession; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; -import org.traccar.helper.PatternUtil; import org.traccar.model.Position; import java.net.SocketAddress; @@ -57,8 +56,6 @@ public class ArknavX8ProtocolDecoder extends BaseProtocolDecoder { return null; } - PatternUtil.MatchResult r = PatternUtil.checkPattern(PATTERN.pattern(), sentence); - Parser parser = new Parser(PATTERN, sentence); if (!parser.matches()) { return null; diff --git a/test/org/traccar/protocol/ArknavX8ProtocolDecoderTest.java b/test/org/traccar/protocol/ArknavX8ProtocolDecoderTest.java index a28e71c64..c5e99f60b 100644 --- a/test/org/traccar/protocol/ArknavX8ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ArknavX8ProtocolDecoderTest.java @@ -10,6 +10,12 @@ public class ArknavX8ProtocolDecoderTest extends ProtocolTest { ArknavX8ProtocolDecoder decoder = new ArknavX8ProtocolDecoder(new ArknavX8Protocol()); + verifyNothing(decoder, text( + "351856045213782,241111")); + + verifyNothing(decoder, text( + "2R,090214235955,00,,00.04,03.76,001892024.9")); + verifyNothing(decoder, text( "351856040005407,240101")); -- cgit v1.2.3 From fd2fd71a522585ade8653618d95eb0f846f4bfbb Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 19 Sep 2016 23:33:42 +1200 Subject: Update regex pattern debugger --- src/org/traccar/helper/PatternUtil.java | 26 ++++++++++---------------- test/org/traccar/helper/PatternUtilTest.java | 2 +- 2 files changed, 11 insertions(+), 17 deletions(-) (limited to 'test') diff --git a/src/org/traccar/helper/PatternUtil.java b/src/org/traccar/helper/PatternUtil.java index 88c3f053b..f665eb30d 100644 --- a/src/org/traccar/helper/PatternUtil.java +++ b/src/org/traccar/helper/PatternUtil.java @@ -25,20 +25,13 @@ public final class PatternUtil { } public static class MatchResult { - private String pattern; - private String matched; - private String remaining; + private String patternMatch; + private String patternTail; + private String stringMatch; + private String stringTail; - public String getPattern() { - return this.pattern; - } - - public String getMatched() { - return this.matched; - } - - public String getRemaining() { - return this.remaining; + public String getPatternMatch() { + return patternMatch; } } @@ -50,9 +43,10 @@ public final class PatternUtil { try { Matcher matcher = Pattern.compile("(" + pattern.substring(0, i) + ").*").matcher(input); if (matcher.matches()) { - result.pattern = pattern.substring(0, i); - result.matched = matcher.group(1); - result.remaining = input.substring(matcher.group(1).length()); + result.patternMatch = pattern.substring(0, i); + result.patternTail = pattern.substring(i); + result.stringMatch = matcher.group(1); + result.stringTail = input.substring(matcher.group(1).length()); } } catch (PatternSyntaxException error) { Log.warning(error); diff --git a/test/org/traccar/helper/PatternUtilTest.java b/test/org/traccar/helper/PatternUtilTest.java index bb1349363..b6b05e88c 100644 --- a/test/org/traccar/helper/PatternUtilTest.java +++ b/test/org/traccar/helper/PatternUtilTest.java @@ -9,7 +9,7 @@ public class PatternUtilTest { @Test public void testCheckPattern() { - assertEquals("ab", PatternUtil.checkPattern("abc", "abd").getPattern()); + assertEquals("ab", PatternUtil.checkPattern("abc", "abd").getPatternMatch()); } -- cgit v1.2.3 From 5c32bb71b06c5f08506e9d1f49925c1d6b833faf Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 19 Sep 2016 23:33:59 +1200 Subject: Add new GoSafe format tests --- test/org/traccar/protocol/GoSafeProtocolDecoderTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test') diff --git a/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java b/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java index cc710def0..fb0dec4fb 100644 --- a/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java @@ -10,6 +10,15 @@ public class GoSafeProtocolDecoderTest extends ProtocolTest { GoSafeProtocolDecoder decoder = new GoSafeProtocolDecoder(new GoSafeProtocol()); + verifyNotNull(decoder, text( + "*GS56,356449063230915,052339180916,,SYS:G7S;V1.08;V1.2,GPS:V;4;N24.730006;E46.637816;14;0;630,GSM:;;420;4;5655;507A;-70,COT:75242;2-8-17,ADC:13.22;0.08,DTT:23004;;0;0;0;1#")); + + verifyNotNull(decoder, text( + "*GS56,356449063230915,052349180916,,SYS:G7S;V1.08;V1.2,GPS:V;6;N24.730384;E46.637620;47;56;607,GSM:;;420;4;5655;507A;-70,COT:75290;2-8-27,ADC:13.24;0.08,DTT:23004;;0;0;0;1#")); + + verifyNotNull(decoder, text( + "*GS56,356449063230915,052444180916,,SYS:G7S;V1.08;V1.2,GPS:V;6;N24.730384;E46.637620;47;56;607,GSM:;;420;4;5655;F319;-102,COT:75290;2-9-27,ADC:13.00;0.08,DTT:23004;;0;0;0;1$052449180916,,SYS:G7S;V1.08;V1.2,GPS:V;6;N24.730384;E46.637620;47;56;607,GSM:;;420;4;5655;F319;-102,COT:75290;2-9-27,ADC:13.13;0.08,DTT:23004;;0;0;0;1#")); + verifyPositions(decoder, text( "*GS16,356449062643845,141224290316,,SYS:G79;V1.13;V1.0.2,GPS:V;5;N24.694972;E46.680736;46;334;606;1.43,GSM:;;420;4;5655;4EB8;-57,COT:330034,ADC:13.31;3.83,DTT:27004;;0;0;0;1,OBD:064101000400000341057E04410304000341510104411001C203410F4B0341112904411F01AB0641010004000014490201FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF03410D21,FUL:28260")); -- cgit v1.2.3 From c5ba4d655d3a0e314ab030a32057397a6a579ef0 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 20 Sep 2016 11:05:19 +1200 Subject: Update JP-KORJAR decoder with regex --- src/org/traccar/protocol/JpKorjarFrameDecoder.java | 2 +- src/org/traccar/protocol/JpKorjarProtocol.java | 2 +- .../traccar/protocol/JpKorjarProtocolDecoder.java | 103 ++++++++++----------- .../protocol/JpKorjarProtocolDecoderTest.java | 1 - 4 files changed, 49 insertions(+), 59 deletions(-) (limited to 'test') diff --git a/src/org/traccar/protocol/JpKorjarFrameDecoder.java b/src/org/traccar/protocol/JpKorjarFrameDecoder.java index 0b32a7f0b..33a1b3f36 100644 --- a/src/org/traccar/protocol/JpKorjarFrameDecoder.java +++ b/src/org/traccar/protocol/JpKorjarFrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 nyashh (nyashh@gmail.com) + * Copyright 2016 Nyash (nyashh@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/org/traccar/protocol/JpKorjarProtocol.java b/src/org/traccar/protocol/JpKorjarProtocol.java index e48e6ea21..c54994708 100644 --- a/src/org/traccar/protocol/JpKorjarProtocol.java +++ b/src/org/traccar/protocol/JpKorjarProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 nyashh (nyashh@gmail.com) + * Copyright 2016 Nyash (nyashh@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/org/traccar/protocol/JpKorjarProtocolDecoder.java b/src/org/traccar/protocol/JpKorjarProtocolDecoder.java index 0cdc958c9..e0fe0678d 100644 --- a/src/org/traccar/protocol/JpKorjarProtocolDecoder.java +++ b/src/org/traccar/protocol/JpKorjarProtocolDecoder.java @@ -1,5 +1,6 @@ /* - * Copyright 2016 nyashh (nyashh@gmail.com) + * Copyright 2016 Nyash (nyashh@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. @@ -19,9 +20,12 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.DateBuilder; +import org.traccar.helper.Parser; +import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; import java.net.SocketAddress; +import java.util.regex.Pattern; public class JpKorjarProtocolDecoder extends BaseProtocolDecoder { @@ -29,74 +33,61 @@ public class JpKorjarProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - @Override - protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - - String line = (String) msg; + private static final Pattern PATTERN = new PatternBuilder() + .text("KORJAR.PL,") + .number("(d+),") // imei + .number("(dd)(dd)(dd)") // date + .number("(dd)(dd)(dd),") // time + .number("(d+.d+)([NS]),") // latitude + .number("(d+.d+)([EW]),") // longitude + .number("(d+.d+),") // speed + .number("(d+),") // course + .number("[FL]:(d+.d+)V,") // battery + .number("([01]) ") // valid + .number("(d+) ") // mcc + .number("(d+) ") // mnc + .number("(x+) ") // lac + .number("(x+),") // cid + .compile(); - String[] parts = line.split(","); + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - if (parts.length == 0) { + Parser parser = new Parser(PATTERN, (String) msg); + if (!parser.matches()) { return null; } - if (!parts[0].equals("KORJAR.PL")) { + Position position = new Position(); + position.setProtocol(getProtocolName()); + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { return null; } + position.setDeviceId(deviceSession.getDeviceId()); - int year = Integer.parseInt(parts[2].substring(0, 2)); - int month = Integer.parseInt(parts[2].substring(2, 4)); - int day = Integer.parseInt(parts[2].substring(4, 6)); - int hour = Integer.parseInt(parts[2].substring(6, 8)); - int minute = Integer.parseInt(parts[2].substring(8, 10)); - int second = Integer.parseInt(parts[2].substring(10, 12)); - - double latitude = Double.parseDouble(parts[3].substring(0, - Math.max(0, parts[3].length() - 1))); - - double longitude = Double.parseDouble(parts[4].substring(0, - Math.max(0, parts[4].length() - 1))); - - double speed = Double.parseDouble(parts[5]); - double course = Double.parseDouble(parts[6]); - - String[] batteryParts = parts[7].split(":"); - - double batteryVoltage = Double.parseDouble(batteryParts[1].substring(0, - Math.max(0, batteryParts[1].length() - 1))); - - String[] codeParts = parts[8].split(" "); + DateBuilder dateBuilder = new DateBuilder() + .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); - int gpsSignal = Integer.parseInt(codeParts[0]); //0 - low, 1 - high - int mcc = Integer.parseInt(codeParts[1]); - int mnc = Integer.parseInt(codeParts[2]); - int lac = Integer.parseInt(codeParts[3], 16); - int cid = Integer.parseInt(codeParts[4], 16); + position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setSpeed(parser.nextDouble()); + position.setCourse(parser.nextDouble()); - DateBuilder builder = new DateBuilder().setDate(year, month, day) - .setTime(hour, minute, second); + position.set(Position.KEY_BATTERY, parser.nextDouble()); - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parts[1]); - if (deviceSession == null) { - return null; - } + position.setValid(parser.nextInt() == 1); - Position position = new Position(); - position.setProtocol(getProtocolName()); - position.setDeviceId(deviceSession.getDeviceId()); - position.setLatitude(latitude); - position.setLongitude(longitude); - position.setSpeed(speed); - position.setCourse(course); - position.set("signal", gpsSignal); - position.set(Position.KEY_POWER, batteryVoltage); - position.set(Position.KEY_MNC, mnc); - position.set(Position.KEY_MCC, mcc); - position.set(Position.KEY_LAC, lac); - position.set(Position.KEY_CID, cid); - position.setTime(builder.getDate()); - position.setValid(true); + position.set(Position.KEY_MCC, parser.nextInt()); + position.set(Position.KEY_MNC, parser.nextInt()); + position.set(Position.KEY_LAC, parser.nextInt(16)); + position.set(Position.KEY_CID, parser.nextInt(16)); return position; } + } diff --git a/test/org/traccar/protocol/JpKorjarProtocolDecoderTest.java b/test/org/traccar/protocol/JpKorjarProtocolDecoderTest.java index 44cdbe2f2..c64be017f 100644 --- a/test/org/traccar/protocol/JpKorjarProtocolDecoderTest.java +++ b/test/org/traccar/protocol/JpKorjarProtocolDecoderTest.java @@ -1,6 +1,5 @@ package org.traccar.protocol; - import org.junit.Test; import org.traccar.ProtocolTest; -- cgit v1.2.3 From 277a28cd11a60246de96bcfb7be75e177f483809 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 21 Sep 2016 05:11:01 +1200 Subject: Read event from OIGO messages --- src/org/traccar/protocol/OigoProtocolDecoder.java | 4 +++- test/org/traccar/protocol/OigoProtocolDecoderTest.java | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/src/org/traccar/protocol/OigoProtocolDecoder.java b/src/org/traccar/protocol/OigoProtocolDecoder.java index 799f47ea3..bbea38183 100644 --- a/src/org/traccar/protocol/OigoProtocolDecoder.java +++ b/src/org/traccar/protocol/OigoProtocolDecoder.java @@ -54,7 +54,7 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder { DeviceSession deviceSession; switch (BitUtil.to(tag, 3)) { case 0: - String imei = ChannelBuffers.hexDump(buf.readBytes(9)).substring(1, 1 + 15); + String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1); deviceSession = getDeviceSession(channel, remoteAddress, imei); break; case 1: @@ -75,6 +75,8 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); + position.set(Position.KEY_EVENT, buf.readUnsignedByte()); + int mask = buf.readInt(); if (BitUtil.check(mask, 0)) { diff --git a/test/org/traccar/protocol/OigoProtocolDecoderTest.java b/test/org/traccar/protocol/OigoProtocolDecoderTest.java index b75f3162b..14c34ae7c 100644 --- a/test/org/traccar/protocol/OigoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/OigoProtocolDecoderTest.java @@ -16,6 +16,9 @@ public class OigoProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, binary( "7e004200000014631000258257000000ffff02d1690e00051f690e00051f0696dbd204bdfde31a070000b307100f35c0106305f500000000010908010402200104ffff8001")); + verifyPosition(decoder, binary( + "7e004200000014631000258257000000ffff0d82691300001669130000160696dbd804bdfdbb1a0800000007101035a2106905f500000000010908010402200104ffff8001")); + } } -- cgit v1.2.3 From de3171940f14fe6d559780027da3efd35bd4ab1c Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 21 Sep 2016 06:27:12 +1200 Subject: Implement Aplicom E protocol --- .../traccar/protocol/AplicomProtocolDecoder.java | 146 +++++++++++++++------ .../protocol/AplicomProtocolDecoderTest.java | 17 ++- 2 files changed, 125 insertions(+), 38 deletions(-) (limited to 'test') diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java index 23397b51c..b7619b38a 100644 --- a/src/org/traccar/protocol/AplicomProtocolDecoder.java +++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2013 - 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. @@ -27,6 +27,7 @@ import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Date; @@ -75,7 +76,8 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { return unitId; } - private static final int DEFAULT_SELECTOR = 0x0002FC; + private static final int DEFAULT_SELECTOR_D = 0x0002FC; + private static final int DEFAULT_SELECTOR_E = 0x007ffc; private static final int EVENT_DATA = 119; @@ -191,44 +193,12 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } } - @Override - protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - - ChannelBuffer buf = (ChannelBuffer) msg; - - buf.readUnsignedByte(); // marker - int version = buf.readUnsignedByte(); - - String imei; - if ((version & 0x80) != 0) { - imei = String.valueOf((buf.readUnsignedInt() << (3 * 8)) | buf.readUnsignedMedium()); - } else { - imei = String.valueOf(imeiFromUnitId(buf.readUnsignedMedium())); - } - - buf.readUnsignedShort(); // length - - int selector = DEFAULT_SELECTOR; - if ((version & 0x40) != 0) { - selector = buf.readUnsignedMedium(); - } - - Position position = new Position(); - position.setProtocol(getProtocolName()); - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); - if (deviceSession == null) { - return null; - } - position.setDeviceId(deviceSession.getDeviceId()); - - int event = buf.readUnsignedByte(); - position.set(Position.KEY_EVENT, event); - position.set("eventInfo", buf.readUnsignedByte()); + private void decodeD(Position position, ChannelBuffer buf, int selector, int event) { if ((selector & 0x0008) != 0) { position.setValid((buf.readUnsignedByte() & 0x40) != 0); } else { - return null; // no location data + getLastLocation(position, null); } if ((selector & 0x0004) != 0) { @@ -318,9 +288,111 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { if (Context.getConfig().getBoolean(getProtocolName() + ".can") && buf.readable() && (selector & 0x1000) != 0 && event == EVENT_DATA) { - decodeCanData(buf, position); } + } + + private void decodeE(Position position, ChannelBuffer buf, int selector) { + + if ((selector & 0x0008) != 0) { + position.set("tachographEvent", buf.readUnsignedShort()); + } + + if ((selector & 0x0004) != 0) { + getLastLocation(position, new Date(buf.readUnsignedInt() * 1000)); + } else { + getLastLocation(position, null); + } + + if ((selector & 0x0010) != 0) { + String time = + buf.readUnsignedByte() + "s " + buf.readUnsignedByte() + "m " + buf.readUnsignedByte() + "h " + + buf.readUnsignedByte() + "M " + buf.readUnsignedByte() + "D " + buf.readUnsignedByte() + "Y " + + buf.readByte() + "m " + buf.readByte() + "h"; + position.set("tachographTime", time); + } + + position.set("workState", buf.readUnsignedByte()); + position.set("driver1State", buf.readUnsignedByte()); + position.set("driver2State", buf.readUnsignedByte()); + + if ((selector & 0x0020) != 0) { + position.set("tachographStatus", buf.readUnsignedByte()); + } + + if ((selector & 0x0040) != 0) { + position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() / 256.0); + } + + if ((selector & 0x0080) != 0) { + position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 5); + } + + if ((selector & 0x0100) != 0) { + position.set(Position.KEY_TRIP_ODOMETER, buf.readUnsignedInt() * 5); + } + + if ((selector & 0x8000) != 0) { + position.set("kFactor", buf.readUnsignedShort() * 0.001 + " pulses/m"); + } + + if ((selector & 0x0200) != 0) { + position.set(Position.KEY_RPM, buf.readUnsignedShort() * 0.125); + } + + if ((selector & 0x0400) != 0) { + position.set("extraInfo", buf.readUnsignedShort()); + } + + if ((selector & 0x0800) != 0) { + position.set(Position.KEY_VIN, buf.readBytes(18).toString(StandardCharsets.US_ASCII).trim()); + } + } + + @Override + protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + ChannelBuffer buf = (ChannelBuffer) msg; + + char protocol = (char) buf.readByte(); + int version = buf.readUnsignedByte(); + + String imei; + if ((version & 0x80) != 0) { + imei = String.valueOf((buf.readUnsignedInt() << (3 * 8)) | buf.readUnsignedMedium()); + } else { + imei = String.valueOf(imeiFromUnitId(buf.readUnsignedMedium())); + } + + buf.readUnsignedShort(); // length + + int selector = DEFAULT_SELECTOR_D; + if (protocol == 'E') { + selector = DEFAULT_SELECTOR_E; + } + if ((version & 0x40) != 0) { + selector = buf.readUnsignedMedium(); + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); + if (deviceSession == null) { + return null; + } + position.setDeviceId(deviceSession.getDeviceId()); + + int event = buf.readUnsignedByte(); + position.set(Position.KEY_EVENT, event); + position.set("eventInfo", buf.readUnsignedByte()); + + if (protocol == 'D') { + decodeD(position, buf, selector, event); + } else if (protocol == 'E') { + decodeE(position, buf, selector); + } else { + return null; + } return position; } diff --git a/test/org/traccar/protocol/AplicomProtocolDecoderTest.java b/test/org/traccar/protocol/AplicomProtocolDecoderTest.java index 26844994e..d6a29c6dd 100644 --- a/test/org/traccar/protocol/AplicomProtocolDecoderTest.java +++ b/test/org/traccar/protocol/AplicomProtocolDecoderTest.java @@ -10,6 +10,21 @@ public class AplicomProtocolDecoderTest extends ProtocolTest { AplicomProtocolDecoder decoder = new AplicomProtocolDecoder(new AplicomProtocol()); + verifyAttributes(decoder, binary( + "45c20145931876ffb2007100ffff6d00000057c6dd1970230d087b1f7d7f0000d0c1000000003580000035801f40ffff5001574442393036363035533132333435363700014142432d333435202020202020000000000000000000000000000000000000000000000001123130343632343639373030303030303100000000")); + + verifyAttributes(decoder, binary( + "45c20145931876ffb2007100ffff6d00000057c6dd9170250d087b1f7d7f0000d0c1000000003580000035801f40ffff5001574442393036363035533132333435363700014142432d333435202020202020000000000000000000000000000000000000000000000001123130343632343639373030303030303100000000")); + + verifyAttributes(decoder, binary( + "45c20145931876ffb2007100ffff6d00000057c6de0970270d087b1f7d7f0000d0c1000000003580000035801f40ffff5001574442393036363035533132333435363700014142432d333435202020202020000000000000000000000000000000000000000000000001123130343632343639373030303030303100000000")); + + verifyNothing(decoder, binary( + "48c10144b9de54e6b2008700205f710a57d23ec957d23b8d00000000300d0106ff00000000000000000000000000000000000000000000000000000000000000010a141e28323c46505a646e7801000f020104ff000000000000000000010102000f020104ff000000000000000000010103000f020104ff000000000000000000010105000f020104ff0000000000000000000101")); + + verifyAttributes(decoder, binary( + "44c3014645e8ecff3c00ea03ffffbc00f457d68a6557d68a6303bb55fa018843da1100009881000000000000000000000000000000000000000000000000000000000000000000000000000000ff0056007600000000000000014542016d0001010095070e14014645e8ecff3c57d68a6403bb55fa018843dac0010d14ff050102030405060708090a0b0c0d0e0f10112a01010730343f3c1ff5cf01020700007d007d23010103022f2e01060c67452301efcdab8967452301010b10000000007d007d007d7dffffffffffff010a2400000000000000010000000000000000ffffffffffffffff00010001ffff00000000ffff010c02fec6")); + verifyPosition(decoder, binary( "44c3014645e8e91b66002300a21f0b01f056d3e62856d3e626031f845f00c6ee440800000000000000000017bd1cb30000")); @@ -19,7 +34,7 @@ public class AplicomProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, binary( "44c3014645e8e91b66001f00221f0b01f456ba1e0d56ba1e0b031f842200c6ef550c000000000017bd1cb30004")); - verifyNothing(decoder, binary( + verifyAttributes(decoder, binary( "44c3014645e8e9bada003e03fff7070055a4f24200000081000000000000000000000000000000000000000000000000000000000000000000000000000000ff00000001000000000000000044c3014645e8e9bada003e03fff77bff55a4f24300000081000000000000000000000000000000000000000000000000000000000000000000000000000000ff00300002000000000000000044c3014645e8e9bada003e03fff7690655a4f24500000081000000000000000000000000000000000000000000000000000000000000000000000000000000ff003000030000000000000000")); verifyPosition(decoder, binary( -- cgit v1.2.3 From 19b17695867e00861c719292aad7ae48f33a8eeb Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 21 Sep 2016 19:31:39 +1200 Subject: Implement cGuard communication protocol --- debug.xml | 1 + src/org/traccar/model/Position.java | 1 + src/org/traccar/protocol/CguardProtocol.java | 47 +++++++++++ .../traccar/protocol/CguardProtocolDecoder.java | 91 ++++++++++++++++++++++ .../protocol/CguardProtocolDecoderTest.java | 54 +++++++++++++ 5 files changed, 194 insertions(+) create mode 100644 src/org/traccar/protocol/CguardProtocol.java create mode 100644 src/org/traccar/protocol/CguardProtocolDecoder.java create mode 100644 test/org/traccar/protocol/CguardProtocolDecoderTest.java (limited to 'test') diff --git a/debug.xml b/debug.xml index 44f4f2c7f..5de42c027 100644 --- a/debug.xml +++ b/debug.xml @@ -457,5 +457,6 @@ 5120 5121 5122 + 5123 diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 710dd1e83..c1058aef9 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -57,6 +57,7 @@ public class Position extends Message { public static final String KEY_THROTTLE = "throttle"; public static final String KEY_MOTION = "motion"; public static final String KEY_ARMED = "armed"; + public static final String KEY_ACCURACY = "accuracy"; public static final String KEY_OBD_SPEED = "obdSpeed"; public static final String KEY_OBD_ODOMETER = "obdOdometer"; diff --git a/src/org/traccar/protocol/CguardProtocol.java b/src/org/traccar/protocol/CguardProtocol.java new file mode 100644 index 000000000..1e6d212c8 --- /dev/null +++ b/src/org/traccar/protocol/CguardProtocol.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.TrackerServer; + +import java.util.List; + +public class CguardProtocol extends BaseProtocol { + + public CguardProtocol() { + super("cguard"); + } + + @Override + public void initTrackerServers(List serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("objectDecoder", new CguardProtocolDecoder(CguardProtocol.this)); + } + }); + } + +} diff --git a/src/org/traccar/protocol/CguardProtocolDecoder.java b/src/org/traccar/protocol/CguardProtocolDecoder.java new file mode 100644 index 000000000..1646363e5 --- /dev/null +++ b/src/org/traccar/protocol/CguardProtocolDecoder.java @@ -0,0 +1,91 @@ +/* + * 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.DeviceSession; +import org.traccar.helper.DateBuilder; +import org.traccar.helper.Parser; +import org.traccar.helper.PatternBuilder; +import org.traccar.helper.UnitsConverter; +import org.traccar.model.Position; + +import java.net.SocketAddress; +import java.util.regex.Pattern; + +public class CguardProtocolDecoder extends BaseProtocolDecoder { + + public CguardProtocolDecoder(CguardProtocol protocol) { + super(protocol); + } + + private static final Pattern PATTERN = new PatternBuilder() + .text("NV:") + .number("(dd)(dd)(dd) ") // date + .number("(dd)(dd)(dd):") // time + .number("(-?d+.d+):") // longitude + .number("(-?d+.d+):") // latitude + .number("(d+.?d*):") // speed + .number("(?:NAN|(d+.?d*)):") // accuracy + .number("(?:NAN|(d+.?d*)):") // course + .number("(?:NAN|(d+.?d*))") // altitude + .compile(); + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + String sentence = (String) msg; + + if (sentence.startsWith("ID:") || sentence.startsWith("IDRO:")) { + getDeviceSession(channel, remoteAddress, sentence.substring(sentence.indexOf(':') + 1)); + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession == null) { + return null; + } + + Parser parser = new Parser(PATTERN, (String) msg); + if (!parser.matches()) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + DateBuilder dateBuilder = new DateBuilder() + .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + position.setValid(true); + position.setLatitude(parser.nextDouble()); + position.setLongitude(parser.nextDouble()); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); + + position.set(Position.KEY_ACCURACY, parser.nextDouble()); + + position.setCourse(parser.nextDouble()); + position.setAltitude(parser.nextDouble()); + + return position; + } + +} diff --git a/test/org/traccar/protocol/CguardProtocolDecoderTest.java b/test/org/traccar/protocol/CguardProtocolDecoderTest.java new file mode 100644 index 000000000..49d037f8f --- /dev/null +++ b/test/org/traccar/protocol/CguardProtocolDecoderTest.java @@ -0,0 +1,54 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class CguardProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + CguardProtocolDecoder decoder = new CguardProtocolDecoder(new CguardProtocol()); + + verifyNothing(decoder, text( + "IDRO:354868050655283")); + + verifyPosition(decoder, text( + "NV:160711 044023:54.342907:48.582590:0:NAN:0:110.1")); + + verifyPosition(decoder, text( + "NV:160711 044023:54.342907:-148.582590:0:NAN:0:110.1")); + + verifyNothing(decoder, text( + "BC:160711 044023:CSQ1:48:NSQ1:7:NSQ2:1:BAT1:98:PWR1:11.7:CLG1:NAN")); + + verifyNothing(decoder, text( + "BC:160711 044524:CSQ1:61:NSQ1:18:BAT1:98:PWR1:11.7:CLG1:NAN")); + + verifyNothing(decoder, text( + "VERSION:3.3")); + + verifyPosition(decoder, text( + "NV:160420 101902:55.799425:37.674033:0.94:NAN:213.59:156.6")); + + verifyNothing(decoder, text( + "BC:160628 081024:CSQ1:32:NSQ1:10:BAT1:100")); + + verifyNothing(decoder, text( + "BC:160628 081033:NSQ2:0")); + + verifyPosition(decoder, text( + "NV:160630 151537:55.799913:37.674267:0.7:NAN:10.21:174.9")); + + verifyNothing(decoder, text( + "BC:160630 153316:BAT1:76")); + + verifyNothing(decoder, text( + "BC:160630 153543:NSQ2:0")); + + verifyNothing(decoder, text( + "PING")); + + } + +} -- cgit v1.2.3 From 22a1aca01ec5feaef59ad2f56eda825a5926e24b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 23 Sep 2016 03:41:40 +1200 Subject: Add new JT600 unit tests --- test/org/traccar/protocol/Jt600ProtocolDecoderTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java b/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java index b95d8ddce..ba39b1846 100644 --- a/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java @@ -11,6 +11,16 @@ public class Jt600ProtocolDecoderTest extends ProtocolTest { Jt600ProtocolDecoder decoder = new Jt600ProtocolDecoder(new Jt600Protocol()); + verifyNothing(decoder, buffer( + "(3460311327,@JT)")); + + /*verifyPosition(decoder, buffer( + "(3460311327,U01,010100,000024,F,0.000000,N,0.000000,E,0.00,0,0,100%,00000001000000,263,1,18,0,0,33)"));*/ + + //(3460311327,U06,11,220916,135643,T,9.552553,N,13.658265,W,0.61,0,9,100%,00000001000000,11012,10,30,0,0,126,0,30) + //(3460311327,U06,10,220916,140619,T,9.552495,N,13.658227,W,0.43,0,7,0%,00101001000000,11012,10,0,0,0,126,0,30) + //(3460311327,U01,220916,135251,T,9.552607,N,13.658292,W,0.31,0,9,0%,00001001000000,11012,10,27,0,0,33) + verifyPosition(decoder, binary( "24311021600111001B16021105591022329862114046227B0598095080012327951435161F"), position("2011-02-16 05:59:10.000", true, 22.54977, -114.07705)); -- cgit v1.2.3 From e3229237eb37654dbf7818fdf92a6f487a95c770 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 23 Sep 2016 06:57:16 +1200 Subject: Extend JT600 protocol support --- src/org/traccar/protocol/Jt600ProtocolDecoder.java | 90 ++++++++++++++++++---- .../traccar/protocol/Jt600ProtocolDecoderTest.java | 38 ++++++--- 2 files changed, 106 insertions(+), 22 deletions(-) (limited to 'test') diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index b7193d24b..b30bd7b85 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 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. @@ -43,7 +43,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { return degrees + minutes / 60; } - private Position decodeNormalMessage(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) { + private Position decodeBinary(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) { Position position = new Position(); position.setProtocol(getProtocolName()); @@ -120,7 +120,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { return position; } - private static final Pattern PATTERN = new PatternBuilder() + private static final Pattern PATTERN_W01 = new PatternBuilder() .text("(") .number("(d+),") // id .text("W01,") // type @@ -138,25 +138,22 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // gsm signal .number("(d+),") // alert type .any() - .text(")") .compile(); - private Position decodeAlertMessage(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) { + private Position decodeW01(String sentence, Channel channel, SocketAddress remoteAddress) { - Parser parser = new Parser(PATTERN, buf.toString(StandardCharsets.US_ASCII)); + Parser parser = new Parser(PATTERN_W01, sentence); if (!parser.matches()) { return null; } - Position position = new Position(); - position.setProtocol(getProtocolName()); - - position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); if (deviceSession == null) { return null; } + + Position position = new Position(); + position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); position.setLongitude(parser.nextCoordinate()); @@ -176,6 +173,68 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { return position; } + private static final Pattern PATTERN_U01 = new PatternBuilder() + .text("(") + .number("(d+),") // id + .number("Udd,") // type + .number("d+,").optional() // alarm + .number("(dd)(dd)(dd),") // date (ddmmyy) + .number("(dd)(dd)(dd),") // time + .expression("([TF]),") // validity + .number("(d+.d+),([NS]),") // latitude + .number("(d+.d+),([EW]),") // longitude + .number("(d+.?d*),") // speed + .number("(d+),") // course + .number("(d+),") // satellites + .number("(d+%),") // battery + .expression("([01]+),") // status + .number("(d+),") // cid + .number("(d+),") // lac + .number("(d+),") // gsm signal + .number("(d+),") // odometer + .number("(d+)") // index + .any() + .compile(); + + private Position decodeU01(String sentence, Channel channel, SocketAddress remoteAddress) { + + Parser parser = new Parser(PATTERN_U01, sentence); + if (!parser.matches()) { + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + DateBuilder dateBuilder = new DateBuilder() + .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + + position.setValid(parser.next().equals("T")); + position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + + position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble())); + position.setCourse(parser.nextDouble()); + + position.set(Position.KEY_SATELLITES, parser.nextInt()); + position.set(Position.KEY_BATTERY, parser.next()); + position.set(Position.KEY_STATUS, parser.nextInt(2)); + position.set(Position.KEY_CID, parser.nextInt()); + position.set(Position.KEY_LAC, parser.nextInt()); + position.set(Position.KEY_GSM, parser.nextInt()); + position.set(Position.KEY_ODOMETER, parser.nextLong() * 1000); + position.set(Position.KEY_INDEX, parser.nextInt()); + + return position; + } @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -184,9 +243,14 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { char first = (char) buf.getByte(0); if (first == '$') { - return decodeNormalMessage(buf, channel, remoteAddress); + return decodeBinary(buf, channel, remoteAddress); } else if (first == '(') { - return decodeAlertMessage(buf, channel, remoteAddress); + String sentence = buf.toString(StandardCharsets.US_ASCII); + if (sentence.contains("W01")) { + return decodeW01(sentence, channel, remoteAddress); + } else { + return decodeU01(sentence, channel, remoteAddress); + } } return null; diff --git a/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java b/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java index ba39b1846..4bbfb5627 100644 --- a/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java @@ -11,15 +11,35 @@ public class Jt600ProtocolDecoderTest extends ProtocolTest { Jt600ProtocolDecoder decoder = new Jt600ProtocolDecoder(new Jt600Protocol()); + verifyPosition(decoder, buffer( + "(3301210003,U01,040812,185302,T,22.564025,N,113.242329,E,5.21,152,9,32%,00000000000011,10133,5173,22,100,1)")); + + verifyPosition(decoder, buffer( + "(3301210003,U02,040812,185302,T,22.564025,N,113.242329,E,5,152,9,32%,00000000000011,10133,5173,22,100,1)")); + + verifyPosition(decoder, buffer( + "(3301210003,U03,040812,185302,T,22.564025,N,113.242329,E,5,152,9,32%,00000000000011,10133,5173,22,100,1)")); + + verifyNothing(decoder, buffer( + "(3301210003,U04)")); + + verifyPosition(decoder, buffer( + "(3301210003,U06,1,040812,185302,T,22.564025,N,113.242329,E,5,152,9,32%,0000000000011,10133,5173,22,100,1,300,100,10)")); + + verifyPosition(decoder, buffer( + "(3460311327,U01,220916,135251,T,9.552607,N,13.658292,W,0.31,0,9,0%,00001001000000,11012,10,27,0,0,33)")); + + verifyPosition(decoder, buffer( + "(3460311327,U01,010100,000024,F,0.000000,N,0.000000,E,0.00,0,0,100%,00000001000000,263,1,18,0,0,33)")); + verifyNothing(decoder, buffer( "(3460311327,@JT)")); - /*verifyPosition(decoder, buffer( - "(3460311327,U01,010100,000024,F,0.000000,N,0.000000,E,0.00,0,0,100%,00000001000000,263,1,18,0,0,33)"));*/ + verifyPosition(decoder, buffer( + "(3460311327,U06,11,220916,135643,T,9.552553,N,13.658265,W,0.61,0,9,100%,00000001000000,11012,10,30,0,0,126,0,30)")); - //(3460311327,U06,11,220916,135643,T,9.552553,N,13.658265,W,0.61,0,9,100%,00000001000000,11012,10,30,0,0,126,0,30) - //(3460311327,U06,10,220916,140619,T,9.552495,N,13.658227,W,0.43,0,7,0%,00101001000000,11012,10,0,0,0,126,0,30) - //(3460311327,U01,220916,135251,T,9.552607,N,13.658292,W,0.31,0,9,0%,00001001000000,11012,10,27,0,0,33) + verifyPosition(decoder, buffer( + "(3460311327,U06,10,220916,140619,T,9.552495,N,13.658227,W,0.43,0,7,0%,00101001000000,11012,10,0,0,0,126,0,30)")); verifyPosition(decoder, binary( "24311021600111001B16021105591022329862114046227B0598095080012327951435161F"), @@ -41,11 +61,11 @@ public class Jt600ProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, buffer( "(3120820029,W01,02553.3555,E,2438.0997,S,A,171012,053339,0,8,20,6,31,5,20,20)")); - /*verifyPosition(decoder, text( ChannelBuffers.copiedBuffer( - "(3330104377,U01,010100,010228,F,00.000000,N,000.000000,E,0,0,0,0%,00001000000000,741,14,22,0,206)", StandardCharsets.US_ASCII))); + verifyPosition(decoder, buffer( + "(3330104377,U01,010100,010228,F,00.000000,N,000.000000,E,0,0,0,0%,00001000000000,741,14,22,0,206)")); - verifyPosition(decoder, text( ChannelBuffers.copiedBuffer( - "(6221107674,2,U09,129,2,A,280513113036,E,02711.0500,S,1721.0876,A,030613171243,E,02756.7618,S,2300.0325,3491,538200,14400,1)",StandardCharsets.US_ASCII))));*/ + verifyNothing(decoder, buffer( + "(6221107674,2,U09,129,2,A,280513113036,E,02711.0500,S,1721.0876,A,030613171243,E,02756.7618,S,2300.0325,3491,538200,14400,1)")); } -- cgit v1.2.3 From 7deebcef53759e0e11702af97462b821bfad5f5d Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 26 Sep 2016 04:23:29 +1300 Subject: Implement Aplicom H protocol --- .../traccar/protocol/AplicomProtocolDecoder.java | 80 ++++++++++++++++++++++ .../protocol/AplicomProtocolDecoderTest.java | 9 ++- 2 files changed, 86 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java index abd30ee45..fa512d8b1 100644 --- a/src/org/traccar/protocol/AplicomProtocolDecoder.java +++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java @@ -348,6 +348,84 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } } + private void decodeH(Position position, ChannelBuffer buf, int selector) { + + if ((selector & 0x0004) != 0) { + getLastLocation(position, new Date(buf.readUnsignedInt() * 1000)); + } else { + getLastLocation(position, null); + } + + if ((selector & 0x0040) != 0) { + buf.readUnsignedInt(); // reset time + } + + if ((selector & 0x2000) != 0) { + buf.readUnsignedShort(); // snapshot counter + } + + int index = 1; + while (buf.readableBytes() > 0) { + + position.set("h" + index + "Index", buf.readUnsignedByte()); + + buf.readUnsignedShort(); // length + + int n = buf.readUnsignedByte(); + int m = buf.readUnsignedByte(); + + position.set("h" + index + "XLength", n); + position.set("h" + index + "YLength", m); + + if ((selector & 0x0008) != 0) { + position.set("h" + index + "XType", buf.readUnsignedByte()); + position.set("h" + index + "YType", buf.readUnsignedByte()); + position.set("h" + index + "Parameters", buf.readUnsignedByte()); + } + + boolean percentageFormat = (selector & 0x0020) != 0; + + StringBuilder data = new StringBuilder(); + for (int i = 0; i < n * m; i++) { + if (percentageFormat) { + data.append(buf.readUnsignedByte() * 0.5).append("%").append(" "); + } else { + data.append(buf.readUnsignedShort()).append(" "); + } + } + + position.set("h" + index + "Data", data.toString().trim()); + + position.set("h" + index + "Total", buf.readUnsignedInt()); + + if ((selector & 0x0010) != 0) { + int k = buf.readUnsignedByte(); + + data = new StringBuilder(); + for (int i = 1; i < n; i++) { + if (k == 1) { + data.append(buf.readByte()).append(" "); + } else if (k == 2) { + data.append(buf.readShort()).append(" "); + } + } + position.set("h" + index + "XLimits", data.toString().trim()); + + data = new StringBuilder(); + for (int i = 1; i < m; i++) { + if (k == 1) { + data.append(buf.readByte()).append(" "); + } else if (k == 2) { + data.append(buf.readShort()).append(" "); + } + } + position.set("h" + index + "YLimits", data.toString().trim()); + } + + index += 1; + } + } + @Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -389,6 +467,8 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { decodeD(position, buf, selector, event); } else if (protocol == 'E') { decodeE(position, buf, selector); + } else if (protocol == 'H') { + decodeH(position, buf, selector); } else { return null; } diff --git a/test/org/traccar/protocol/AplicomProtocolDecoderTest.java b/test/org/traccar/protocol/AplicomProtocolDecoderTest.java index d6a29c6dd..cb39b5d2e 100644 --- a/test/org/traccar/protocol/AplicomProtocolDecoderTest.java +++ b/test/org/traccar/protocol/AplicomProtocolDecoderTest.java @@ -10,6 +10,12 @@ public class AplicomProtocolDecoderTest extends ProtocolTest { AplicomProtocolDecoder decoder = new AplicomProtocolDecoder(new AplicomProtocol()); + verifyAttributes(decoder, binary( + "48C1014143B4493145004900203F6D014B5557C20003000015060110FF00C800000000000000003D01141E283C500100260404010200000000000000000000000000C8000000000000010200110019001E0064019003E8")); + + verifyAttributes(decoder, binary( + "48c10144b9de54e6b2008700205f710a57d23ec957d23b8d00000000300d0106ff00000000000000000000000000000000000000000000000000000000000000010a141e28323c46505a646e7801000f020104ff000000000000000000010102000f020104ff000000000000000000010103000f020104ff000000000000000000010105000f020104ff0000000000000000000101")); + verifyAttributes(decoder, binary( "45c20145931876ffb2007100ffff6d00000057c6dd1970230d087b1f7d7f0000d0c1000000003580000035801f40ffff5001574442393036363035533132333435363700014142432d333435202020202020000000000000000000000000000000000000000000000001123130343632343639373030303030303100000000")); @@ -19,9 +25,6 @@ public class AplicomProtocolDecoderTest extends ProtocolTest { verifyAttributes(decoder, binary( "45c20145931876ffb2007100ffff6d00000057c6de0970270d087b1f7d7f0000d0c1000000003580000035801f40ffff5001574442393036363035533132333435363700014142432d333435202020202020000000000000000000000000000000000000000000000001123130343632343639373030303030303100000000")); - verifyNothing(decoder, binary( - "48c10144b9de54e6b2008700205f710a57d23ec957d23b8d00000000300d0106ff00000000000000000000000000000000000000000000000000000000000000010a141e28323c46505a646e7801000f020104ff000000000000000000010102000f020104ff000000000000000000010103000f020104ff000000000000000000010105000f020104ff0000000000000000000101")); - verifyAttributes(decoder, binary( "44c3014645e8ecff3c00ea03ffffbc00f457d68a6557d68a6303bb55fa018843da1100009881000000000000000000000000000000000000000000000000000000000000000000000000000000ff0056007600000000000000014542016d0001010095070e14014645e8ecff3c57d68a6403bb55fa018843dac0010d14ff050102030405060708090a0b0c0d0e0f10112a01010730343f3c1ff5cf01020700007d007d23010103022f2e01060c67452301efcdab8967452301010b10000000007d007d007d7dffffffffffff010a2400000000000000010000000000000000ffffffffffffffff00010001ffff00000000ffff010c02fec6")); -- cgit v1.2.3