Search in sources :

Example 16 with CellTower

use of org.traccar.model.CellTower in project traccar by traccar.

the class OpenCellIdGeolocationProvider method getLocation.

@Override
public void getLocation(Network network, final LocationProviderCallback callback) {
    if (network.getCellTowers() != null && !network.getCellTowers().isEmpty()) {
        CellTower cellTower = network.getCellTowers().iterator().next();
        String request = String.format(url, cellTower.getMobileCountryCode(), cellTower.getMobileNetworkCode(), cellTower.getLocationAreaCode(), cellTower.getCellId());
        Context.getAsyncHttpClient().prepareGet(request).execute(new AsyncCompletionHandler() {

            @Override
            public Object onCompleted(Response response) throws Exception {
                try (JsonReader reader = Json.createReader(response.getResponseBodyAsStream())) {
                    JsonObject json = reader.readObject();
                    if (json.containsKey("lat") && json.containsKey("lon")) {
                        callback.onSuccess(json.getJsonNumber("lat").doubleValue(), json.getJsonNumber("lon").doubleValue(), 0);
                    } else {
                        callback.onFailure(new GeolocationException("Coordinates are missing"));
                    }
                }
                return null;
            }

            @Override
            public void onThrowable(Throwable t) {
                callback.onFailure(t);
            }
        });
    } else {
        callback.onFailure(new GeolocationException("No network information"));
    }
}
Also used : Response(com.ning.http.client.Response) AsyncCompletionHandler(com.ning.http.client.AsyncCompletionHandler) CellTower(org.traccar.model.CellTower) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) JsonObject(javax.json.JsonObject)

Example 17 with CellTower

use of org.traccar.model.CellTower in project traccar by traccar.

the class AtrackProtocolDecoder method readCustomData.

private void readCustomData(Position position, ChannelBuffer buf, String form) {
    CellTower cellTower = new CellTower();
    String[] keys = form.substring(1).split("%");
    for (String key : keys) {
        switch(key) {
            case "SA":
                position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
                break;
            case "MV":
                position.set(Position.KEY_POWER, buf.readUnsignedShort());
                break;
            case "BV":
                position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
                break;
            case "GQ":
                cellTower.setSignalStrength((int) buf.readUnsignedByte());
                break;
            case "CE":
                cellTower.setCellId(buf.readUnsignedInt());
                break;
            case "LC":
                cellTower.setLocationAreaCode(buf.readUnsignedShort());
                break;
            case "CN":
                // cccnn
                int combinedMobileCodes = (int) (buf.readUnsignedInt() % 100000);
                cellTower.setMobileCountryCode(combinedMobileCodes / 100);
                cellTower.setMobileNetworkCode(combinedMobileCodes % 100);
                break;
            case "RL":
                // rxlev
                buf.readUnsignedByte();
                break;
            case "PC":
                position.set(Position.PREFIX_COUNT + 1, buf.readUnsignedInt());
                break;
            case "AT":
                position.setAltitude(buf.readUnsignedInt());
                break;
            case "RP":
                position.set(Position.KEY_RPM, buf.readUnsignedShort());
                break;
            case "GS":
                position.set(Position.KEY_RSSI, buf.readUnsignedByte());
                break;
            case "DT":
                position.set(Position.KEY_ARCHIVE, buf.readUnsignedByte() == 1);
                break;
            case "VN":
                position.set(Position.KEY_VIN, readString(buf));
                break;
            case "MF":
                // mass air flow rate
                buf.readUnsignedShort();
                break;
            case "EL":
                // engine load
                buf.readUnsignedByte();
                break;
            case "TR":
                position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
                break;
            case "ET":
                position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShort());
                break;
            case "FL":
                position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
                break;
            case "ML":
                // mil status
                buf.readUnsignedByte();
                break;
            case "FC":
                position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt());
                break;
            case "CI":
                // format string
                readString(buf);
                break;
            case "AV1":
                position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
                break;
            case "NC":
                // gsm neighbor cell info
                readString(buf);
                break;
            case "SM":
                // max speed between reports
                buf.readUnsignedShort();
                break;
            case "GL":
                // google link
                readString(buf);
                break;
            case "MA":
                // mac address
                readString(buf);
                break;
            default:
                break;
        }
    }
    if (cellTower.getMobileCountryCode() != null && cellTower.getMobileNetworkCode() != null && cellTower.getCellId() != null && cellTower.getLocationAreaCode() != null) {
        position.setNetwork(new Network(cellTower));
    } else if (cellTower.getSignalStrength() != null) {
        position.set(Position.KEY_RSSI, cellTower.getSignalStrength());
    }
}
Also used : CellTower(org.traccar.model.CellTower) Network(org.traccar.model.Network)

Example 18 with CellTower

use of org.traccar.model.CellTower in project traccar by traccar.

the class Jt600ProtocolDecoder method decodeBinary.

private List<Position> decodeBinary(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
    List<Position> positions = new LinkedList<>();
    // header
    buf.readByte();
    boolean longFormat = buf.getUnsignedByte(buf.readerIndex()) == 0x75;
    String id = String.valueOf(Long.parseLong(ChannelBuffers.hexDump(buf.readBytes(5))));
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
    if (deviceSession == null) {
        return null;
    }
    int protocolVersion = 0;
    if (longFormat) {
        protocolVersion = buf.readUnsignedByte();
    }
    int version = BitUtil.from(buf.readUnsignedByte(), 4);
    // length
    buf.readUnsignedShort();
    while (buf.readableBytes() > 1) {
        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());
        DateBuilder dateBuilder = new DateBuilder().setDay(BcdUtil.readInteger(buf, 2)).setMonth(BcdUtil.readInteger(buf, 2)).setYear(BcdUtil.readInteger(buf, 2)).setHour(BcdUtil.readInteger(buf, 2)).setMinute(BcdUtil.readInteger(buf, 2)).setSecond(BcdUtil.readInteger(buf, 2));
        position.setTime(dateBuilder.getDate());
        double latitude = convertCoordinate(BcdUtil.readInteger(buf, 8));
        double longitude = convertCoordinate(BcdUtil.readInteger(buf, 9));
        byte flags = buf.readByte();
        position.setValid((flags & 0x1) == 0x1);
        if ((flags & 0x2) == 0) {
            latitude = -latitude;
        }
        position.setLatitude(latitude);
        if ((flags & 0x4) == 0) {
            longitude = -longitude;
        }
        position.setLongitude(longitude);
        position.setSpeed(BcdUtil.readInteger(buf, 2));
        position.setCourse(buf.readUnsignedByte() * 2.0);
        if (longFormat) {
            position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000);
            position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
            // vehicle id combined
            buf.readUnsignedInt();
            position.set(Position.KEY_STATUS, buf.readUnsignedShort());
            int battery = buf.readUnsignedByte();
            if (battery == 0xff) {
                position.set(Position.KEY_CHARGE, true);
            } else {
                position.set(Position.KEY_BATTERY_LEVEL, battery);
            }
            CellTower cellTower = CellTower.fromCidLac(buf.readUnsignedShort(), buf.readUnsignedShort());
            cellTower.setSignalStrength((int) buf.readUnsignedByte());
            position.setNetwork(new Network(cellTower));
            if (protocolVersion == 0x17) {
                // geofence id
                buf.readUnsignedByte();
                // reserved
                buf.skipBytes(3);
            }
        } else if (version == 1) {
            position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
            position.set(Position.KEY_POWER, buf.readUnsignedByte());
            // other flags and sensors
            buf.readByte();
            position.setAltitude(buf.readUnsignedShort());
            int cid = buf.readUnsignedShort();
            int lac = buf.readUnsignedShort();
            int rssi = buf.readUnsignedByte();
            if (cid != 0 && lac != 0) {
                CellTower cellTower = CellTower.fromCidLac(cid, lac);
                cellTower.setSignalStrength(rssi);
                position.setNetwork(new Network(cellTower));
            } else {
                position.set(Position.KEY_RSSI, rssi);
            }
        } else if (version == 2) {
            int fuel = buf.readUnsignedByte() << 8;
            position.set(Position.KEY_STATUS, buf.readUnsignedInt());
            position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000);
            fuel += buf.readUnsignedByte();
            position.set(Position.KEY_FUEL_LEVEL, fuel);
        } else if (version == 3) {
            BitBuffer bitBuffer = new BitBuffer(buf);
            position.set("fuel1", bitBuffer.readUnsigned(12));
            position.set("fuel2", bitBuffer.readUnsigned(12));
            position.set("fuel3", bitBuffer.readUnsigned(12));
            position.set(Position.KEY_ODOMETER, bitBuffer.readUnsigned(20) * 1000);
            int status = bitBuffer.readUnsigned(24);
            position.set(Position.KEY_IGNITION, BitUtil.check(status, 0));
            position.set(Position.KEY_STATUS, status);
        }
        positions.add(position);
    }
    // index
    buf.readUnsignedByte();
    return positions;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) CellTower(org.traccar.model.CellTower) LinkedList(java.util.LinkedList) Network(org.traccar.model.Network) BitBuffer(org.traccar.helper.BitBuffer)

Example 19 with CellTower

use of org.traccar.model.CellTower in project traccar by traccar.

the class TeltonikaProtocolDecoder method decodeNetwork.

private void decodeNetwork(Position position) {
    long cid = position.getLong(Position.PREFIX_IO + 205);
    int lac = position.getInteger(Position.PREFIX_IO + 206);
    if (cid != 0 && lac != 0) {
        CellTower cellTower = CellTower.fromLacCid(lac, cid);
        long operator = position.getInteger(Position.KEY_OPERATOR);
        if (operator != 0) {
            cellTower.setOperator(operator);
        }
        position.setNetwork(new Network(cellTower));
    }
}
Also used : CellTower(org.traccar.model.CellTower) Network(org.traccar.model.Network)

Example 20 with CellTower

use of org.traccar.model.CellTower in project traccar by traccar.

the class TotemProtocolDecoder method decode4.

private boolean decode4(Position position, Parser parser) {
    long status = parser.nextHexLong();
    position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 1) ? Position.ALARM_SOS : null);
    position.set(Position.KEY_IGNITION, BitUtil.check(status, 32 - 2));
    position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 3) ? Position.ALARM_OVERSPEED : null);
    position.set(Position.KEY_CHARGE, BitUtil.check(status, 32 - 4));
    position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 5) ? Position.ALARM_GEOFENCE_EXIT : null);
    position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 6) ? Position.ALARM_GEOFENCE_ENTER : null);
    position.set(Position.PREFIX_OUT + 1, BitUtil.check(status, 32 - 9));
    position.set(Position.PREFIX_OUT + 2, BitUtil.check(status, 32 - 10));
    position.set(Position.PREFIX_OUT + 3, BitUtil.check(status, 32 - 11));
    position.set(Position.PREFIX_OUT + 4, BitUtil.check(status, 32 - 12));
    position.set(Position.PREFIX_IN + 2, BitUtil.check(status, 32 - 13));
    position.set(Position.PREFIX_IN + 3, BitUtil.check(status, 32 - 14));
    position.set(Position.PREFIX_IN + 4, BitUtil.check(status, 32 - 15));
    position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 16) ? Position.ALARM_SHOCK : null);
    position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 18) ? Position.ALARM_LOW_BATTERY : null);
    position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 22) ? Position.ALARM_JAMMING : null);
    position.setValid(BitUtil.check(status, 32 - 20));
    position.setTime(parser.nextDateTime());
    position.set(Position.KEY_BATTERY, parser.nextDouble(0) * 0.1);
    position.set(Position.KEY_POWER, parser.nextDouble(0));
    position.set(Position.PREFIX_ADC + 1, parser.next());
    position.set(Position.PREFIX_ADC + 2, parser.next());
    position.set(Position.PREFIX_ADC + 3, parser.next());
    position.set(Position.PREFIX_ADC + 4, parser.next());
    position.set(Position.PREFIX_TEMP + 1, parser.next());
    position.set(Position.PREFIX_TEMP + 2, parser.next());
    CellTower cellTower = CellTower.fromLacCid(parser.nextHexInt(0), parser.nextHexInt(0));
    position.set(Position.KEY_SATELLITES, parser.nextInt(0));
    cellTower.setSignalStrength(parser.nextInt(0));
    position.setNetwork(new Network(cellTower));
    position.setCourse(parser.nextDouble(0));
    position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
    position.set(Position.KEY_HDOP, parser.nextDouble(0));
    position.set(Position.KEY_ODOMETER, parser.nextInt(0) * 1000);
    position.setLatitude(parser.nextCoordinate());
    position.setLongitude(parser.nextCoordinate());
    return true;
}
Also used : CellTower(org.traccar.model.CellTower) Network(org.traccar.model.Network)

Aggregations

CellTower (org.traccar.model.CellTower)29 Network (org.traccar.model.Network)25 Position (org.traccar.model.Position)16 DeviceSession (org.traccar.DeviceSession)10 Date (java.util.Date)7 DateBuilder (org.traccar.helper.DateBuilder)6 Parser (org.traccar.helper.Parser)4 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 LinkedList (java.util.LinkedList)3 JsonObject (javax.json.JsonObject)3 NetworkMessage (org.traccar.NetworkMessage)3 BitBuffer (org.traccar.helper.BitBuffer)3 AsyncCompletionHandler (com.ning.http.client.AsyncCompletionHandler)1 Response (com.ning.http.client.Response)1 ByteBuf (io.netty.buffer.ByteBuf)1 StringReader (java.io.StringReader)1 JsonReader (javax.json.JsonReader)1 WifiAccessPoint (org.traccar.model.WifiAccessPoint)1