use of org.traccar.helper.Parser in project traccar by tananaev.
the class Gl200TextProtocolDecoder method decodeIda.
private Object decodeIda(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_IDA, sentence);
Position position = initPosition(parser, channel, remoteAddress);
if (position == null) {
return null;
}
position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
decodeLocation(position, parser);
position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
decodeDeviceTime(position, parser);
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class Gl200TextProtocolDecoder method decodeObd.
private Object decodeObd(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_OBD, sentence);
Position position = initPosition(parser, channel, remoteAddress);
if (position == null) {
return null;
}
position.set(Position.KEY_RPM, parser.nextInt());
position.set(Position.KEY_OBD_SPEED, parser.nextInt());
position.set(Position.PREFIX_TEMP + 1, parser.nextInt());
position.set(Position.KEY_FUEL_CONSUMPTION, parser.next());
position.set("dtcsClearedDistance", parser.nextInt());
if (parser.hasNext()) {
position.set("odbConnect", parser.nextInt() == 1);
}
position.set("dtcsNumber", parser.nextInt());
position.set("dtcsCodes", parser.next());
position.set(Position.KEY_THROTTLE, parser.nextInt());
position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
if (parser.hasNext()) {
position.set(Position.KEY_OBD_ODOMETER, parser.nextInt() * 1000);
}
decodeLocation(position, parser);
if (parser.hasNext()) {
position.set(Position.KEY_OBD_ODOMETER, (int) (parser.nextDouble() * 1000));
}
decodeDeviceTime(position, parser);
return position;
}
use of org.traccar.helper.Parser 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;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class H02ProtocolDecoder method decodeLbs.
private Position decodeLbs(String sentence, Channel channel, SocketAddress remoteAddress) {
Parser parser = new Parser(PATTERN_NBR, sentence);
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());
DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
Network network = new Network();
int mcc = parser.nextInt(0);
int mnc = parser.nextInt(0);
String[] cells = parser.next().split(",");
for (int i = 0; i < cells.length / 3; i++) {
network.addCellTower(CellTower.from(mcc, mnc, Integer.parseInt(cells[i * 3]), Integer.parseInt(cells[i * 3 + 1]), Integer.parseInt(cells[i * 3 + 2])));
}
position.setNetwork(network);
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
getLastLocation(position, dateBuilder.getDate());
processStatus(position, parser.nextLong(16, 0));
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class HunterProProtocolDecoder 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());
DateBuilder dateBuilder = new DateBuilder();
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;
}
Aggregations