From b2cca44879abd12492054bde4d84b8b8ae1c3cea Mon Sep 17 00:00:00 2001 From: Oliver S Date: Mon, 24 May 2021 02:47:35 +0200 Subject: Fix poweroff alarm and extend megastek protocol --- .../traccar/protocol/MegastekProtocolDecoder.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java b/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java index d81cc0eda..fc27d3502 100644 --- a/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java @@ -275,10 +275,15 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { .or().text(" ") .groupEnd("?").text(",") .number("(d+)?,") // rfid + .groupBegin() // ext accessories + .number("([01])") // charging + .number("(d)?") // belt status + .groupEnd("?") .expression("[^,]*,") .number("(d+)?,") // battery - .expression("([^,]*)") // alert + .expression("([^,]*),?") // alert .any() + .text(";") .compile(); private Position decodeNew(Channel channel, SocketAddress remoteAddress, String sentence) { @@ -354,6 +359,13 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { } position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next()); + + if (parser.hasNext()) { + position.set(Position.KEY_CHARGE, parser.nextInt() == 1); + } + if (parser.hasNext()) { + position.set("belt", parser.nextInt()); + } String battery = parser.next(); if (battery != null) { @@ -378,7 +390,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { case "poweron": return Position.ALARM_POWER_ON; case "poweroff": - return Position.ALARM_POWER_ON; + return Position.ALARM_POWER_OFF; case "sos": case "help": return Position.ALARM_SOS; @@ -396,6 +408,12 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { return Position.ALARM_GEOFENCE_ENTER; case "move out": return Position.ALARM_GEOFENCE_EXIT; + case "belt on": + case "belton": + return Position.ALARM_LOCK; + case "belt off": + case "beltoff": + return Position.ALARM_UNLOCK; case "error": return Position.ALARM_FAULT; default: -- cgit v1.2.3 From b9c27acb7f4d6f81dbc783365ed58d3708f8e7a2 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Tue, 25 May 2021 03:10:49 +0200 Subject: Fix and add tests and add alert event types --- .../org/traccar/protocol/MegastekProtocolDecoder.java | 18 ++++++++++++++++-- .../traccar/protocol/MegastekProtocolDecoderTest.java | 11 ++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java b/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java index fc27d3502..074523a76 100644 --- a/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java @@ -281,9 +281,8 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { .groupEnd("?") .expression("[^,]*,") .number("(d+)?,") // battery - .expression("([^,]*),?") // alert + .expression("([^,]*)[,;]") // alert .any() - .text(";") .compile(); private Position decodeNew(Channel channel, SocketAddress remoteAddress, String sentence) { @@ -387,6 +386,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { } } switch (value) { + case "pw on": case "poweron": return Position.ALARM_POWER_ON; case "poweroff": @@ -402,12 +402,26 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { case "low battery": case "lowbattery": return Position.ALARM_LOW_BATTERY; + case "low extern voltage": + return Position.ALARM_LOW_POWER; + case "gps cut": + return Position.ALARM_GPS_ANTENNA_CUT; case "vib": return Position.ALARM_VIBRATION; case "move in": return Position.ALARM_GEOFENCE_ENTER; case "move out": return Position.ALARM_GEOFENCE_EXIT; + case "corner": + return Position.ALARM_CORNERING; + case "fatigue": + return Position.ALARM_FATIGUE_DRIVING; + case "psd": + return Position.ALARM_POWER_CUT; + case "psr": + return Position.ALARM_POWER_RESTORED; + case "hit": + return Position.ALARM_SHOCK; case "belt on": case "belton": return Position.ALARM_LOCK; diff --git a/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java index 6b7eb2e99..4a5ffaccc 100644 --- a/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java @@ -1,8 +1,11 @@ package org.traccar.protocol; import org.junit.Test; +import org.traccar.model.Position; import org.traccar.ProtocolTest; +import static org.junit.Assert.assertEquals; + public class MegastekProtocolDecoderTest extends ProtocolTest { @Test @@ -50,7 +53,10 @@ public class MegastekProtocolDecoderTest extends ProtocolTest { "0125$MGV002,860719020193193,DeviceName,R,240214,104742,A,2238.20471,N,11401.97967,E,00,03,00,1.20,0.462,356.23,137.9,1.5,460,07,262C,0F54,25,0000,0000,0,0,0,28.5,28.3,,,100,Timer;")); verifyPosition(decoder, text( - "$MGV002,860719020193193,DeviceName,R,240214,104742,A,2238.20471,N,11401.97967,E,00,03,00,1.20,0.462,356.23,137.9,1.5,460,07,262C,0F54,25,0000,0000,0,0,0,28.5,28.3,,,100,Timer;!"), + "0339$MGV002,860719020193193,DeviceName,R,240214,104742,A,2238.20471,N,11401.97967,E,00,03,00,1.20,0.462,356.23,137.9,1.5,460,07,262C,0F54,25,0000,0000,0,0,0,28.5,28.3,,10,100,Timer,18339df945d0:53|108c0fb0a2f1:57|e46f133d6f5c:59|108ccf109f21:59|8adc963d752a:82|04c5a48cc6c0:82|9adc963d752a:83|8800b0b00004:85|90671c80e2fc:85|80c5e68c8d36:86,;!")); + + verifyPosition(decoder, text( + "$MGV002,860719020193193,DeviceName,R,240214,104742,A,2238.20471,N,11401.97967,E,00,03,00,1.20,0.462,356.23,137.9,1.5,460,07,262C,0F54,25,0000,0000,0,0,0,28.5,28.3,,10,100,Timer;!"), position("2014-02-24 10:47:42.000", true, 22.63675, 114.03299)); verifyPosition(decoder, text( @@ -95,6 +101,9 @@ public class MegastekProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, text( "LOGSTX,123456789012345,$GPRMC,230739.000,A,3841.81895,N,09494.12409,W,0.00,0.00,270914,,,A*70,L,,imei:123456789012345,0/7,269.7,Battery=100%,,0,,,5856,78A3;78")); + Position testPosition = (Position) decoder.decode(null, null, "$MGV002,860719020193193,DeviceName,R,240214,104742,A,2238.20471,N,11401.97967,E,00,03,00,1.20,0.462,356.23,137.9,1.5,460,07,262C,0F54,25,0000,0000,0,0,0,28.5,28.3,,10,100,Timer;!"); + assertEquals(true, testPosition.getBoolean(Position.KEY_CHARGE)); + assertEquals(0, testPosition.getInteger("belt")); } } -- cgit v1.2.3 From 8d1e86a7a06f1525a64c44b262758a216b084159 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Tue, 25 May 2021 23:28:14 +0200 Subject: Use verifyAttribute in megastek test --- .../org/traccar/protocol/MegastekProtocolDecoderTest.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java index 4a5ffaccc..b086364ab 100644 --- a/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java @@ -4,8 +4,6 @@ import org.junit.Test; import org.traccar.model.Position; import org.traccar.ProtocolTest; -import static org.junit.Assert.assertEquals; - public class MegastekProtocolDecoderTest extends ProtocolTest { @Test @@ -59,6 +57,14 @@ public class MegastekProtocolDecoderTest extends ProtocolTest { "$MGV002,860719020193193,DeviceName,R,240214,104742,A,2238.20471,N,11401.97967,E,00,03,00,1.20,0.462,356.23,137.9,1.5,460,07,262C,0F54,25,0000,0000,0,0,0,28.5,28.3,,10,100,Timer;!"), position("2014-02-24 10:47:42.000", true, 22.63675, 114.03299)); + verifyAttribute(decoder, text( + "$MGV002,860719020193193,DeviceName,R,240214,104742,A,2238.20471,N,11401.97967,E,00,03,00,1.20,0.462,356.23,137.9,1.5,460,07,262C,0F54,25,0000,0000,0,0,0,28.5,28.3,,10,100,Timer;!"), + Position.KEY_CHARGE, true); + + verifyAttribute(decoder, text( + "$MGV002,860719020193193,DeviceName,R,240214,104742,A,2238.20471,N,11401.97967,E,00,03,00,1.20,0.462,356.23,137.9,1.5,460,07,262C,0F54,25,0000,0000,0,0,0,28.5,28.3,,02,100,Timer;!"), + "belt", 2); + verifyPosition(decoder, text( "STX2010101801 j$GPRMC,101053.000,A,2232.7607,N,11404.7669,E,0.00,,231110,,,A*7F,460,00,2795,0E6A,14,94,1000,0000,91,Timer;1D")); @@ -100,10 +106,6 @@ public class MegastekProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, text( "LOGSTX,123456789012345,$GPRMC,230739.000,A,3841.81895,N,09494.12409,W,0.00,0.00,270914,,,A*70,L,,imei:123456789012345,0/7,269.7,Battery=100%,,0,,,5856,78A3;78")); - - Position testPosition = (Position) decoder.decode(null, null, "$MGV002,860719020193193,DeviceName,R,240214,104742,A,2238.20471,N,11401.97967,E,00,03,00,1.20,0.462,356.23,137.9,1.5,460,07,262C,0F54,25,0000,0000,0,0,0,28.5,28.3,,10,100,Timer;!"); - assertEquals(true, testPosition.getBoolean(Position.KEY_CHARGE)); - assertEquals(0, testPosition.getInteger("belt")); } } -- cgit v1.2.3 From 4581380113a7edf67936a0d567fc469de709e508 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Wed, 26 May 2021 02:19:11 +0200 Subject: Adjust code style --- src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java | 7 ++----- .../java/org/traccar/protocol/MegastekProtocolDecoderTest.java | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java b/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java index 074523a76..82c616245 100644 --- a/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java @@ -275,10 +275,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { .or().text(" ") .groupEnd("?").text(",") .number("(d+)?,") // rfid - .groupBegin() // ext accessories - .number("([01])") // charging - .number("(d)?") // belt status - .groupEnd("?") + .number("([01])(d)?").optional() // charge and belt status .expression("[^,]*,") .number("(d+)?,") // battery .expression("([^,]*)[,;]") // alert @@ -360,7 +357,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next()); if (parser.hasNext()) { - position.set(Position.KEY_CHARGE, parser.nextInt() == 1); + position.set(Position.KEY_CHARGE, parser.nextInt() > 0); } if (parser.hasNext()) { position.set("belt", parser.nextInt()); diff --git a/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java index b086364ab..d2201a4a9 100644 --- a/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java @@ -54,7 +54,7 @@ public class MegastekProtocolDecoderTest extends ProtocolTest { "0339$MGV002,860719020193193,DeviceName,R,240214,104742,A,2238.20471,N,11401.97967,E,00,03,00,1.20,0.462,356.23,137.9,1.5,460,07,262C,0F54,25,0000,0000,0,0,0,28.5,28.3,,10,100,Timer,18339df945d0:53|108c0fb0a2f1:57|e46f133d6f5c:59|108ccf109f21:59|8adc963d752a:82|04c5a48cc6c0:82|9adc963d752a:83|8800b0b00004:85|90671c80e2fc:85|80c5e68c8d36:86,;!")); verifyPosition(decoder, text( - "$MGV002,860719020193193,DeviceName,R,240214,104742,A,2238.20471,N,11401.97967,E,00,03,00,1.20,0.462,356.23,137.9,1.5,460,07,262C,0F54,25,0000,0000,0,0,0,28.5,28.3,,10,100,Timer;!"), + "$MGV002,860719020193193,DeviceName,R,240214,104742,A,2238.20471,N,11401.97967,E,00,03,00,1.20,0.462,356.23,137.9,1.5,460,07,262C,0F54,25,0000,0000,0,0,0,28.5,28.3,,,100,Timer;!"), position("2014-02-24 10:47:42.000", true, 22.63675, 114.03299)); verifyAttribute(decoder, text( @@ -106,6 +106,7 @@ public class MegastekProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, text( "LOGSTX,123456789012345,$GPRMC,230739.000,A,3841.81895,N,09494.12409,W,0.00,0.00,270914,,,A*70,L,,imei:123456789012345,0/7,269.7,Battery=100%,,0,,,5856,78A3;78")); + } } -- cgit v1.2.3 From cac617f6518ed5ad048cc9c57b80849c34650afa Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Thu, 27 May 2021 15:28:16 +0200 Subject: Add unit test for alarm event decoding --- src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java index d2201a4a9..3747d9200 100644 --- a/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java @@ -29,6 +29,10 @@ public class MegastekProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, text( "0140$MGV002,354550056642321,GVT900-3,S,300917,071731,V,,,,,00,00,00,99.9,0.000,0.00,,0.0,457,01,0741,00CD,,0000,0000,20,10,0, , ,,1-1,94,PW ON;!")); + verifyAttribute(decoder, text( + "$MGV002,869152024446923,,S,290816,200627,V,5056.21059,N,00439.25034,E,00,00,00,99.9,,,-25.1,,206,01,0BBB,4418,28,,,,,,,,,01,093,PW ON;"), + Position.KEY_ALARM, Position.ALARM_POWER_ON); + verifyPosition(decoder, text( "$MGV002,869152024446923,,S,290816,200627,V,5056.21059,N,00439.25034,E,00,00,00,99.9,,,-25.1,,206,01,0BBB,4418,28,,,,,,,,,01,093,Timer;")); -- cgit v1.2.3 From bea7b241c4d29a7c7b49192ac1170ddeeb8bd90d Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Fri, 28 May 2021 04:30:54 +0200 Subject: Fix trailing spaces --- src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java b/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java index 82c616245..fae73d931 100644 --- a/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java @@ -355,7 +355,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { } position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next()); - + if (parser.hasNext()) { position.set(Position.KEY_CHARGE, parser.nextInt() > 0); } -- cgit v1.2.3