Package org.traccar.model

Examples of org.traccar.model.Position


        position.setExtendedInfo(extendedInfo.toString());
        return position;
    }
   
    private Position parseTrackingData(ChannelBuffer buf, long deviceId, int sequenceNumber, long timestamp) {
        Position position = new Position();
        ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());

        extendedInfo.set("index", sequenceNumber);
        position.setDeviceId(deviceId);
        position.setTime(convertTimestamp(timestamp));

        buf.readUnsignedByte(); // tracking mode
       
        short flags = buf.readUnsignedByte();
        position.setValid((flags & 0x01) == 0x01);
       
        buf.readUnsignedShort(); // duration

        position.setLatitude(buf.readInt() * 0.0000001);
        position.setLongitude(buf.readInt() * 0.0000001);
        position.setAltitude(0.0);
       
        position.setSpeed(buf.readUnsignedByte() * 0.539957);
        position.setCourse(buf.readUnsignedByte() * 2.0);

        buf.readUnsignedByte(); // satellites in fix
       
        extendedInfo.set("battery", buf.readUnsignedShort() * 0.001);
       
        buf.readUnsignedInt(); // distance

        position.setExtendedInfo(extendedInfo.toString());
        return position;
    }
View Full Code Here


                int type = buf.readUnsignedByte();
                buf.readUnsignedByte(); // length
               
                if (type == MSG_GPS || type == MSG_GPS_SENSORS) {
                   
                    Position position = new Position();
                    ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
                    position.setDeviceId(deviceId);
                   
                    // Time
                    Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
                    time.clear();
                    time.set(Calendar.DAY_OF_MONTH, buf.readUnsignedByte());
                    time.set(Calendar.MONTH, (buf.getByte(buf.readerIndex()) & 0x0f) - 1);
                    time.set(Calendar.YEAR, 2010 + (buf.readUnsignedByte() >> 4));
                    time.set(Calendar.HOUR_OF_DAY, buf.readUnsignedByte());
                    time.set(Calendar.MINUTE, buf.readUnsignedByte());
                    time.set(Calendar.SECOND, buf.readUnsignedByte());
                    position.setTime(time.getTime());
                   
                    // Latitude
                    double latitude = buf.readUnsignedByte();
                    latitude += buf.readUnsignedByte() / 60.0;
                    latitude += buf.readUnsignedByte() / 6000.0;
                    latitude += buf.readUnsignedByte() / 600000.0;
                   
                    // Longitude
                    double longitude = buf.readUnsignedByte();
                    longitude += buf.readUnsignedByte() / 60.0;
                    longitude += buf.readUnsignedByte() / 6000.0;
                    longitude += buf.readUnsignedByte() / 600000.0;
                   
                    // Hemisphere
                    int flags = buf.readUnsignedByte();
                    if ((flags & 0x01) != 0) latitude = -latitude;
                    if ((flags & 0x02) != 0) longitude = -longitude;
                    position.setLatitude(latitude);
                    position.setLongitude(longitude);
                    position.setAltitude(0.0);
                   
                    // Satellites
                    int satellites = buf.readUnsignedByte();
                    extendedInfo.set("satellites", satellites);
                    position.setValid(satellites >= 3);
                   
                    // Speed
                    position.setSpeed((double) buf.readUnsignedByte());
                   
                    // Course
                    double course = buf.readUnsignedByte() << 1;
                    course += (flags >> 2) & 1;
                    course += buf.readUnsignedByte() / 100.0;
                    position.setCourse(course);

                    // Sensors
                    if (type == MSG_GPS_SENSORS) {

                        // External power
                        double power = buf.readUnsignedByte();
                        power += buf.readUnsignedByte() << 8;
                        extendedInfo.set("power", power / 100);

                        // Battery
                        double battery = buf.readUnsignedByte();
                        battery += buf.readUnsignedByte() << 8;
                        extendedInfo.set("battery", battery / 100);
                       
                        buf.skipBytes(6);
                       
                    }
                   
                    position.setExtendedInfo(extendedInfo.toString());
                    positions.add(position);
                   
                } else if (type == MSG_EVENTS) {
                   
                    buf.skipBytes(13);
View Full Code Here

            commandType == 2 &&
            messageType == 1 &&
            checkBit(mask, 0)) {

            // Create new position
            Position position = new Position();
            ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());

            // Status code
            if (checkBit(mask, 1)) {
                extendedInfo.set("status", buf.readUnsignedInt());
            }

            // Device id
            String id = null;
            if (checkBit(mask, 23)) {
                id = buf.toString(buf.readerIndex(), 8, Charset.defaultCharset()).trim();
                buf.skipBytes(8);
            } else if (checkBit(mask, 2)) {
                id = buf.toString(buf.readerIndex(), 22, Charset.defaultCharset()).trim();
                buf.skipBytes(22);
            } else {
                Log.warning("No device id field");
                return null;
            }
            try {
                position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
            } catch(Exception error) {
                Log.warning("Unknown device - " + id);
                return null;
            }

            // IO data
            if (checkBit(mask, 3)) {
                buf.readUnsignedShort();
            }

            // ADC 1
            if (checkBit(mask, 4)) {
                buf.readUnsignedShort();
            }

            // ADC 2
            if (checkBit(mask, 5)) {
                buf.readUnsignedShort();
            }

            // Function category
            if (checkBit(mask, 7)) {
                buf.readUnsignedByte();
            }

            Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            time.clear();

            // Date
            if (checkBit(mask, 8)) {
                time.set(Calendar.DAY_OF_MONTH, buf.readUnsignedByte());
                time.set(Calendar.MONTH, buf.readUnsignedByte() - 1);
                time.set(Calendar.YEAR, 2000 + buf.readUnsignedByte());
            }

            // GPS status
            if (checkBit(mask, 9)) {
                position.setValid(buf.readUnsignedByte() == 1);
            }

            // Latitude
            if (checkBit(mask, 10)) {
                position.setLatitude(convertCoordinate(buf.readUnsignedInt()));
            }

            // Longitude
            if (checkBit(mask, 11)) {
                position.setLongitude(convertCoordinate(buf.readUnsignedInt()));
            }

            // Speed
            if (checkBit(mask, 12)) {
                position.setSpeed(buf.readUnsignedShort() / 10.0);
            }

            // Course
            if (checkBit(mask, 13)) {
                position.setCourse(buf.readUnsignedShort() / 10.0);
            }

            // Time
            if (checkBit(mask, 14)) {
                time.set(Calendar.HOUR_OF_DAY, buf.readUnsignedByte());
                time.set(Calendar.MINUTE, buf.readUnsignedByte());
                time.set(Calendar.SECOND, buf.readUnsignedByte());
            }

            position.setTime(time.getTime());

            // Altitude
            if (checkBit(mask, 15)) {
                position.setAltitude((double) buf.readMedium());
            }

            // Satellites
            if (checkBit(mask, 16)) {
                extendedInfo.set("satellites", buf.readUnsignedByte());
            }

            // Battery percentage
            if (checkBit(mask, 17)) {
                buf.readUnsignedShort();
            }

            // Trip milage
            if (checkBit(mask, 20)) {
                extendedInfo.set("trip", buf.readUnsignedInt());
            }

            // Milage
            if (checkBit(mask, 21)) {
                extendedInfo.set("milage", buf.readUnsignedInt());
            }

            // Time of message generation
            if (checkBit(mask, 22)) {
                buf.skipBytes(6);
            }

            // Battery level
            if (checkBit(mask, 24)) {
                extendedInfo.set("power", buf.readUnsignedShort() / 1000.0);
            }

            // GPS overspeed
            if (checkBit(mask, 25)) {
                buf.skipBytes(18);
            }

            // Cell information
            if (checkBit(mask, 26)) {
                buf.skipBytes(54);
            }

            // Sequence number
            if (checkBit(mask, 28)) {
                extendedInfo.set("index", buf.readUnsignedShort());
            }

            // Extended info
            position.setExtendedInfo(extendedInfo.toString());

            return position;
        }

        return null;
View Full Code Here

        else if (type == MSG_UPLOAD_POSITION ||
                 type == MSG_CONTROL_RESPONSE ||
                 type == MSG_ALARM) {
           
            // Create new position
            Position position = new Position();
            ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
           
            if (type == MSG_CONTROL_RESPONSE) {
                buf.readUnsignedInt(); // GIS ip
                buf.readUnsignedInt(); // GIS port
            }

            // Flags
            int flags = buf.readUnsignedByte();
            position.setValid((flags & 0x01) != 0);

            // Alarm type
            extendedInfo.set("alarm", buf.readUnsignedByte());

            // Location
            position.setSpeed((double) buf.readUnsignedByte());
            position.setCourse((double) buf.readUnsignedShort());
            position.setLongitude((double) buf.readFloat());
            position.setLatitude((double) buf.readFloat());
            position.setAltitude(0.0);

            // Time
            long timeValue = buf.readUnsignedInt();
            Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            time.clear();
            time.set(Calendar.YEAR, 2000 + (int) (timeValue >> 26));
            time.set(Calendar.MONTH, (int) (timeValue >> 22 & 0x0f) - 1);
            time.set(Calendar.DAY_OF_MONTH, (int) (timeValue >> 17 & 0x1f));
            time.set(Calendar.HOUR_OF_DAY, (int) (timeValue >> 12 & 0x1f));
            time.set(Calendar.MINUTE, (int) (timeValue >> 6 & 0x3f));
            time.set(Calendar.SECOND, (int) (timeValue & 0x3f));
            position.setTime(time.getTime());

            // Identification
            ChannelBuffer rawId = buf.readBytes(11);
            int index = 0;
            while (rawId.readable() && rawId.readByte() != 0) {
                index += 1;
            }
            String id = rawId.toString(0, index, Charset.defaultCharset());
            try {
                position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
            } catch(Exception error) {
                Log.warning("Unknown device - " + id);
                return null;
            }
           
            // IO status
            extendedInfo.set("io", buf.readUnsignedByte());
           
            // Fuel
            extendedInfo.set("fuel", buf.readUnsignedByte());
           
            position.setExtendedInfo(extendedInfo.toString());
            return position;
        }

        return null;
    }
View Full Code Here

            }
           
        } else if (deviceId != null) {
           
            // Create new position
            Position position = new Position();
            ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
            position.setDeviceId(deviceId);

            // Date and time
            Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            time.clear();
            time.set(Calendar.DAY_OF_MONTH, buf.readUnsignedByte() & 0x3f);
            time.set(Calendar.MONTH, (buf.readUnsignedByte() & 0x3f) - 1);
            time.set(Calendar.YEAR, 2000 + buf.readUnsignedByte());
            time.set(Calendar.HOUR_OF_DAY, buf.readUnsignedByte() & 0x3f);
            time.set(Calendar.MINUTE, buf.readUnsignedByte() & 0x7f);
            time.set(Calendar.SECOND, buf.readUnsignedByte() & 0x7f);
            position.setTime(time.getTime());
           
            // Location
            int degrees = buf.readUnsignedByte();
            double latitude = buf.readUnsignedByte();
            latitude += buf.readUnsignedByte() / 100.0;
            latitude += buf.readUnsignedByte() / 10000.0;
            latitude /= 60;
            latitude += degrees;

            int b = buf.readUnsignedByte();

            degrees = (b & 0x7f) * 100 + buf.readUnsignedByte();
            double longitude = buf.readUnsignedByte();
            longitude += buf.readUnsignedByte() / 100.0;
            longitude += buf.readUnsignedByte() / 10000.0;
            longitude /= 60;
            longitude += degrees;
           
            if ((b & 0x80) != 0) {
                longitude = -longitude;
            }
            if ((b & 0x40) != 0) {
                latitude = -latitude;
            }
           
            position.setLatitude(latitude);
            position.setLongitude(longitude);
            position.setSpeed((double) buf.readUnsignedByte());
            position.setCourse(0.0);
            position.setAltitude(0.0);

            // Satellites
            int satellites = buf.readUnsignedByte();
            if (satellites == 0) {
                return null; // cell information
            }
            extendedInfo.set("satellites", satellites);
            position.setValid(true);

            // TODO decode everything else

            position.setExtendedInfo(extendedInfo.toString());
            return position;

        }

        return null;
View Full Code Here

        if (!parser.matches()) {
            return null;
        }

        // Create new position
        Position position = new Position();
        ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());

        Integer index = 1;

        // Identifier
        String imei = parser.group(index++);
        try {
            position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
        } catch(Exception error) {
            Log.warning("Unknown device - " + imei);
        }       
       
        // Time
        Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        time.clear();
        time.set(Calendar.HOUR_OF_DAY, Integer.valueOf(parser.group(index++)));
        time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++)));
        time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++)));

        // Validity
        position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);

        // Latitude
        Double latitude = Double.valueOf(parser.group(index++));
        latitude += Double.valueOf(parser.group(index++)) / 60;
        if (parser.group(index++).compareTo("S") == 0) latitude = -latitude;
        position.setLatitude(latitude);

        // Longitude
        Double longitude = Double.valueOf(parser.group(index++));
        longitude += Double.valueOf(parser.group(index++)) / 60;
        if (parser.group(index++).compareTo("W") == 0) longitude = -longitude;
        position.setLongitude(longitude);

        // Speed
        String speed = parser.group(index++);
        if (speed != null) {
            position.setSpeed(Double.valueOf(speed));
        } else {
            position.setSpeed(0.0);
        }

        // Course
        String course = parser.group(index++);
        if (course != null) {
            position.setCourse(Double.valueOf(course));
        } else {
            position.setCourse(0.0);
        }

        // Date
        time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++)));
        time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1);
        time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++)));
        position.setTime(time.getTime());

        // Altitude
        position.setAltitude(0.0);

        position.setExtendedInfo(extendedInfo.toString());
        return position;
    }
View Full Code Here

            ChannelHandlerContext ctx, Channel channel, Object msg)
            throws Exception {
       
        if (geocoder != null) {
            if (msg instanceof Position) {
                Position position = (Position) msg;
               
                if (processInvalidPositions || position.getValid()) {
                    position.setAddress(geocoder.getAddress(
                            position.getLatitude(), position.getLongitude()));
                }
            } else if (msg instanceof List) {
                List<Position> positions = (List<Position>) msg;
                for (Position position : positions) {
                    if (processInvalidPositions || position.getValid()) {
                        position.setAddress(geocoder.getAddress(
                                position.getLatitude(), position.getLongitude()));
                    }
                }
            }
        }
View Full Code Here

    }

    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
        Long id = null;
        Position lastPostition = null;
        if (e.getMessage() instanceof Position) {
            id = processSinglePosition((Position) e.getMessage());
            lastPostition = (Position) e.getMessage();
        } else if (e.getMessage() instanceof List) {
            List<Position> positions = (List<Position>) e.getMessage();
View Full Code Here

                (position.getLongitude() == 0.0);
    }
   
    private boolean filterDuplicate(Position position) {
        if (filterDuplicate) {
            Position last = lastPositions.get(position.getDeviceId());
            if (last != null) {
                return position.getTime().equals(last.getTime());
            } else {
                return false;
            }
        } else {
            return false;
View Full Code Here

        }
    }
   
    private boolean filterDistance(Position position) {
        if (filterDistance != 0) {
            Position last = lastPositions.get(position.getDeviceId());
            if (last != null) {
                double distance = DistanceCalculator.distance(
                        position.getLatitude(), position.getLongitude(),
                        last.getLatitude(), last.getLongitude());
                return distance < filterDistance;
            } else {
                return false;
            }
        } else {
View Full Code Here

TOP

Related Classes of org.traccar.model.Position

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.