aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-05-27 20:12:39 -0700
committerGitHub <noreply@github.com>2021-05-27 20:12:39 -0700
commit3ebd7383a9fdf797ac06fbe8988c2cba0430410d (patch)
treeeb69ff2879fac473b30f5a5785380a6e68c0b0e9
parent0e050e0f85422377096abd0ee8e7deead693c41a (diff)
parentbea7b241c4d29a7c7b49192ac1170ddeeb8bd90d (diff)
downloadtraccar-server-3ebd7383a9fdf797ac06fbe8988c2cba0430410d.tar.gz
traccar-server-3ebd7383a9fdf797ac06fbe8988c2cba0430410d.tar.bz2
traccar-server-3ebd7383a9fdf797ac06fbe8988c2cba0430410d.zip
Merge pull request #4684 from Elsensee/patch-2
Fix poweroff alarm and extend megastek protocol
-rw-r--r--src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java33
-rw-r--r--src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java16
2 files changed, 47 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..fae73d931 100644
--- a/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java
@@ -275,9 +275,10 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
.or().text(" ")
.groupEnd("?").text(",")
.number("(d+)?,") // rfid
+ .number("([01])(d)?").optional() // charge and belt status
.expression("[^,]*,")
.number("(d+)?,") // battery
- .expression("([^,]*)") // alert
+ .expression("([^,]*)[,;]") // alert
.any()
.compile();
@@ -355,6 +356,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() > 0);
+ }
+ if (parser.hasNext()) {
+ position.set("belt", parser.nextInt());
+ }
+
String battery = parser.next();
if (battery != null) {
position.set(Position.KEY_BATTERY, Integer.parseInt(battery));
@@ -375,10 +383,11 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
}
}
switch (value) {
+ case "pw on":
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;
@@ -390,12 +399,32 @@ 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;
+ case "belt off":
+ case "beltoff":
+ return Position.ALARM_UNLOCK;
case "error":
return Position.ALARM_FAULT;
default:
diff --git a/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java
index 6b7eb2e99..3747d9200 100644
--- a/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java
@@ -1,6 +1,7 @@
package org.traccar.protocol;
import org.junit.Test;
+import org.traccar.model.Position;
import org.traccar.ProtocolTest;
public class MegastekProtocolDecoderTest extends ProtocolTest {
@@ -28,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;"));
@@ -50,9 +55,20 @@ 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(
+ "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,,,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"));