aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-12-17 21:47:29 +1300
committerGitHub <noreply@github.com>2016-12-17 21:47:29 +1300
commit8d84469407ea7e6ee84adc9e7fd68f26d07805b9 (patch)
tree626400c7ca61da92acf0bc1ef348ced9024e066e
parentf8280619a39cd05106b58b7198a99fd724d9b482 (diff)
parentd9e0b44ed13f9dd1aac96551555191283e45e020 (diff)
downloadtraccar-server-8d84469407ea7e6ee84adc9e7fd68f26d07805b9.tar.gz
traccar-server-8d84469407ea7e6ee84adc9e7fd68f26d07805b9.tar.bz2
traccar-server-8d84469407ea7e6ee84adc9e7fd68f26d07805b9.zip
Merge pull request #2682 from joseant/master
Fix Meiligao Protocol to work with tk228
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolDecoder.java58
-rw-r--r--test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java3
2 files changed, 50 insertions, 11 deletions
diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
index 9915eab8c..706655b83 100644
--- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
@@ -87,29 +87,40 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
.number("(d+.d+),") // throttle
.number("(d+.d+),") // engine load
.number("(-?d+),") // coolant temp
- .number("d+.d+,") // instantaneous fuel
+ .number("(d+.d+),") // instantaneous fuel
.number("(d+.d+),") // average fuel
.number("(d+.d+),") // driving range
.number("(d+.?d*),") // odometer
- .number("(d+.d+),")
- .number("(d+.d+),")
+ .number("(d+.d+),") // Single Fuel Consumption
+ .number("(d+.d+),") // Total Fuel Consumption
.number("(d+),") // error code count
- .number("d+,") // harsh acceleration count
- .number("d+") // harsh break count
+ .number("(d+),") // harsh acceleration count
+ .number("(d+)") // harsh break count
+ .compile();
+
+ private static final Pattern PATTERN_OBDA = new PatternBuilder()
+ .number("(d+),") // Total ignition
+ .number("(d+.d+),") // Total driving time
+ .number("(d+.d+),") // Total idling time
+ .number("(d+),") // Average hot start time
+ .number("(d+),") // Average speed
+ .number("(d+),") // history hightest speed
+ .number("(d+),") // history hightest rpm
+ .number("(d+),") // total harsh acceleration
+ .number("(d+)") // total harsh break n0
.compile();
public static final int MSG_HEARTBEAT = 0x0001;
public static final int MSG_SERVER = 0x0002;
public static final int MSG_LOGIN = 0x5000;
public static final int MSG_LOGIN_RESPONSE = 0x4000;
-
public static final int MSG_POSITION = 0x9955;
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_OBD_RT = 0x9901;
+ public static final int MSG_OBD_RTA = 0x9902;
private DeviceSession identify(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
StringBuilder builder = new StringBuilder();
@@ -284,11 +295,34 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
position.set("engineLoad", parser.nextDouble());
position.set(Position.PREFIX_TEMP + 1, parser.nextInt());
position.set(Position.KEY_FUEL_CONSUMPTION, parser.nextDouble());
- position.set("drivingRange", parser.nextDouble() * 1000);
- position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
+ position.set("averageFuelConsumition", parser.nextDouble());
+ position.set("drivingRange", parser.nextDouble());
+ position.set(Position.KEY_ODOMETER, parser.nextDouble());
position.set("singleFuelConsumption", parser.nextDouble());
position.set("totalFuelConsumption", parser.nextDouble());
+ position.set(Position.KEY_DTCS, parser.nextInt());
+ position.set("harshAcelerationNo", parser.nextInt());
+ position.set("harshBreakerNo", parser.nextInt());
+ return position;
+ }
+
+ private Position decodeObdA(Position position, String sentence) {
+ Parser parser = new Parser(PATTERN_OBDA, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ getLastLocation(position, null);
+ position.set("totalIgnitionNo", parser.nextInt());
+ position.set("totalDrivingTime", parser.nextDouble());
+ position.set("totalIdlingTime", parser.nextDouble());
+ position.set("averageHotStartTime", parser.nextInt());
+ position.set("averageSpeed", parser.nextInt());
+ position.set("historyHightestSpeed", parser.nextInt());
+ position.set("historyHightestRPM", parser.nextInt());
+ position.set("totalHarshAccerleration", parser.nextInt());
+ position.set("totalHarshBrake", parser.nextInt());
return position;
}
@@ -305,11 +339,11 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
if (channel != null) {
if (command == MSG_LOGIN) {
- response = ChannelBuffers.wrappedBuffer(new byte[] {0x01});
+ response = ChannelBuffers.wrappedBuffer(new byte[]{0x01});
sendResponse(channel, remoteAddress, id, MSG_LOGIN_RESPONSE, response);
return null;
} else if (command == MSG_HEARTBEAT) {
- response = ChannelBuffers.wrappedBuffer(new byte[] {0x01});
+ response = ChannelBuffers.wrappedBuffer(new byte[]{0x01});
sendResponse(channel, remoteAddress, id, MSG_HEARTBEAT, response);
return null;
} else if (command == MSG_SERVER) {
@@ -353,6 +387,8 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
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 10fa3f971..0633a6291 100644
--- a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java
@@ -18,6 +18,9 @@ public class MeiligaoProtocolDecoderTest extends ProtocolTest {
verifyAttributes(decoder, binary(
"4040005066104020094432990131302E312C302C3135362C302E30302C31392E36312C2D33342C33342E32362C32312E38332C372E39312C313033332C322E36392C362E35352C302C302C309DBF0D0A"));
+
+ verifyAttributes(decoder, binary(
+ "242400736610402421174399553130353033342e3937382c412c333933352e333638392c4e2c30303233382e313638342c452c303034382c3034322c3038313231362c2c2a31437c31312e357c3139347c313030317c303341362c303030307c30303130343030307c3030303030303cd00d0a2424004e66104024211743990131342e312c323638372c39302c32312e35372c342e37312c38352c372e31302c382e31362c342e32372c3130342c302e33342c392e33342c302c312c30b7160d0a2424003266104024211743990232352c322e34302c302e37392c32322c34332c3131392c333735362c37352c3132e4c90d0a"));
verifyPosition(decoder, binary(
"242400746251103044ffff99553033353033392e3939392c412c323832332e373632312c4e2c31303635322e303730342c572c3030302e302c3030302e302c3136303631362c2c2c412a37357c302e397c323038332e327c303030307c303030302c303030307c31303034333736333265780d0a"));