diff options
author | michaelloliveira <michaelloliveira@gmail.com> | 2018-06-05 15:46:23 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-05 15:46:23 -0300 |
commit | 7d83f65d3b2f9f57f3c1a4fc1288272571662f55 (patch) | |
tree | deb426ebe6adb5c4bc84a75056e04a8fd2e66dbb /src | |
parent | 974ff50c441baa9c0a574ccb4b52e79e256b2492 (diff) | |
download | traccar-server-7d83f65d3b2f9f57f3c1a4fc1288272571662f55.tar.gz traccar-server-7d83f65d3b2f9f57f3c1a4fc1288272571662f55.tar.bz2 traccar-server-7d83f65d3b2f9f57f3c1a4fc1288272571662f55.zip |
Optimized!
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/protocol/SviasProtocolDecoder.java | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/src/org/traccar/protocol/SviasProtocolDecoder.java b/src/org/traccar/protocol/SviasProtocolDecoder.java index ef631bf64..bc459de25 100644 --- a/src/org/traccar/protocol/SviasProtocolDecoder.java +++ b/src/org/traccar/protocol/SviasProtocolDecoder.java @@ -31,19 +31,15 @@ import org.traccar.model.Position; public class SviasProtocolDecoder extends BaseProtocolDecoder {
- private static final String MSG_KEEPALIVE = "@";
-
public SviasProtocolDecoder(SviasProtocol protocol) {
super(protocol);
}
private static final Pattern PATTERN = new PatternBuilder()
- .text("[") // delimiter init
- .number("(dddd),") // version hardware
- .number("(dddd),") // version software
- .number("(d+),") // counter
- .number("(d+),") // imei
- .any() // model or hourmeter
+ .text("[") // delimiter init
+ .any()
+ .number("(dddddddd),") // imei
+ .any()
.number("(d+),") // date (yyyymmdd)
.number("(d+),") // time (hhmmss)
.number("(-?d+),") // longitude
@@ -53,9 +49,8 @@ public class SviasProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // odometer
.number("(d+),") // input
.number("(d+),") // output / status
- .number("(d+),") // flag pack input 1
- .number("(d+),") // flag pack input 2
- .number("(d+),") // main power voltage
+ .any()
+ .number("(ddddd),") // main power voltage
.number("(d+),") // percentual power internal battery
.number("(d+),") // RSSID
.any()
@@ -71,6 +66,7 @@ public class SviasProtocolDecoder extends BaseProtocolDecoder { throws Exception {
String sentence = (String) msg;
+ Object result = null;
if (!sentence.contains(":")) {
@@ -81,10 +77,6 @@ public class SviasProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(getProtocolName());
- String versionHard = parser.next();
- String versionSoft = parser.next();
- String counterInternal = parser.next();
-
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
@@ -102,8 +94,8 @@ public class SviasProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(convertCoordinates(parser.nextLong()));
position.setLongitude(convertCoordinates(parser.nextLong()));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt() / 100));
- position.setCourse(parser.nextInt() / 100);
+ position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0) / 100));
+ position.setCourse(parser.nextDouble(0) / 100);
position.setAltitude(0);
position.set(Position.KEY_ODOMETER, parser.nextInt());
@@ -121,30 +113,22 @@ public class SviasProtocolDecoder extends BaseProtocolDecoder { position.setValid(output.substring(0, 1).equals("1"));
- String pck1 = parser.next();
- String pck2 = parser.next();
-
- position.set(Position.KEY_POWER, parser.nextInt() / 1000);
+ position.set(Position.KEY_POWER, parser.nextDouble(0) / 1000);
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
position.set(Position.KEY_RSSI, parser.nextInt());
- if (channel != null) {
- channel.write(MSG_KEEPALIVE);
- }
-
- return position;
+ result = position;
- } else {
- //send keepalive for message check
- if (channel != null) {
- channel.write(MSG_KEEPALIVE);
- }
+ }
- return null;
+ if (channel != null) {
+ channel.write("@");
}
+ return result;
+
}
}
|