Examples of ExtendedInfoFormatter


Examples of org.traccar.model.ExtendedInfoFormatter

                 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

Examples of org.traccar.model.ExtendedInfoFormatter

            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;
        }
       
        // Alarm type
        extendedInfo.set("alarm", parser.group(index++));
       
        if (format == MessageFormat.first || format == MessageFormat.second) {

            // Time
            Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            time.clear();
            int year = 0;
            if (format == MessageFormat.second) {
                time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++)));
                time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1);
                year = Integer.valueOf(parser.group(index++));
                time.set(Calendar.YEAR, 2000 + year);
            }
            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);

            // 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
            if (format == MessageFormat.first) {
                time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++)));
                time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1);
                year = Integer.valueOf(parser.group(index++));
                time.set(Calendar.YEAR, 2000 + year);
            }
            if (year == 0) {
                return null; // ignore invalid data
            }
            position.setTime(time.getTime());

            // Altitude
            position.setAltitude(0.0);

            // Accuracy
            extendedInfo.set("hdop", parser.group(index++));

            // IO Status
            extendedInfo.set("io", parser.group(index++));

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

            // ADC
            extendedInfo.set("adc", parser.group(index++));

            // Location Code
            extendedInfo.set("lac", parser.group(index++));

            // Temperature
            extendedInfo.set("temperature", parser.group(index++));

            // Milage
            extendedInfo.set("milage", parser.group(index++));
       
        } else if (format == MessageFormat.third) {

            // Time
            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());
           
            // IO Status
            extendedInfo.set("io", parser.group(index++));

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

            // ADC
            extendedInfo.set("adc1", parser.group(index++));
            extendedInfo.set("adc2", parser.group(index++));

            // Temperature
            extendedInfo.set("temperature1", parser.group(index++));
            extendedInfo.set("temperature2", parser.group(index++));

            // Location Code
            extendedInfo.set("lac", parser.group(index++));

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

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

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

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

            // Altitude
            position.setAltitude(0.0);

            // PDOP
            extendedInfo.set("pdop", parser.group(index++));

            // Milage
            extendedInfo.set("milage", parser.group(index++));

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

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

        return position;
    }
View Full Code Here

Examples of org.traccar.model.ExtendedInfoFormatter

           
        } 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

Examples of org.traccar.model.ExtendedInfoFormatter

            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

Examples of org.traccar.model.ExtendedInfoFormatter

   
    private Position decodeBinary(ChannelBuffer buf) {
       
        // Create new position
        Position position = new Position();
        ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
       
        buf.readByte(); // marker

        // Identification
        String id = ChannelBufferTools.readHexString(buf, 10);
        try {
            position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
        } catch(Exception error) {
            Log.warning("Unknown device - " + id);
            return null;
        }
       
        // Time
        Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        time.clear();
        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));
        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));
        position.setTime(time.getTime());
       
        // Location
        double latitude = readCoordinate(buf, false);
        int x = buf.readByte(); // reserved
        double longitude = readCoordinate(buf, true);
        int flags = buf.readUnsignedByte() & 0x0f;
        position.setValid((flags & 0x02) != 0);
        if ((flags & 0x04) == 0) latitude = -latitude;
        if ((flags & 0x08) == 0) longitude = -longitude;
        position.setLatitude(latitude);
        position.setLongitude(longitude);
        position.setAltitude(0.0);

        // Speed and course
        position.setSpeed((double) ChannelBufferTools.readHexInteger(buf, 3));
        position.setCourse((buf.readUnsignedByte() & 0x0f) * 100.0 + ChannelBufferTools.readHexInteger(buf, 2));
       
        // Status
        extendedInfo.set("status", ChannelBufferTools.readHexString(buf, 8));
       
        position.setExtendedInfo(extendedInfo.toString());
        return position;
    }
View Full Code Here

Examples of org.traccar.model.ExtendedInfoFormatter

            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;
        }

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

        // 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());
       
        // Status
        extendedInfo.set("status", parser.group(index++));

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

Examples of org.traccar.model.ExtendedInfoFormatter

            return null;
        }

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

        Integer index = 1;
       
        // Time
        String week = parser.group(index++);
        String day = parser.group(index++);
        int seconds = Integer.valueOf(parser.group(index++));
        if (week != null && day != null) {
            position.setTime(getTime(Integer.valueOf(week), Integer.valueOf(day), seconds));
        } else {
            position.setTime(getTime(seconds));
        }

        // Latitude
        String latitude = parser.group(index) + '.' + parser.group(index + 1);
        index += 2;
        position.setLatitude(Double.valueOf(latitude));

        // Latitude
        String longitude = parser.group(index) + '.' + parser.group(index + 1);
        index += 2;
        position.setLongitude(Double.valueOf(longitude));

        // Altitude
        position.setAltitude(0.0);
       
        // Speed and Course
        position.setSpeed(Double.valueOf(parser.group(index++)) * 0.868976);
        position.setCourse(Double.valueOf(parser.group(index++)));
       
        // Validity
        position.setValid(Integer.valueOf(parser.group(index++)) == 2);

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

Examples of org.traccar.model.ExtendedInfoFormatter

                return null;
            }

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

            Integer index = 1;

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

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

            // Time
            Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            time.clear();
            time.set(Calendar.YEAR, 2000 + Integer.parseInt(parser.group(index++)));
            time.set(Calendar.MONTH, Integer.parseInt(parser.group(index++)) - 1);
            time.set(Calendar.DAY_OF_MONTH, Integer.parseInt(parser.group(index++)));
            time.set(Calendar.HOUR_OF_DAY, Integer.parseInt(parser.group(index++)));
            time.set(Calendar.MINUTE, Integer.parseInt(parser.group(index++)));
            time.set(Calendar.SECOND, Integer.parseInt(parser.group(index++)));
            position.setTime(time.getTime());

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

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

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

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

            // Altitude
            position.setAltitude(0.0);

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

            return position;
        }

        return null;
View Full Code Here

Examples of org.traccar.model.ExtendedInfoFormatter

       
        int count = buf.readUnsignedByte();
       
        for (int i = 0; i < count; i++) {
            Position position = new Position();
            ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
           
            position.setDeviceId(deviceId);
           
            int globalMask = 0x0f;
           
            if (codec == CODEC_GH3000) {

                long time = buf.readUnsignedInt() & 0x3fffffff;
                time += 1167609600; // 2007-01-01 00:00:00
                position.setTime(new Date(time * 1000));
               
                globalMask = buf.readUnsignedByte();
                if (!checkBit(globalMask, 0)) {
                    return null;
                }
               
                int locationMask = buf.readUnsignedByte();
               
                if (checkBit(locationMask, 0)) {
                    position.setLatitude(Double.valueOf(buf.readFloat()));
                    position.setLongitude(Double.valueOf(buf.readFloat()));
                }
               
                if (checkBit(locationMask, 1)) {
                    position.setAltitude((double) buf.readUnsignedShort());
                }
               
                if (checkBit(locationMask, 2)) {
                    position.setCourse(buf.readUnsignedByte() * 360.0 / 256);
                }
               
                if (checkBit(locationMask, 3)) {
                    position.setSpeed(buf.readUnsignedByte() * 0.539957);
                }
               
                if (checkBit(locationMask, 4)) {
                    int satellites = buf.readUnsignedByte();
                    extendedInfo.set("satellites", satellites);
                    position.setValid(satellites >= 3);
                }
               
                if (checkBit(locationMask, 5)) {
                    extendedInfo.set("area", buf.readUnsignedShort());
                    extendedInfo.set("cell", buf.readUnsignedShort());
                }
               
                if (checkBit(locationMask, 6)) {
                    extendedInfo.set("gsm", buf.readUnsignedByte());
                }
               
                if (checkBit(locationMask, 7)) {
                    extendedInfo.set("operator", buf.readUnsignedInt());
                }

            } else {

                position.setTime(new Date(buf.readLong()));

                extendedInfo.set("priority", buf.readUnsignedByte());

                position.setLongitude(buf.readInt() / 10000000.0);
                position.setLatitude(buf.readInt() / 10000000.0);
                position.setAltitude((double) buf.readShort());
                position.setCourse((double) buf.readUnsignedShort());

                int satellites = buf.readUnsignedByte();
                extendedInfo.set("satellites", satellites);

                position.setValid(satellites != 0);

                position.setSpeed(buf.readUnsignedShort() * 0.539957);

                extendedInfo.set("event", buf.readUnsignedByte());

                buf.readUnsignedByte(); // total IO data records

            }
           
            // Read 1 byte data
            if (checkBit(globalMask, 1)) {
                int cnt = buf.readUnsignedByte();
                for (int j = 0; j < cnt; j++) {
                    extendedInfo.set("io" + buf.readUnsignedByte(), buf.readUnsignedByte());
                }
            }

           
            // Read 2 byte data
            if (checkBit(globalMask, 2)) {
                int cnt = buf.readUnsignedByte();
                for (int j = 0; j < cnt; j++) {
                    extendedInfo.set("io" + buf.readUnsignedByte(), buf.readUnsignedShort());
                }
            }

            // Read 4 byte data
            if (checkBit(globalMask, 3)) {
                int cnt = buf.readUnsignedByte();
                for (int j = 0; j < cnt; j++) {
                    extendedInfo.set("io" + buf.readUnsignedByte(), buf.readUnsignedInt());
                }
            }

            // Read 8 byte data
            if (codec == CODEC_FM4X00) {
                int cnt = buf.readUnsignedByte();
                for (int j = 0; j < cnt; j++) {
                    extendedInfo.set("io" + buf.readUnsignedByte(), buf.readLong());
                }
            }
       
            position.setExtendedInfo(extendedInfo.toString());
            positions.add(position);
        }
       
        if (channel != null) {
            ChannelBuffer response = ChannelBuffers.directBuffer(4);
View Full Code Here

Examples of org.traccar.model.ExtendedInfoFormatter

            return null;
        }

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

        // Detect device
        String id = parser.group(index++);
        try {
            position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
        } catch(Exception error) {
            Log.warning("Unknown device - " + id);
            return null;
        }
       
        // Date and 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());
       
        // Location data
        position.setLongitude(Double.valueOf(parser.group(index++)));
        position.setLatitude(Double.valueOf(parser.group(index++)));
        position.setSpeed(Double.valueOf(parser.group(index++)));
        position.setCourse(Double.valueOf(parser.group(index++)));
        position.setAltitude(Double.valueOf(parser.group(index++)));
       
        // Satellites
        int satellites = Integer.valueOf(parser.group(index++));
        position.setValid(satellites >= 3);
        extendedInfo.set("satellites", satellites);
       
        // Report identifier
        extendedInfo.set("index", Long.valueOf(parser.group(index++)));

        // Input
        extendedInfo.set("input", parser.group(index++));

        // Output
        extendedInfo.set("output", parser.group(index++));

        // ADC1
        extendedInfo.set("adc1", parser.group(index++));

        // ADC2
        extendedInfo.set("adc2", parser.group(index++));

        // J1939 data
        extendedInfo.set("vss", parser.group(index++));
        extendedInfo.set("rpm", parser.group(index++));
        extendedInfo.set("coolant", parser.group(index++));
        extendedInfo.set("fuel", parser.group(index++));
        extendedInfo.set("consumption", parser.group(index++));
        extendedInfo.set("temperature", parser.group(index++));
        extendedInfo.set("charger", parser.group(index++));
        extendedInfo.set("tpl", parser.group(index++));
        extendedInfo.set("axle", parser.group(index++));
        extendedInfo.set("milage", parser.group(index++));
       
        position.setExtendedInfo(extendedInfo.toString());
        return position;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.