diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-12-20 08:42:20 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-12-20 08:42:20 +1300 |
commit | 13c1b5a0f68cf3f9a6a8fee43a4e5c1406dac32a (patch) | |
tree | a7d3450db8ccb6698ed4e7794f27ceaf939807c9 /src/org | |
parent | 301b44775fb4ed66fae5c801da3c52f7b88b9697 (diff) | |
download | trackermap-server-13c1b5a0f68cf3f9a6a8fee43a4e5c1406dac32a.tar.gz trackermap-server-13c1b5a0f68cf3f9a6a8fee43a4e5c1406dac32a.tar.bz2 trackermap-server-13c1b5a0f68cf3f9a6a8fee43a4e5c1406dac32a.zip |
Refactor protocols for network location
Diffstat (limited to 'src/org')
30 files changed, 210 insertions, 143 deletions
diff --git a/src/org/traccar/model/CellTower.java b/src/org/traccar/model/CellTower.java index 3447bb921..e572dfb10 100644 --- a/src/org/traccar/model/CellTower.java +++ b/src/org/traccar/model/CellTower.java @@ -16,17 +16,43 @@ package org.traccar.model; import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.traccar.Context; @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) public class CellTower { - private Integer cellId; + public static CellTower from(int mcc, int mnc, int lac, long cid) { + CellTower cellTower = new CellTower(); + cellTower.setMobileCountryCode(mcc); + cellTower.setMobileNetworkCode(mnc); + cellTower.setLocationAreaCode(lac); + cellTower.setCellId(cid); + return cellTower; + } + + public static CellTower from(int mcc, int mnc, int lac, long cid, int rssi) { + CellTower cellTower = CellTower.from(mcc, mnc, lac, cid); + cellTower.setSignalStrength(rssi); + return cellTower; + } + + public static CellTower fromLacCid(int lac, long cid) { + return from( + Context.getConfig().getInteger("location.mcc"), + Context.getConfig().getInteger("location.mnc"), lac, cid); + } + + public static CellTower fromCidLac(long cid, int lac) { + return fromLacCid(lac, cid); + } - public Integer getCellId() { + private Long cellId; + + public Long getCellId() { return cellId; } - public void setCellId(Integer cellId) { + public void setCellId(Long cellId) { this.cellId = cellId; } @@ -60,4 +86,14 @@ public class CellTower { this.mobileNetworkCode = mobileNetworkCode; } + private Integer signalStrength; + + public Integer getSignalStrength() { + return signalStrength; + } + + public void setSignalStrength(Integer signalStrength) { + this.signalStrength = signalStrength; + } + } diff --git a/src/org/traccar/model/Network.java b/src/org/traccar/model/Network.java index 9dd315640..389ce1fdd 100644 --- a/src/org/traccar/model/Network.java +++ b/src/org/traccar/model/Network.java @@ -23,6 +23,13 @@ import java.util.Collection; @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) public class Network { + public Network() { + } + + public Network(CellTower cellTower) { + addCellTower(cellTower); + } + private Integer homeMobileCountryCode; public Integer getHomeMobileCountryCode() { diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java index 9c34a2e78..8e3cd2089 100644 --- a/src/org/traccar/protocol/AtrackProtocolDecoder.java +++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java @@ -93,13 +93,13 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_BATTERY, buf.readUnsignedShort()); break; case "GQ": - position.set(Position.KEY_GSM, buf.readUnsignedByte()); + buf.readUnsignedByte(); // rssi break; case "CE": - position.set(Position.KEY_CID, buf.readUnsignedInt()); + buf.readUnsignedInt(); // cid break; case "LC": - position.set(Position.KEY_LAC, buf.readUnsignedShort()); + buf.readUnsignedShort(); // lac break; case "CN": buf.readUnsignedInt(); // mcc + mnc diff --git a/src/org/traccar/protocol/Avl301ProtocolDecoder.java b/src/org/traccar/protocol/Avl301ProtocolDecoder.java index cac6f717f..e3bc2ca90 100644 --- a/src/org/traccar/protocol/Avl301ProtocolDecoder.java +++ b/src/org/traccar/protocol/Avl301ProtocolDecoder.java @@ -21,6 +21,8 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.DateBuilder; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -121,8 +123,9 @@ public class Avl301ProtocolDecoder extends BaseProtocolDecoder { position.set("acc", (union & 0x8000) != 0); } - position.set(Position.KEY_LAC, buf.readUnsignedShort()); - position.set(Position.KEY_CID, buf.readUnsignedMedium()); + position.setNetwork(new Network( + CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedMedium()))); + position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); int flags = buf.readUnsignedByte(); position.set("acc", (flags & 0x2) != 0); diff --git a/src/org/traccar/protocol/BceProtocolDecoder.java b/src/org/traccar/protocol/BceProtocolDecoder.java index dace89659..633ccf793 100644 --- a/src/org/traccar/protocol/BceProtocolDecoder.java +++ b/src/org/traccar/protocol/BceProtocolDecoder.java @@ -21,6 +21,8 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -128,10 +130,9 @@ public class BceProtocolDecoder extends BaseProtocolDecoder { } if (BitUtil.check(mask, 14)) { - position.set(Position.KEY_MCC, buf.readUnsignedShort()); - position.set(Position.KEY_MNC, buf.readUnsignedByte()); - position.set(Position.KEY_LAC, buf.readUnsignedShort()); - position.set(Position.KEY_CID, buf.readUnsignedShort()); + position.setNetwork(new Network(CellTower.from( + buf.readUnsignedShort(), buf.readUnsignedByte(), + buf.readUnsignedShort(), buf.readUnsignedShort()))); position.set(Position.KEY_GSM, buf.readUnsignedByte()); buf.readUnsignedByte(); } diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index 790dcd932..07d26f2b1 100644 --- a/src/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/org/traccar/protocol/CastelProtocolDecoder.java @@ -24,6 +24,8 @@ import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.ObdDecoder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -331,8 +333,8 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { decodeStat(position, buf); - position.set(Position.KEY_LAC, buf.readUnsignedShort()); - position.set(Position.KEY_CID, buf.readUnsignedShort()); + position.setNetwork(new Network( + CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort()))); return position; @@ -366,8 +368,8 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // geo-fencing flags buf.readUnsignedByte(); // additional flags - position.set(Position.KEY_LAC, buf.readUnsignedShort()); - position.set(Position.KEY_CID, buf.readUnsignedShort()); + position.setNetwork(new Network( + CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort()))); positions.add(position); } diff --git a/src/org/traccar/protocol/CityeasyProtocolDecoder.java b/src/org/traccar/protocol/CityeasyProtocolDecoder.java index 9f2a0250d..2351232f9 100644 --- a/src/org/traccar/protocol/CityeasyProtocolDecoder.java +++ b/src/org/traccar/protocol/CityeasyProtocolDecoder.java @@ -24,6 +24,8 @@ import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -117,10 +119,8 @@ public class CityeasyProtocolDecoder extends BaseProtocolDecoder { } - position.set(Position.KEY_MCC, parser.nextInt()); - position.set(Position.KEY_MNC, parser.nextInt()); - position.set(Position.KEY_LAC, parser.nextInt()); - position.set(Position.KEY_CID, parser.nextInt()); + position.setNetwork(new Network(CellTower.from( + parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt()))); return position; } diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java index 0bf7d229b..b1634042d 100644 --- a/src/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java @@ -22,6 +22,8 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -108,10 +110,8 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); position.setCourse(buf.readUnsignedShort()); - position.set(Position.KEY_MCC, buf.readUnsignedShort()); - position.set(Position.KEY_MNC, buf.readUnsignedShort()); - position.set(Position.KEY_LAC, buf.readUnsignedShort()); - position.set(Position.KEY_CID, buf.readUnsignedMedium()); + position.setNetwork(new Network(CellTower.from( + buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedMedium()))); position.setValid((buf.readUnsignedByte() & 0x01) != 0); @@ -148,11 +148,9 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { } if (BitUtil.check(flags, 1)) { - position.set(Position.KEY_MCC, buf.readUnsignedShort()); - position.set(Position.KEY_MNC, buf.readUnsignedShort()); - position.set(Position.KEY_LAC, buf.readUnsignedShort()); - position.set(Position.KEY_CID, buf.readUnsignedInt()); - position.set(Position.KEY_GSM, buf.readUnsignedByte()); + position.setNetwork(new Network(CellTower.from( + buf.readUnsignedShort(), buf.readUnsignedShort(), + buf.readUnsignedShort(), buf.readUnsignedInt(), buf.readUnsignedByte()))); } if (BitUtil.check(flags, 2)) { diff --git a/src/org/traccar/protocol/FifotrackProtocolDecoder.java b/src/org/traccar/protocol/FifotrackProtocolDecoder.java index 9243d1894..9ccc34384 100644 --- a/src/org/traccar/protocol/FifotrackProtocolDecoder.java +++ b/src/org/traccar/protocol/FifotrackProtocolDecoder.java @@ -22,6 +22,8 @@ import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -104,10 +106,8 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_OUTPUT, parser.nextInt(16)); } - position.set(Position.KEY_MCC, parser.nextInt()); - position.set(Position.KEY_MNC, parser.nextInt()); - position.set(Position.KEY_LAC, parser.nextInt(16)); - position.set(Position.KEY_CID, parser.nextInt(16)); + position.setNetwork(new Network(CellTower.from( + parser.nextInt(), parser.nextInt(), parser.nextInt(16), parser.nextInt(16)))); String[] adc = parser.next().split("\\|"); for (int i = 0; i < adc.length; i++) { diff --git a/src/org/traccar/protocol/FlextrackProtocolDecoder.java b/src/org/traccar/protocol/FlextrackProtocolDecoder.java index db85acd5d..953fb1207 100644 --- a/src/org/traccar/protocol/FlextrackProtocolDecoder.java +++ b/src/org/traccar/protocol/FlextrackProtocolDecoder.java @@ -22,6 +22,8 @@ import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -123,14 +125,16 @@ public class FlextrackProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_BATTERY, parser.nextInt()); position.set(Position.KEY_GSM, parser.nextInt()); position.set(Position.KEY_STATUS, parser.nextInt(16)); - position.set(Position.KEY_MCC, parser.nextInt()); - position.set(Position.KEY_MNC, parser.nextInt()); + + int mcc = parser.nextInt(); + int mnc = parser.nextInt(); position.setAltitude(parser.nextInt()); position.set(Position.KEY_HDOP, parser.nextInt() * 0.1); - position.set(Position.KEY_CID, parser.nextInt(16)); - position.set(Position.KEY_LAC, parser.nextInt(16)); + + position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextInt(16), parser.nextInt(16)))); + position.set(Position.KEY_ODOMETER, parser.nextInt()); return position; diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index 66a4e2f7e..ff500f8f1 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -24,6 +24,8 @@ import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -392,10 +394,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { } if (parser.hasNext(4)) { - position.set(Position.KEY_MCC, parser.nextInt()); - position.set(Position.KEY_MNC, parser.nextInt()); - position.set(Position.KEY_LAC, parser.nextInt(16)); - position.set(Position.KEY_CID, parser.nextInt(16)); + position.setNetwork(new Network(CellTower.from( + parser.nextInt(), parser.nextInt(), parser.nextInt(16), parser.nextInt(16)))); } parser.skip(4); // alternative networks diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java index a7f1024c6..40a0d4d73 100644 --- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java +++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java @@ -23,6 +23,8 @@ import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -155,10 +157,8 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_HDOP, parser.next()); if (parser.hasNext(4)) { - position.set(Position.KEY_MCC, parser.nextInt()); - position.set(Position.KEY_MNC, parser.nextInt()); - position.set(Position.KEY_LAC, parser.nextInt(16)); - position.set(Position.KEY_CID, parser.nextInt(16)); + position.setNetwork(new Network(CellTower.from( + parser.nextInt(), parser.nextInt(), parser.nextInt(16), parser.nextInt(16)))); } if (parser.hasNext()) { position.set(Position.KEY_ODOMETER, parser.nextInt()); diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index d929ae917..0320f785f 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -21,6 +21,8 @@ import org.traccar.DeviceSession; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -171,8 +173,8 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { getLastLocation(position, null); - position.set(Position.KEY_LAC, parser.nextInt(16)); - position.set(Position.KEY_CID, parser.nextInt(16)); + position.setNetwork(new Network( + CellTower.fromLacCid(parser.nextInt(16), parser.nextInt(16)))); return position; diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 35cb83dac..a8788e686 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -25,6 +25,8 @@ import org.traccar.helper.BitUtil; import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -142,10 +144,8 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { lbsLength = buf.readUnsignedByte(); } - position.set(Position.KEY_MCC, buf.readUnsignedShort()); - position.set(Position.KEY_MNC, buf.readUnsignedByte()); - position.set(Position.KEY_LAC, buf.readUnsignedShort()); - position.set(Position.KEY_CID, buf.readUnsignedMedium()); + position.setNetwork(new Network(CellTower.from( + buf.readUnsignedShort(), buf.readUnsignedByte(), buf.readUnsignedShort(), buf.readUnsignedMedium()))); if (lbsLength > 0) { buf.skipBytes(lbsLength - 9); diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index 2c7852d16..431dd5c3c 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -25,6 +25,8 @@ import org.traccar.helper.BitUtil; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -249,10 +251,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { int lac = parser.nextInt(16); int cid = parser.nextInt(16); if (mcc != 0 && mnc != 0 && lac != 0 && cid != 0) { - position.set(Position.KEY_MCC, mcc); - position.set(Position.KEY_MNC, mnc); - position.set(Position.KEY_LAC, lac); - position.set(Position.KEY_CID, cid); + position.setNetwork(new Network(CellTower.from(mcc, mnc, lac, cid))); } } @@ -278,13 +277,17 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { DateBuilder dateBuilder = new DateBuilder() .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.set(Position.KEY_MCC, parser.nextInt()); - position.set(Position.KEY_MNC, parser.nextInt()); + Network network = new Network(); + int mcc = parser.nextInt(); + int mnc = parser.nextInt(); - String[] cells = parser.next().split(","); // decode all in future - position.set(Position.KEY_LAC, Integer.parseInt(cells[0])); - position.set(Position.KEY_CID, Integer.parseInt(cells[1])); - position.set(Position.KEY_GSM, Integer.parseInt(cells[2])); + String[] cells = parser.next().split(","); + for (int i = 0; i < cells.length / 3; i++) { + network.addCellTower(CellTower.from(mcc, mnc, Integer.parseInt(cells[i * 3]), + Integer.parseInt(cells[i * 3 + 1]), Integer.parseInt(cells[i * 3 + 2]))); + } + + position.setNetwork(network); dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt()); diff --git a/src/org/traccar/protocol/JpKorjarProtocolDecoder.java b/src/org/traccar/protocol/JpKorjarProtocolDecoder.java index debc66673..60aadd025 100644 --- a/src/org/traccar/protocol/JpKorjarProtocolDecoder.java +++ b/src/org/traccar/protocol/JpKorjarProtocolDecoder.java @@ -22,6 +22,8 @@ import org.traccar.DeviceSession; import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
+import org.traccar.model.CellTower;
+import org.traccar.model.Network;
import org.traccar.model.Position;
import java.net.SocketAddress;
@@ -82,10 +84,8 @@ public class JpKorjarProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.nextInt() == 1);
- position.set(Position.KEY_MCC, parser.nextInt());
- position.set(Position.KEY_MNC, parser.nextInt());
- position.set(Position.KEY_LAC, parser.nextInt(16));
- position.set(Position.KEY_CID, parser.nextInt(16));
+ position.setNetwork(new Network(CellTower.from(
+ parser.nextInt(), parser.nextInt(), parser.nextInt(16), parser.nextInt(16))));
return position;
}
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index ad7a00dc2..54f5e43a8 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -25,6 +25,8 @@ import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -108,8 +110,9 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_BATTERY, battery + "%"); } - position.set(Position.KEY_CID, buf.readUnsignedShort()); - position.set(Position.KEY_LAC, buf.readUnsignedShort()); + position.setNetwork(new Network( + CellTower.fromCidLac(buf.readUnsignedShort(), buf.readUnsignedShort()))); + position.set(Position.KEY_GSM, buf.readUnsignedByte()); position.set(Position.KEY_INDEX, buf.readUnsignedByte()); @@ -125,8 +128,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { int cid = buf.readUnsignedShort(); int lac = buf.readUnsignedShort(); if (cid != 0 && lac != 0) { - position.set(Position.KEY_CID, cid); - position.set(Position.KEY_LAC, lac); + position.setNetwork(new Network(CellTower.fromCidLac(cid, lac))); } position.set(Position.KEY_GSM, buf.readUnsignedByte()); @@ -256,8 +258,9 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_SATELLITES, parser.nextInt()); position.set(Position.KEY_BATTERY, parser.next()); position.set(Position.KEY_STATUS, parser.nextInt(2)); - position.set(Position.KEY_CID, parser.nextInt()); - position.set(Position.KEY_LAC, parser.nextInt()); + + position.setNetwork(new Network(CellTower.fromCidLac(parser.nextInt(), parser.nextInt()))); + position.set(Position.KEY_GSM, parser.nextInt()); position.set(Position.KEY_ODOMETER, parser.nextLong() * 1000); position.set(Position.KEY_INDEX, parser.nextInt()); diff --git a/src/org/traccar/protocol/L100ProtocolDecoder.java b/src/org/traccar/protocol/L100ProtocolDecoder.java index 7eed7df9a..bdf4ba29b 100644 --- a/src/org/traccar/protocol/L100ProtocolDecoder.java +++ b/src/org/traccar/protocol/L100ProtocolDecoder.java @@ -22,6 +22,8 @@ import org.traccar.DeviceSession; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -106,11 +108,10 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, parser.nextDouble()); position.set(Position.PREFIX_TEMP + 1, parser.nextDouble()); position.set(Position.KEY_BATTERY, parser.nextDouble()); - position.set(Position.KEY_GSM, parser.nextInt()); - position.set(Position.KEY_MCC, parser.nextInt()); - position.set(Position.KEY_MNC, parser.nextInt()); - position.set(Position.KEY_LAC, parser.nextInt()); - position.set(Position.KEY_CID, parser.nextInt()); + + int rssi = parser.nextInt(); + position.setNetwork(new Network(CellTower.from( + parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt(), rssi))); return position; } diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index 005d38c41..60660adf6 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -21,6 +21,8 @@ import org.traccar.DeviceSession; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -176,10 +178,8 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { } if (parser.hasNext(4)) { - position.set(Position.KEY_MCC, parser.nextInt()); - position.set(Position.KEY_MNC, parser.nextInt()); - position.set(Position.KEY_LAC, parser.nextInt(16)); - position.set(Position.KEY_CID, parser.nextInt(16)); + position.setNetwork(new Network(CellTower.from( + parser.nextInt(), parser.nextInt(), parser.nextInt(16), parser.nextInt(16)))); } } else { @@ -203,11 +203,8 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - position.set(Position.KEY_MCC, parser.nextInt()); - position.set(Position.KEY_MNC, parser.nextInt()); - position.set(Position.KEY_LAC, parser.nextInt(16)); - position.set(Position.KEY_CID, parser.nextInt(16)); - position.set(Position.KEY_GSM, parser.next()); + position.setNetwork(new Network(CellTower.from( + parser.nextInt(), parser.nextInt(), parser.nextInt(16), parser.nextInt(16), parser.nextInt()))); position.set(Position.KEY_BATTERY, Double.parseDouble(parser.next())); @@ -310,11 +307,9 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); } - position.set(Position.KEY_MCC, parser.nextInt()); - position.set(Position.KEY_MNC, parser.nextInt()); - position.set(Position.KEY_LAC, parser.nextInt(16)); - position.set(Position.KEY_CID, parser.nextInt(16)); - position.set(Position.KEY_GSM, parser.nextInt()); + position.setNetwork(new Network(CellTower.from( + parser.nextInt(), parser.nextInt(), parser.nextInt(16), parser.nextInt(16), parser.nextInt()))); + position.set(Position.KEY_INPUT, parser.nextInt(2)); position.set(Position.KEY_OUTPUT, parser.nextInt(2)); diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index 72ccaa037..195b11349 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -24,6 +24,8 @@ import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -124,10 +126,10 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, parser.next()); position.set("runtime", parser.next()); - position.set(Position.KEY_MCC, parser.nextInt()); - position.set(Position.KEY_MNC, parser.nextInt()); - position.set(Position.KEY_LAC, parser.nextInt(16)); - position.set(Position.KEY_CID, parser.nextInt(16)); + + position.setNetwork(new Network( + CellTower.from(parser.nextInt(), parser.nextInt(), parser.nextInt(16), parser.nextInt(16)))); + position.set(Position.KEY_STATUS, parser.next()); for (int i = 1; i <= 3; i++) { @@ -209,10 +211,11 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); position.set("runtime", buf.readUnsignedInt()); - position.set(Position.KEY_MCC, buf.readUnsignedShort()); - position.set(Position.KEY_MNC, buf.readUnsignedShort()); - position.set(Position.KEY_LAC, buf.readUnsignedShort()); - position.set(Position.KEY_CID, buf.readUnsignedShort()); + + position.setNetwork(new Network(CellTower.from( + buf.readUnsignedShort(), buf.readUnsignedShort(), + buf.readUnsignedShort(), buf.readUnsignedShort()))); + position.set(Position.KEY_STATUS, buf.readUnsignedShort()); position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort()); diff --git a/src/org/traccar/protocol/T800xProtocolDecoder.java b/src/org/traccar/protocol/T800xProtocolDecoder.java index 52d711a8d..6430b1344 100644 --- a/src/org/traccar/protocol/T800xProtocolDecoder.java +++ b/src/org/traccar/protocol/T800xProtocolDecoder.java @@ -24,6 +24,8 @@ import org.traccar.helper.BcdUtil; import org.traccar.helper.BitUtil; import org.traccar.helper.DateBuilder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -169,10 +171,9 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder { buf.readBytes(array); ChannelBuffer swapped = ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, array); - position.set(Position.KEY_MCC, swapped.readUnsignedShort()); - position.set(Position.KEY_MNC, swapped.readUnsignedShort()); - position.set(Position.KEY_LAC, swapped.readUnsignedShort()); - position.set(Position.KEY_CID, swapped.readUnsignedShort()); + position.setNetwork(new Network(CellTower.from( + swapped.readUnsignedShort(), swapped.readUnsignedShort(), + swapped.readUnsignedShort(), swapped.readUnsignedShort()))); // two more cell towers diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index 474718ee8..074d89703 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -22,6 +22,8 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -133,12 +135,12 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } if (BitUtil.check(locationMask, 5)) { - position.set(Position.KEY_LAC, buf.readUnsignedShort()); - position.set(Position.KEY_CID, buf.readUnsignedShort()); + position.setNetwork(new Network( + CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort()))); } if (BitUtil.check(locationMask, 6)) { - position.set(Position.KEY_GSM, buf.readUnsignedByte()); + buf.readUnsignedByte(); // rssi } if (BitUtil.check(locationMask, 7)) { diff --git a/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java b/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java index f78f01329..4a97fa1a1 100644 --- a/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java +++ b/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java @@ -21,6 +21,8 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -100,8 +102,8 @@ public class ThinkRaceProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(buf.readUnsignedByte()); position.setCourse(buf.readUnsignedByte()); - position.set(Position.KEY_LAC, buf.readUnsignedShort()); - position.set(Position.KEY_CID, buf.readUnsignedShort()); + position.setNetwork(new Network( + CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort()))); return position; diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index d3bc0efdc..9dc94678e 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -24,6 +24,8 @@ import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -165,10 +167,8 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { getLastLocation(position, null); - position.set(Position.KEY_MCC, parser.nextInt()); - position.set(Position.KEY_MNC, parser.nextInt()); - position.set(Position.KEY_LAC, parser.nextInt(16)); - position.set(Position.KEY_CID, parser.nextInt(16)); + position.setNetwork(new Network(CellTower.from( + parser.nextInt(), parser.nextInt(), parser.nextInt(16), parser.nextInt(16)))); return position; } diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java index 1fe91b942..059eaa529 100644 --- a/src/org/traccar/protocol/TotemProtocolDecoder.java +++ b/src/org/traccar/protocol/TotemProtocolDecoder.java @@ -22,6 +22,8 @@ import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -249,8 +251,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { int lac = parser.nextInt(16); int cid = parser.nextInt(16); if (lac != 0 && cid != 0) { - position.set(Position.KEY_LAC, lac); - position.set(Position.KEY_CID, cid); + position.setNetwork(new Network(CellTower.fromLacCid(lac, cid))); } position.set(Position.PREFIX_TEMP + 1, parser.next()); @@ -272,8 +273,9 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { position.set(Position.PREFIX_ADC + 2, parser.next()); position.set(Position.PREFIX_TEMP + 1, parser.next()); position.set(Position.PREFIX_TEMP + 2, parser.next()); - position.set(Position.KEY_LAC, parser.nextInt(16)); - position.set(Position.KEY_CID, parser.nextInt(16)); + + position.setNetwork(new Network( + CellTower.fromLacCid(parser.nextInt(16), parser.nextInt(16)))); position.setValid(parser.next().equals("A")); position.set(Position.KEY_SATELLITES, parser.next()); @@ -307,8 +309,9 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { position.set(Position.PREFIX_TEMP + 1, parser.next()); position.set(Position.PREFIX_TEMP + 2, parser.next()); - position.set(Position.KEY_LAC, parser.nextInt(16)); - position.set(Position.KEY_CID, parser.nextInt(16)); + position.setNetwork(new Network( + CellTower.fromLacCid(parser.nextInt(16), parser.nextInt(16)))); + position.set(Position.KEY_SATELLITES, parser.nextInt()); position.set(Position.KEY_GSM, parser.nextInt()); diff --git a/src/org/traccar/protocol/TrvProtocolDecoder.java b/src/org/traccar/protocol/TrvProtocolDecoder.java index 0afe065c2..a45f29252 100644 --- a/src/org/traccar/protocol/TrvProtocolDecoder.java +++ b/src/org/traccar/protocol/TrvProtocolDecoder.java @@ -22,6 +22,8 @@ import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -147,10 +149,8 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_IGNITION, acc == 1); } - position.set(Position.KEY_MCC, parser.nextInt()); - position.set(Position.KEY_MNC, parser.nextInt()); - position.set(Position.KEY_LAC, parser.nextInt()); - position.set(Position.KEY_CID, parser.nextInt()); + position.setNetwork(new Network(CellTower.from( + parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt()))); return position; } diff --git a/src/org/traccar/protocol/Tt8850ProtocolDecoder.java b/src/org/traccar/protocol/Tt8850ProtocolDecoder.java index b128068be..040783ba2 100644 --- a/src/org/traccar/protocol/Tt8850ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tt8850ProtocolDecoder.java @@ -22,6 +22,8 @@ import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -90,10 +92,8 @@ public class Tt8850ProtocolDecoder extends BaseProtocolDecoder { position.setTime(dateBuilder.getDate()); if (parser.hasNext(4)) { - position.set(Position.KEY_MCC, parser.nextInt()); - position.set(Position.KEY_MNC, parser.nextInt()); - position.set(Position.KEY_LAC, parser.nextInt(16)); - position.set(Position.KEY_CID, parser.nextInt(16)); + position.setNetwork(new Network( + CellTower.from(parser.nextInt(), parser.nextInt(), parser.nextInt(16), parser.nextInt(16)))); } return position; diff --git a/src/org/traccar/protocol/TzoneProtocolDecoder.java b/src/org/traccar/protocol/TzoneProtocolDecoder.java index 8fd695b80..ecce3798c 100644 --- a/src/org/traccar/protocol/TzoneProtocolDecoder.java +++ b/src/org/traccar/protocol/TzoneProtocolDecoder.java @@ -22,6 +22,8 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; import org.traccar.helper.DateBuilder; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -118,10 +120,8 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { blockEnd = buf.readerIndex() + blockLength; if (blockLength > 0) { - - position.set(Position.KEY_LAC, buf.readUnsignedShort()); - position.set(Position.KEY_CID, buf.readUnsignedShort()); - + position.setNetwork(new Network( + CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort()))); } buf.readerIndex(blockEnd); diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java index d2a58f1b8..c4ddca219 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java @@ -24,6 +24,8 @@ import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; import org.traccar.helper.ObdDecoder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -182,15 +184,15 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { break; case DATA_LBS: - position.set(Position.KEY_MCC, buf.readUnsignedShort()); - position.set(Position.KEY_MNC, buf.readUnsignedShort()); - position.set(Position.KEY_LAC, buf.readUnsignedShort()); if (length == 11) { - position.set(Position.KEY_CID, buf.readUnsignedInt()); + position.setNetwork(new Network(CellTower.from( + buf.readUnsignedShort(), buf.readUnsignedShort(), + buf.readUnsignedShort(), buf.readUnsignedInt(), -buf.readUnsignedByte()))); } else { - position.set(Position.KEY_CID, buf.readUnsignedShort()); + position.setNetwork(new Network(CellTower.from( + buf.readUnsignedShort(), buf.readUnsignedShort(), + buf.readUnsignedShort(), buf.readUnsignedShort(), -buf.readUnsignedByte()))); } - position.set(Position.KEY_GSM, -buf.readUnsignedByte()); if (length > 9 && length != 11) { buf.skipBytes(length - 9); } diff --git a/src/org/traccar/protocol/UproProtocolDecoder.java b/src/org/traccar/protocol/UproProtocolDecoder.java index e47dd8595..37536d1dd 100644 --- a/src/org/traccar/protocol/UproProtocolDecoder.java +++ b/src/org/traccar/protocol/UproProtocolDecoder.java @@ -24,6 +24,8 @@ import org.traccar.helper.BitUtil; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -154,14 +156,11 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, odometer * 2 * 1852 / 3600); break; case 'P': - position.set(Position.KEY_MCC, - Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII))); - position.set(Position.KEY_MNC, - Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII))); - position.set(Position.KEY_LAC, - Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII), 16)); - position.set(Position.KEY_CID, - Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII), 16)); + position.setNetwork(new Network(CellTower.from( + Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII)), + Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII)), + Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII), 16), + Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII), 16)))); break; case 'Q': position.set("obd-pid", ChannelBuffers.hexDump(data)); |