aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-09-23 15:32:43 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-09-23 15:32:43 +1200
commite61e883a013d7e46f42d1037dcf79857a9a558b9 (patch)
treead54ed23800321efa0013e5094ff48e90e56dcee
parenta228c176c61dcb69815d5667a418f6d77eb40d16 (diff)
downloadtrackermap-server-e61e883a013d7e46f42d1037dcf79857a9a558b9.tar.gz
trackermap-server-e61e883a013d7e46f42d1037dcf79857a9a558b9.tar.bz2
trackermap-server-e61e883a013d7e46f42d1037dcf79857a9a558b9.zip
Extend megastek protocol decoder
-rw-r--r--src/org/traccar/protocol/MegastekProtocolDecoder.java47
-rw-r--r--test/org/traccar/protocol/MegastekProtocolDecoderTest.java5
2 files changed, 49 insertions, 3 deletions
diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java
index c07e73533..fa6c7495f 100644
--- a/src/org/traccar/protocol/MegastekProtocolDecoder.java
+++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java
@@ -275,6 +275,20 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
"(\\d+\\.\\d+)," + // Course
"(\\d+\\.\\d+)," + // Altitude
"(\\d+\\.\\d+)," + // Odometer
+ "(\\d+)," + // MCC
+ "(\\d+)," + // MNC
+ "(\\p{XDigit}{4},\\p{XDigit}{4})," + // Cell
+ "(\\d+)?," + // GSM
+ "([01]+)," + // Input
+ "([01]+)," + // Output
+ "(\\d+)," + // ADC1
+ "(\\d+)," + // ADC2
+ "(\\d+)," + // ADC3
+ "(?:(-?\\d+\\.?\\d*)| )," + // Temperature 1
+ "(?:(-?\\d+\\.?\\d*)| )," + // Temperature 2
+ "(\\d+)?,," + // RFID
+ "(\\d+)?," + // Battery
+ "([^,]*);" + // Alert
".*");
private Position decodeNew(Channel channel, String sentence) {
@@ -297,7 +311,6 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
position.set(Event.KEY_ARCHIVE, true);
}
- // Date and Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++)));
@@ -308,7 +321,6 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++)));
position.setTime(time.getTime());
- // Validity
position.setValid(parser.group(index++).equals("A"));
// Latitude
@@ -331,6 +343,37 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
position.setAltitude(Double.parseDouble(parser.group(index++)));
position.set(Event.KEY_ODOMETER, Double.parseDouble(parser.group(index++)));
+ position.set(Event.KEY_MCC, Integer.parseInt(parser.group(index++)));
+ position.set(Event.KEY_MNC, Integer.parseInt(parser.group(index++)));
+ position.set(Event.KEY_CELL, parser.group(index++));
+
+ String gsm = parser.group(index++);
+ if (gsm != null) {
+ position.set(Event.KEY_GSM, Integer.parseInt(gsm));
+ }
+
+ position.set(Event.KEY_INPUT, Integer.parseInt(parser.group(index++), 2));
+ position.set(Event.KEY_OUTPUT, Integer.parseInt(parser.group(index++), 2));
+
+ for (int i = 1; i <= 3; i++) {
+ position.set(Event.PREFIX_ADC + i, Integer.parseInt(parser.group(index++)));
+ }
+
+ for (int i = 1; i <= 2; i++) {
+ String adc = parser.group(index++);
+ if (adc != null) {
+ position.set(Event.PREFIX_TEMP + i, Double.parseDouble(adc));
+ }
+ }
+
+ position.set(Event.KEY_RFID, parser.group(index++));
+
+ String battery = parser.group(index++);
+ if (battery != null) {
+ position.set(Event.KEY_BATTERY, Integer.parseInt(battery));
+ }
+
+ position.set(Event.KEY_ALARM, parser.group(index++));
return position;
}
diff --git a/test/org/traccar/protocol/MegastekProtocolDecoderTest.java b/test/org/traccar/protocol/MegastekProtocolDecoderTest.java
index 7c0cedb8c..ece6b6642 100644
--- a/test/org/traccar/protocol/MegastekProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/MegastekProtocolDecoderTest.java
@@ -9,7 +9,10 @@ public class MegastekProtocolDecoderTest extends ProtocolDecoderTest {
public void testDecode() throws Exception {
MegastekProtocolDecoder decoder = new MegastekProtocolDecoder(new MegastekProtocol());
-
+
+ verify(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,,,100,Timer;!"));
+
verify(decoder.decode(null, null,
"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"));