diff options
author | Ivan Muratov <binakot@gmail.com> | 2017-10-24 14:52:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-24 14:52:48 +0300 |
commit | db02157dbb29539dda4b51a5e8b317293cfc536c (patch) | |
tree | b974f082172406e16a92cb9da8136ef856f571a5 /src/org/traccar/protocol/MeitrackProtocolDecoder.java | |
parent | 09d3cf2b5416327700ad22b652cf4a0dca09aaf2 (diff) | |
parent | 96e15853b9c28bd31295ca2c014e226e4a50aaa1 (diff) | |
download | trackermap-server-db02157dbb29539dda4b51a5e8b317293cfc536c.tar.gz trackermap-server-db02157dbb29539dda4b51a5e8b317293cfc536c.tar.bz2 trackermap-server-db02157dbb29539dda4b51a5e8b317293cfc536c.zip |
Merge branch 'master' into master
Diffstat (limited to 'src/org/traccar/protocol/MeitrackProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/MeitrackProtocolDecoder.java | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index 38ecde519..efc9c24db 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -20,6 +20,7 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.DeviceSession; +import org.traccar.helper.Checksum; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -69,16 +70,15 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { .number("(x+)?|") // adc2 .number("(x+)?|") // adc3 .number("(x+)|") // battery - .number("(x+),") // power + .number("(x+)?,") // power .groupBegin() .expression("([^,]+)?,") // event specific .expression("[^,]*,") // reserved - .number("d*,") // protocol + .number("(d+)?,") // protocol .number("(x{4})?") // fuel .number("(?:,(x{6}(?:|x{6})*))?") // temperature - .or() + .groupEnd("?") .any() - .groupEnd() .text("*") .number("xx") .text("\r\n").optional() @@ -160,7 +160,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { } } - String deviceModel = Context.getIdentityManager().getDeviceById(deviceSession.getDeviceId()).getModel(); + String deviceModel = Context.getIdentityManager().getById(deviceSession.getDeviceId()).getModel(); if (deviceModel == null) { deviceModel = ""; } @@ -201,7 +201,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { if (eventData != null && !eventData.isEmpty()) { switch (event) { case 37: - position.set(Position.KEY_RFID, eventData); + position.set(Position.KEY_DRIVER_UNIQUE_ID, eventData); break; default: position.set("eventData", eventData); @@ -209,6 +209,8 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { } } + int protocol = parser.nextInt(0); + if (parser.hasNext()) { String fuel = parser.next(); position.set(Position.KEY_FUEL_LEVEL, @@ -218,9 +220,14 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { if (parser.hasNext()) { for (String temp : parser.next().split("\\|")) { int index = Integer.valueOf(temp.substring(0, 2), 16); - double value = Byte.valueOf(temp.substring(2, 4), 16); - value += (value < 0 ? -0.01 : 0.01) * Integer.valueOf(temp.substring(4), 16); - position.set(Position.PREFIX_TEMP + index, value); + if (protocol >= 3) { + double value = Short.valueOf(temp.substring(2), 16); + position.set(Position.PREFIX_TEMP + index, value * 0.01); + } else { + double value = Byte.valueOf(temp.substring(2, 4), 16); + value += (value < 0 ? -0.01 : 0.01) * Integer.valueOf(temp.substring(4), 16); + position.set(Position.PREFIX_TEMP + index, value); + } } } @@ -307,7 +314,6 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { ChannelBuffer buf = (ChannelBuffer) msg; - // Find type int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ','); index = buf.indexOf(index + 1, buf.writerIndex(), (byte) ','); @@ -316,8 +322,12 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { case "D03": if (channel != null) { DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); - String imei = Context.getIdentityManager().getDeviceById(deviceSession.getDeviceId()).getUniqueId(); - channel.write("@@O46," + imei + ",D00,camera_picture.jpg,0*00\r\n"); + String imei = Context.getIdentityManager().getById(deviceSession.getDeviceId()).getUniqueId(); + String content = "D00,camera_picture.jpg,0"; + int length = 1 + imei.length() + 1 + content.length() + 5; + String response = String.format("@@O%02d,%s,%s*", length, imei, content); + response += Checksum.sum(response) + "\r\n"; + channel.write(response); } return null; case "CCC": |