Search in sources :

Example 1 with Position

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

the class MainEventHandler method messageReceived.

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
    if (e.getMessage() != null && e.getMessage() instanceof Position) {
        Position position = (Position) e.getMessage();
        try {
            Context.getDeviceManager().updateLatestPosition(position);
        } catch (SQLException error) {
            Log.warning(error);
        }
        String uniqueId = Context.getIdentityManager().getById(position.getDeviceId()).getUniqueId();
        // Log position
        StringBuilder s = new StringBuilder();
        s.append(formatChannel(e.getChannel())).append(" ");
        s.append("id: ").append(uniqueId).append(", ");
        s.append("time: ").append(new SimpleDateFormat(Log.DATE_FORMAT).format(position.getFixTime())).append(", ");
        s.append("lat: ").append(String.format("%.5f", position.getLatitude())).append(", ");
        s.append("lon: ").append(String.format("%.5f", position.getLongitude())).append(", ");
        s.append("speed: ").append(String.format("%.1f", position.getSpeed())).append(", ");
        s.append("course: ").append(String.format("%.1f", position.getCourse()));
        Object cmdResult = position.getAttributes().get(Position.KEY_RESULT);
        if (cmdResult != null) {
            s.append(", result: ").append(cmdResult);
        }
        Log.info(s.toString());
        Context.getStatisticsManager().registerMessageStored(position.getDeviceId());
    }
}
Also used : Position(org.traccar.model.Position) SQLException(java.sql.SQLException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with Position

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

the class PositionResource method getCsv.

@GET
@Produces(TEXT_CSV)
public Response getCsv(@QueryParam("deviceId") long deviceId, @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException {
    Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
    CsvBuilder csv = new CsvBuilder();
    csv.addHeaderLine(new Position());
    csv.addArray(Context.getDataManager().getPositions(deviceId, DateUtil.parseDate(from), DateUtil.parseDate(to)));
    return Response.ok(csv.build()).header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_CSV).build();
}
Also used : Position(org.traccar.model.Position) CsvBuilder(org.traccar.web.CsvBuilder) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with Position

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

the class CommandsManager method getCommandTypes.

public Collection<Typed> getCommandTypes(long deviceId, boolean textChannel) {
    List<Typed> result = new ArrayList<>();
    Position lastPosition = Context.getIdentityManager().getLastPosition(deviceId);
    if (lastPosition != null) {
        BaseProtocol protocol = Context.getServerManager().getProtocol(lastPosition.getProtocol());
        Collection<String> commands;
        commands = textChannel ? protocol.getSupportedTextCommands() : protocol.getSupportedDataCommands();
        for (String commandKey : commands) {
            result.add(new Typed(commandKey));
        }
    } else {
        result.add(new Typed(Command.TYPE_CUSTOM));
    }
    return result;
}
Also used : Typed(org.traccar.model.Typed) Position(org.traccar.model.Position) ArrayList(java.util.ArrayList) BaseProtocol(org.traccar.BaseProtocol)

Example 4 with Position

use of org.traccar.model.Position 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 5 with Position

use of org.traccar.model.Position 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)

Aggregations

Position (org.traccar.model.Position)831 DeviceSession (org.traccar.DeviceSession)505 Parser (org.traccar.helper.Parser)319 DateBuilder (org.traccar.helper.DateBuilder)179 Date (java.util.Date)154 Network (org.traccar.model.Network)143 LinkedList (java.util.LinkedList)112 ByteBuf (io.netty.buffer.ByteBuf)105 Event (org.traccar.model.Event)75 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)69 NetworkMessage (org.traccar.NetworkMessage)67 Test (org.junit.Test)56 WifiAccessPoint (org.traccar.model.WifiAccessPoint)54 BaseTest (org.traccar.BaseTest)40 SimpleDateFormat (java.text.SimpleDateFormat)38 Device (org.traccar.model.Device)29 DateFormat (java.text.DateFormat)27 DeviceState (org.traccar.model.DeviceState)27 List (java.util.List)25 TripsConfig (org.traccar.reports.model.TripsConfig)25