Search in sources :

Example 96 with Position

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

the class MaintenanceEventHandler method analyzePosition.

@Override
protected Map<Event, Position> analyzePosition(Position position) {
    Device device = Context.getIdentityManager().getById(position.getDeviceId());
    if (device == null || !Context.getIdentityManager().isLatestPosition(position)) {
        return null;
    }
    double maintenanceInterval = Context.getDeviceManager().lookupAttributeDouble(device.getId(), ATTRIBUTE_MAINTENANCE_INTERVAL, 0, false);
    if (maintenanceInterval == 0) {
        return null;
    }
    double maintenanceStart = Context.getDeviceManager().lookupAttributeDouble(device.getId(), ATTRIBUTE_MAINTENANCE_START, 0, false);
    double oldTotalDistance = 0.0;
    double newTotalDistance = 0.0;
    Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
    if (lastPosition != null) {
        oldTotalDistance = lastPosition.getDouble(Position.KEY_TOTAL_DISTANCE);
    }
    newTotalDistance = position.getDouble(Position.KEY_TOTAL_DISTANCE);
    oldTotalDistance -= maintenanceStart;
    newTotalDistance -= maintenanceStart;
    if ((long) (oldTotalDistance / maintenanceInterval) < (long) (newTotalDistance / maintenanceInterval)) {
        Event event = new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId());
        event.set(Position.KEY_TOTAL_DISTANCE, newTotalDistance);
        return Collections.singletonMap(event, position);
    }
    return null;
}
Also used : Position(org.traccar.model.Position) Device(org.traccar.model.Device) Event(org.traccar.model.Event)

Example 97 with Position

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

the class OverspeedEventHandler method analyzePosition.

@Override
protected Map<Event, Position> analyzePosition(Position position) {
    long deviceId = position.getDeviceId();
    Device device = Context.getIdentityManager().getById(deviceId);
    if (device == null) {
        return null;
    }
    if (!Context.getIdentityManager().isLatestPosition(position) || !position.getValid()) {
        return null;
    }
    double speedLimit = Context.getDeviceManager().lookupAttributeDouble(deviceId, ATTRIBUTE_SPEED_LIMIT, 0, false);
    if (speedLimit == 0) {
        return null;
    }
    Map<Event, Position> result = null;
    DeviceState deviceState = Context.getDeviceManager().getDeviceState(deviceId);
    if (deviceState.getOverspeedState() == null) {
        deviceState.setOverspeedState(position.getSpeed() > speedLimit);
    } else {
        result = updateOverspeedState(deviceState, position, speedLimit);
    }
    Context.getDeviceManager().setDeviceState(deviceId, deviceState);
    return result;
}
Also used : DeviceState(org.traccar.model.DeviceState) Position(org.traccar.model.Position) Device(org.traccar.model.Device) Event(org.traccar.model.Event)

Example 98 with Position

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

the class OverspeedEventHandler method newEvent.

private Map<Event, Position> newEvent(DeviceState deviceState, double speedLimit) {
    Position position = deviceState.getOverspeedPosition();
    Event event = new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId());
    event.set("speed", deviceState.getOverspeedPosition().getSpeed());
    event.set(ATTRIBUTE_SPEED_LIMIT, speedLimit);
    deviceState.setOverspeedState(notRepeat);
    deviceState.setOverspeedPosition(null);
    return Collections.singletonMap(event, position);
}
Also used : Position(org.traccar.model.Position) Event(org.traccar.model.Event)

Example 99 with Position

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

the class MotionEventHandler method analyzePosition.

@Override
protected Map<Event, Position> analyzePosition(Position position) {
    long deviceId = position.getDeviceId();
    Device device = Context.getIdentityManager().getById(deviceId);
    if (device == null) {
        return null;
    }
    if (!Context.getIdentityManager().isLatestPosition(position) || !tripsConfig.getProcessInvalidPositions() && !position.getValid()) {
        return null;
    }
    Map<Event, Position> result = null;
    DeviceState deviceState = Context.getDeviceManager().getDeviceState(deviceId);
    if (deviceState.getMotionState() == null) {
        deviceState.setMotionState(position.getBoolean(Position.KEY_MOTION));
    } else {
        result = updateMotionState(deviceState, position);
    }
    Context.getDeviceManager().setDeviceState(deviceId, deviceState);
    return result;
}
Also used : DeviceState(org.traccar.model.DeviceState) Position(org.traccar.model.Position) Device(org.traccar.model.Device) Event(org.traccar.model.Event)

Example 100 with Position

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

the class MotionEventHandler method updateMotionState.

public Map<Event, Position> updateMotionState(DeviceState deviceState) {
    Map<Event, Position> result = null;
    if (deviceState.getMotionState() != null && deviceState.getMotionPosition() != null) {
        boolean newMotion = !deviceState.getMotionState();
        Position motionPosition = deviceState.getMotionPosition();
        long currentTime = System.currentTimeMillis();
        long motionTime = motionPosition.getFixTime().getTime() + (newMotion ? tripsConfig.getMinimalTripDuration() : tripsConfig.getMinimalParkingDuration());
        if (motionTime <= currentTime) {
            result = newEvent(deviceState, newMotion);
        }
    }
    return result;
}
Also used : Position(org.traccar.model.Position) Event(org.traccar.model.Event)

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