use of org.traccar.helper.Parser in project traccar by tananaev.
the class MiniFinderProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
if (sentence.startsWith("!1,")) {
int index = sentence.indexOf(',', 3);
if (index < 0) {
index = sentence.length();
}
getDeviceSession(channel, remoteAddress, sentence.substring(3, index));
return null;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null || !sentence.matches("![A-D],.*")) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
String type = sentence.substring(1, 2);
position.set(Position.KEY_TYPE, type);
if (type.equals("B") || type.equals("D")) {
Parser parser = new Parser(PATTERN_BD, sentence);
if (!parser.matches()) {
return null;
}
decodeFix(position, parser);
decodeState(position, parser);
position.set(Position.KEY_SATELLITES, parser.nextInt(0));
position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt(0));
position.set(Position.KEY_HDOP, parser.nextDouble(0));
return position;
} else if (type.equals("C")) {
Parser parser = new Parser(PATTERN_C, sentence);
if (!parser.matches()) {
return null;
}
decodeFix(position, parser);
decodeState(position, parser);
return position;
} else if (type.equals("A")) {
Parser parser = new Parser(PATTERN_A, sentence);
if (!parser.matches()) {
return null;
}
decodeFix(position, parser);
return position;
}
return null;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class M2cProtocolDecoder method decodePosition.
private Position decodePosition(Channel channel, SocketAddress remoteAddress, String line) {
Parser parser = new Parser(PATTERN, line);
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_INDEX, parser.nextInt());
if (parser.next().equals("H")) {
position.set(Position.KEY_ARCHIVE, true);
}
position.set(Position.KEY_EVENT, parser.nextInt());
position.setValid(true);
position.setTime(parser.nextDateTime());
position.setLatitude(parser.nextDouble());
position.setLongitude(parser.nextDouble());
position.setAltitude(parser.nextInt());
position.setCourse(parser.nextInt());
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.set(Position.KEY_ODOMETER, parser.nextLong());
position.set(Position.KEY_INPUT, parser.nextInt());
position.set(Position.KEY_OUTPUT, parser.nextInt());
position.set(Position.KEY_POWER, parser.nextInt() * 0.001);
position.set(Position.KEY_BATTERY, parser.nextInt() * 0.001);
position.set(Position.PREFIX_ADC + 1, parser.nextInt());
position.set(Position.PREFIX_ADC + 2, parser.nextInt());
position.set(Position.PREFIX_TEMP + 1, parser.nextDouble());
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class MaestroProtocolDecoder 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.setValid(parser.nextInt(0) == 1);
position.set(Position.KEY_BATTERY, parser.nextDouble(0));
position.set(Position.KEY_RSSI, parser.nextInt(0));
position.set(Position.KEY_CHARGE, parser.nextInt(0) == 1);
position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
position.setTime(parser.nextDateTime());
position.setLatitude(parser.nextDouble(0));
position.setLongitude(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble(0)));
position.setCourse(parser.nextDouble(0));
position.set(Position.KEY_SATELLITES, parser.nextInt(0));
position.set(Position.KEY_HDOP, parser.nextDouble(0));
position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1609.34);
if (parser.hasNext()) {
position.set(Position.PREFIX_ADC + 1, parser.nextInt(0));
}
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class ManPowerProtocolDecoder 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_STATUS, parser.next());
position.setTime(parser.nextDateTime());
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(parser.nextDouble(0));
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class MeiligaoProtocolDecoder method decodeRfid.
private Position decodeRfid(Position position, String sentence) {
Parser parser = new Parser(PATTERN_RFID, sentence);
if (!parser.matches()) {
return null;
}
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY));
position.setValid(true);
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
return position;
}
Aggregations