Search in sources :

Example 6 with DeviceState

use of org.traccar.model.DeviceState in project traccar by tananaev.

the class MotionEventHandlerTest method testMotionWithStatus.

@Test
public void testMotionWithStatus() throws Exception {
    MotionEventHandler motionEventHandler = new MotionEventHandler(new TripsConfig(500, 300 * 1000, 300 * 1000, 0, false, false, 0.01));
    Position position = new Position();
    position.setTime(new Date(System.currentTimeMillis() - 360000));
    position.set(Position.KEY_MOTION, true);
    DeviceState deviceState = new DeviceState();
    deviceState.setMotionState(false);
    deviceState.setMotionPosition(position);
    Map<Event, Position> events = motionEventHandler.updateMotionState(deviceState);
    assertNotNull(events);
    Event event = events.keySet().iterator().next();
    assertEquals(Event.TYPE_DEVICE_MOVING, event.getType());
    assertTrue(deviceState.getMotionState());
    assertNull(deviceState.getMotionPosition());
}
Also used : DeviceState(org.traccar.model.DeviceState) TripsConfig(org.traccar.reports.model.TripsConfig) Position(org.traccar.model.Position) Event(org.traccar.model.Event) Date(java.util.Date) Test(org.junit.Test) BaseTest(org.traccar.BaseTest)

Example 7 with DeviceState

use of org.traccar.model.DeviceState in project traccar by tananaev.

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 8 with DeviceState

use of org.traccar.model.DeviceState in project traccar by tananaev.

the class ConnectionManager method updateDeviceState.

public Map<Event, Position> updateDeviceState(long deviceId) {
    DeviceState deviceState = Context.getDeviceManager().getDeviceState(deviceId);
    Map<Event, Position> result = new HashMap<>();
    Map<Event, Position> event = Context.getMotionEventHandler().updateMotionState(deviceState);
    if (event != null) {
        result.putAll(event);
    }
    event = Context.getOverspeedEventHandler().updateOverspeedState(deviceState, Context.getDeviceManager().lookupAttributeDouble(deviceId, OverspeedEventHandler.ATTRIBUTE_SPEED_LIMIT, 0, false));
    if (event != null) {
        result.putAll(event);
    }
    return result;
}
Also used : DeviceState(org.traccar.model.DeviceState) Position(org.traccar.model.Position) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Event(org.traccar.model.Event)

Example 9 with DeviceState

use of org.traccar.model.DeviceState in project traccar by tananaev.

the class DeviceManager method getDeviceState.

public DeviceState getDeviceState(long deviceId) {
    DeviceState deviceState = deviceStates.get(deviceId);
    if (deviceState == null) {
        deviceState = new DeviceState();
        deviceStates.put(deviceId, deviceState);
    }
    return deviceState;
}
Also used : DeviceState(org.traccar.model.DeviceState)

Example 10 with DeviceState

use of org.traccar.model.DeviceState in project traccar by tananaev.

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)

Aggregations

DeviceState (org.traccar.model.DeviceState)10 Event (org.traccar.model.Event)9 Position (org.traccar.model.Position)9 Test (org.junit.Test)3 BaseTest (org.traccar.BaseTest)3 TripsConfig (org.traccar.reports.model.TripsConfig)3 Date (java.util.Date)2 Device (org.traccar.model.Device)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 MotionEventHandler (org.traccar.events.MotionEventHandler)1