Package org.traccar.model

Examples of org.traccar.model.Position


        List<Position> positions = new LinkedList<Position>();
       
        for (String message : messages) {
            parser = patternPosition.matcher(message);
            if (parser.matches()) {
                Position position = new Position();
                ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
                position.setDeviceId(deviceId);

                Integer index = 1;
               
                // Cell
                extendedInfo.set("cell", parser.group(index++));

                // 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++)));
                index += 1; // Skip milliseconds

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

                // 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);
               
                // Status
                extendedInfo.set("status", status);
               
                position.setExtendedInfo(extendedInfo.toString());
                positions.add(position);
            }
        }

        return positions;
View Full Code Here


                 type == MSG_GPS_LBS_STATUS_2 ||
                 type == MSG_GPS_PHONE ||
                 type == MSG_GPS_LBS_EXTEND)) {

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

            // Date and time
            Calendar time = Calendar.getInstance(timeZone);
            time.clear();
            time.set(Calendar.YEAR, 2000 + buf.readUnsignedByte());
            time.set(Calendar.MONTH, buf.readUnsignedByte() - 1);
            time.set(Calendar.DAY_OF_MONTH, buf.readUnsignedByte());
            time.set(Calendar.HOUR_OF_DAY, buf.readUnsignedByte());
            time.set(Calendar.MINUTE, buf.readUnsignedByte());
            time.set(Calendar.SECOND, buf.readUnsignedByte());
            position.setTime(time.getTime());

            // GPS length and Satellites count
            int gpsLength = buf.readUnsignedByte();
            extendedInfo.set("satellites", gpsLength & 0xf);
            gpsLength >>= 4;

            // Latitude
            double latitude = buf.readUnsignedInt() / (60.0 * 30000.0);

            // Longitude
            double longitude = buf.readUnsignedInt() / (60.0 * 30000.0);

            // Speed
            position.setSpeed(buf.readUnsignedByte() * 0.539957);

            // Course and flags
            int union = buf.readUnsignedShort();
            position.setCourse((double) (union & 0x03FF));
            position.setValid((union & 0x1000) != 0);
            if ((union & 0x0400) == 0) latitude = -latitude;
            if ((union & 0x0800) != 0) longitude = -longitude;

            position.setLatitude(latitude);
            position.setLongitude(longitude);
            position.setAltitude(0.0);
           
            if ((union & 0x4000) != 0) {
                extendedInfo.set("acc", (union & 0x8000) != 0);
            }

            buf.skipBytes(gpsLength - 12); // skip reserved

            if (type == MSG_GPS_LBS_1 || type == MSG_GPS_LBS_2 ||
                type == MSG_GPS_LBS_STATUS_1 || type == MSG_GPS_LBS_STATUS_2) {

                int lbsLength = 0;
                if (type == MSG_GPS_LBS_STATUS_1 || type == MSG_GPS_LBS_STATUS_2) {
                    lbsLength = buf.readUnsignedByte();
                }

                // Cell information
                extendedInfo.set("mcc", buf.readUnsignedShort());
                extendedInfo.set("mnc", buf.readUnsignedByte());
                extendedInfo.set("lac", buf.readUnsignedShort());
                extendedInfo.set("cell", buf.readUnsignedShort() << 8 + buf.readUnsignedByte());
                buf.skipBytes(lbsLength - 9);

                // Status
                if (type == MSG_GPS_LBS_STATUS_1 || type == MSG_GPS_LBS_STATUS_2) {
                    extendedInfo.set("alarm", true);
                   
                    int flags = buf.readUnsignedByte();
                    extendedInfo.set("acc", (flags & 0x2) != 0);
                    // TODO parse other flags

                    // Voltage
                    extendedInfo.set("power", buf.readUnsignedByte());

                    // GSM signal
                    extendedInfo.set("gsm", buf.readUnsignedByte());
                }
            }

            // Index
            if (buf.readableBytes() > 6) {
                buf.skipBytes(buf.readableBytes() - 6);
            }
            int index = buf.readUnsignedShort();
            extendedInfo.set("index", index);
            sendResponse(channel, type, index);

            position.setExtendedInfo(extendedInfo.toString());
            return position;
        }
       
        else {
            buf.skipBytes(dataLength);
View Full Code Here

        FloatReader longitudeReader = new FloatReader();
        TimeReader timeReader = new TimeReader();
       
        try {
            while (buf.readable()) {
                Position position = new Position();
                position.setDeviceId(deviceId);
                ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());

                short flags = buf.readUnsignedByte();

                // Skip events
                short event = buf.readUnsignedByte();
                if (checkBit(event, 7)) {
                    if (checkBit(event, 6)) {
                        buf.skipBytes(8);
                    } else {
                        while (checkBit(event, 7)) {
                            event = buf.readUnsignedByte();
                        }
                    }
                }

                position.setLatitude(latitudeReader.readFloat(buf) / Math.PI * 180);
                position.setLongitude(longitudeReader.readFloat(buf) / Math.PI * 180);
                position.setTime(timeReader.readTime(buf));

                if (checkBit(flags, 0)) {
                    buf.readUnsignedByte(); // status
                }

                if (checkBit(flags, 1)) {
                    position.setAltitude((double) buf.readUnsignedShort());
                }

                if (checkBit(flags, 2)) {
                    position.setSpeed((double) (buf.readUnsignedShort() & 0x03ff));
                    position.setCourse((double) buf.readUnsignedByte());
                }

                if (checkBit(flags, 3)) {
                    extendedInfo.set("milage", buf.readUnsignedShort());
                }

                if (checkBit(flags, 4)) {
                    extendedInfo.set("fuel1", buf.readUnsignedInt());
                    extendedInfo.set("fuel2", buf.readUnsignedInt());
                    extendedInfo.set("hours1", buf.readUnsignedShort());
                    extendedInfo.set("hours2", buf.readUnsignedShort());
                }

                if (checkBit(flags, 5)) {
                    extendedInfo.set("adc1", buf.readUnsignedShort() & 0x03ff);
                    extendedInfo.set("adc2", buf.readUnsignedShort() & 0x03ff);
                    extendedInfo.set("adc3", buf.readUnsignedShort() & 0x03ff);
                    extendedInfo.set("adc4", buf.readUnsignedShort() & 0x03ff);
                }

                if (checkBit(flags, 6)) {
                    extendedInfo.set("temperature", buf.readByte());
                    buf.getUnsignedByte(buf.readerIndex()); // control (>> 4)
                    extendedInfo.set("sensor", buf.readUnsignedShort() & 0x0fff);
                    buf.readUnsignedShort(); // old sensor state (& 0x0fff)
                }

                if (checkBit(flags, 7)) {
                    extendedInfo.set("battery", buf.getUnsignedByte(buf.readerIndex()) >> 2);
                    extendedInfo.set("power", buf.readUnsignedShort() & 0x03ff);
                    buf.readByte(); // microcontroller temperature

                    extendedInfo.set("gsm", (buf.getUnsignedByte(buf.readerIndex()) >> 4) & 0x07);

                    int satellites = buf.readUnsignedByte() & 0x0f;
                    position.setValid(satellites >= 3);
                    extendedInfo.set("satellites", satellites);
                }

                position.setExtendedInfo(extendedInfo.toString());
                positions.add(position);
            }
        } catch (IndexOutOfBoundsException error) {
        }
       
View Full Code Here

       
        return positions;
    }

    private Position parseFormatA1(ChannelBuffer buf, long deviceId) {
        Position position = new Position();
        position.setDeviceId(deviceId);
        ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());

        short flags = buf.readUnsignedByte();

        // Skip events
        short event = buf.readUnsignedByte();
        if (checkBit(event, 7)) {
            if (checkBit(event, 6)) {
                buf.skipBytes(8);
            } else {
                while (checkBit(event, 7)) {
                    event = buf.readUnsignedByte();
                }
            }
        }

        position.setLatitude(new FloatReader().readFloat(buf) / Math.PI * 180);
        position.setLongitude(new FloatReader().readFloat(buf) / Math.PI * 180);
        position.setTime(new TimeReader().readTime(buf));

        buf.readUnsignedByte(); // status

        if (checkBit(flags, 0)) {
            position.setAltitude((double) buf.readUnsignedShort());
            position.setSpeed((double) buf.readUnsignedByte());
            position.setCourse((double) buf.readByte());
            extendedInfo.set("milage", new FloatReader().readFloat(buf));
        }

        if (checkBit(flags, 1)) {
            new FloatReader().readFloat(buf); // fuel consumtion
            extendedInfo.set("hours", new FloatReader().readFloat(buf));
            extendedInfo.set("tank", buf.readUnsignedByte() * 0.4);
        }

        if (checkBit(flags, 2)) {
            extendedInfo.set("engine", buf.readUnsignedShort() * 0.125);
            extendedInfo.set("pedals", buf.readUnsignedByte());
            extendedInfo.set("temperature", buf.readUnsignedByte() - 40);
            buf.readUnsignedShort(); // service milage
        }

        if (checkBit(flags, 3)) {
            extendedInfo.set("fuel", buf.readUnsignedShort());
            extendedInfo.set("adc2", buf.readUnsignedShort());
            extendedInfo.set("adc3", buf.readUnsignedShort());
            extendedInfo.set("adc4", buf.readUnsignedShort());
        }

        if (checkBit(flags, 4)) {
            extendedInfo.set("temperature", buf.readByte());
            buf.getUnsignedByte(buf.readerIndex()); // control (>> 4)
            extendedInfo.set("sensor", buf.readUnsignedShort() & 0x0fff);
            buf.readUnsignedShort(); // old sensor state (& 0x0fff)
        }

        if (checkBit(flags, 5)) {
            extendedInfo.set("battery", buf.getUnsignedByte(buf.readerIndex()) >> 2);
            extendedInfo.set("power", buf.readUnsignedShort() & 0x03ff);
            buf.readByte(); // microcontroller temperature

            extendedInfo.set("gsm", buf.getUnsignedByte(buf.readerIndex()) >> 5);

            int satellites = buf.readUnsignedByte() & 0x1f;
            position.setValid(satellites >= 3);
            extendedInfo.set("satellites", satellites);
        }
       
        // TODO: process other data

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

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

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

        // Get device by unique identifier
        String id = parser.group(index++);
        try {
            position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
        } catch(Exception error) {
            Log.warning("Unknown device - " + id);
            return null;
        }

        // Command
        extendedInfo.set("command", parser.group(index++));

        // 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++)));
        time.set(Calendar.MILLISECOND, Integer.valueOf(parser.group(index++)));
       
        // Validity
        position.setValid(parser.group(index++).compareTo("A") == 0);

        // 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);
       
        // State
        extendedInfo.set("io", parser.group(index++));
        /* Start : Added By Rohit Singhal, Decode Milage Data*/
        // Prepare Mile Meter Data
        String milage = parser.group(index++);
        milage = milage.replace(":", "A");
        milage = milage.replace(";", "B");
        milage = milage.replace("<", "C");
        milage = milage.replace("=", "D");
        milage = milage.replace(">", "E");
        milage = milage.replace("?", "F");
        extendedInfo.set("milage", Integer.parseInt(milage, 16));
        /* Commented By Rohit extendedInfo.set("milage", parser.group(index++)); */
        /*End : Added By Rohit Singhal, Decode Milage Data*/
        extendedInfo.set("alarm", parser.group(index++));
        extendedInfo.set("ad", parser.group(index++));

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

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

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

        // Identification
        String imei = parser.group(index++);
        try {
            position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
        } catch(Exception error) {
            Log.warning("Unknown device - " + imei);
            return null;
        }
       
        // Validity
        position.setValid(true);

        // Time
        Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        time.clear();
        time.set(Calendar.YEAR, Integer.valueOf(parser.group(index++)));
        time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1);
        time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++)));
        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++)));
        position.setTime(time.getTime());

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

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

        // Speed
        position.setSpeed(Double.valueOf(parser.group(index++)));

        // Course
        position.setCourse(0.0);

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

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

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

        Integer index = 1;

        // Get device by IMEI
        String imei = parser.group(index++);
        try {
            position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
        } catch(Exception error) {
            Log.warning("Unknown device - " + imei);
            return null;
        }

        // Firmware version
        extendedInfo.set("version", parser.group(index++));
       
        // Date
        Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        time.clear();
        time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++)));
        time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1);
        time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++)));
        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++)));
        position.setTime(time.getTime());

        // Validity
        int flags = Integer.valueOf(parser.group(index++));
        position.setValid((flags & 0x1) != 0);

        // Latitude
        Double latitude = Double.valueOf(parser.group(index++));
        latitude += Double.valueOf(parser.group(index++)) / 60000;
        if ((flags & 0x2) == 0) latitude = -latitude;
        position.setLatitude(latitude);

        // Longitude
        Double longitude = Double.valueOf(parser.group(index++));
        longitude += Double.valueOf(parser.group(index++)) / 60000;
        if ((flags & 0x4) == 0) longitude = -longitude;
        position.setLongitude(longitude);

        // Speed
        position.setSpeed(Double.valueOf(parser.group(index++)) / 10);

        // Course
        position.setCourse(Double.valueOf(parser.group(index++)) / 10);

        // Altitude
        position.setAltitude(0.0);
       
        // Additional data
        extendedInfo.set("status", parser.group(index++));
        extendedInfo.set("gprs", parser.group(index++));
        extendedInfo.set("gps", parser.group(index++));
        extendedInfo.set("input", parser.group(index++));
        extendedInfo.set("output", parser.group(index++));
        extendedInfo.set("battery", Double.valueOf(parser.group(index++)) / 10);

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

        return position;
    }
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.