Search in sources :

Example 51 with Position

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

the class NavigilProtocolDecoder method parseUnitReport.

private Position parseUnitReport(DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber) {
    Position position = new Position(getProtocolName());
    position.setValid(true);
    position.set(Position.KEY_INDEX, sequenceNumber);
    position.setDeviceId(deviceSession.getDeviceId());
    // report trigger
    buf.readUnsignedShort();
    position.set(Position.KEY_FLAGS, buf.readUnsignedShort());
    position.setLatitude(buf.readInt() * 0.0000001);
    position.setLongitude(buf.readInt() * 0.0000001);
    position.setAltitude(buf.readUnsignedShort());
    position.set(Position.KEY_SATELLITES, buf.readUnsignedShort());
    position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedShort());
    position.set("gpsAntennaState", buf.readUnsignedShort());
    position.setSpeed(buf.readUnsignedShort() * 0.194384);
    position.setCourse(buf.readUnsignedShort());
    position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
    position.set(Position.KEY_DISTANCE, buf.readUnsignedInt());
    position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
    position.set(Position.KEY_CHARGE, buf.readUnsignedShort());
    position.setTime(convertTimestamp(buf.readUnsignedInt()));
    return position;
}
Also used : Position(org.traccar.model.Position)

Example 52 with Position

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

the class NavigilProtocolDecoder method parseSnapshot4.

private Position parseSnapshot4(DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber) {
    Position position = new Position(getProtocolName());
    position.set(Position.KEY_INDEX, sequenceNumber);
    position.setDeviceId(deviceSession.getDeviceId());
    // report trigger
    buf.readUnsignedByte();
    // position fix source
    buf.readUnsignedByte();
    // GNSS fix quality
    buf.readUnsignedByte();
    // GNSS assistance age
    buf.readUnsignedByte();
    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(buf.readUnsignedShort());
    position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
    position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte());
    position.setSpeed(buf.readUnsignedShort() * 0.194384);
    position.setCourse(buf.readUnsignedShort() * 0.1);
    position.set("maximumSpeed", buf.readUnsignedByte());
    position.set("minimumSpeed", buf.readUnsignedByte());
    position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
    // supply voltage 1
    position.set(Position.PREFIX_IO + 1, buf.readUnsignedByte());
    // supply voltage 2
    position.set(Position.PREFIX_IO + 2, buf.readUnsignedByte());
    position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
    return position;
}
Also used : Position(org.traccar.model.Position)

Example 53 with Position

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

the class NavigilProtocolDecoder method parseTg2Report.

private Position parseTg2Report(DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber) {
    Position position = new Position(getProtocolName());
    position.setValid(true);
    position.set(Position.KEY_INDEX, sequenceNumber);
    position.setDeviceId(deviceSession.getDeviceId());
    // report trigger
    buf.readUnsignedShort();
    // reserved
    buf.readUnsignedByte();
    // assisted GPS age
    buf.readUnsignedByte();
    position.setTime(convertTimestamp(buf.readUnsignedInt()));
    position.setLatitude(buf.readInt() * 0.0000001);
    position.setLongitude(buf.readInt() * 0.0000001);
    position.setAltitude(buf.readUnsignedShort());
    position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
    position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte());
    position.setSpeed(buf.readUnsignedShort() * 0.194384);
    position.setCourse(buf.readUnsignedShort());
    position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
    position.set("maximumSpeed", buf.readUnsignedShort());
    position.set("minimumSpeed", buf.readUnsignedShort());
    // VSAUT1 voltage
    position.set(Position.PREFIX_IO + 1, buf.readUnsignedShort());
    // VSAUT2 voltage
    position.set(Position.PREFIX_IO + 2, buf.readUnsignedShort());
    // solar voltage
    position.set(Position.PREFIX_IO + 3, buf.readUnsignedShort());
    position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
    return position;
}
Also used : Position(org.traccar.model.Position)

Example 54 with Position

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

the class NavisProtocolDecoder method processArray.

private Object processArray(DeviceSession deviceSession, Channel channel, ChannelBuffer buf) {
    List<Position> positions = new LinkedList<>();
    int count = buf.readUnsignedByte();
    for (int i = 0; i < count; i++) {
        Position position = parsePosition(deviceSession, buf).getPosition();
        if (position.getFixTime() != null) {
            positions.add(position);
        }
    }
    ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 8);
    response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<A", StandardCharsets.US_ASCII));
    response.writeByte(count);
    sendReply(channel, response);
    if (positions.isEmpty()) {
        return null;
    }
    return positions;
}
Also used : Position(org.traccar.model.Position) LinkedList(java.util.LinkedList) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 55 with Position

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

the class ObdDongleProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    ChannelBuffer buf = (ChannelBuffer) msg;
    // header
    buf.skipBytes(2);
    int index = buf.readUnsignedShort();
    String imei = buf.readBytes(15).toString(StandardCharsets.US_ASCII);
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
    if (deviceSession == null) {
        return null;
    }
    int type = buf.readUnsignedByte();
    // data length
    buf.readUnsignedShort();
    if (type == MSG_TYPE_CONNECT) {
        ChannelBuffer response = ChannelBuffers.dynamicBuffer();
        response.writeByte(1);
        response.writeShort(0);
        response.writeInt(0);
        sendResponse(channel, MSG_TYPE_CONNACK, index, imei, response);
    } else if (type == MSG_TYPE_PUBLISH) {
        int typeMajor = buf.readUnsignedByte();
        int typeMinor = buf.readUnsignedByte();
        // event id
        buf.readUnsignedByte();
        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());
        position.setTime(new Date(buf.readUnsignedInt() * 1000));
        int flags = buf.readUnsignedByte();
        position.setValid(!BitUtil.check(flags, 6));
        position.set(Position.KEY_SATELLITES, BitUtil.to(flags, 4));
        double longitude = ((BitUtil.to(buf.readUnsignedShort(), 1) << 24) + buf.readUnsignedMedium()) * 0.00001;
        position.setLongitude(BitUtil.check(flags, 5) ? longitude : -longitude);
        double latitude = buf.readUnsignedMedium() * 0.00001;
        position.setLatitude(BitUtil.check(flags, 4) ? latitude : -latitude);
        int speedCourse = buf.readUnsignedMedium();
        position.setSpeed(UnitsConverter.knotsFromMph(BitUtil.from(speedCourse, 10) * 0.1));
        position.setCourse(BitUtil.to(speedCourse, 10));
        ChannelBuffer response = ChannelBuffers.dynamicBuffer();
        response.writeByte(typeMajor);
        response.writeByte(typeMinor);
        sendResponse(channel, MSG_TYPE_PUBACK, index, imei, response);
        return position;
    }
    return null;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Date(java.util.Date) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

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