use of org.traccar.model.Device in project traccar by tananaev.
the class DeviceManager method updateDeviceStatus.
public void updateDeviceStatus(Device device) throws SQLException {
getDataManager().updateDeviceStatus(device);
Device cachedDevice = getById(device.getId());
if (cachedDevice != null) {
cachedDevice.setStatus(device.getStatus());
}
}
use of org.traccar.model.Device in project traccar by tananaev.
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;
}
use of org.traccar.model.Device 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