Search in sources :

Example 6 with Event

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

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)

Example 7 with Event

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

the class TextMessageEventHandler method handleTextMessage.

public static void handleTextMessage(String phone, String message) {
    Device device = Context.getDeviceManager().getDeviceByPhone(phone);
    if (device != null && Context.getNotificationManager() != null) {
        Event event = new Event(Event.TYPE_TEXT_MESSAGE, device.getId());
        event.set("message", message);
        Context.getNotificationManager().updateEvent(event, null);
    }
}
Also used : Device(org.traccar.model.Device) Event(org.traccar.model.Event)

Example 8 with Event

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

the class EventResource method get.

@Path("{id}")
@GET
public Event get(@PathParam("id") long id) throws SQLException {
    Event event = Context.getDataManager().getObject(Event.class, id);
    Context.getPermissionsManager().checkDevice(getUserId(), event.getDeviceId());
    if (event.getGeofenceId() != 0) {
        Context.getPermissionsManager().checkPermission(Geofence.class, getUserId(), event.getGeofenceId());
    }
    return event;
}
Also used : Event(org.traccar.model.Event) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 9 with Event

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

the class GeofenceEventHandler method analyzePosition.

@Override
protected Map<Event, Position> analyzePosition(Position position) {
    Device device = Context.getIdentityManager().getById(position.getDeviceId());
    if (device == null) {
        return null;
    }
    if (!Context.getIdentityManager().isLatestPosition(position) || !position.getValid()) {
        return null;
    }
    List<Long> currentGeofences = geofenceManager.getCurrentDeviceGeofences(position);
    List<Long> oldGeofences = new ArrayList<>();
    if (device.getGeofenceIds() != null) {
        oldGeofences.addAll(device.getGeofenceIds());
    }
    List<Long> newGeofences = new ArrayList<>(currentGeofences);
    newGeofences.removeAll(oldGeofences);
    oldGeofences.removeAll(currentGeofences);
    device.setGeofenceIds(currentGeofences);
    Map<Event, Position> events = new HashMap<>();
    for (long geofenceId : newGeofences) {
        long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
        Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null;
        if (calendar == null || calendar.checkMoment(position.getFixTime())) {
            Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position.getDeviceId(), position.getId());
            event.setGeofenceId(geofenceId);
            events.put(event, position);
        }
    }
    for (long geofenceId : oldGeofences) {
        long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
        Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null;
        if (calendar == null || calendar.checkMoment(position.getFixTime())) {
            Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position.getDeviceId(), position.getId());
            event.setGeofenceId(geofenceId);
            events.put(event, position);
        }
    }
    return events;
}
Also used : Position(org.traccar.model.Position) HashMap(java.util.HashMap) Device(org.traccar.model.Device) Calendar(org.traccar.model.Calendar) ArrayList(java.util.ArrayList) Event(org.traccar.model.Event)

Example 10 with Event

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

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)

Aggregations

Event (org.traccar.model.Event)31 Position (org.traccar.model.Position)25 Device (org.traccar.model.Device)9 DeviceState (org.traccar.model.DeviceState)9 Test (org.junit.Test)6 BaseTest (org.traccar.BaseTest)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 TripsConfig (org.traccar.reports.model.TripsConfig)3 Date (java.util.Date)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Path (javax.ws.rs.Path)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 SQLException (java.sql.SQLException)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 Timeout (org.jboss.netty.util.Timeout)1 TimerTask (org.jboss.netty.util.TimerTask)1 MotionEventHandler (org.traccar.events.MotionEventHandler)1