Search in sources :

Example 51 with DeviceSession

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

the class Tt8850ProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    Parser parser = new Parser(PATTERN, (String) msg);
    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(true);
    position.setAccuracy(parser.nextInt(0));
    position.setSpeed(UnitsConverter.knotsFromKph(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());
    if (parser.hasNext(4)) {
        position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0))));
    }
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Network(org.traccar.model.Network) Parser(org.traccar.helper.Parser)

Example 52 with DeviceSession

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

the class FlexCommProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    Parser parser = new Parser(PATTERN, (String) msg);
    if (!parser.matches()) {
        return null;
    }
    Position position = new Position(getProtocolName());
    position.set(Position.KEY_STATUS, parser.nextInt());
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
    if (deviceSession == null) {
        return null;
    }
    position.setDeviceId(deviceSession.getDeviceId());
    position.setTime(parser.nextDateTime());
    position.setValid(parser.next().equals("1"));
    position.setLatitude(parseSignedValue(parser, 6));
    position.setLongitude(parseSignedValue(parser, 6));
    position.setAltitude(parseSignedValue(parser, 0));
    position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt()));
    position.setCourse(parser.nextDouble(0));
    position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt());
    position.set(Position.KEY_SATELLITES, parser.nextInt());
    position.set(Position.KEY_RSSI, parser.nextInt());
    position.setNetwork(new Network(CellTower.from(parser.nextInt(), parser.nextInt(), parser.nextHexInt(), parser.nextHexInt())));
    for (int i = 1; i <= 3; i++) {
        position.set(Position.PREFIX_IN + i, parser.nextInt());
    }
    for (int i = 1; i <= 2; i++) {
        position.set(Position.PREFIX_OUT + i, parser.nextInt());
    }
    position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
    position.set(Position.PREFIX_TEMP + 1, parseSignedValue(parser, 0));
    position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
    position.set(Position.KEY_POWER, parser.nextInt() * 0.1);
    if (channel != null) {
        channel.write("{01}");
    }
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Network(org.traccar.model.Network) Parser(org.traccar.helper.Parser)

Example 53 with DeviceSession

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

the class FlextrackProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    String sentence = (String) msg;
    if (sentence.contains("LOGON")) {
        Parser parser = new Parser(PATTERN_LOGON, sentence);
        if (!parser.matches()) {
            return null;
        }
        sendAcknowledgement(channel, parser.next());
        String id = parser.next();
        String iccid = parser.next();
        getDeviceSession(channel, remoteAddress, iccid, id);
    } else if (sentence.contains("UNITSTAT")) {
        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
        if (deviceSession == null) {
            return null;
        }
        Parser parser = new Parser(PATTERN, sentence);
        if (!parser.matches()) {
            return null;
        }
        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());
        sendAcknowledgement(channel, parser.next());
        position.setTime(parser.nextDateTime());
        position.setValid(true);
        position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
        position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
        position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
        position.setCourse(parser.nextInt(0));
        position.set(Position.KEY_SATELLITES, parser.nextInt(0));
        position.set(Position.KEY_BATTERY, parser.nextInt(0));
        int rssi = parser.nextInt(0);
        position.set(Position.KEY_STATUS, parser.nextHexInt(0));
        int mcc = parser.nextInt(0);
        int mnc = parser.nextInt(0);
        position.setAltitude(parser.nextInt(0));
        position.set(Position.KEY_HDOP, parser.nextInt(0) * 0.1);
        position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextHexInt(0), parser.nextHexInt(0), rssi)));
        position.set(Position.KEY_ODOMETER, parser.nextInt(0));
        return position;
    }
    return null;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Network(org.traccar.model.Network) Parser(org.traccar.helper.Parser)

Example 54 with DeviceSession

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

the class FoxProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    String xml = (String) msg;
    String id = getAttribute(xml, "id");
    String data = getAttribute(xml, "data");
    if (id != null && data != null) {
        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
        if (deviceSession == null) {
            return null;
        }
        Parser parser = new Parser(PATTERN, data);
        if (!parser.matches()) {
            return null;
        }
        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());
        position.set(Position.KEY_STATUS, parser.nextInt(0));
        position.setValid(parser.next().equals("A"));
        position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
        position.setLatitude(parser.nextCoordinate());
        position.setLongitude(parser.nextCoordinate());
        position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
        position.setCourse(parser.nextDouble(0));
        position.set(Position.KEY_INPUT, parser.nextBinInt(0));
        position.set(Position.KEY_POWER, parser.nextDouble(0) * 0.1);
        position.set(Position.PREFIX_TEMP + 1, parser.nextInt(0));
        position.set(Position.KEY_RPM, parser.nextInt(0));
        position.set(Position.KEY_FUEL_LEVEL, parser.nextInt(0));
        position.set(Position.PREFIX_ADC + 1, parser.nextInt(0));
        position.set(Position.PREFIX_ADC + 2, parser.nextInt(0));
        position.set(Position.KEY_OUTPUT, parser.nextBinInt(0));
        position.set(Position.KEY_ODOMETER, parser.nextInt(0));
        position.set("statusData", parser.next());
        return position;
    }
    return null;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 55 with DeviceSession

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

the class GatorProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    ChannelBuffer buf = (ChannelBuffer) msg;
    // header
    buf.skipBytes(2);
    int type = buf.readUnsignedByte();
    // length
    buf.readUnsignedShort();
    String id = decodeId(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
    sendResponse(channel, buf.getByte(buf.writerIndex() - 2));
    if (type == MSG_POSITION_DATA || type == MSG_ROLLCALL_RESPONSE || type == MSG_ALARM_DATA || type == MSG_BLIND_AREA) {
        Position position = new Position(getProtocolName());
        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, "1" + id, id);
        if (deviceSession == null) {
            return null;
        }
        position.setDeviceId(deviceSession.getDeviceId());
        DateBuilder dateBuilder = new DateBuilder().setYear(BcdUtil.readInteger(buf, 2)).setMonth(BcdUtil.readInteger(buf, 2)).setDay(BcdUtil.readInteger(buf, 2)).setHour(BcdUtil.readInteger(buf, 2)).setMinute(BcdUtil.readInteger(buf, 2)).setSecond(BcdUtil.readInteger(buf, 2));
        position.setTime(dateBuilder.getDate());
        position.setLatitude(BcdUtil.readCoordinate(buf));
        position.setLongitude(BcdUtil.readCoordinate(buf));
        position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4)));
        position.setCourse(BcdUtil.readInteger(buf, 4));
        int flags = buf.readUnsignedByte();
        position.setValid((flags & 0x80) != 0);
        position.set(Position.KEY_SATELLITES, flags & 0x0f);
        position.set(Position.KEY_STATUS, buf.readUnsignedByte());
        position.set("key", buf.readUnsignedByte());
        position.set("oil", buf.readUnsignedShort() / 10.0);
        position.set(Position.KEY_POWER, buf.readUnsignedByte() + buf.readUnsignedByte() * 0.01);
        position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
        return position;
    }
    return null;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

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