aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolDecoder.java116
-rw-r--r--test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java6
2 files changed, 87 insertions, 35 deletions
diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
index e41a42843..0b63620b5 100644
--- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,6 +30,8 @@ import org.traccar.model.Position;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
+import java.util.LinkedList;
+import java.util.List;
import java.util.regex.Pattern;
public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
@@ -118,6 +120,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_POSITION_LOGGED = 0x9016;
public static final int MSG_ALARM = 0x9999;
public static final int MSG_RFID = 0x9966;
+ public static final int MSG_RETRANSMISSION = 0x6688;
public static final int MSG_OBD_RT = 0x9901;
public static final int MSG_OBD_RTA = 0x9902;
@@ -328,6 +331,40 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private List<Position> decodeRetransmission(ChannelBuffer buf, DeviceSession deviceSession) {
+ List<Position> positions = new LinkedList<>();
+
+ int count = buf.readUnsignedByte();
+ for (int i = 0; i < count; i++) {
+
+ buf.readUnsignedByte(); // alarm
+
+ int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\\');
+ if (endIndex < 0) {
+ endIndex = buf.writerIndex() - 4;
+ }
+
+ String sentence = buf.readBytes(endIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position = decodeRegular(position, sentence);
+
+ if (position != null) {
+ positions.add(position);
+ }
+
+ if (buf.readableBytes() > 4) {
+ buf.readUnsignedByte(); // delimiter
+ }
+
+ }
+
+ return positions;
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -355,48 +392,57 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
}
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- if (command == MSG_ALARM) {
- short alarmCode = buf.readUnsignedByte();
- position.set(Position.KEY_ALARM, decodeAlarm(alarmCode));
- if (alarmCode >= 0x02 && alarmCode <= 0x05) {
- position.set(Position.PREFIX_IN + alarmCode, 1);
- } else if (alarmCode >= 0x32 && alarmCode <= 0x35) {
- position.set(Position.PREFIX_IN + (alarmCode - 0x30), 0);
- }
- } else if (command == MSG_POSITION_LOGGED) {
- buf.skipBytes(6);
- }
-
DeviceSession deviceSession = identify(id, channel, remoteAddress);
if (deviceSession == null) {
return null;
}
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (command == MSG_RFID) {
- for (int i = 0; i < 15; i++) {
- long rfid = buf.readUnsignedInt();
- if (rfid != 0) {
- String card = String.format("%010d", rfid);
- position.set("card" + (i + 1), card);
- position.set(Position.KEY_DRIVER_UNIQUE_ID, card);
+
+ if (command == MSG_RETRANSMISSION) {
+
+ return decodeRetransmission(buf, deviceSession);
+
+ } else {
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+
+ if (command == MSG_ALARM) {
+ short alarmCode = buf.readUnsignedByte();
+ position.set(Position.KEY_ALARM, decodeAlarm(alarmCode));
+ if (alarmCode >= 0x02 && alarmCode <= 0x05) {
+ position.set(Position.PREFIX_IN + alarmCode, 1);
+ } else if (alarmCode >= 0x32 && alarmCode <= 0x35) {
+ position.set(Position.PREFIX_IN + (alarmCode - 0x30), 0);
+ }
+ } else if (command == MSG_POSITION_LOGGED) {
+ buf.skipBytes(6);
+ }
+
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ if (command == MSG_RFID) {
+ for (int i = 0; i < 15; i++) {
+ long rfid = buf.readUnsignedInt();
+ if (rfid != 0) {
+ String card = String.format("%010d", rfid);
+ position.set("card" + (i + 1), card);
+ position.set(Position.KEY_DRIVER_UNIQUE_ID, card);
+ }
}
}
- }
- String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 4, StandardCharsets.US_ASCII);
+ String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 4, StandardCharsets.US_ASCII);
+
+ if (command == MSG_POSITION || command == MSG_POSITION_LOGGED || command == MSG_ALARM) {
+ return decodeRegular(position, sentence);
+ } else if (command == MSG_RFID) {
+ return decodeRfid(position, sentence);
+ } else if (command == MSG_OBD_RT) {
+ return decodeObd(position, sentence);
+ } else if (command == MSG_OBD_RTA) {
+ return decodeObdA(position, sentence);
+ }
- if (command == MSG_POSITION || command == MSG_POSITION_LOGGED || command == MSG_ALARM) {
- return decodeRegular(position, sentence);
- } else if (command == MSG_RFID) {
- return decodeRfid(position, sentence);
- } else if (command == MSG_OBD_RT) {
- return decodeObd(position, sentence);
- } else if (command == MSG_OBD_RTA) {
- return decodeObdA(position, sentence);
}
return null;
diff --git a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java
index 03be4807c..020078f4a 100644
--- a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java
@@ -10,6 +10,12 @@ public class MeiligaoProtocolDecoderTest extends ProtocolTest {
MeiligaoProtocolDecoder decoder = new MeiligaoProtocolDecoder(new MeiligaoProtocol());
+ verifyPositions(decoder, binary(
+ "2424006661172036237118668801003039333630342e3030302c562c303330332e333231352c4e2c31303134372e313530302c452c302e30302c2c3235313031377c302e307c302e307c303030307c303030302c303030307c30303030303230343259ca0d0a"));
+
+ verifyPositions(decoder, binary(
+ "242401d961172036237118668805003039353830332e3030302c412c303330332e333431392c4e2c31303134372e343130342c452c372e30342c3230362e36312c3235313031377c302e307c302e307c303230307c303030302c303030307c3030303031313532325c003039353833332e3030302c412c303330332e323630302c4e2c31303134372e333734342c452c31302e33382c3236332e31342c3235313031377c302e307c302e307c303230307c303030302c303030307c3030303031313734355c003039353930332e3030302c412c303330332e313833382c4e2c31303134372e333735362c452c382e34392c3232332e37372c3235313031377c302e307c302e307c303230307c303030302c303030307c3030303031313839375c003039353933332e3030302c412c303330332e313033312c4e2c31303134372e333435332c452c382e37312c3139312e35302c3235313031377c302e307c302e307c303230307c303030302c303030307c3030303031323130325c003130303030302e3030302c412c303330332e313032332c4e2c31303134372e333338372c452c302e30302c3231332e36392c3235313031377c302e307c302e307c303030307c303030312c303030307c3030303031323131380d110d0a"));
+
verifyPosition(decoder, binary(
"2424007f1092ffffffffff9999523232303534392e3030302c412c333533372e313231372c4e2c30313130302e303633332c452c362e34382c3139332c3238303631372c2c2a30357c302e387c32347c323030307c303030432c303030417c303235443030303230303833354437427c31357c3037303636424142f7310d0a"));