Search in sources :

Example 91 with Position

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

the class Vt200ProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    ChannelBuffer buf = (ChannelBuffer) msg;
    // header
    buf.skipBytes(1);
    String id = ChannelBuffers.hexDump(buf.readBytes(6));
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
    if (deviceSession == null) {
        return null;
    }
    int type = buf.readUnsignedShort();
    // length
    buf.readUnsignedShort();
    if (type == 0x2086 || type == 0x2084 || type == 0x2082) {
        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());
        // data type
        buf.readUnsignedByte();
        // trip id
        buf.readUnsignedShort();
        position.setTime(decodeDate(buf));
        position.setLatitude(decodeCoordinate(BcdUtil.readInteger(buf, 8)));
        position.setLongitude(decodeCoordinate(BcdUtil.readInteger(buf, 9)));
        int flags = buf.readUnsignedByte();
        position.setValid(BitUtil.check(flags, 0));
        if (!BitUtil.check(flags, 1)) {
            position.setLatitude(-position.getLatitude());
        }
        if (!BitUtil.check(flags, 2)) {
            position.setLongitude(-position.getLongitude());
        }
        position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
        position.setCourse(buf.readUnsignedByte() * 2);
        position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
        position.set(Position.KEY_RSSI, buf.readUnsignedByte());
        position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000);
        position.set(Position.KEY_STATUS, buf.readUnsignedInt());
        return position;
    } else if (type == 0x3088) {
        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());
        getLastLocation(position, null);
        // trip id
        buf.readUnsignedShort();
        // imei
        buf.skipBytes(8);
        // imsi
        buf.skipBytes(8);
        position.set("tripStart", decodeDate(buf).getTime());
        position.set("tripEnd", decodeDate(buf).getTime());
        position.set("drivingTime", buf.readUnsignedShort());
        position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt());
        position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt());
        position.set("maxSpeed", UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
        position.set("maxRpm", buf.readUnsignedShort());
        position.set("maxTemp", buf.readUnsignedByte() - 40);
        position.set("hardAccelerationCount", buf.readUnsignedByte());
        position.set("hardBrakingCount", buf.readUnsignedByte());
        for (String speedType : Arrays.asList("over", "high", "normal", "low")) {
            position.set(speedType + "SpeedTime", buf.readUnsignedShort());
            position.set(speedType + "SpeedDistance", buf.readUnsignedInt());
            position.set(speedType + "SpeedFuel", buf.readUnsignedInt());
        }
        position.set("idleTime", buf.readUnsignedShort());
        position.set("idleFuel", buf.readUnsignedInt());
        position.set("hardCorneringCount", buf.readUnsignedByte());
        position.set("overspeedCount", buf.readUnsignedByte());
        position.set("overheatCount", buf.readUnsignedShort());
        position.set("laneChangeCount", buf.readUnsignedByte());
        position.set("emergencyRefueling", buf.readUnsignedByte());
        return position;
    }
    return null;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 92 with Position

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

the class MotionHandlerTest method testCalculateMotion.

@Test
public void testCalculateMotion() throws Exception {
    MotionHandler motionHandler = new MotionHandler(0.01);
    Position position = motionHandler.handlePosition(new Position());
    assertEquals(false, position.getAttributes().get(Position.KEY_MOTION));
}
Also used : Position(org.traccar.model.Position) Test(org.junit.Test)

Example 93 with Position

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

the class AisProtocolDecoder method decodePayload.

private Position decodePayload(Channel channel, SocketAddress remoteAddress, BitBuffer buf) {
    int type = buf.readUnsigned(6);
    if (type == 1 || type == 2 || type == 3 || type == 18) {
        buf.readUnsigned(2);
        int mmsi = buf.readUnsigned(30);
        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(mmsi));
        if (deviceSession == null) {
            return null;
        }
        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());
        position.setTime(new Date());
        if (type == 18) {
            // reserved
            buf.readUnsigned(8);
        } else {
            position.set(Position.KEY_STATUS, buf.readUnsigned(4));
            position.set("turn", buf.readSigned(8));
        }
        position.setSpeed(buf.readUnsigned(10) * 0.1);
        position.setValid(buf.readUnsigned(1) != 0);
        position.setLongitude(buf.readSigned(28) * 0.0001 / 60.0);
        position.setLatitude(buf.readSigned(27) * 0.0001 / 60.0);
        position.setCourse(buf.readUnsigned(12) * 0.1);
        position.set("heading", buf.readUnsigned(9));
        return position;
    }
    return null;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Date(java.util.Date)

Example 94 with Position

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

the class AppelloProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    Parser parser = new Parser(PATTERN, (String) msg);
    if (!parser.matches()) {
        return null;
    }
    String imei = parser.next();
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
    if (deviceSession == null) {
        return null;
    }
    Position position = new Position(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    if (parser.hasNext(6)) {
        position.setTime(parser.nextDateTime());
    } else {
        getLastLocation(position, null);
    }
    position.setLatitude(parser.nextDouble(0));
    position.setLongitude(parser.nextDouble(0));
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));
    position.set(Position.KEY_SATELLITES, parser.nextInt(0));
    position.setAltitude(parser.nextDouble(0));
    position.setValid(parser.next().equals("F"));
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 95 with Position

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

the class AquilaProtocolDecoder method decodeA.

private Position decodeA(Channel channel, SocketAddress remoteAddress, String sentence) {
    Parser parser = new Parser(PATTERN_A, sentence);
    if (!parser.matches()) {
        return null;
    }
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
    if (deviceSession == null) {
        return null;
    }
    Position position = new Position(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    position.set(Position.KEY_EVENT, parser.nextInt(0));
    position.setLatitude(parser.nextDouble(0));
    position.setLongitude(parser.nextDouble(0));
    position.setTime(parser.nextDateTime());
    position.setValid(parser.next().equals("A"));
    if (parser.hasNext(3)) {
        position.set(Position.KEY_RSSI, parser.nextInt(0));
        position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
        position.set(Position.KEY_ODOMETER, parser.nextInt(0));
    }
    if (parser.hasNext(9)) {
        position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
        position.set(Position.PREFIX_IN + 1, parser.next());
        position.set(Position.KEY_CHARGE, parser.next().equals("1"));
        position.set(Position.PREFIX_IN + 2, parser.next());
        position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
        int course = (parser.nextInt(0) << 3) + (parser.nextInt(0) << 2) + (parser.nextInt(0) << 1) + parser.nextInt(0);
        if (course > 0 && course <= 8) {
            position.setCourse((course - 1) * 45);
        }
    } else if (parser.hasNext(7)) {
        position.setCourse(parser.nextInt(0));
        position.set(Position.KEY_CHARGE, parser.next().equals("1"));
        position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
        position.set(Position.KEY_POWER, parser.nextInt(0));
        position.set(Position.KEY_BATTERY, parser.nextInt(0));
        String obd = parser.next();
        position.set("obd", obd.substring(1, obd.length() - 1));
        String dtcs = parser.next();
        position.set(Position.KEY_DTCS, dtcs.substring(1, dtcs.length() - 1).replace('|', ' '));
    } else if (parser.hasNext(10)) {
        position.setCourse(parser.nextInt(0));
        position.set(Position.KEY_SATELLITES, parser.nextInt(0));
        position.set(Position.KEY_HDOP, parser.nextDouble(0));
        position.set(Position.PREFIX_ADC + 1, parser.nextInt(0));
        position.set(Position.PREFIX_IN + 1, parser.nextInt(0));
        position.set(Position.KEY_CHARGE, parser.next().equals("1"));
        position.set(Position.PREFIX_IN + 2, parser.nextInt(0));
        position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
        position.set(Position.KEY_POWER, parser.nextInt(0));
        position.set(Position.KEY_BATTERY, parser.nextInt(0));
    } else if (parser.hasNext(2)) {
        position.set("sensorId", parser.nextInt());
        position.set("sensorData", parser.next());
    }
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Aggregations

Position (org.traccar.model.Position)831 DeviceSession (org.traccar.DeviceSession)505 Parser (org.traccar.helper.Parser)319 DateBuilder (org.traccar.helper.DateBuilder)179 Date (java.util.Date)154 Network (org.traccar.model.Network)143 LinkedList (java.util.LinkedList)112 ByteBuf (io.netty.buffer.ByteBuf)105 Event (org.traccar.model.Event)75 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)69 NetworkMessage (org.traccar.NetworkMessage)67 Test (org.junit.Test)56 WifiAccessPoint (org.traccar.model.WifiAccessPoint)54 BaseTest (org.traccar.BaseTest)40 SimpleDateFormat (java.text.SimpleDateFormat)38 Device (org.traccar.model.Device)29 DateFormat (java.text.DateFormat)27 DeviceState (org.traccar.model.DeviceState)27 List (java.util.List)25 TripsConfig (org.traccar.reports.model.TripsConfig)25