use of org.traccar.model.Network in project traccar by tananaev.
the class GeolocationProviderTest method testLocationProvider.
public void testLocationProvider() throws Exception {
MozillaGeolocationProvider provider = new MozillaGeolocationProvider(null);
Network network = new Network(CellTower.from(208, 1, 2, 1234567));
provider.getLocation(network, new GeolocationProvider.LocationProviderCallback() {
@Override
public void onSuccess(double latitude, double longitude, double accuracy) {
assertEquals(60.07254, latitude, 0.00001);
assertEquals(30.30996, longitude, 0.00001);
}
@Override
public void onFailure(Throwable e) {
fail();
}
});
Thread.sleep(Long.MAX_VALUE);
}
use of org.traccar.model.Network in project traccar by tananaev.
the class Gl200TextProtocolDecoder method decodeLocation.
private void decodeLocation(Position position, Parser parser) {
Integer hdop = parser.nextInt();
position.setValid(hdop == null || hdop > 0);
position.set(Position.KEY_HDOP, hdop);
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
position.setCourse(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
if (parser.hasNext(8)) {
position.setValid(true);
position.setLongitude(parser.nextDouble());
position.setLatitude(parser.nextDouble());
position.setTime(parser.nextDateTime());
} else {
getLastLocation(position, null);
}
if (parser.hasNext(6)) {
int mcc = parser.nextInt();
int mnc = parser.nextInt();
if (parser.hasNext(2)) {
position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextInt(), parser.nextInt())));
}
if (parser.hasNext(2)) {
position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextHexInt(), parser.nextHexInt())));
}
}
if (parser.hasNext()) {
position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
}
}
use of org.traccar.model.Network in project traccar by tananaev.
the class Gl200TextProtocolDecoder method decodeGsm.
private Object decodeGsm(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_GSM, sentence);
Position position = initPosition(parser, channel, remoteAddress);
if (position == null) {
return null;
}
getLastLocation(position, null);
Network network = new Network();
String[] data = parser.next().split(",");
for (int i = 0; i < 6; i++) {
if (!data[i * 6].isEmpty()) {
network.addCellTower(CellTower.from(Integer.parseInt(data[i * 6]), Integer.parseInt(data[i * 6 + 1]), Integer.parseInt(data[i * 6 + 2], 16), Integer.parseInt(data[i * 6 + 3], 16), Integer.parseInt(data[i * 6 + 4])));
}
}
position.setNetwork(network);
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class GoSafeProtocolDecoder method decodePosition.
private Position decodePosition(DeviceSession deviceSession, Parser parser, Date time) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (time != null) {
position.setTime(time);
}
position.set(Position.KEY_EVENT, parser.next());
position.setValid(parser.next().equals("A"));
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
position.setCourse(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
position.set(Position.KEY_HDOP, parser.nextDouble(0));
position.set(Position.KEY_VDOP, parser.nextDouble(0));
if (parser.hasNext(5)) {
position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0), parser.nextInt(0))));
}
if (parser.hasNext()) {
position.set(Position.KEY_ODOMETER, parser.nextInt(0));
}
position.set(Position.KEY_POWER, parser.nextDouble());
position.set(Position.KEY_BATTERY, parser.nextDouble());
if (parser.hasNext(6)) {
position.set(Position.KEY_STATUS, parser.nextHexLong());
Integer io = parser.nextHexInt();
if (io != null) {
position.set(Position.KEY_IGNITION, BitUtil.check(io, 0));
position.set(Position.PREFIX_IN + 1, BitUtil.check(io, 1));
position.set(Position.PREFIX_IN + 2, BitUtil.check(io, 2));
position.set(Position.PREFIX_IN + 3, BitUtil.check(io, 3));
position.set(Position.PREFIX_IN + 4, BitUtil.check(io, 4));
position.set(Position.PREFIX_OUT + 1, BitUtil.check(io, 5));
position.set(Position.PREFIX_OUT + 2, BitUtil.check(io, 6));
position.set(Position.PREFIX_OUT + 3, BitUtil.check(io, 7));
}
position.set(Position.KEY_GEOFENCE, parser.next() + parser.next());
position.set("eventStatus", parser.next());
position.set("packetType", parser.next());
}
if (parser.hasNext()) {
position.set("eventData", parser.next());
}
if (parser.hasNext()) {
position.set("obd", parser.next());
}
if (parser.hasNext()) {
position.set("tagData", parser.next());
}
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class H02ProtocolDecoder method decodeV3.
private Position decodeV3(String sentence, Channel channel, SocketAddress remoteAddress) {
Parser parser = new Parser(PATTERN_V3, sentence);
if (!parser.matches()) {
return null;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
int mcc = parser.nextInt();
int mnc = parser.nextInt();
int count = parser.nextInt();
Network network = new Network();
String[] values = parser.next().split(",");
for (int i = 0; i < count; i++) {
network.addCellTower(CellTower.from(mcc, mnc, Integer.parseInt(values[i * 4]), Integer.parseInt(values[i * 4 + 1])));
}
position.setNetwork(network);
position.set(Position.KEY_BATTERY, parser.nextHexInt());
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
getLastLocation(position, dateBuilder.getDate());
processStatus(position, parser.nextLong(16, 0));
return position;
}
Aggregations