diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/BasePipelineFactory.java | 13 | ||||
-rw-r--r-- | src/org/traccar/events/AlertEventHandler.java | 46 | ||||
-rw-r--r-- | src/org/traccar/model/Event.java | 5 | ||||
-rw-r--r-- | src/org/traccar/model/Position.java | 1 | ||||
-rw-r--r-- | src/org/traccar/protocol/H02ProtocolDecoder.java | 12 |
5 files changed, 66 insertions, 11 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 44f1b0657..eb08c7e08 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -29,10 +29,7 @@ import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.handler.logging.LoggingHandler; import org.jboss.netty.handler.timeout.IdleStateHandler; -import org.traccar.events.CommandResultEventHandler; -import org.traccar.events.GeofenceEventHandler; -import org.traccar.events.MotionEventHandler; -import org.traccar.events.OverspeedEventHandler; +import org.traccar.events.*; import org.traccar.helper.Log; import java.net.InetSocketAddress; @@ -52,6 +49,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { private OverspeedEventHandler overspeedEventHandler; private MotionEventHandler motionEventHandler; private GeofenceEventHandler geofenceEventHandler; + private AlertEventHandler alertEventHandler; private static final class OpenChannelHandler extends SimpleChannelHandler { @@ -146,6 +144,9 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { if (Context.getConfig().getBoolean("event.geofenceHandler")) { geofenceEventHandler = new GeofenceEventHandler(); } + if (Context.getConfig().getBoolean("event.alertHandler")) { + alertEventHandler = new AlertEventHandler(); + } } protected abstract void addSpecificHandlers(ChannelPipeline pipeline); @@ -207,6 +208,10 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { pipeline.addLast("GeofenceEventHandler", geofenceEventHandler); } + if (alertEventHandler != null) { + pipeline.addLast("AlertEventHandler", alertEventHandler); + } + pipeline.addLast("mainHandler", new MainEventHandler()); return pipeline; } diff --git a/src/org/traccar/events/AlertEventHandler.java b/src/org/traccar/events/AlertEventHandler.java new file mode 100644 index 000000000..92d1566a7 --- /dev/null +++ b/src/org/traccar/events/AlertEventHandler.java @@ -0,0 +1,46 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.events; + +import java.util.ArrayList; +import java.util.Collection; + +import org.traccar.BaseEventHandler; +import org.traccar.model.Event; +import org.traccar.model.Position; + +public class AlertEventHandler extends BaseEventHandler { + + @Override + protected Collection<Event> analyzePosition(Position position) { + Object alarm = position.getAttributes().get(Position.KEY_ALARM); + if (alarm != null) { + Collection<Event> events = new ArrayList<>(); + if(alarm.equals(Event.TYPE_SOS_ALARM)){ + events.add(new Event(Event.TYPE_SOS_ALARM, position.getDeviceId(), position.getId())); + } else if(alarm.equals(Event.TYPE_VIBRATION_ALARM)){ + events.add(new Event(Event.TYPE_VIBRATION_ALARM, position.getDeviceId(), position.getId())); + } else if(alarm.equals(Event.TYPE_MOVEMENT_ALARM)){ + events.add(new Event(Event.TYPE_MOVEMENT_ALARM, position.getDeviceId(), position.getId())); + } else if(alarm.equals(Event.TYPE_OVERSPEED_ALARM)){ + events.add(new Event(Event.TYPE_OVERSPEED_ALARM, position.getDeviceId(), position.getId())); + } + return events; + } + return null; + } + +} diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java index 235a39f9a..3a0056bd6 100644 --- a/src/org/traccar/model/Event.java +++ b/src/org/traccar/model/Event.java @@ -48,6 +48,11 @@ public class Event extends Message { public static final String TYPE_GEOFENCE_ENTER = "geofenceEnter"; public static final String TYPE_GEOFENCE_EXIT = "geofenceExit"; + public static final String TYPE_SOS_ALARM = "sosAlarm"; + public static final String TYPE_VIBRATION_ALARM = "vibrationAlarm"; + public static final String TYPE_MOVEMENT_ALARM = "movementAlarm"; + public static final String TYPE_OVERSPEED_ALARM = "overspeedAlarm"; + private Date serverTime; public Date getServerTime() { diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index c5a7889bd..4e03b2097 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -28,7 +28,6 @@ public class Position extends Message { public static final String KEY_GPS = "gps"; public static final String KEY_EVENT = "event"; public static final String KEY_ALARM = "alarm"; - public static final String KEY_ALARM_TYPE = "alarm-type"; public static final String KEY_STATUS = "status"; public static final String KEY_ODOMETER = "odometer"; public static final String KEY_HOURS = "hours"; diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index ffe16e975..09375958e 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -24,6 +24,7 @@ import org.traccar.helper.BitUtil; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; +import org.traccar.model.Event; import org.traccar.model.Position; import java.net.SocketAddress; @@ -65,18 +66,17 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { private void processStatus(Position position, long status) { if (!BitUtil.check(status, 0) || !BitUtil.check(status, 1) || !BitUtil.check(status, 3) || !BitUtil.check(status, 4) || !BitUtil.check(status, 7)) { - position.set(Position.KEY_ALARM, true); if (!BitUtil.check(status, 0)){ - position.set(Position.KEY_ALARM_TYPE, "theft"); + position.set(Position.KEY_ALARM, Event.TYPE_VIBRATION_ALARM);//theft alarm } else if (!BitUtil.check(status, 1)){ - position.set(Position.KEY_ALARM_TYPE, "robbery"); + position.set(Position.KEY_ALARM, "robbery"); } else if (!BitUtil.check(status, 3)){ - position.set(Position.KEY_ALARM_TYPE, "illegal ignition"); + position.set(Position.KEY_ALARM, "illegal ignition"); } else if (!BitUtil.check(status, 4)){ - position.set(Position.KEY_ALARM_TYPE, "entering"); + position.set(Position.KEY_ALARM, "entering"); } else if (!BitUtil.check(status, 7)){ - position.set(Position.KEY_ALARM_TYPE, "out"); + position.set(Position.KEY_ALARM, "out"); } } |