diff options
-rw-r--r-- | src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java | 18 | ||||
-rw-r--r-- | src/test/java/org/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")); } } |