Search in sources :

Example 91 with Parser

use of org.traccar.helper.Parser in project traccar by tananaev.

the class CarscopProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    String sentence = (String) msg;
    DeviceSession deviceSession;
    int index = sentence.indexOf("UB05");
    if (index != -1) {
        String imei = sentence.substring(index + 4, index + 4 + 15);
        deviceSession = getDeviceSession(channel, remoteAddress, imei);
    } else {
        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());
    DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    position.setValid(parser.next().equals("A"));
    position.setLatitude(parser.nextCoordinate());
    position.setLongitude(parser.nextCoordinate());
    position.setSpeed(parser.nextDouble(0));
    dateBuilder.setDate(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    position.setTime(dateBuilder.getDate());
    position.setCourse(parser.nextDouble(0));
    if (parser.hasNext(2)) {
        position.set(Position.KEY_STATUS, parser.next());
        position.set(Position.KEY_ODOMETER, parser.nextInt(0));
    }
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) Parser(org.traccar.helper.Parser)

Example 92 with Parser

use of org.traccar.helper.Parser in project traccar by tananaev.

the class CradlepointProtocolDecoder 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;
    }
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
    if (deviceSession == null) {
        return null;
    }
    Position position = new Position(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    int time = parser.nextInt();
    DateBuilder dateBuilder = new DateBuilder(new Date());
    dateBuilder.setHour(time / 100 / 100);
    dateBuilder.setMinute(time / 100 % 100);
    dateBuilder.setSecond(time % 100);
    position.setTime(dateBuilder.getDate());
    position.setValid(true);
    position.setLatitude(parser.nextCoordinate());
    position.setLongitude(parser.nextCoordinate());
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));
    position.set("carrid", parser.next());
    position.set("serdis", parser.next());
    position.set("rsrp", parser.next());
    position.set("dbm", parser.next());
    position.set("rsrq", parser.next());
    position.set("ecio", parser.next());
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) Date(java.util.Date) Parser(org.traccar.helper.Parser)

Example 93 with Parser

use of org.traccar.helper.Parser in project traccar by tananaev.

the class DwayProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    String sentence = (String) msg;
    if (sentence.equals("AA55,HB")) {
        if (channel != null) {
            channel.write("55AA,HB,OK\r\n");
        }
        return null;
    }
    Parser parser = new Parser(PATTERN, (String) msg);
    if (!parser.matches()) {
        return null;
    }
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
    if (deviceSession == null) {
        return null;
    }
    Position position = new Position(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    position.setValid(true);
    position.setTime(parser.nextDateTime());
    position.setLatitude(parser.nextDouble());
    position.setLongitude(parser.nextDouble());
    position.setAltitude(parser.nextDouble(0));
    position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
    position.setCourse(parser.nextDouble(0));
    position.set(Position.KEY_INPUT, parser.nextBinInt());
    position.set(Position.KEY_OUTPUT, parser.nextBinInt());
    position.set(Position.KEY_BATTERY, parser.nextInt() * 0.001);
    position.set(Position.PREFIX_ADC + 1, parser.nextInt() * 0.001);
    position.set(Position.PREFIX_ADC + 2, parser.nextInt() * 0.001);
    position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 94 with Parser

use of org.traccar.helper.Parser in project traccar by tananaev.

the class EnforaProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    ChannelBuffer buf = (ChannelBuffer) msg;
    // Find IMEI number
    int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new ChannelBufferIndexFinder() {

        @Override
        public boolean find(ChannelBuffer buffer, int guessedIndex) {
            if (buffer.writerIndex() - guessedIndex >= IMEI_LENGTH) {
                for (int i = 0; i < IMEI_LENGTH; i++) {
                    if (!Character.isDigit((char) buffer.getByte(guessedIndex + i))) {
                        return false;
                    }
                }
                return true;
            }
            return false;
        }
    });
    if (index == -1) {
        return null;
    }
    String imei = buf.toString(index, IMEI_LENGTH, StandardCharsets.US_ASCII);
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
    if (deviceSession == null) {
        return null;
    }
    // Find NMEA sentence
    int start = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("GPRMC"));
    if (start == -1) {
        return null;
    }
    String sentence = buf.toString(start, buf.readableBytes() - start, StandardCharsets.US_ASCII);
    Parser parser = new Parser(PATTERN, sentence);
    if (!parser.matches()) {
        return null;
    }
    Position position = new Position(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    position.setValid(parser.next().equals("A"));
    position.setLatitude(parser.nextCoordinate());
    position.setLongitude(parser.nextCoordinate());
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));
    dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    position.setTime(dateBuilder.getDate());
    return position;
}
Also used : ChannelBufferIndexFinder(org.jboss.netty.buffer.ChannelBufferIndexFinder) DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) StringFinder(org.traccar.helper.StringFinder) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Parser(org.traccar.helper.Parser)

Example 95 with Parser

use of org.traccar.helper.Parser in project traccar by tananaev.

the class EskyProtocolDecoder 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;
    }
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
    if (deviceSession == null) {
        return null;
    }
    Position position = new Position(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    position.set(Position.KEY_SATELLITES, parser.nextInt());
    position.setValid(true);
    position.setTime(parser.nextDateTime());
    position.setLatitude(parser.nextDouble());
    position.setLongitude(parser.nextDouble());
    position.setSpeed(UnitsConverter.knotsFromMps(parser.nextDouble()));
    position.setCourse(parser.nextDouble());
    position.set(Position.KEY_INPUT, parser.nextHexInt());
    position.set(Position.KEY_EVENT, parser.nextInt());
    position.set(Position.KEY_ODOMETER, parser.nextInt());
    position.set(Position.KEY_POWER, parser.nextInt());
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Aggregations

Parser (org.traccar.helper.Parser)137 Position (org.traccar.model.Position)129 DeviceSession (org.traccar.DeviceSession)110 DateBuilder (org.traccar.helper.DateBuilder)41 Network (org.traccar.model.Network)25 WifiAccessPoint (org.traccar.model.WifiAccessPoint)8 Date (java.util.Date)7 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)7 LinkedList (java.util.LinkedList)4 Pattern (java.util.regex.Pattern)4 Matcher (java.util.regex.Matcher)2 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)2 QueryStringDecoder (org.jboss.netty.handler.codec.http.QueryStringDecoder)2 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1