Search in sources :

Example 1 with Event

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

the class NotificationResource method testMessage.

@POST
@Path("test")
public Response testMessage() throws MessagingException, RecoverablePduException, UnrecoverablePduException, SmppTimeoutException, SmppChannelException, InterruptedException {
    NotificationMail.sendMailSync(getUserId(), new Event("test", 0), null);
    NotificationSms.sendSmsSync(getUserId(), new Event("test", 0), null);
    return Response.noContent().build();
}
Also used : Event(org.traccar.model.Event) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 2 with Event

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

the class CommandResultEventHandler method analyzePosition.

@Override
protected Map<Event, Position> analyzePosition(Position position) {
    Object commandResult = position.getAttributes().get(Position.KEY_RESULT);
    if (commandResult != null) {
        Event event = new Event(Event.TYPE_COMMAND_RESULT, position.getDeviceId(), position.getId());
        event.set(Position.KEY_RESULT, (String) commandResult);
        return Collections.singletonMap(event, position);
    }
    return null;
}
Also used : Event(org.traccar.model.Event)

Example 3 with Event

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

the class FuelDropEventHandler 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)) {
        return null;
    }
    double fuelDropThreshold = Context.getDeviceManager().lookupAttributeDouble(device.getId(), ATTRIBUTE_FUEL_DROP_THRESHOLD, 0, false);
    if (fuelDropThreshold > 0) {
        Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
        if (position.getAttributes().containsKey(Position.KEY_FUEL_LEVEL) && lastPosition != null && lastPosition.getAttributes().containsKey(Position.KEY_FUEL_LEVEL)) {
            double drop = lastPosition.getDouble(Position.KEY_FUEL_LEVEL) - position.getDouble(Position.KEY_FUEL_LEVEL);
            if (drop >= fuelDropThreshold) {
                Event event = new Event(Event.TYPE_DEVICE_FUEL_DROP, position.getDeviceId(), position.getId());
                event.set(ATTRIBUTE_FUEL_DROP_THRESHOLD, fuelDropThreshold);
                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 4 with Event

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

the class IgnitionEventHandler 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;
    }
    Map<Event, Position> result = null;
    if (position.getAttributes().containsKey(Position.KEY_IGNITION)) {
        boolean ignition = position.getBoolean(Position.KEY_IGNITION);
        Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
        if (lastPosition != null && lastPosition.getAttributes().containsKey(Position.KEY_IGNITION)) {
            boolean oldIgnition = lastPosition.getBoolean(Position.KEY_IGNITION);
            if (ignition && !oldIgnition) {
                result = Collections.singletonMap(new Event(Event.TYPE_IGNITION_ON, position.getDeviceId(), position.getId()), position);
            } else if (!ignition && oldIgnition) {
                result = Collections.singletonMap(new Event(Event.TYPE_IGNITION_OFF, position.getDeviceId(), position.getId()), position);
            }
        }
    }
    return result;
}
Also used : Position(org.traccar.model.Position) Device(org.traccar.model.Device) Event(org.traccar.model.Event)

Example 5 with Event

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

the class MotionEventHandler method newEvent.

private Map<Event, Position> newEvent(DeviceState deviceState, boolean newMotion) {
    String eventType = newMotion ? Event.TYPE_DEVICE_MOVING : Event.TYPE_DEVICE_STOPPED;
    Position position = deviceState.getMotionPosition();
    Event event = new Event(eventType, position.getDeviceId(), position.getId());
    deviceState.setMotionState(newMotion);
    deviceState.setMotionPosition(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