use of org.traccar.helper.Parser in project traccar by tananaev.
the class CguardProtocolDecoder method decodeStatus.
private Position decodeStatus(DeviceSession deviceSession, String sentence) {
Parser parser = new Parser(PATTERN_BC, sentence);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, parser.nextDateTime());
String[] data = parser.next().split(":");
for (int i = 0; i < data.length / 2; i++) {
String key = data[i * 2];
String value = data[i * 2 + 1];
switch(key) {
case "CSQ1":
position.set(Position.KEY_RSSI, Integer.parseInt(value));
break;
case "NSQ1":
position.set(Position.KEY_SATELLITES, Integer.parseInt(value));
break;
case "BAT1":
position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(value));
break;
case "PWR1":
position.set(Position.KEY_POWER, Double.parseDouble(value));
break;
default:
position.set(key.toLowerCase(), value);
break;
}
}
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class DishaProtocolDecoder 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(parser.next().equals("A"));
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.set(Position.KEY_HDOP, parser.nextDouble());
position.set(Position.KEY_RSSI, parser.nextDouble());
position.set(Position.KEY_CHARGE, parser.nextInt(0) == 2);
position.set(Position.KEY_BATTERY_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_ODOMETER, parser.nextDouble(0) * 1000);
position.set(Position.KEY_INPUT, parser.next());
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class EasyTrackProtocolDecoder 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.set(Position.KEY_COMMAND, parser.next());
position.setValid(parser.next().equals("A"));
DateBuilder dateBuilder = new DateBuilder().setDate(parser.nextHexInt(0), parser.nextHexInt(0), parser.nextHexInt(0)).setTime(parser.nextHexInt(0), parser.nextHexInt(0), parser.nextHexInt(0));
position.setTime(dateBuilder.getDate());
if (BitUtil.check(parser.nextHexInt(0), 3)) {
position.setLatitude(-parser.nextHexInt(0) / 600000.0);
} else {
position.setLatitude(parser.nextHexInt(0) / 600000.0);
}
if (BitUtil.check(parser.nextHexInt(0), 3)) {
position.setLongitude(-parser.nextHexInt(0) / 600000.0);
} else {
position.setLongitude(parser.nextHexInt(0) / 600000.0);
}
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextHexInt(0) / 100.0));
position.setCourse(parser.nextHexInt(0) / 100.0);
position.set(Position.KEY_STATUS, parser.next());
position.set("signal", parser.next());
position.set(Position.KEY_POWER, parser.nextDouble(0));
position.set("oil", parser.nextHexInt(0));
position.set(Position.KEY_ODOMETER, parser.nextHexInt(0) * 100);
position.setAltitude(parser.nextDouble(0));
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class EelinkProtocolDecoder method decodeResult.
private Position decodeResult(DeviceSession deviceSession, ChannelBuffer buf, int index) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_INDEX, index);
// type
buf.readUnsignedByte();
// uid
buf.readUnsignedInt();
String sentence = buf.toString(StandardCharsets.UTF_8);
Parser parser = new Parser(PATTERN, sentence);
if (parser.matches()) {
position.setValid(true);
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
position.setCourse(parser.nextDouble());
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
position.setTime(parser.nextDateTime());
} else {
getLastLocation(position, null);
position.set(Position.KEY_RESULT, sentence);
}
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class Gps103ProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
// Send response #1
if (sentence.contains("##")) {
if (channel != null) {
channel.write("LOAD", remoteAddress);
Parser handshakeParser = new Parser(PATTERN_HANDSHAKE, sentence);
if (handshakeParser.matches()) {
getDeviceSession(channel, remoteAddress, handshakeParser.next());
}
}
return null;
}
// Send response #2
if (!sentence.isEmpty() && Character.isDigit(sentence.charAt(0))) {
if (channel != null) {
channel.write("ON", remoteAddress);
}
int start = sentence.indexOf("imei:");
if (start >= 0) {
sentence = sentence.substring(start);
} else {
return null;
}
}
Position position = new Position(getProtocolName());
Parser parser = new Parser(PATTERN_NETWORK, sentence);
if (parser.matches()) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
position.setNetwork(new Network(CellTower.fromLacCid(parser.nextHexInt(0), parser.nextHexInt(0))));
return position;
}
parser = new Parser(PATTERN_OBD, sentence);
if (parser.matches()) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, parser.nextDateTime());
position.set(Position.KEY_ODOMETER, parser.nextInt(0));
// instant fuel consumption
parser.nextDouble(0);
position.set(Position.KEY_FUEL_CONSUMPTION, parser.nextDouble(0));
position.set(Position.KEY_HOURS, parser.nextInt());
position.set(Position.KEY_OBD_SPEED, parser.nextInt(0));
position.set(Position.KEY_ENGINE_LOAD, parser.next());
position.set(Position.KEY_COOLANT_TEMP, parser.nextInt());
position.set(Position.KEY_THROTTLE, parser.next());
position.set(Position.KEY_RPM, parser.nextInt(0));
position.set(Position.KEY_BATTERY, parser.nextDouble(0));
position.set(Position.KEY_DTCS, parser.next().replace(',', ' ').trim());
return position;
}
parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
String imei = parser.next();
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
String alarm = parser.next();
position.set(Position.KEY_ALARM, decodeAlarm(alarm));
if (alarm.equals("help me")) {
if (channel != null) {
channel.write("**,imei:" + imei + ",E;", remoteAddress);
}
} else if (alarm.equals("acc on")) {
position.set(Position.KEY_IGNITION, true);
} else if (alarm.equals("acc off")) {
position.set(Position.KEY_IGNITION, false);
} else if (alarm.startsWith("T:")) {
position.set(Position.PREFIX_TEMP + 1, alarm.substring(2));
} else if (alarm.startsWith("oil ")) {
position.set("oil", alarm.substring(4));
} else if (!position.getAttributes().containsKey(Position.KEY_ALARM) && !alarm.equals("tracker")) {
position.set(Position.KEY_EVENT, alarm);
}
DateBuilder dateBuilder = new DateBuilder().setDate(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
int localHours = parser.nextInt(0);
int localMinutes = parser.nextInt(0);
String rfid = parser.next();
if (alarm.equals("rfid")) {
position.set(Position.KEY_DRIVER_UNIQUE_ID, rfid);
}
String utcHours = parser.next();
String utcMinutes = parser.next();
dateBuilder.setTime(localHours, localMinutes, parser.nextInt(0));
// Timezone calculation
if (utcHours != null && utcMinutes != null) {
int deltaMinutes = (localHours - Integer.parseInt(utcHours)) * 60;
deltaMinutes += localMinutes - Integer.parseInt(utcMinutes);
if (deltaMinutes <= -12 * 60) {
deltaMinutes += 24 * 60;
} else if (deltaMinutes > 12 * 60) {
deltaMinutes -= 24 * 60;
}
dateBuilder.addMinute(-deltaMinutes);
}
position.setTime(dateBuilder.getDate());
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_HEM));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_HEM));
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
for (int i = 1; i <= 5; i++) {
position.set(Position.PREFIX_IO + i, parser.next());
}
return position;
}
Aggregations