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());
}
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;
}
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;
}
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;
}
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;
}
Aggregations