Package org.traccar.model

Examples of org.traccar.model.Position


            status = sentence.substring(beginIndex);
       
        }

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

        // Parse location data
        if (!parseGPRMC(gprmc, position)) {
            return null;
        }
       
        if (simple) {

            // Parse status
            Matcher parser = patternSimple.matcher(status);
            if (!parser.matches()) {
                return null;
            }
           
            int index = 1;

            // Alarm
            extendedInfo.set("alarm", parser.group(index++));

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

            // Satellites
            extendedInfo.set("satellites", parser.group(index++));

            // Altitude
            String altitude = parser.group(index++);
            if (altitude != null) {
                position.setAltitude(Double.valueOf(altitude));
            } else {
                position.setAltitude(0.0);
            }

            // Battery
            extendedInfo.set("power", Double.valueOf(parser.group(index++)));

            // Charger
            String charger = parser.group(index++);
            if (charger != null) {
                extendedInfo.set("charger", Integer.valueOf(charger) == 1);
            }

            extendedInfo.set("mcc", parser.group(index++));
            extendedInfo.set("mnc", parser.group(index++));
            extendedInfo.set("lac", parser.group(index++));
           
        } else {

            // Parse status
            Matcher parser = patternAlternative.matcher(status);
            if (!parser.matches()) {
                return null;
            }
           
            int index = 1;

            // Altitude
            position.setAltitude(0.0);
           
            try {
                position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
            } catch(Exception error) {
                Log.warning("Unknown device - " + id);
                return null;
            }

            extendedInfo.set("mcc", parser.group(index++));
            extendedInfo.set("mnc", parser.group(index++));
            extendedInfo.set("lac", parser.group(index++));
            extendedInfo.set("gsm", parser.group(index++));

            // Battery
            extendedInfo.set("battery", Double.valueOf(parser.group(index++)));
           
            extendedInfo.set("flags", parser.group(index++));
            extendedInfo.set("input", parser.group(index++));
            extendedInfo.set("output", parser.group(index++));
            extendedInfo.set("adc1", parser.group(index++));
            extendedInfo.set("adc2", parser.group(index++));
            extendedInfo.set("adc3", parser.group(index++));
            extendedInfo.set("alarm", parser.group(index++));
           
        }

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


        super(dataManager, protocol, properties);
    }

    private Position decodeNormalMessage(ChannelBuffer buf) throws Exception {

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

        buf.readByte(); // header

        // Get device by identifier
        String id = Long.valueOf(ChannelBufferTools.readHexString(buf, 10)).toString();
        try {
            position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
        } catch(Exception error) {
            Log.warning("Unknown device - " + id);
            //return null;
        }

        // Protocol and type
        int version = ChannelBufferTools.readHexInteger(buf, 1);
        int type = buf.readUnsignedByte() & 0xf;

        buf.readBytes(2); // length

        // Time
        Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        time.clear();
        time.set(Calendar.DAY_OF_MONTH, ChannelBufferTools.readHexInteger(buf, 2));
        time.set(Calendar.MONTH, ChannelBufferTools.readHexInteger(buf, 2) - 1);
        time.set(Calendar.YEAR, 2000 + ChannelBufferTools.readHexInteger(buf, 2));
        time.set(Calendar.HOUR_OF_DAY, ChannelBufferTools.readHexInteger(buf, 2));
        time.set(Calendar.MINUTE, ChannelBufferTools.readHexInteger(buf, 2));
        time.set(Calendar.SECOND, ChannelBufferTools.readHexInteger(buf, 2));
        position.setTime(time.getTime());

        // Coordinates
        int temp = ChannelBufferTools.readHexInteger(buf, 8);
        double latitude = temp % 1000000;
        latitude /= 60 * 10000;
        latitude += temp / 1000000;
        temp = ChannelBufferTools.readHexInteger(buf, 9);
        double longitude = temp % 1000000;
        longitude /= 60 * 10000;
        longitude += temp / 1000000;

        // Flags
        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);

        // Speed
        position.setSpeed((double) ChannelBufferTools.readHexInteger(buf, 2));

        // Course
        position.setCourse(buf.readUnsignedByte() * 2.0);
       
        if (version == 1) {
           
            extendedInfo.set("satellites", buf.readUnsignedByte());

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

            buf.readByte(); // other flags and sensors

            // Altitude
            position.setAltitude((double) buf.readUnsignedShort());

            extendedInfo.set("cell", buf.readUnsignedShort());
            extendedInfo.set("lac", buf.readUnsignedShort());
            extendedInfo.set("gsm", buf.readUnsignedByte());

        } else if (version == 2) {

            position.setAltitude(0.0);

            int fuel = buf.readUnsignedByte() << 8;

            extendedInfo.set("status", buf.readUnsignedInt());
            extendedInfo.set("milage", buf.readUnsignedInt());

            fuel += buf.readUnsignedByte();
            extendedInfo.set("fuel", fuel);

        }
       
        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());
        extendedInfo.set("alert", "true");
        Integer index = 1;

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

        // 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);

        // 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);

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

        // Time
        Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        time.clear();
        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++)));
        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());

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

        // Course
        position.setCourse(Double.valueOf(parser.group(index++)));
       
        // Altitude
        position.setAltitude(0.0);

        // Power
        extendedInfo.set("power", Double.valueOf(parser.group(index++)));

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

            type == PACKET_ROLLCALL_RESPONSE ||
            type == PACKET_ALARM_DATA ||
            type == PACKET_BLIND_AREA) {
           
            // Create new position
            Position position = new Position();
            ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());

            // Identification
            try {
                position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
            } catch(Exception error) {
                Log.warning("Unknown device - " + id);
            }
           
            // Date and time
            Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            time.clear();
            time.set(Calendar.YEAR, 2000 + ChannelBufferTools.readHexInteger(buf, 2));
            time.set(Calendar.MONTH, ChannelBufferTools.readHexInteger(buf, 2) - 1);
            time.set(Calendar.DAY_OF_MONTH, ChannelBufferTools.readHexInteger(buf, 2));
            time.set(Calendar.HOUR_OF_DAY, ChannelBufferTools.readHexInteger(buf, 2));
            time.set(Calendar.MINUTE, ChannelBufferTools.readHexInteger(buf, 2));
            time.set(Calendar.SECOND, ChannelBufferTools.readHexInteger(buf, 2));
            position.setTime(time.getTime());

            // Location
            position.setLatitude(ChannelBufferTools.readCoordinate(buf));
            position.setLongitude(ChannelBufferTools.readCoordinate(buf));
            position.setSpeed(ChannelBufferTools.readHexInteger(buf, 4) * 0.539957);
            position.setCourse((double) ChannelBufferTools.readHexInteger(buf, 4));
            position.setAltitude(0.0);

            // Flags
            int flags = buf.readUnsignedByte();
            position.setValid((flags & 0x80) != 0);
            extendedInfo.set("satellites", flags & 0x0f);

            // Status
            extendedInfo.set("status", buf.readUnsignedByte());

            // Key switch
            extendedInfo.set("key", buf.readUnsignedByte());

            // Oil
            extendedInfo.set("oil", buf.readUnsignedShort() / 10.0);

            // Power
            extendedInfo.set("power", buf.readUnsignedByte() + buf.readUnsignedByte() / 100.0);

            // Milage
            extendedInfo.set("milage", buf.readUnsignedInt());

            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;

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

        // 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++)) * 10);

        // 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);

        // Altitude
        position.setAltitude(0.0);

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

        // 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());

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

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

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

            // Date
            Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            time.clear();
            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++)));

            // Time
            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
            position.setValid(true);

            // Coordinates
            position.setLatitude(Double.valueOf(parser.group(index++)));
            position.setLongitude(Double.valueOf(parser.group(index++)));

            // Altitude
            position.setAltitude(0.0);

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

            // Course
            position.setCourse(Double.valueOf(parser.group(index++)));
            if (position.getCourse() > 360) {
                position.setCourse(0.0);
            }

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

        return null;
    }
View Full Code Here

        }

        else if (type == MSG_DATA) {

            // Create new position
            Position position = new Position();
            ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
            extendedInfo.set("index", index);

            // Get device id
            try {
                position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
            } catch(Exception error) {
                Log.warning("Unknown device - " + imei);
            }

            // Date and time
            Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            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());

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

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

            // Speed
            position.setSpeed((double) buf.readUnsignedByte());

            // Course
            position.setCourse((double) buf.readUnsignedShort());

            buf.skipBytes(3); // reserved

            // Flags
            long flags = buf.readUnsignedInt();
            position.setValid((flags & 0x1) == 0x1);
            if ((flags & 0x2) == 0) latitude = -latitude;
            if ((flags & 0x4) == 0) longitude = -longitude;

            position.setLatitude(latitude);
            position.setLongitude(longitude);
            position.setAltitude(0.0);

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

        return null;
    }
View Full Code Here

        position.setExtendedInfo(extendedInfo.toString());
        return position;
    }
   
    private Position parsePositionReport(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));
       
        position.setLatitude(buf.readMedium() * 0.00002);
        position.setLongitude(buf.readMedium() * 0.00002);
        position.setAltitude(0.0);
       
        position.setSpeed(buf.readUnsignedByte() * 0.539957);
        position.setCourse(buf.readUnsignedByte() * 2.0);
       
        short flags = buf.readUnsignedByte();
        position.setValid((flags & 0x80) == 0x80 && (flags & 0x40) == 0x40);
       
        buf.readUnsignedByte(); // reserved

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

        position.setExtendedInfo(extendedInfo.toString());
        return position;
    }
   
    private Position parsePositionReport2(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));
       
        position.setLatitude(buf.readInt() * 0.0000001);
        position.setLongitude(buf.readInt() * 0.0000001);
        position.setAltitude(0.0);
       
        buf.readUnsignedByte(); // report trigger

        position.setSpeed(buf.readUnsignedByte() * 0.539957);
        position.setCourse(0.0);
       
        short flags = buf.readUnsignedByte();
        position.setValid((flags & 0x80) == 0x80 && (flags & 0x40) == 0x40);
       
        int x = buf.readUnsignedByte(); // satellites in fix
        buf.readUnsignedInt(); // distance

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

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

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

        buf.readUnsignedByte(); // report trigger
        buf.readUnsignedByte(); // position fix source
        buf.readUnsignedByte(); // GNSS fix quality
        buf.readUnsignedByte(); // GNSS assistance age
       
        long flags = buf.readUnsignedInt();
        position.setValid((flags & 0x0400) == 0x0400);
       
        position.setTime(convertTimestamp(buf.readUnsignedInt()));
       
        position.setLatitude(buf.readInt() * 0.0000001);
        position.setLongitude(buf.readInt() * 0.0000001);
        position.setAltitude((double) buf.readUnsignedShort());
       
        buf.readUnsignedByte(); // satellites in fix
        buf.readUnsignedByte(); // satellites in track
       
        position.setSpeed(buf.readUnsignedShort() * 0.194384);
        position.setCourse(buf.readUnsignedShort() * 0.1);
       
        buf.readUnsignedByte(); // maximum speed
        buf.readUnsignedByte(); // minimum speed
        buf.readUnsignedInt(); // distance

        buf.readUnsignedByte(); // supply voltage 1
        buf.readUnsignedByte(); // supply voltage 2
        extendedInfo.set("battery", buf.readUnsignedShort() * 0.001);

        // TODO: a lot of other stuff

        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.