Search in sources :

Example 56 with DeviceSession

use of org.traccar.DeviceSession in project traccar by tananaev.

the class Gl100ProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    String sentence = (String) msg;
    if (sentence.contains("AT+GTHBD=") && channel != null) {
        String response = "+RESP:GTHBD,GPRS ACTIVE,";
        response += sentence.substring(9, sentence.lastIndexOf(','));
        response += '\0';
        // heartbeat response
        channel.write(response);
    }
    Parser parser = new Parser(PATTERN, sentence);
    if (!parser.matches()) {
        return null;
    }
    Position position = new Position(getProtocolName());
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
    if (deviceSession == null) {
        return null;
    }
    position.setDeviceId(deviceSession.getDeviceId());
    position.setValid(parser.nextInt(0) == 0);
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));
    position.setAltitude(parser.nextDouble(0));
    position.setLongitude(parser.nextDouble(0));
    position.setLatitude(parser.nextDouble(0));
    position.setTime(parser.nextDateTime());
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 57 with DeviceSession

use of org.traccar.DeviceSession in project traccar by tananaev.

the class Gl200TextProtocolDecoder method decodeFri.

private Object decodeFri(Channel channel, SocketAddress remoteAddress, String sentence) {
    Parser parser = new Parser(PATTERN_FRI, sentence);
    if (!parser.matches()) {
        return null;
    }
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
    if (deviceSession == null) {
        return null;
    }
    LinkedList<Position> positions = new LinkedList<>();
    String vin = parser.next();
    Integer power = parser.nextInt();
    Parser itemParser = new Parser(PATTERN_LOCATION, parser.next());
    while (itemParser.find()) {
        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());
        position.set(Position.KEY_VIN, vin);
        decodeLocation(position, itemParser);
        positions.add(position);
    }
    Position position = positions.getLast();
    decodeLocation(position, parser);
    if (power != null && power > 10) {
        // only on some devices
        position.set(Position.KEY_POWER, power * 0.001);
    }
    if (parser.hasNext()) {
        position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
    }
    position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
    if (parser.hasNext()) {
        position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
    }
    position.set(Position.KEY_HOURS, parser.next());
    position.set(Position.PREFIX_ADC + 1, parser.next());
    position.set(Position.PREFIX_ADC + 2, parser.next());
    position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
    decodeStatus(position, parser);
    position.set(Position.KEY_RPM, parser.nextInt());
    position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
    decodeDeviceTime(position, parser);
    if (ignoreFixTime) {
        positions.clear();
        positions.add(position);
    }
    return positions;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) LinkedList(java.util.LinkedList) Parser(org.traccar.helper.Parser)

Example 58 with DeviceSession

use of org.traccar.DeviceSession in project traccar by tananaev.

the class Gl200TextProtocolDecoder method decodeCan.

private Object decodeCan(Channel channel, SocketAddress remoteAddress, String sentence) throws ParseException {
    Position position = new Position(getProtocolName());
    int index = 0;
    String[] values = sentence.split(",");
    // header
    index += 1;
    // protocol version
    index += 1;
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[index++]);
    position.setDeviceId(deviceSession.getDeviceId());
    // device name
    index += 1;
    // report type
    index += 1;
    // canbus state
    index += 1;
    long reportMask = Long.parseLong(values[index++], 16);
    if (BitUtil.check(reportMask, 0)) {
        position.set(Position.KEY_VIN, values[index++]);
    }
    if (BitUtil.check(reportMask, 1)) {
        position.set(Position.KEY_IGNITION, Integer.parseInt(values[index++]) > 0);
    }
    if (BitUtil.check(reportMask, 2)) {
        position.set("totalVehicleDistance", values[index++]);
    }
    if (BitUtil.check(reportMask, 3)) {
        position.set("totalFuelConsumption", Double.parseDouble(values[index++]));
    }
    if (BitUtil.check(reportMask, 5) && !values[index++].isEmpty()) {
        position.set(Position.KEY_RPM, Integer.parseInt(values[index - 1]));
    }
    if (BitUtil.check(reportMask, 4) && !values[index++].isEmpty()) {
        position.set(Position.KEY_OBD_SPEED, UnitsConverter.knotsFromKph(Integer.parseInt(values[index - 1])));
    }
    if (BitUtil.check(reportMask, 6) && !values[index++].isEmpty()) {
        position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(values[index - 1]));
    }
    if (BitUtil.check(reportMask, 7) && !values[index++].isEmpty()) {
        position.set(Position.KEY_FUEL_CONSUMPTION, Double.parseDouble(values[index - 1].substring(1)));
    }
    if (BitUtil.check(reportMask, 8) && !values[index++].isEmpty()) {
        position.set(Position.KEY_FUEL_LEVEL, Double.parseDouble(values[index - 1].substring(1)));
    }
    if (BitUtil.check(reportMask, 9) && !values[index++].isEmpty()) {
        position.set("range", Long.parseLong(values[index - 1]) * 100);
    }
    if (BitUtil.check(reportMask, 10) && !values[index++].isEmpty()) {
        position.set(Position.KEY_THROTTLE, Integer.parseInt(values[index - 1]));
    }
    if (BitUtil.check(reportMask, 11)) {
        position.set(Position.KEY_HOURS, Double.parseDouble(values[index++]));
    }
    if (BitUtil.check(reportMask, 12)) {
        position.set("drivingHours", Double.parseDouble(values[index++]));
    }
    if (BitUtil.check(reportMask, 13)) {
        position.set("idleHours", Double.parseDouble(values[index++]));
    }
    if (BitUtil.check(reportMask, 14) && !values[index++].isEmpty()) {
        position.set("idleFuelConsumption", Double.parseDouble(values[index - 1]));
    }
    if (BitUtil.check(reportMask, 15) && !values[index++].isEmpty()) {
        position.set(Position.KEY_AXLE_WEIGHT, Integer.parseInt(values[index - 1]));
    }
    if (BitUtil.check(reportMask, 16) && !values[index++].isEmpty()) {
        position.set("tachographInfo", Integer.parseInt(values[index - 1]));
    }
    if (BitUtil.check(reportMask, 17) && !values[index++].isEmpty()) {
        position.set("indicators", Integer.parseInt(values[index - 1]));
    }
    if (BitUtil.check(reportMask, 18) && !values[index++].isEmpty()) {
        position.set("lights", Integer.parseInt(values[index - 1]));
    }
    if (BitUtil.check(reportMask, 19) && !values[index++].isEmpty()) {
        position.set("doors", Integer.parseInt(values[index - 1]));
    }
    if (BitUtil.check(reportMask, 20) && !values[index++].isEmpty()) {
        position.set("vehicleOverspeed", Double.parseDouble(values[index - 1]));
    }
    if (BitUtil.check(reportMask, 21) && !values[index++].isEmpty()) {
        position.set("engineOverspeed", Double.parseDouble(values[index - 1]));
    }
    if (BitUtil.check(reportMask, 29)) {
        // expansion
        index += 1;
    }
    DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    if (BitUtil.check(reportMask, 30)) {
        position.setValid(Integer.parseInt(values[index++]) > 0);
        if (!values[index].isEmpty()) {
            position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[index++])));
            position.setCourse(Integer.parseInt(values[index++]));
            position.setAltitude(Double.parseDouble(values[index++]));
            position.setLongitude(Double.parseDouble(values[index++]));
            position.setLatitude(Double.parseDouble(values[index++]));
            position.setTime(dateFormat.parse(values[index++]));
        } else {
            // no location
            index += 6;
            getLastLocation(position, null);
        }
    } else {
        getLastLocation(position, null);
    }
    if (BitUtil.check(reportMask, 31)) {
        // cell
        index += 4;
    }
    // reserved
    index += 1;
    if (ignoreFixTime) {
        position.setTime(dateFormat.parse(values[index]));
    } else {
        position.setDeviceTime(dateFormat.parse(values[index]));
    }
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) WifiAccessPoint(org.traccar.model.WifiAccessPoint)

Example 59 with DeviceSession

use of org.traccar.DeviceSession in project traccar by tananaev.

the class Gl200TextProtocolDecoder method initPosition.

private Position initPosition(Parser parser, Channel channel, SocketAddress remoteAddress) {
    if (parser.matches()) {
        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
        if (deviceSession != null) {
            Position position = new Position(getProtocolName());
            position.setDeviceId(deviceSession.getDeviceId());
            return position;
        }
    }
    return null;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position)

Example 60 with DeviceSession

use of org.traccar.DeviceSession in project traccar by tananaev.

the class GlobalSatProtocolDecoder method decodeAlternative.

private Position decodeAlternative(Channel channel, SocketAddress remoteAddress, String sentence) {
    Parser parser = new Parser(PATTERN, sentence);
    if (!parser.matches()) {
        return null;
    }
    Position position = new Position(getProtocolName());
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
    if (deviceSession == null) {
        return null;
    }
    position.setDeviceId(deviceSession.getDeviceId());
    position.setValid(!parser.next().equals("1"));
    position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
    position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
    position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
    position.setAltitude(parser.nextDouble(0));
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));
    position.set(Position.KEY_SATELLITES, parser.nextInt(0));
    position.set(Position.KEY_HDOP, parser.nextDouble());
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Aggregations

DeviceSession (org.traccar.DeviceSession)197 Position (org.traccar.model.Position)188 Parser (org.traccar.helper.Parser)110 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)64 DateBuilder (org.traccar.helper.DateBuilder)63 Date (java.util.Date)37 Network (org.traccar.model.Network)37 LinkedList (java.util.LinkedList)30 SimpleDateFormat (java.text.SimpleDateFormat)10 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)10 List (java.util.List)9 WifiAccessPoint (org.traccar.model.WifiAccessPoint)9 DateFormat (java.text.DateFormat)8 Pattern (java.util.regex.Pattern)6 StringReader (java.io.StringReader)4 JsonObject (javax.json.JsonObject)4 QueryStringDecoder (org.jboss.netty.handler.codec.http.QueryStringDecoder)4 Matcher (java.util.regex.Matcher)3 Calendar (java.util.Calendar)2 HashSet (java.util.HashSet)2